Daniele Bartolini 12 лет назад
Родитель
Сommit
ec7dc6a353
3 измененных файлов с 42 добавлено и 52 удалено
  1. 0 48
      engine/Device.cpp
  2. 0 4
      engine/Device.h
  3. 42 0
      engine/os/linux/main.cpp

+ 0 - 48
engine/Device.cpp

@@ -130,9 +130,6 @@ void Device::init()
 	#endif
 	Log::d("Filesystem created.");
 
-	// Read settings from crown.config
-	read_engine_settings();
-
 	m_resource_bundle = Bundle::create(m_allocator, *m_filesystem);
 
 	// Create resource manager
@@ -486,51 +483,6 @@ void Device::reload(const char* type, const char* name)
 		}
 	#endif
 }
-//-------------------------------------------------------------------------
-void Device::read_engine_settings()
-{
-	// // Check crown.config existance
-	// CE_ASSERT(m_filesystem->is_file("crown.config"), "Unable to open crown.config");
-
-	// // Copy crown config in a buffer
-	// TempAllocator4096 allocator;
-
-	// File* config_file = m_filesystem->open("crown.config", FOM_READ);
-
-	// char* json_string = (char*)allocator.allocate(config_file->size());
-
-	// config_file->read(json_string, config_file->size());
-
-	// m_filesystem->close(config_file);
-
-	// // Parse crown.config
-	// JSONParser parser(json_string);
-
-	// JSONElement root = parser.root();
-
-	// // Boot
-	// if (root.has_key("boot"))
-	// {
-	// 	const char* boot = root.key("boot").string_value();
-	// 	const size_t boot_length = string::strlen(boot) + 1;
-
-	// 	string::strncpy(m_boot_file, boot, boot_length);
-	// }
-	// // Window width
-	// if (root.has_key("window_width"))
-	// {
-	// 	m_preferred_window_width = root.key("window_width").int_value();
-	// }
-	// // Window height
-	// if (root.has_key("window_height"))
-	// {
-	// 	m_preferred_window_height = root.key("window_height").int_value();
-	// }
-
-	// allocator.deallocate(json_string);
-
-	// Log::i("Configuration set");
-}
 
 static Device* g_device;
 void set_device(Device* device)

+ 0 - 4
engine/Device.h

@@ -140,10 +140,6 @@ public:
 	Accelerometer*			accelerometer();
 	RPCServer*				rpc() { return m_rpc; }
 
-private:
-
-	void					read_engine_settings();
-
 protected:
 
 	// Used to allocate all subsystems

+ 42 - 0
engine/os/linux/main.cpp

@@ -143,6 +143,7 @@ public:
 	void init(int argc, char** argv)
 	{
 		parse_command_line(argc, argv);
+		read_configuration();
 		check_preferred_settings();
 
 		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
@@ -163,6 +164,7 @@ public:
 				}
 			}
 		#endif
+
 	}
 
 	//-----------------------------------------------------------------------------
@@ -574,6 +576,46 @@ public:
 		}
 	}
 
+	//-------------------------------------------------------------------------
+	void read_configuration()
+	{
+		DiskFilesystem fs(m_bundle_dir);
+
+		// crown.config is mandatory
+		CE_ASSERT(fs.is_file("crown.config"), "Unable to open crown.config");
+
+		File* config_file = fs.open("crown.config", FOM_READ);
+
+		TempAllocator4096 alloc;
+		char* json_string = (char*)alloc.allocate(config_file->size());
+		config_file->read(json_string, config_file->size());
+		fs.close(config_file);
+
+		// Parse crown.config
+		JSONParser parser(json_string);
+		JSONElement root = parser.root();
+
+		// Boot
+		if (root.has_key("boot"))
+		{
+			const char* boot = root.key("boot").string_value();
+			const size_t boot_length = string::strlen(boot);
+
+			string::strncpy(m_boot_file, boot, (boot_length > MAX_PATH_LENGTH) ? MAX_PATH_LENGTH : boot_length + 1);
+		}
+
+		// Window width
+		if (root.has_key("window_width"))
+		{
+			m_width = root.key("window_width").int_value();
+		}
+
+		// Window height
+		if (root.has_key("window_height"))
+		{
+			m_height = root.key("window_height").int_value();
+		}
+	}
 
 private: