Daniele Bartolini 10 лет назад
Родитель
Сommit
2efd169d93

+ 2 - 2
src/lua/lua_environment.cpp

@@ -54,7 +54,7 @@ static int require(lua_State* L)
 	using namespace lua_resource;
 	LuaStack stack(L);
 	const LuaResource* lr = (LuaResource*)device()->resource_manager()->get(SCRIPT_TYPE, stack.get_resource_id(1));
-	luaL_loadbuffer(L, program(lr), size(lr), "");
+	luaL_loadbuffer(L, program(lr), lr->size, "");
 	return 1;
 }
 
@@ -116,7 +116,7 @@ void LuaEnvironment::execute(const LuaResource* lr)
 {
 	using namespace lua_resource;
 	lua_pushcfunction(L, error_handler);
-	luaL_loadbuffer(L, program(lr), size(lr), "<unknown>");
+	luaL_loadbuffer(L, program(lr), lr->size, "<unknown>");
 	lua_pcall(L, 0, 0, -2);
 	lua_pop(L, 1);
 }

+ 2 - 17
src/resource/font_resource.cpp

@@ -95,28 +95,13 @@ namespace font_resource
 		allocator.deallocate(resource);
 	}
 
-	uint32_t num_glyphs(const FontResource* fr)
-	{
-		return fr->num_glyphs;
-	}
-
-	uint32_t texture_size(const FontResource* fr)
-	{
-		return fr->texture_size;
-	}
-
-	uint32_t font_size(const FontResource* fr)
-	{
-		return fr->font_size;
-	}
-
 	const FontGlyphData* get_glyph(const FontResource* fr, uint32_t i)
 	{
-		CE_ASSERT(i < num_glyphs(fr), "Index out of bounds");
+		CE_ASSERT(i < fr->num_glyphs, "Index out of bounds");
 
 		FontGlyphData* begin = (FontGlyphData*)((char*)fr + sizeof(FontResource));
 
-		for (uint32_t i = 0; i < num_glyphs(fr); i++)
+		for (uint32_t i = 0; i < fr->num_glyphs; ++i)
 		{
 			if (begin[i].id == i)
 				return &begin[i];

+ 0 - 3
src/resource/font_resource.h

@@ -41,9 +41,6 @@ namespace font_resource
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 
-	uint32_t num_glyphs(const FontResource* fr);
-	uint32_t texture_size(const FontResource* fr);
-	uint32_t font_size(const FontResource* fr);
 	const FontGlyphData* get_glyph(const FontResource* fr, uint32_t i);
 } // namespace font_resource
 } // namespace crown

+ 1 - 6
src/resource/lua_resource.cpp

@@ -81,14 +81,9 @@ namespace lua_resource
 		allocator.deallocate(resource);
 	}
 
-	uint32_t size(const LuaResource* lr)
-	{
-		return lr->size;
-	}
-
 	const char* program(const LuaResource* lr)
 	{
-		return (char*)lr + sizeof(LuaResource);
+		return (char*)&lr[1];
 	}
 } // namespace lua_resource
 } // namespace crown

+ 0 - 3
src/resource/lua_resource.h

@@ -25,9 +25,6 @@ namespace lua_resource
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 
-	/// Returns the size in bytes of the lua program.
-	uint32_t size(const LuaResource* lr);
-
 	/// Returns the lua program.
 	const char* program(const LuaResource* lr);
 } // namespace lua_resource

+ 0 - 20
src/resource/physics_resource.cpp

@@ -611,11 +611,6 @@ namespace physics_config_resource
 		allocator.deallocate(resource);
 	}
 
-	uint32_t num_materials(const PhysicsConfigResource* pcr)
-	{
-		return pcr->num_materials;
-	}
-
 	/// Returns the material with the given @a name
 	const PhysicsConfigMaterial* material(const PhysicsConfigResource* pcr, StringId32 name)
 	{
@@ -630,11 +625,6 @@ namespace physics_config_resource
 		return NULL;
 	}
 
-	uint32_t num_shapes(const PhysicsConfigResource* pcr)
-	{
-		return pcr->num_shapes;
-	}
-
 	const PhysicsConfigShape* shape(const PhysicsConfigResource* pcr, StringId32 name)
 	{
 		const PhysicsConfigShape* begin = (PhysicsConfigShape*)((const char*)pcr + pcr->shapes_offset);
@@ -648,11 +638,6 @@ namespace physics_config_resource
 		return NULL;
 	}
 
-	uint32_t num_actors(const PhysicsConfigResource* pcr)
-	{
-		return pcr->num_actors;
-	}
-
 	/// Returns the actor with the given @a name
 	const PhysicsConfigActor* actor(const PhysicsConfigResource* pcr, StringId32 name)
 	{
@@ -667,11 +652,6 @@ namespace physics_config_resource
 		return NULL;
 	}
 
-	uint32_t num_filters(const PhysicsConfigResource* pcr)
-	{
-		return pcr->num_filters;
-	}
-
 	const PhysicsCollisionFilter* filter(const PhysicsConfigResource* pcr, StringId32 name)
 	{
 		const PhysicsCollisionFilter* begin = (PhysicsCollisionFilter*)((const char*)pcr + pcr->filters_offset);

+ 0 - 8
src/resource/physics_resource.h

@@ -83,17 +83,9 @@ namespace physics_config_resource
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 
-	uint32_t num_materials(const PhysicsConfigResource* pcr);
 	const PhysicsConfigMaterial* material(const PhysicsConfigResource* pcr, StringId32 name);
-	const PhysicsConfigMaterial* material_by_index(const PhysicsConfigResource* pcr, uint32_t i);
-	uint32_t num_shapes(const PhysicsConfigResource* pcr);
 	const PhysicsConfigShape* shape(const PhysicsConfigResource* pcr, StringId32 name);
-	const PhysicsConfigShape* shape_by_index(const PhysicsConfigResource* pcr, uint32_t i);
-	uint32_t num_actors(const PhysicsConfigResource* pcr);
 	const PhysicsConfigActor* actor(const PhysicsConfigResource* pcr, StringId32 name);
-	const PhysicsConfigActor* actor_by_index(const PhysicsConfigResource* pcr, uint32_t i);
-	uint32_t num_filters(const PhysicsConfigResource* pcr);
 	const PhysicsCollisionFilter* filter(const PhysicsConfigResource* pcr, StringId32 name);
-	const PhysicsCollisionFilter* filter_by_index(const PhysicsConfigResource* pcr, uint32_t i);
 } // namespace physics_resource
 } // namespace crown

+ 9 - 47
src/resource/sound_resource.cpp

@@ -44,18 +44,18 @@ namespace sound_resource
 
 		Buffer sound = opts.read(name.c_str());
 		const WAVHeader* wav = (const WAVHeader*)array::begin(sound);
-		const char* wavdata = (const char*) (wav + 1);
+		const char* wavdata = (const char*)&wav[1];
 
 		// Write
 		SoundResource sr;
-		sr.version = SOUND_VERSION;
-		sr.size = wav->data_size;
-		sr.sample_rate = wav->fmt_sample_rate;
+		sr.version      = SOUND_VERSION;
+		sr.size         = wav->data_size;
+		sr.sample_rate  = wav->fmt_sample_rate;
 		sr.avg_bytes_ps = wav->fmt_avarage;
-		sr.channels = wav->fmt_channels;
-		sr.block_size = wav->fmt_block_align;
-		sr.bits_ps = wav->fmt_bits_ps;
-		sr.sound_type = SoundType::WAV;
+		sr.channels     = wav->fmt_channels;
+		sr.block_size   = wav->fmt_block_align;
+		sr.bits_ps      = wav->fmt_bits_ps;
+		sr.sound_type   = SoundType::WAV;
 
 		opts.write(sr.version);
 		opts.write(sr.size);
@@ -65,9 +65,6 @@ namespace sound_resource
 		opts.write(sr.block_size);
 		opts.write(sr.bits_ps);
 		opts.write(sr.sound_type);
-		opts.write(sr._pad[0]);
-		opts.write(sr._pad[1]);
-		opts.write(sr._pad[2]);
 
 		opts.write(wavdata, wav->data_size);
 	}
@@ -86,44 +83,9 @@ namespace sound_resource
 		allocator.deallocate(resource);
 	}
 
-	uint32_t size(const SoundResource* sr)
-	{
-		return sr->size;
-	}
-
-	uint32_t sample_rate(const SoundResource* sr)
-	{
-		return sr->sample_rate;
-	}
-
-	uint32_t avg_bytes_ps(const SoundResource* sr)
-	{
-		return sr->avg_bytes_ps;
-	}
-
-	uint32_t channels(const SoundResource* sr)
-	{
-		return sr->channels;
-	}
-
-	uint16_t block_size(const SoundResource* sr)
-	{
-		return sr->block_size;
-	}
-
-	uint16_t bits_ps(const SoundResource* sr)
-	{
-		return sr->bits_ps;
-	}
-
-	uint8_t sound_type(const SoundResource* sr)
-	{
-		return sr->sound_type;
-	}
-
 	const char* data(const SoundResource* sr)
 	{
-		return (char*)sr + sizeof(SoundResource);
+		return (char*)&sr[1];
 	}
 } // namespace sound_resource
 } // namespace crown

+ 1 - 9
src/resource/sound_resource.h

@@ -33,8 +33,7 @@ struct SoundResource
 	uint32_t channels;
 	uint16_t block_size;
 	uint16_t bits_ps;
-	uint8_t sound_type;
-	char _pad[3];
+	uint32_t sound_type;
 };
 
 namespace sound_resource
@@ -43,13 +42,6 @@ namespace sound_resource
 	void* load(File& file, Allocator& a);
 	void unload(Allocator& allocator, void* resource);
 
-	uint32_t size(const SoundResource* sr);
-	uint32_t sample_rate(const SoundResource* sr);
-	uint32_t avg_bytes_ps(const SoundResource* sr);
-	uint32_t channels(const SoundResource* sr);
-	uint16_t block_size(const SoundResource* sr);
-	uint16_t bits_ps(const SoundResource* sr);
-	uint8_t sound_type(const SoundResource* sr);
 	const char* data(const SoundResource* sr);
 } // namespace sound_resource
 } // namespace crown