Browse Source

Clean compilation code a little bit...

Daniele Bartolini 12 năm trước cách đây
mục cha
commit
6b7d600200

+ 9 - 11
engine/resource/LuaResource.cpp

@@ -49,9 +49,6 @@ namespace crown
 namespace lua_resource
 {
 
-size_t			m_luajit_blob_size = 0;
-char*			m_luajit_blob = NULL;
-
 //-----------------------------------------------------------------------------
 void compile(Filesystem& fs, const char* resource_path, File* out_file)
 {
@@ -73,12 +70,15 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 
 	os::execute_process(luajit);
 
+	size_t program_size = 0;
+	char* program = NULL;
+
 	File* bc = fs.open(bc_abs_path.c_str(), FOM_READ);
 	if (bc != NULL)
 	{
-		m_luajit_blob_size = bc->size();
-		m_luajit_blob = (char*) default_allocator().allocate(m_luajit_blob_size);
-		bc->read(m_luajit_blob, m_luajit_blob_size);
+		program_size = bc->size();
+		program = (char*) default_allocator().allocate(program_size);
+		bc->read(program, program_size);
 		fs.close(bc);
 		fs.delete_file(bc_abs_path.c_str());
 	}
@@ -90,14 +90,12 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 
 	LuaHeader header;
 	header.version = LUA_RESOURCE_VERSION;
-	header.size = m_luajit_blob_size;
+	header.size = program_size;
 
 	out_file->write((char*)&header, sizeof(LuaHeader));
-	out_file->write((char*)m_luajit_blob, m_luajit_blob_size);
+	out_file->write((char*)program, program_size);
 
-	default_allocator().deallocate(m_luajit_blob);
-	m_luajit_blob_size = 0;
-	m_luajit_blob = NULL;
+	default_allocator().deallocate(program);
 }
 
 } // namespace lua_resource

+ 18 - 18
engine/resource/PhysicsResource.cpp

@@ -36,25 +36,22 @@ namespace crown
 namespace physics_resource
 {
 
-bool					m_has_controller = false;
-PhysicsController		m_controller;
-
 //-----------------------------------------------------------------------------
-void parse_controller(JSONElement controller)
+void parse_controller(JSONElement e, PhysicsController& controller)
 {
-	JSONElement name = controller.key("name");
-	JSONElement height = controller.key("height");
-	JSONElement radius = controller.key("radius");
-	JSONElement slope_limit = controller.key("slope_limit");
-	JSONElement step_offset = controller.key("step_offset");
-	JSONElement contact_offset = controller.key("contact_offset");
-
-	m_controller.name = hash::murmur2_32(name.string_value(), name.size(), 0);
-	m_controller.height = height.float_value();
-	m_controller.radius = radius.float_value();
-	m_controller.slope_limit = slope_limit.float_value();
-	m_controller.step_offset = step_offset.float_value();
-	m_controller.contact_offset = contact_offset.float_value();
+	JSONElement name = e.key("name");
+	JSONElement height = e.key("height");
+	JSONElement radius = e.key("radius");
+	JSONElement slope_limit = e.key("slope_limit");
+	JSONElement step_offset = e.key("step_offset");
+	JSONElement contact_offset = e.key("contact_offset");
+
+	controller.name = hash::murmur2_32(name.string_value(), name.size(), 0);
+	controller.height = height.float_value();
+	controller.radius = radius.float_value();
+	controller.slope_limit = slope_limit.float_value();
+	controller.step_offset = step_offset.float_value();
+	controller.contact_offset = contact_offset.float_value();
 }
 
 //-----------------------------------------------------------------------------
@@ -67,6 +64,9 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONParser json(buf);
 	JSONElement root = json.root();
 
+	bool m_has_controller = false;
+	PhysicsController m_controller;
+
 	// Read controller
 	JSONElement controller = root.key_or_nil("controller");
 	if (controller.is_nil())
@@ -75,7 +75,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	}
 	else
 	{
-		parse_controller(controller);
+		parse_controller(controller, m_controller);
 		m_has_controller = true;
 	}
 

+ 0 - 1
engine/resource/SoundResource.cpp

@@ -64,7 +64,6 @@ SoundHeader			m_sound_header;
 size_t				m_sound_data_size = 0;
 uint8_t*			m_sound_data = NULL;
 
-
 //-----------------------------------------------------------------------------
 size_t compile_if_wav(Filesystem& fs, const char* resource_path)
 {