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

Do not pass source path explicitly

Daniele Bartolini 8 лет назад
Родитель
Сommit
431e504c16

+ 13 - 1
src/resource/compile_options.cpp

@@ -19,9 +19,10 @@
 
 
 namespace crown
 namespace crown
 {
 {
-CompileOptions::CompileOptions(DataCompiler& dc, Filesystem& data_filesystem, Buffer& output, const char* platform)
+CompileOptions::CompileOptions(DataCompiler& dc, Filesystem& data_filesystem, DynamicString& source_path, Buffer& output, const char* platform)
 	: _data_compiler(dc)
 	: _data_compiler(dc)
 	, _data_filesystem(data_filesystem)
 	, _data_filesystem(data_filesystem)
+	, _source_path(source_path)
 	, _output(output)
 	, _output(output)
 	, _platform(platform)
 	, _platform(platform)
 	, _dependencies(default_allocator())
 	, _dependencies(default_allocator())
@@ -41,6 +42,11 @@ void CompileOptions::error(const char* msg, ...)
 	va_end(args);
 	va_end(args);
 }
 }
 
 
+const char* CompileOptions::source_path()
+{
+	return _source_path.c_str();
+}
+
 bool CompileOptions::file_exists(const char* path)
 bool CompileOptions::file_exists(const char* path)
 {
 {
 	TempAllocator256 ta;
 	TempAllocator256 ta;
@@ -86,6 +92,12 @@ void CompileOptions::write_temporary(const char* path, const Buffer& data)
 	write_temporary(path, array::begin(data), array::size(data));
 	write_temporary(path, array::begin(data), array::size(data));
 }
 }
 
 
+///
+Buffer CompileOptions::read()
+{
+	return read(_source_path.c_str());
+}
+
 Buffer CompileOptions::read(const char* path)
 Buffer CompileOptions::read(const char* path)
 {
 {
 	add_dependency(path);
 	add_dependency(path);

+ 9 - 1
src/resource/compile_options.h

@@ -7,6 +7,7 @@
 
 
 #include "core/containers/types.h"
 #include "core/containers/types.h"
 #include "core/filesystem/types.h"
 #include "core/filesystem/types.h"
+#include "core/strings/dynamic_string.h"
 #include "core/strings/types.h"
 #include "core/strings/types.h"
 #include "resource/types.h"
 #include "resource/types.h"
 #include <stdarg.h>
 #include <stdarg.h>
@@ -39,12 +40,13 @@ struct CompileOptions
 {
 {
 	DataCompiler& _data_compiler;
 	DataCompiler& _data_compiler;
 	Filesystem& _data_filesystem;
 	Filesystem& _data_filesystem;
+	DynamicString _source_path;
 	Buffer& _output;
 	Buffer& _output;
 	const char* _platform;
 	const char* _platform;
 	Vector<DynamicString> _dependencies;
 	Vector<DynamicString> _dependencies;
 
 
 	///
 	///
-	CompileOptions(DataCompiler& dc, Filesystem& data_filesystem, Buffer& output, const char* platform);
+	CompileOptions(DataCompiler& dc, Filesystem& data_filesystem, DynamicString& source_path, Buffer& output, const char* platform);
 
 
 	///
 	///
 	void error(const char* msg, va_list args);
 	void error(const char* msg, va_list args);
@@ -52,6 +54,9 @@ struct CompileOptions
 	///
 	///
 	void error(const char* msg, ...);
 	void error(const char* msg, ...);
 
 
+	///
+	const char* source_path();
+
 	///
 	///
 	bool file_exists(const char* path);
 	bool file_exists(const char* path);
 
 
@@ -67,6 +72,9 @@ struct CompileOptions
 	///
 	///
 	void write_temporary(const char* path, const Buffer& data);
 	void write_temporary(const char* path, const Buffer& data);
 
 
+	///
+	Buffer read();
+
 	///
 	///
 	Buffer read(const char* path);
 	Buffer read(const char* path);
 
 

+ 2 - 2
src/resource/config_resource.cpp

@@ -17,9 +17,9 @@ namespace crown
 {
 {
 namespace config_resource_internal
 namespace config_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator1024 ta;
 		TempAllocator1024 ta;
 		JsonObject boot(ta);
 		JsonObject boot(ta);

+ 1 - 1
src/resource/config_resource.h

@@ -14,7 +14,7 @@ namespace crown
 {
 {
 namespace config_resource_internal
 namespace config_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 	void unload(Allocator& allocator, void* resource);
 
 

+ 2 - 2
src/resource/data_compiler.cpp

@@ -389,9 +389,9 @@ bool DataCompiler::compile(const char* data_dir, const char* platform)
 
 
 		if (!setjmp(_jmpbuf))
 		if (!setjmp(_jmpbuf))
 		{
 		{
-			CompileOptions opts(*this, data_filesystem, output, platform);
+			CompileOptions opts(*this, data_filesystem, src_path, output, platform);
 
 
-			hash_map::get(_compilers, _type, ResourceTypeData()).compiler(src_path.c_str(), opts);
+			hash_map::get(_compilers, _type, ResourceTypeData()).compiler(opts);
 
 
 			File* outf = data_filesystem.open(path.c_str(), FileOpenMode::WRITE);
 			File* outf = data_filesystem.open(path.c_str(), FileOpenMode::WRITE);
 			u32 size = array::size(output);
 			u32 size = array::size(output);

+ 1 - 1
src/resource/data_compiler.h

@@ -19,7 +19,7 @@ namespace crown
 /// @ingroup Resource
 /// @ingroup Resource
 struct DataCompiler
 struct DataCompiler
 {
 {
-	typedef void (*CompileFunction)(const char* path, CompileOptions& opts);
+	typedef void (*CompileFunction)(CompileOptions& opts);
 
 
 	struct ResourceTypeData
 	struct ResourceTypeData
 	{
 	{

+ 2 - 2
src/resource/font_resource.cpp

@@ -47,9 +47,9 @@ namespace font_resource_internal
 		glyph.gd.x_advance = sjson::parse_float(obj["x_advance"]);
 		glyph.gd.x_advance = sjson::parse_float(obj["x_advance"]);
 	}
 	}
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 1 - 1
src/resource/font_resource.h

@@ -35,7 +35,7 @@ typedef u32 CodePoint;
 
 
 namespace font_resource_internal
 namespace font_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace font_resource_internal
 } // namespace font_resource_internal
 
 

+ 2 - 2
src/resource/level_resource.cpp

@@ -20,9 +20,9 @@ namespace crown
 {
 {
 namespace level_resource_internal
 namespace level_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);
 		sjson::parse(buf, object);
 		sjson::parse(buf, object);

+ 1 - 1
src/resource/level_resource.h

@@ -34,7 +34,7 @@ struct LevelSound
 
 
 namespace level_resource_internal
 namespace level_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace level_resource_internal
 } // namespace level_resource_internal
 
 

+ 2 - 2
src/resource/lua_resource.cpp

@@ -32,12 +32,12 @@ namespace crown
 {
 {
 namespace lua_resource_internal
 namespace lua_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
 		TempAllocator1024 ta;
 		TempAllocator1024 ta;
 		DynamicString luasrc(ta);
 		DynamicString luasrc(ta);
 		DynamicString luabin(ta);
 		DynamicString luabin(ta);
-		opts.get_absolute_path(path, luasrc);
+		opts.get_absolute_path(opts.source_path(), luasrc);
 		opts.get_temporary_path("lua.bin", luabin);
 		opts.get_temporary_path("lua.bin", luabin);
 
 
 		StringStream output(ta);
 		StringStream output(ta);

+ 1 - 1
src/resource/lua_resource.h

@@ -21,7 +21,7 @@ struct LuaResource
 
 
 namespace lua_resource_internal
 namespace lua_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace lua_resource_internal
 } // namespace lua_resource_internal
 
 

+ 2 - 2
src/resource/material_resource.cpp

@@ -176,9 +176,9 @@ namespace material_resource_internal
 		}
 		}
 	}
 	}
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);
 		sjson::parse(buf, object);
 		sjson::parse(buf, object);

+ 1 - 1
src/resource/material_resource.h

@@ -69,7 +69,7 @@ struct UniformHandle
 
 
 namespace material_resource_internal
 namespace material_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void online(StringId64 id, ResourceManager& rm);
 	void online(StringId64 id, ResourceManager& rm);
 	void offline(StringId64 id, ResourceManager& rm);
 	void offline(StringId64 id, ResourceManager& rm);

+ 2 - 2
src/resource/mesh_resource.cpp

@@ -261,9 +261,9 @@ namespace mesh_resource_internal
 		}
 		}
 	};
 	};
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 1 - 1
src/resource/mesh_resource.h

@@ -66,7 +66,7 @@ struct MeshResource
 
 
 namespace mesh_resource_internal
 namespace mesh_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void online(StringId64 /*id*/, ResourceManager& /*rm*/);
 	void online(StringId64 /*id*/, ResourceManager& /*rm*/);
 	void offline(StringId64 /*id*/, ResourceManager& /*rm*/);
 	void offline(StringId64 /*id*/, ResourceManager& /*rm*/);

+ 2 - 2
src/resource/package_resource.cpp

@@ -37,9 +37,9 @@ namespace package_resource_internal
 		}
 		}
 	}
 	}
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 1 - 1
src/resource/package_resource.h

@@ -49,7 +49,7 @@ struct PackageResource
 
 
 namespace package_resource_internal
 namespace package_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 	void unload(Allocator& allocator, void* resource);
 
 

+ 2 - 2
src/resource/physics_resource.cpp

@@ -498,9 +498,9 @@ namespace physics_config_resource_internal
 		}
 		}
 	};
 	};
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);
 		sjson::parse(buf, object);
 		sjson::parse(buf, object);

+ 2 - 2
src/resource/physics_resource.h

@@ -17,7 +17,7 @@ namespace crown
 {
 {
 namespace physics_resource_internal
 namespace physics_resource_internal
 {
 {
-	inline void compile(const char* /*path*/, CompileOptions& /*opts*/) {}
+	inline void compile(CompileOptions& /*opts*/) {}
 	Buffer compile_controller(const char* json, CompileOptions& opts);
 	Buffer compile_controller(const char* json, CompileOptions& opts);
 	Buffer compile_collider(const char* json, CompileOptions& opts);
 	Buffer compile_collider(const char* json, CompileOptions& opts);
 	Buffer compile_actor(const char* json, CompileOptions& opts);
 	Buffer compile_actor(const char* json, CompileOptions& opts);
@@ -77,7 +77,7 @@ struct PhysicsConfigActor
 
 
 namespace physics_config_resource_internal
 namespace physics_config_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace physics_config_resource_internal
 } // namespace physics_config_resource_internal
 
 

+ 2 - 2
src/resource/shader_resource.cpp

@@ -1230,10 +1230,10 @@ namespace shader_resource_internal
 		}
 		}
 	};
 	};
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
 		ShaderCompiler sc(opts);
 		ShaderCompiler sc(opts);
-		sc.parse(path);
+		sc.parse(opts.source_path());
 		sc.compile();
 		sc.compile();
 	}
 	}
 
 

+ 1 - 1
src/resource/shader_resource.h

@@ -36,7 +36,7 @@ struct ShaderResource
 
 
 namespace shader_resource_internal
 namespace shader_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void online(StringId64 id, ResourceManager& rm);
 	void online(StringId64 id, ResourceManager& rm);
 	void offline(StringId64 id, ResourceManager& rm);
 	void offline(StringId64 id, ResourceManager& rm);

+ 2 - 2
src/resource/sound_resource.cpp

@@ -33,9 +33,9 @@ namespace sound_resource_internal
 		s32 data_size;       // Data dimension
 		s32 data_size;       // Data dimension
 	};
 	};
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 1 - 1
src/resource/sound_resource.h

@@ -37,7 +37,7 @@ struct SoundResource
 
 
 namespace sound_resource_internal
 namespace sound_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace	sound_resource_internal
 } // namespace	sound_resource_internal
 
 

+ 4 - 4
src/resource/sprite_resource.cpp

@@ -39,9 +39,9 @@ namespace sprite_resource_internal
 		frame.pivot  = sjson::parse_vector2(obj["pivot"]);
 		frame.pivot  = sjson::parse_vector2(obj["pivot"]);
 	}
 	}
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);
@@ -146,9 +146,9 @@ namespace sprite_resource
 
 
 namespace sprite_animation_resource_internal
 namespace sprite_animation_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 2 - 2
src/resource/sprite_resource.h

@@ -25,7 +25,7 @@ struct SpriteResource
 
 
 namespace sprite_resource_internal
 namespace sprite_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace sprite_resource_internal
 } // namespace sprite_resource_internal
 
 
@@ -45,7 +45,7 @@ struct SpriteAnimationResource
 
 
 namespace sprite_animation_resource_internal
 namespace sprite_animation_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace sprite_animation_resource_internal
 } // namespace sprite_animation_resource_internal
 
 

+ 2 - 2
src/resource/state_machine_resource.cpp

@@ -431,9 +431,9 @@ namespace state_machine_internal
 		}
 		}
 	};
 	};
 
 
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		StateMachineCompiler smc(opts);
 		StateMachineCompiler smc(opts);
 		smc.parse(buf);
 		smc.parse(buf);

+ 1 - 1
src/resource/state_machine_resource.h

@@ -74,7 +74,7 @@ struct TransitionMode
 
 
 namespace state_machine_internal
 namespace state_machine_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace state_machine_internal
 } // namespace state_machine_internal
 
 

+ 2 - 2
src/resource/texture_resource.cpp

@@ -33,9 +33,9 @@ namespace crown
 {
 {
 namespace texture_resource_internal
 namespace texture_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
-		Buffer buf = opts.read(path);
+		Buffer buf = opts.read();
 
 
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject object(ta);
 		JsonObject object(ta);

+ 1 - 1
src/resource/texture_resource.h

@@ -22,7 +22,7 @@ struct TextureResource
 
 
 namespace texture_resource_internal
 namespace texture_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 	void* load(File& file, Allocator& a);
 	void* load(File& file, Allocator& a);
 	void offline(StringId64 id, ResourceManager& rm);
 	void offline(StringId64 id, ResourceManager& rm);
 	void online(StringId64 id, ResourceManager& rm);
 	void online(StringId64 id, ResourceManager& rm);

+ 2 - 2
src/resource/unit_resource.cpp

@@ -15,12 +15,12 @@ namespace crown
 {
 {
 namespace unit_resource_internal
 namespace unit_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts)
+	void compile(CompileOptions& opts)
 	{
 	{
 		Buffer unit_data(default_allocator());
 		Buffer unit_data(default_allocator());
 
 
 		UnitCompiler uc(opts);
 		UnitCompiler uc(opts);
-		uc.compile_unit(path);
+		uc.compile_unit(opts.source_path());
 
 
 		opts.write(uc.blob());
 		opts.write(uc.blob());
 	}
 	}

+ 1 - 1
src/resource/unit_resource.h

@@ -30,7 +30,7 @@ struct ComponentData
 
 
 namespace unit_resource_internal
 namespace unit_resource_internal
 {
 {
-	void compile(const char* path, CompileOptions& opts);
+	void compile(CompileOptions& opts);
 
 
 } // namespace unit_resource_internal
 } // namespace unit_resource_internal