Daniele Bartolini 9 лет назад
Родитель
Сommit
aa2566b96e

+ 159 - 0
src/resource/compile_options.cpp

@@ -3,11 +3,170 @@
  * License: https://github.com/taylor001/crown/blob/master/LICENSE
  */
 
+#include "array.h"
 #include "compile_options.h"
+#include "data_compiler.h"
+#include "dynamic_string.h"
+#include "file.h"
+#include "filesystem.h"
+#include "guid.h"
+#include "log.h"
 #include "os.h"
+#include "path.h"
+#include "string_stream.h"
+#include "temp_allocator.h"
+#include "vector.h"
 
 namespace crown
 {
+CompileOptions::CompileOptions(DataCompiler& dc, Filesystem& bundle_fs, Buffer& output, const char* platform, jmp_buf* buf)
+	: _data_compiler(dc)
+	, _bundle_fs(bundle_fs)
+	, _output(output)
+	, _platform(platform)
+	, _jmpbuf(buf)
+	, _dependencies(default_allocator())
+{
+}
+
+void CompileOptions::error(const char* msg, va_list args)
+{
+	logev(msg, args);
+	longjmp(*_jmpbuf, 1);
+}
+
+void CompileOptions::error(const char* msg, ...)
+{
+	va_list args;
+	va_start(args, msg);
+	error(msg, args);
+	va_end(args);
+}
+
+bool CompileOptions::file_exists(const char* path)
+{
+	TempAllocator256 ta;
+	DynamicString source_dir(ta);
+	FilesystemDisk fs(ta);
+
+	_data_compiler.source_dir(path, source_dir);
+	fs.set_prefix(source_dir.c_str());
+
+	return fs.exists(path);
+}
+
+bool CompileOptions::resource_exists(const char* type, const char* name)
+{
+	TempAllocator1024 ta;
+	DynamicString path(ta);
+	path += name;
+	path += ".";
+	path += type;
+	return file_exists(path.c_str());
+}
+
+Buffer CompileOptions::read_temporary(const char* path)
+{
+	File* file = _bundle_fs.open(path, FileOpenMode::READ);
+	u32 size = file->size();
+	Buffer buf(default_allocator());
+	array::resize(buf, size);
+	file->read(array::begin(buf), size);
+	_bundle_fs.close(*file);
+	return buf;
+}
+
+void CompileOptions::write_temporary(const char* path, const char* data, u32 size)
+{
+	File* file = _bundle_fs.open(path, FileOpenMode::WRITE);
+	file->write(data, size);
+	_bundle_fs.close(*file);
+}
+
+void CompileOptions::write_temporary(const char* path, const Buffer& data)
+{
+	write_temporary(path, array::begin(data), array::size(data));
+}
+
+Buffer CompileOptions::read(const char* path)
+{
+	add_dependency(path);
+
+	TempAllocator256 ta;
+	DynamicString source_dir(ta);
+	FilesystemDisk source_fs(ta);
+
+	_data_compiler.source_dir(path, source_dir);
+	source_fs.set_prefix(source_dir.c_str());
+
+	File* file = source_fs.open(path, FileOpenMode::READ);
+	u32 size = file->size();
+	Buffer buf(default_allocator());
+	array::resize(buf, size);
+	file->read(array::begin(buf), size);
+	source_fs.close(*file);
+	return buf;
+}
+
+void CompileOptions::get_absolute_path(const char* path, DynamicString& abs)
+{
+	TempAllocator256 ta;
+	DynamicString source_dir(ta);
+	FilesystemDisk source_fs(ta);
+
+	_data_compiler.source_dir(path, source_dir);
+	source_fs.set_prefix(source_dir.c_str());
+
+	source_fs.get_absolute_path(path, abs);
+}
+
+void CompileOptions::get_temporary_path(const char* suffix, DynamicString& abs)
+{
+	_bundle_fs.get_absolute_path(CROWN_TEMP_DIRECTORY, abs);
+
+	TempAllocator64 ta;
+	DynamicString prefix(ta);
+	guid::to_string(guid::new_guid(), prefix);
+
+	abs += '/';
+	abs += prefix;
+	abs += '.';
+	abs += suffix;
+}
+
+void CompileOptions::delete_file(const char* path)
+{
+	_bundle_fs.delete_file(path);
+}
+
+void CompileOptions::write(const void* data, u32 size)
+{
+	array::push(_output, (const char*)data, size);
+}
+
+void CompileOptions::write(const Buffer& data)
+{
+	array::push(_output, array::begin(data), array::size(data));
+}
+
+const char* CompileOptions::platform() const
+{
+	return _platform;
+}
+
+const Vector<DynamicString>& CompileOptions::dependencies() const
+{
+	return _dependencies;
+}
+
+void CompileOptions::add_dependency(const char* path)
+{
+	TempAllocator256 ta;
+	DynamicString dep(ta);
+	dep += path;
+	vector::push_back(_dependencies, dep);
+}
+
 int CompileOptions::run_external_compiler(const char* const* argv, StringStream& output)
 {
 	TempAllocator512 ta;

+ 22 - 142
src/resource/compile_options.h

@@ -5,18 +5,12 @@
 
 #pragma once
 
-#include "array.h"
-#include "data_compiler.h"
-#include "dynamic_string.h"
-#include "file.h"
-#include "filesystem.h"
-#include "guid.h"
-#include "log.h"
-#include "path.h"
-#include "string_stream.h"
-#include "temp_allocator.h"
-#include "vector.h"
+#include "compiler_types.h"
+#include "container_types.h"
+#include "filesystem_types.h"
+#include "string_types.h"
 #include <setjmp.h>
+#include <stdarg.h>
 
 #define DATA_COMPILER_ASSERT(condition, opts, msg, ...) \
 	do                                                  \
@@ -53,130 +47,31 @@ class CompileOptions
 
 public:
 
-	CompileOptions(DataCompiler& dc, Filesystem& bundle_fs, Buffer& output, const char* platform, jmp_buf* buf)
-		: _data_compiler(dc)
-		, _bundle_fs(bundle_fs)
-		, _output(output)
-		, _platform(platform)
-		, _jmpbuf(buf)
-		, _dependencies(default_allocator())
-	{
-	}
-
-	void error(const char* msg, va_list args)
-	{
-		logev(msg, args);
-		longjmp(*_jmpbuf, 1);
-	}
-
-	void error(const char* msg, ...)
-	{
-		va_list args;
-		va_start(args, msg);
-		error(msg, args);
-		va_end(args);
-	}
-
-	bool file_exists(const char* path)
-	{
-		TempAllocator256 ta;
-		DynamicString source_dir(ta);
-		FilesystemDisk fs(ta);
+	CompileOptions(DataCompiler& dc, Filesystem& bundle_fs, Buffer& output, const char* platform, jmp_buf* buf);
 
-		_data_compiler.source_dir(path, source_dir);
-		fs.set_prefix(source_dir.c_str());
+	void error(const char* msg, va_list args);
 
-		return fs.exists(path);
-	}
-
-	bool resource_exists(const char* type, const char* name)
-	{
-		TempAllocator1024 ta;
-		DynamicString path(ta);
-		path += name;
-		path += ".";
-		path += type;
-		return file_exists(path.c_str());
-	}
-
-	Buffer read_temporary(const char* path)
-	{
-		File* file = _bundle_fs.open(path, FileOpenMode::READ);
-		u32 size = file->size();
-		Buffer buf(default_allocator());
-		array::resize(buf, size);
-		file->read(array::begin(buf), size);
-		_bundle_fs.close(*file);
-		return buf;
-	}
-
-	void write_temporary(const char* path, const char* data, u32 size)
-	{
-		File* file = _bundle_fs.open(path, FileOpenMode::WRITE);
-		file->write(data, size);
-		_bundle_fs.close(*file);
-	}
+	void error(const char* msg, ...);
 
-	void write_temporary(const char* path, const Buffer& data)
-	{
-		write_temporary(path, array::begin(data), array::size(data));
-	}
+	bool file_exists(const char* path);
 
-	Buffer read(const char* path)
-	{
-		add_dependency(path);
-
-		TempAllocator256 ta;
-		DynamicString source_dir(ta);
-		FilesystemDisk source_fs(ta);
-
-		_data_compiler.source_dir(path, source_dir);
-		source_fs.set_prefix(source_dir.c_str());
-
-		File* file = source_fs.open(path, FileOpenMode::READ);
-		u32 size = file->size();
-		Buffer buf(default_allocator());
-		array::resize(buf, size);
-		file->read(array::begin(buf), size);
-		source_fs.close(*file);
-		return buf;
-	}
+	bool resource_exists(const char* type, const char* name);
 
-	void get_absolute_path(const char* path, DynamicString& abs)
-	{
-		TempAllocator256 ta;
-		DynamicString source_dir(ta);
-		FilesystemDisk source_fs(ta);
+	Buffer read_temporary(const char* path);
 
-		_data_compiler.source_dir(path, source_dir);
-		source_fs.set_prefix(source_dir.c_str());
+	void write_temporary(const char* path, const char* data, u32 size);
 
-		source_fs.get_absolute_path(path, abs);
-	}
+	void write_temporary(const char* path, const Buffer& data);
 
-	void get_temporary_path(const char* suffix, DynamicString& abs)
-	{
-		_bundle_fs.get_absolute_path(CROWN_TEMP_DIRECTORY, abs);
+	Buffer read(const char* path);
 
-		TempAllocator64 ta;
-		DynamicString prefix(ta);
-		guid::to_string(guid::new_guid(), prefix);
+	void get_absolute_path(const char* path, DynamicString& abs);
 
-		abs += '/';
-		abs += prefix;
-		abs += '.';
-		abs += suffix;
-	}
+	void get_temporary_path(const char* suffix, DynamicString& abs);
 
-	void delete_file(const char* path)
-	{
-		_bundle_fs.delete_file(path);
-	}
+	void delete_file(const char* path);
 
-	void write(const void* data, u32 size)
-	{
-		array::push(_output, (const char*)data, size);
-	}
+	void write(const void* data, u32 size);
 
 	template <typename T>
 	void write(const T& data)
@@ -184,28 +79,13 @@ public:
 		write(&data, sizeof(data));
 	}
 
-	void write(const Buffer& data)
-	{
-		array::push(_output, array::begin(data), array::size(data));
-	}
+	void write(const Buffer& data);
 
-	const char* platform() const
-	{
-		return _platform;
-	}
+	const char* platform() const;
 
-	const Vector<DynamicString>& dependencies() const
-	{
-		return _dependencies;
-	}
+	const Vector<DynamicString>& dependencies() const;
 
-	void add_dependency(const char* path)
-	{
-		TempAllocator256 ta;
-		DynamicString dep(ta);
-		dep += path;
-		vector::push_back(_dependencies, dep);
-	}
+	void add_dependency(const char* path);
 
 	int run_external_compiler(const char* const* argv, StringStream& output);
 };

+ 3 - 0
src/resource/config_resource.cpp

@@ -6,9 +6,12 @@
 #include "allocator.h"
 #include "compile_options.h"
 #include "config_resource.h"
+#include "dynamic_string.h"
+#include "file.h"
 #include "json_object.h"
 #include "resource_types.h"
 #include "sjson.h"
+#include "temp_allocator.h"
 
 namespace crown
 {

+ 3 - 0
src/resource/font_resource.cpp

@@ -4,13 +4,16 @@
  */
 
 #include "allocator.h"
+#include "array.h"
 #include "compile_options.h"
+#include "file.h"
 #include "filesystem.h"
 #include "font_resource.h"
 #include "json_object.h"
 #include "resource_types.h"
 #include "sjson.h"
 #include "string_utils.h"
+#include "temp_allocator.h"
 #include <algorithm>
 
 namespace crown

+ 2 - 0
src/resource/level_resource.cpp

@@ -5,12 +5,14 @@
 
 #include "array.h"
 #include "compile_options.h"
+#include "file.h"
 #include "filesystem.h"
 #include "json_object.h"
 #include "level_resource.h"
 #include "map.h"
 #include "memory.h"
 #include "sjson.h"
+#include "temp_allocator.h"
 #include "unit_compiler.h"
 
 namespace crown

+ 1 - 0
src/resource/lua_resource.cpp

@@ -7,6 +7,7 @@
 #include "compile_options.h"
 #include "config.h"
 #include "dynamic_string.h"
+#include "file.h"
 #include "lua_resource.h"
 #include "string_stream.h"
 #include "temp_allocator.h"

+ 1 - 0
src/resource/material_resource.cpp

@@ -15,6 +15,7 @@
 #include "resource_manager.h"
 #include "sjson.h"
 #include "string_utils.h"
+#include "temp_allocator.h"
 #include "vector.h"
 
 namespace crown

+ 1 - 0
src/resource/package_resource.cpp

@@ -5,6 +5,7 @@
 
 #include "array.h"
 #include "compile_options.h"
+#include "dynamic_string.h"
 #include "file.h"
 #include "filesystem.h"
 #include "json_object.h"

+ 2 - 0
src/resource/physics_resource.cpp

@@ -6,6 +6,7 @@
 #include "aabb.h"
 #include "compile_options.h"
 #include "dynamic_string.h"
+#include "file.h"
 #include "filesystem.h"
 #include "json_object.h"
 #include "map.h"
@@ -14,6 +15,7 @@
 #include "sjson.h"
 #include "sphere.h"
 #include "string_utils.h"
+#include "temp_allocator.h"
 #include "world_types.h"
 
 namespace crown

+ 2 - 0
src/resource/sound_resource.cpp

@@ -6,9 +6,11 @@
 #include "allocator.h"
 #include "compile_options.h"
 #include "dynamic_string.h"
+#include "file.h"
 #include "json_object.h"
 #include "sjson.h"
 #include "sound_resource.h"
+#include "temp_allocator.h"
 
 namespace crown
 {

+ 1 - 0
src/resource/sprite_resource.cpp

@@ -12,6 +12,7 @@
 #include "sjson.h"
 #include "sprite_resource.h"
 #include "string_utils.h"
+#include "temp_allocator.h"
 #include "vector2.h"
 #include "vector4.h"
 

+ 2 - 0
src/resource/texture_resource.cpp

@@ -4,11 +4,13 @@
  */
 
 #include "compile_options.h"
+#include "dynamic_string.h"
 #include "json_object.h"
 #include "reader_writer.h"
 #include "resource_manager.h"
 #include "sjson.h"
 #include "string_stream.h"
+#include "temp_allocator.h"
 #include "texture_resource.h"
 
 #if CROWN_DEVELOPMENT

+ 1 - 0
src/resource/unit_compiler.cpp

@@ -5,6 +5,7 @@
 
 #include "array.h"
 #include "compile_options.h"
+#include "dynamic_string.h"
 #include "json_object.h"
 #include "map.h"
 #include "math_utils.h"

+ 1 - 0
src/resource/unit_compiler.h

@@ -8,6 +8,7 @@
 #include "compile_options.h"
 #include "container_types.h"
 #include "json_types.h"
+#include "string_id.h"
 
 namespace crown
 {

+ 2 - 0
src/resource/unit_resource.cpp

@@ -4,9 +4,11 @@
  */
 
 #include "allocator.h"
+#include "array.h"
 #include "file.h"
 #include "filesystem.h"
 #include "resource_types.h"
+#include "sort_map.h"
 #include "unit_compiler.h"
 
 namespace crown