瀏覽代碼

define g_default_mountpoint and use it across classes

mikymod 12 年之前
父節點
當前提交
2faee7f8e4
共有 4 個文件被更改,包括 40 次插入18 次删除
  1. 19 15
      engine/Device.cpp
  2. 13 0
      engine/Device.h
  3. 3 1
      engine/lua/LuaEnvironment.cpp
  4. 5 2
      engine/resource/FileBundle.cpp

+ 19 - 15
engine/Device.cpp

@@ -22,6 +22,7 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
+OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <cstdlib>
@@ -53,14 +54,19 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ConsoleServer.h"
 #include "TextReader.h"
 #include "SoundResource.h"
-#include "DiskMountPoint.h"
-#include "AndroidMountPoint.h"
+#include "StringSetting.h"
 
 namespace crown
 {
 
+#ifdef ANDROID
+	StringSetting g_default_mountpoint("default_mountpoint", "define default mount point for filesystem", "android");
+#else
+	StringSetting g_default_mountpoint("default_mountpoint", "define default mount point for filesystem", "disk");
+#endif
+
 //-----------------------------------------------------------------------------
-Device::Device() :
+Device::Device() : 
 	m_allocator(m_subsystems_heap, MAX_SUBSYSTEMS_HEAP),
 
 	m_preferred_window_width(1000),
@@ -92,6 +98,12 @@ Device::Device() :
 {
 	// Select executable dir by default
 	string::strncpy(m_preferred_root_path, os::get_cwd(), MAX_PATH_LENGTH);
+
+	#ifdef ANDROID
+	m_root_mountpoint = AndroidMountPoint();
+	#else
+	m_root_mountpoint = DiskMountPoint();
+	#endif
 }
 
 //-----------------------------------------------------------------------------
@@ -358,7 +370,6 @@ void Device::frame()
 
 	m_window->frame();
 	m_input_manager->frame(frame_count());
-
 	m_lua_environment->game_frame(last_delta_time());
 
 	// m_console_server->execute();
@@ -380,13 +391,12 @@ void Device::create_filesystem()
 {
 	m_filesystem = CE_NEW(m_allocator, Filesystem)();
 
-	// DiskMountPoint* root = CE_NEW(m_allocator, DiskMountPoint)(m_preferred_root_path);
-	AndroidMountPoint* root = CE_NEW(m_allocator, AndroidMountPoint)();
+	m_root_mountpoint.set_root_path(m_preferred_root_path);
 
-	m_filesystem->mount(*root);
+	m_filesystem->mount(m_root_mountpoint);
 
 	Log::d("Filesystem created.");
-	Log::d("Filesystem root path: %s",root->root_path());
+	Log::d("Filesystem root path: %s", m_root_mountpoint.root_path());
 }
 
 //-----------------------------------------------------------------------------
@@ -403,7 +413,7 @@ void Device::create_resource_manager()
 	}
 
 	// Read resource seed
-	DiskFile* seed_file = (DiskFile*)filesystem()->open("android", "seed.ini", FOM_READ);
+	DiskFile* seed_file = (DiskFile*)filesystem()->open(g_default_mountpoint.value(), "seed.ini", FOM_READ);
 	TextReader reader(*seed_file);
 
 	char tmp_buf[32];
@@ -416,12 +426,6 @@ void Device::create_resource_manager()
 	// Create resource manager
 	m_resource_manager = CE_NEW(m_allocator, ResourceManager)(*m_resource_bundle, seed);
 
-	ResourceId rid = m_resource_manager->load("wav", "beep");
-
-	m_resource_manager->flush();
-
-	SoundResource* res = (SoundResource*)m_resource_manager->data(rid);
-
 	Log::d("Resource manager created.");
 	Log::d("Resource seed: %d", m_resource_manager->seed());
 }

+ 13 - 0
engine/Device.h

@@ -31,6 +31,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "OS.h"
 #include "LinearAllocator.h"
 #include "Resource.h"
+#include "DiskMountPoint.h"
+
+#ifdef ANDROID
+#include "AndroidMountPoint.h"
+#endif
 
 #define MAX_SUBSYSTEMS_HEAP 1024 * 1024
 
@@ -169,6 +174,14 @@ private:
 	// Debug subsystems
 	ConsoleServer*			m_console_server;
 
+	#ifdef ANDROID
+	AndroidMountPoint		m_root_mountpoint;
+	#else
+	DiskMountPoint			m_root_mountpoint;
+	#endif
+
+	// TODO set default StringSetting for default_mountpoint
+
 private:
 
 	enum

+ 3 - 1
engine/lua/LuaEnvironment.cpp

@@ -36,6 +36,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
+extern StringSetting g_default_mountpoint;
+
 StringSetting g_boot("boot_file", "lua main file", "lua/game.raw");
 
 /*
@@ -170,7 +172,7 @@ void LuaEnvironment::execute(int32_t args, int32_t results)
 //-----------------------------------------------------------------------------
 void LuaEnvironment::game_init()
 {
-	const char* path = device()->filesystem()->os_path("disk", g_boot.value());
+	const char* path = device()->filesystem()->os_path(g_default_mountpoint.value(), g_boot.value());
 
 	load_file(path);
 	execute(0, 0);

+ 5 - 2
engine/resource/FileBundle.cpp

@@ -32,10 +32,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Log.h"
 #include "StringUtils.h" 
 #include "OS.h"
+#include "StringSetting.h"
 
 namespace crown
 {
 
+extern StringSetting g_default_mountpoint;
+
 //-----------------------------------------------------------------------------
 FileBundle::FileBundle(Filesystem& fs) :
 	m_filesystem(fs)
@@ -55,11 +58,11 @@ DiskFile* FileBundle::open(ResourceId name)
 	snprintf(resource_name, 512, "%.8X%.8X", name.name, name.type);
 	
 	// Search the resource in the filesystem
-	bool exists = m_filesystem.exists("android", resource_name);
+	bool exists = m_filesystem.exists(g_default_mountpoint.value(), resource_name);
 	CE_ASSERT(exists == true, "Resource does not exist: %s", resource_name);
 
 	// Open the resource and check magic number/version
-	DiskFile* file = (DiskFile*)m_filesystem.open("android", resource_name, FOM_READ);
+	DiskFile* file = (DiskFile*)m_filesystem.open(g_default_mountpoint.value(), resource_name, FOM_READ);
 
 	ResourceHeader header;
 	file->read(&header, sizeof(ResourceHeader));