Daniele Bartolini 10 rokov pred
rodič
commit
29b9426269
5 zmenil súbory, kde vykonal 31 pridanie a 34 odobranie
  1. 2 2
      src/crown.cpp
  2. 1 1
      src/crown.h
  3. 10 7
      src/device.cpp
  4. 3 3
      src/device.h
  5. 15 21
      src/main/main_linux.cpp

+ 2 - 2
src/crown.cpp

@@ -56,13 +56,13 @@ static void help(const char* msg = NULL)
 	);
 }
 
-bool init(const DeviceOptions& opts, Filesystem& fs)
+bool init(const DeviceOptions& opts)
 {
 	profiler_globals::init();
 	audio_globals::init();
 	physics_globals::init();
 	bgfx::init();
-	device_globals::init(opts, fs);
+	device_globals::init(opts);
 	return true;
 }
 

+ 1 - 1
src/crown.h

@@ -12,7 +12,7 @@
 namespace crown
 {
 	/// Initializes the engine.
-	bool init(const DeviceOptions& opts, Filesystem& fs);
+	bool init(const DeviceOptions& opts);
 
 	/// Updates all the subsystems.
 	void update();

+ 10 - 7
src/device.cpp

@@ -20,13 +20,14 @@
 #include "json_parser.h"
 #include "filesystem.h"
 #include "path.h"
+#include "disk_filesystem.h"
 
 #define MAX_SUBSYSTEMS_HEAP 8 * 1024 * 1024
 
 namespace crown
 {
 
-Device::Device(const DeviceOptions& opts, Filesystem& fs)
+Device::Device(const DeviceOptions& opts)
 	: _allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
 	, _width(0)
 	, _height(0)
@@ -39,7 +40,7 @@ Device::Device(const DeviceOptions& opts, Filesystem& fs)
 	, _last_delta_time(0.0f)
 	, _time_since_start(0.0)
 	, _device_options(opts)
-	, _fs(fs)
+	, _bundle_filesystem(NULL)
 	, _boot_package_id(uint64_t(0))
 	, _boot_script_id(uint64_t(0))
 	, _boot_package(NULL)
@@ -55,11 +56,13 @@ void Device::init()
 	// Initialize
 	CE_LOGI("Initializing Crown Engine %s...", version());
 
+	_bundle_filesystem = CE_NEW(_allocator, DiskFilesystem)(_device_options.bundle_dir());
+
 	read_config();
 
 	// Create resource manager
 	CE_LOGD("Creating resource manager...");
-	_resource_manager = CE_NEW(_allocator, ResourceManager)(_fs);
+	_resource_manager = CE_NEW(_allocator, ResourceManager)(*_bundle_filesystem);
 
 	CE_LOGD("Creating material manager...");
 	material_manager::init();
@@ -259,9 +262,9 @@ void Device::read_config()
 
 	project_path += "crown.config";
 
-	File* tmpfile = _fs.open(project_path.c_str(), FOM_READ);
+	File* tmpfile = _bundle_filesystem->open(project_path.c_str(), FOM_READ);
 	JSONParser config(*tmpfile);
-	_fs.close(tmpfile);
+	_bundle_filesystem->close(tmpfile);
 	JSONElement root = config.root();
 
 	_boot_script_id = root.key("boot_script").to_resource_id();
@@ -273,10 +276,10 @@ namespace device_globals
 	char _buffer[sizeof(Device)];
 	Device* _device = NULL;
 
-	void init(const DeviceOptions& opts, Filesystem& fs)
+	void init(const DeviceOptions& opts)
 	{
 		CE_ASSERT(_device == NULL, "Crown already initialized");
-		_device = new (_buffer) Device(opts, fs);
+		_device = new (_buffer) Device(opts);
 		_device->init();
 	}
 

+ 3 - 3
src/device.h

@@ -27,7 +27,7 @@ namespace crown
 /// @ingroup Device
 struct Device
 {
-	Device(const DeviceOptions& opts, Filesystem& fs);
+	Device(const DeviceOptions& opts);
 
 	void init();
 
@@ -126,7 +126,7 @@ private:
 	double _time_since_start;
 
 	const DeviceOptions& _device_options;
-	Filesystem& _fs;
+	Filesystem* _bundle_filesystem;
 	StringId64 _boot_package_id;
 	StringId64 _boot_script_id;
 	ResourcePackage* _boot_package;
@@ -146,7 +146,7 @@ private:
 
 namespace device_globals
 {
-	void init(const DeviceOptions& opts, Filesystem& fs);
+	void init(const DeviceOptions& opts);
 	void shutdown();
 } // namespace device_globals
 

+ 15 - 21
src/main/main_linux.cpp

@@ -165,14 +165,13 @@ static bool s_exit = false;
 
 struct MainThreadArgs
 {
-	Filesystem* fs;
-	DeviceOptions* ds;
+	DeviceOptions* opts;
 };
 
 int32_t func(void* data)
 {
-	MainThreadArgs* args = (MainThreadArgs*) data;
-	crown::init(*args->ds, *args->fs);
+	MainThreadArgs* args = (MainThreadArgs*)data;
+	crown::init(*args->opts);
 	crown::update();
 	crown::shutdown();
 	s_exit = true;
@@ -190,7 +189,7 @@ struct LinuxDevice
 	{
 	}
 
-	int32_t run(Filesystem* fs, DeviceOptions* ds)
+	int32_t run(DeviceOptions* opts)
 	{
 		// http://tronche.com/gui/x/xlib/display/XInitThreads.html
 		Status xs = XInitThreads();
@@ -204,8 +203,8 @@ struct LinuxDevice
 		int depth = DefaultDepth(_x11_display, screen);
 		Visual* visual = DefaultVisual(_x11_display, screen);
 
-		_x11_parent_window = (ds->parent_window() == 0) ? RootWindow(_x11_display, screen) :
-			(Window)ds->parent_window();
+		_x11_parent_window = (opts->parent_window() == 0) ? RootWindow(_x11_display, screen) :
+			(Window)opts->parent_window();
 
 		// Create main window
 		XSetWindowAttributes win_attribs;
@@ -221,10 +220,10 @@ struct LinuxDevice
 
 		_x11_window = XCreateWindow(_x11_display
 			, _x11_parent_window
-			, ds->window_x()
-			, ds->window_y()
-			, ds->window_width()
-			, ds->window_height()
+			, opts->window_x()
+			, opts->window_y()
+			, opts->window_width()
+			, opts->window_height()
 			, 0
 			, depth
 			, InputOutput
@@ -233,6 +232,9 @@ struct LinuxDevice
 			, &win_attribs);
 		CE_ASSERT(_x11_window != None, "XCreateWindow: error");
 
+		_wm_delete_message = XInternAtom(_x11_display, "WM_DELETE_WINDOW", False);
+		XSetWMProtocols(_x11_display, _x11_window, &_wm_delete_message, 1);
+
 		// Do we have detectable autorepeat?
 		Bool detectable;
 		_x11_detectable_autorepeat = (bool) XkbSetDetectableAutoRepeat(_x11_display, true, &detectable);
@@ -248,10 +250,6 @@ struct LinuxDevice
 		bm_no = XCreateBitmapFromData(_x11_display, _x11_window, no_data, 8, 8);
 		_x11_hidden_cursor = XCreatePixmapCursor(_x11_display, bm_no, bm_no, &black, &black, 0, 0);
 
-		_wm_delete_message = XInternAtom(_x11_display, "WM_DELETE_WINDOW", False);
-		XSetWMProtocols(_x11_display, _x11_window, &_wm_delete_message, 1);
-
-		oswindow_set_window(_x11_display, _x11_window);
 		bgfx::x11SetDisplayWindow(_x11_display, _x11_window);
 		XMapRaised(_x11_display, _x11_window);
 
@@ -263,8 +261,7 @@ struct LinuxDevice
 
 		// Start main thread
 		MainThreadArgs mta;
-		mta.fs = fs;
-		mta.ds = ds;
+		mta.opts = opts;
 
 		Thread main_thread;
 		main_thread.start(func, &mta);
@@ -414,10 +411,7 @@ int main(int argc, char** argv)
 	do_continue = bundle_compiler::main(opts.do_compile(), opts.do_continue(), opts.platform());
 
 	if (do_continue)
-	{
-		DiskFilesystem dst_fs(opts.bundle_dir());
-		exitcode = crown::s_ldvc.run(&dst_fs, &opts);
-	}
+		exitcode = crown::s_ldvc.run(&opts);
 
 	bundle_compiler_globals::shutdown();
 	console_server_globals::shutdown();