Daniele Bartolini 10 лет назад
Родитель
Сommit
a897812b2a
3 измененных файлов с 99 добавлено и 100 удалено
  1. 42 42
      src/device.cpp
  2. 42 45
      src/device.h
  3. 15 13
      src/resource/shader_resource.cpp

+ 42 - 42
src/device.cpp

@@ -121,20 +121,6 @@ private:
 
 Device::Device(const DeviceOptions& opts)
 	: _allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
-	, _width(0)
-	, _height(0)
-	, _mouse_curr_x(0)
-	, _mouse_curr_y(0)
-	, _mouse_last_x(0)
-	, _mouse_last_y(0)
-	, _is_init(false)
-	, _is_running(false)
-	, _is_paused(false)
-	, _frame_count(0)
-	, _last_time(0)
-	, _current_time(0)
-	, _last_delta_time(0.0f)
-	, _time_since_start(0.0)
 	, _device_options(opts)
 	, _boot_package_id(uint64_t(0))
 	, _boot_script_id(uint64_t(0))
@@ -150,6 +136,20 @@ Device::Device(const DeviceOptions& opts)
 	, _unit_manager(NULL)
 	, _lua_environment(NULL)
 	, _worlds(default_allocator())
+	, _width(0)
+	, _height(0)
+	, _mouse_curr_x(0)
+	, _mouse_curr_y(0)
+	, _mouse_last_x(0)
+	, _mouse_last_y(0)
+	, _is_init(false)
+	, _is_running(false)
+	, _is_paused(false)
+	, _frame_count(0)
+	, _last_time(0)
+	, _current_time(0)
+	, _last_delta_time(0.0f)
+	, _time_since_start(0.0)
 {
 }
 
@@ -406,6 +406,34 @@ UnitManager* Device::unit_manager()
 	return _unit_manager;
 }
 
+void Device::read_config()
+{
+	TempAllocator4096 ta;
+	DynamicString project_path(ta);
+
+	if (_device_options.project() != NULL)
+	{
+		project_path += _device_options.project();
+		project_path += '/';
+	}
+
+	project_path += CROWN_BOOT_CONFIG;
+
+	const StringId64 config_name(project_path.c_str());
+
+	_resource_manager->load(CONFIG_TYPE, config_name);
+	_resource_manager->flush();
+	const char* cfile = (const char*)_resource_manager->get(CONFIG_TYPE, config_name);
+
+	JsonObject config(ta);
+	sjson::parse(cfile, config);
+
+	_boot_script_id  = sjson::parse_resource_id(config["boot_script"]);
+	_boot_package_id = sjson::parse_resource_id(config["boot_package"]);
+
+	_resource_manager->unload(CONFIG_TYPE, config_name);
+}
+
 bool Device::process_events()
 {
 	OsEvent event;
@@ -523,34 +551,6 @@ bool Device::process_events()
 	return exit;
 }
 
-void Device::read_config()
-{
-	TempAllocator4096 ta;
-	DynamicString project_path(ta);
-
-	if (_device_options.project() != NULL)
-	{
-		project_path += _device_options.project();
-		project_path += '/';
-	}
-
-	project_path += CROWN_BOOT_CONFIG;
-
-	const StringId64 config_name(project_path.c_str());
-
-	_resource_manager->load(CONFIG_TYPE, config_name);
-	_resource_manager->flush();
-	const char* cfile = (const char*)_resource_manager->get(CONFIG_TYPE, config_name);
-
-	JsonObject config(ta);
-	sjson::parse(cfile, config);
-
-	_boot_script_id  = sjson::parse_resource_id(config["boot_script"]);
-	_boot_package_id = sjson::parse_resource_id(config["boot_package"]);
-
-	_resource_manager->unload(CONFIG_TYPE, config_name);
-}
-
 char _buffer[sizeof(Device)];
 Device* _device = NULL;
 

+ 42 - 45
src/device.h

@@ -32,8 +32,49 @@ struct BgfxCallback;
 /// the engine subsystems and related stuff.
 ///
 /// @ingroup Device
-struct Device
+class Device
 {
+	LinearAllocator _allocator;
+
+	const DeviceOptions& _device_options;
+	Filesystem* _bundle_filesystem;
+	ResourceLoader* _resource_loader;
+	ResourceManager* _resource_manager;
+	BgfxAllocator* _bgfx_allocator;
+	BgfxCallback* _bgfx_callback;
+	ShaderManager* _shader_manager;
+	MaterialManager* _material_manager;
+	InputManager* _input_manager;
+	UnitManager* _unit_manager;
+	LuaEnvironment* _lua_environment;
+	StringId64 _boot_package_id;
+	StringId64 _boot_script_id;
+	ResourcePackage* _boot_package;
+
+	Array<World*> _worlds;
+
+	uint16_t _width;
+	uint16_t _height;
+	int16_t _mouse_curr_x;
+	int16_t _mouse_curr_y;
+	int16_t _mouse_last_x;
+	int16_t _mouse_last_y;
+
+	bool _is_init;
+	bool _is_running;
+	bool _is_paused;
+
+	uint64_t _frame_count;
+	int64_t _last_time;
+	int64_t _current_time;
+	float _last_delta_time;
+	double _time_since_start;
+
+	void read_config();
+	bool process_events();
+
+public:
+
 	Device(const DeviceOptions& opts);
 
 	/// Initializes the engine.
@@ -117,50 +158,6 @@ struct Device
 	/// Returns the unit manager.
 	UnitManager* unit_manager();
 
-private:
-
-	bool process_events();
-	void read_config();
-
-private:
-
-	// Used to allocate all subsystems
-	LinearAllocator _allocator;
-
-	uint16_t _width;
-	uint16_t _height;
-	int16_t _mouse_curr_x;
-	int16_t _mouse_curr_y;
-	int16_t _mouse_last_x;
-	int16_t _mouse_last_y;
-
-	bool _is_init;
-	bool _is_running;
-	bool _is_paused;
-
-	uint64_t _frame_count;
-	int64_t _last_time;
-	int64_t _current_time;
-	float _last_delta_time;
-	double _time_since_start;
-
-	const DeviceOptions& _device_options;
-	Filesystem* _bundle_filesystem;
-	ResourceLoader* _resource_loader;
-	ResourceManager* _resource_manager;
-	BgfxAllocator* _bgfx_allocator;
-	BgfxCallback* _bgfx_callback;
-	ShaderManager* _shader_manager;
-	MaterialManager* _material_manager;
-	InputManager* _input_manager;
-	UnitManager* _unit_manager;
-	LuaEnvironment* _lua_environment;
-	StringId64 _boot_package_id;
-	StringId64 _boot_script_id;
-	ResourcePackage* _boot_package;
-
-	Array<World*> _worlds;
-
 private:
 
 	// Disable copying

+ 15 - 13
src/resource/shader_resource.cpp

@@ -403,6 +403,16 @@ namespace shader_resource
 
 	struct BgfxShader
 	{
+		ALLOCATOR_AWARE;
+
+		DynamicString _includes;
+		DynamicString _code;
+		DynamicString _vs_code;
+		DynamicString _fs_code;
+		DynamicString _varying;
+		DynamicString _vs_input_output;
+		DynamicString _fs_input_output;
+
 		BgfxShader()
 			: _includes(default_allocator())
 			, _code(default_allocator())
@@ -424,20 +434,15 @@ namespace shader_resource
 			, _fs_input_output(a)
 		{
 		}
-
-		DynamicString _includes;
-		DynamicString _code;
-		DynamicString _vs_code;
-		DynamicString _fs_code;
-		DynamicString _varying;
-		DynamicString _vs_input_output;
-		DynamicString _fs_input_output;
-
-		ALLOCATOR_AWARE;
 	};
 
 	struct ShaderPermutation
 	{
+		ALLOCATOR_AWARE;
+
+		DynamicString _bgfx_shader;
+		DynamicString _render_state;
+
 		ShaderPermutation()
 			: _bgfx_shader(default_allocator())
 			, _render_state(default_allocator())
@@ -449,9 +454,6 @@ namespace shader_resource
 			, _render_state(a)
 		{
 		}
-
-		DynamicString _bgfx_shader;
-		DynamicString _render_state;
 	};
 
 	struct ShaderCompiler