Browse Source

Remove Bundle

Daniele Bartolini 11 years ago
parent
commit
0f4b40f256

+ 6 - 12
engine/device.cpp

@@ -4,20 +4,18 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
+#include "debug_line.h"
 #include "device.h"
 #include "device.h"
 #include "log.h"
 #include "log.h"
 #include "lua_environment.h"
 #include "lua_environment.h"
+#include "lua_stack.h"
+#include "lua_system.h"
+#include "material_manager.h"
 #include "resource_manager.h"
 #include "resource_manager.h"
-#include "types.h"
-#include "bundle.h"
 #include "resource_package.h"
 #include "resource_package.h"
+#include "types.h"
 #include "world.h"
 #include "world.h"
-#include "lua_stack.h"
 #include "world_manager.h"
 #include "world_manager.h"
-#include "network_filesystem.h"
-#include "lua_system.h"
-#include "debug_line.h"
-#include "material_manager.h"
 #include <cstdlib>
 #include <cstdlib>
 
 
 #define MAX_SUBSYSTEMS_HEAP 8 * 1024 * 1024
 #define MAX_SUBSYSTEMS_HEAP 8 * 1024 * 1024
@@ -42,7 +40,6 @@ Device::Device(Filesystem& fs, StringId64 boot_package, StringId64 boot_script)
 	, _boot_package(NULL)
 	, _boot_package(NULL)
 	, _lua_environment(NULL)
 	, _lua_environment(NULL)
 	, _resource_manager(NULL)
 	, _resource_manager(NULL)
-	, _resource_bundle(NULL)
 	, _world_manager(NULL)
 	, _world_manager(NULL)
 {
 {
 }
 }
@@ -51,11 +48,10 @@ void Device::init()
 {
 {
 	// Initialize
 	// Initialize
 	CE_LOGI("Initializing Crown Engine %s...", version());
 	CE_LOGI("Initializing Crown Engine %s...", version());
-	_resource_bundle = Bundle::create(_allocator, _fs);
 
 
 	// Create resource manager
 	// Create resource manager
 	CE_LOGD("Creating resource manager...");
 	CE_LOGD("Creating resource manager...");
-	_resource_manager = CE_NEW(_allocator, ResourceManager)(*_resource_bundle);
+	_resource_manager = CE_NEW(_allocator, ResourceManager)(_fs);
 
 
 	// Create world manager
 	// Create world manager
 	CE_LOGD("Creating world manager...");
 	CE_LOGD("Creating world manager...");
@@ -104,8 +100,6 @@ void Device::shutdown()
 	CE_LOGD("Releasing resource manager...");
 	CE_LOGD("Releasing resource manager...");
 	CE_DELETE(_allocator, _resource_manager);
 	CE_DELETE(_allocator, _resource_manager);
 
 
-	Bundle::destroy(_allocator, _resource_bundle);
-
 	_allocator.clear();
 	_allocator.clear();
 	_is_init = false;
 	_is_init = false;
 }
 }

+ 0 - 3
engine/device.h

@@ -7,14 +7,12 @@
 
 
 #include "types.h"
 #include "types.h"
 #include "config.h"
 #include "config.h"
-#include "os.h"
 #include "linear_allocator.h"
 #include "linear_allocator.h"
 #include "world_types.h"
 #include "world_types.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-class Bundle;
 class Filesystem;
 class Filesystem;
 struct LuaEnvironment;
 struct LuaEnvironment;
 class ResourceManager;
 class ResourceManager;
@@ -146,7 +144,6 @@ private:
 
 
 	LuaEnvironment* _lua_environment;
 	LuaEnvironment* _lua_environment;
 	ResourceManager* _resource_manager;
 	ResourceManager* _resource_manager;
-	Bundle* _resource_bundle;
 	WorldManager* _world_manager;
 	WorldManager* _world_manager;
 
 
 private:
 private:

+ 3 - 2
engine/renderers/shader.cpp

@@ -4,12 +4,13 @@
  */
  */
 
 
 #include "shader.h"
 #include "shader.h"
+#include "config.h"
 #include "filesystem.h"
 #include "filesystem.h"
 #include "json_parser.h"
 #include "json_parser.h"
 #include "os.h"
 #include "os.h"
 #include "reader_writer.h"
 #include "reader_writer.h"
-#include "config.h"
-#include "resource_types.h"
+#include "resource_manager.h"
+#include "compile_options.h"
 
 
 #if CROWN_DEBUG
 #if CROWN_DEBUG
 		#define SHADERC_NAME "shadercDebug"
 		#define SHADERC_NAME "shadercDebug"

+ 5 - 6
engine/renderers/shader.h

@@ -5,12 +5,11 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "resource_manager.h"
-#include "bundle.h"
-#include "file.h"
-#include "reader_writer.h"
-#include "memory.h"
-#include "compile_options.h"
+#include "types.h"
+#include "resource_types.h"
+#include "filesystem_types.h"
+#include "memory_types.h"
+#include "compiler_types.h"
 #include <bgfx.h>
 #include <bgfx.h>
 
 
 namespace crown
 namespace crown

+ 0 - 38
engine/resource/bundle.h

@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "resource_id.h"
-
-namespace crown
-{
-
-class Filesystem;
-class File;
-
-class Bundle
-{
-public:
-
-	static Bundle* create(Allocator& a, Filesystem& fs);
-	static void destroy(Allocator& a, Bundle* bundle);
-
-	virtual ~Bundle() {}
-
-	/// Opens the resource file containing @a name resource
-	/// and returns a stream from which read the data from.
-	/// @note
-	/// The resource stream points exactly at the start
-	/// of the useful resource data, so you do not have to
-	/// care about skipping headers, metadatas and so on.
-	virtual File* open(ResourceId name) = 0;
-
-	/// Closes the resource file.
-	virtual void close(File* resource) = 0;
-};
-
-} // namespace crown
-

+ 0 - 61
engine/resource/file_bundle.cpp

@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include <stdio.h>
-#include <inttypes.h>
-
-#include "memory.h"
-#include "bundle.h"
-#include "filesystem.h"
-
-#include "string_utils.h"
-#include "types.h"
-#include "os.h"
-#include "log.h"
-
-namespace crown
-{
-
-class FileBundle : public Bundle
-{
-public:
-
-
-	FileBundle(Filesystem& fs) : m_filesystem(fs) {}
-
-	File* open(ResourceId name)
-	{
-		// Convert name/type into strings
-		char resource_name[512];
-		snprintf(resource_name, 512, "%.16"PRIx64"-%.16"PRIx64, name.type, name.name);
-
-		// Open the resource and check magic number/version
-		File* file = m_filesystem.open(resource_name, FOM_READ);
-
-		CE_ASSERT(file != NULL, "Resource %s does not exist", resource_name);
-		return file;
-	}
-
-	void close(File* resource)
-	{
-		m_filesystem.close(resource);
-	}
-
-private:
-
-	Filesystem& m_filesystem;
-};
-
-Bundle* Bundle::create(Allocator& a, Filesystem& fs)
-{
-	return CE_NEW(a, FileBundle)(fs);
-}
-
-void Bundle::destroy(Allocator& a, Bundle* bundle)
-{
-	CE_DELETE(a, bundle);
-}
-
-} // namespace crown

+ 6 - 0
engine/resource/resource_id.h

@@ -6,6 +6,7 @@
 #pragma once
 #pragma once
 
 
 #include "string_utils.h"
 #include "string_utils.h"
+#include <inttypes.h>
 
 
 namespace crown
 namespace crown
 {
 {
@@ -30,6 +31,11 @@ struct ResourceId
 	{
 	{
 	}
 	}
 
 
+	void to_string(char out[64])
+	{
+		snprintf(out, 64, "%.16"PRIx64"-%.16"PRIx64, type, name);
+	}
+
 	bool operator==(const ResourceId& a) const
 	bool operator==(const ResourceId& a) const
 	{
 	{
 		return type == a.type && name == a.name;
 		return type == a.type && name == a.name;

+ 10 - 5
engine/resource/resource_loader.cpp

@@ -8,13 +8,13 @@
 #include "resource_registry.h"
 #include "resource_registry.h"
 #include "log.h"
 #include "log.h"
 #include "queue.h"
 #include "queue.h"
-#include "bundle.h"
+#include "filesystem.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-ResourceLoader::ResourceLoader(Bundle& bundle, Allocator& resource_heap)
-	: _bundle(bundle)
+ResourceLoader::ResourceLoader(Filesystem& fs, Allocator& resource_heap)
+	: _fs(fs)
 	, _resource_heap(resource_heap)
 	, _resource_heap(resource_heap)
 	, _requests(default_allocator())
 	, _requests(default_allocator())
 	, _loaded(default_allocator())
 	, _loaded(default_allocator())
@@ -83,9 +83,14 @@ int32_t ResourceLoader::run()
 
 
 		ResourceData rd;
 		ResourceData rd;
 		rd.id = id;
 		rd.id = id;
-		File* file = _bundle.open(id);
+
+		char path[64];
+		id.to_string(path);
+
+		File* file = _fs.open(path, FOM_READ);
 		rd.data = resource_on_load(id.type, *file, _resource_heap);
 		rd.data = resource_on_load(id.type, *file, _resource_heap);
-		_bundle.close(file);
+		_fs.close(file);
+
 		add_loaded(rd);
 		add_loaded(rd);
 		_mutex.lock();
 		_mutex.lock();
 		queue::pop_front(_requests);
 		queue::pop_front(_requests);

+ 4 - 5
engine/resource/resource_loader.h

@@ -6,6 +6,7 @@
 #pragma once
 #pragma once
 
 
 #include "types.h"
 #include "types.h"
+#include "filesystem_types.h"
 #include "thread.h"
 #include "thread.h"
 #include "container_types.h"
 #include "container_types.h"
 #include "mutex.h"
 #include "mutex.h"
@@ -15,8 +16,6 @@
 namespace crown
 namespace crown
 {
 {
 
 
-class Bundle;
-
 struct ResourceData
 struct ResourceData
 {
 {
 	ResourceId id;
 	ResourceId id;
@@ -30,9 +29,9 @@ class ResourceLoader
 {
 {
 public:
 public:
 
 
-	/// Reads the resources data from the given @a bundle using
+	/// Reads the resources data from the given @a fs using
 	/// @a resource_heap to allocate memory for them.
 	/// @a resource_heap to allocate memory for them.
-	ResourceLoader(Bundle& bundle, Allocator& resource_heap);
+	ResourceLoader(Filesystem& fs, Allocator& resource_heap);
 	~ResourceLoader();
 	~ResourceLoader();
 
 
 	/// Loads the @a resource in a background thread.
 	/// Loads the @a resource in a background thread.
@@ -61,7 +60,7 @@ private:
 private:
 private:
 
 
 	Thread _thread;
 	Thread _thread;
-	Bundle& _bundle;
+	Filesystem& _fs;
 	Allocator& _resource_heap;
 	Allocator& _resource_heap;
 
 
 	Queue<ResourceId> _requests;
 	Queue<ResourceId> _requests;

+ 2 - 2
engine/resource/resource_manager.cpp

@@ -18,9 +18,9 @@
 namespace crown
 namespace crown
 {
 {
 
 
-ResourceManager::ResourceManager(Bundle& bundle)
+ResourceManager::ResourceManager(Filesystem& fs)
 	: _resource_heap("resource", default_allocator())
 	: _resource_heap("resource", default_allocator())
-	, _loader(bundle, _resource_heap)
+	, _loader(fs, _resource_heap)
 	, _rm(default_allocator())
 	, _rm(default_allocator())
 	, _autoload(false)
 	, _autoload(false)
 {
 {

+ 2 - 4
engine/resource/resource_manager.h

@@ -13,8 +13,6 @@
 namespace crown
 namespace crown
 {
 {
 
 
-class Bundle;
-
 /// @defgroup Resource Resource
 /// @defgroup Resource Resource
 
 
 /// Keeps track and manages resources loaded by ResourceLoader.
 /// Keeps track and manages resources loaded by ResourceLoader.
@@ -24,8 +22,8 @@ class ResourceManager
 {
 {
 public:
 public:
 
 
-	/// The resources will be loaded from @a bundle.
-	ResourceManager(Bundle& bundle);
+	/// The resources will be loaded from @a fs.
+	ResourceManager(Filesystem& fs);
 	~ResourceManager();
 	~ResourceManager();
 
 
 	/// Loads the resource (@a type, @a name).
 	/// Loads the resource (@a type, @a name).