소스 검색

Merge CommandLineSettings and ConfigSettings

Daniele Bartolini 11 년 전
부모
커밋
2b676e0459
7개의 변경된 파일62개의 추가작업 그리고 65개의 파일을 삭제
  1. 4 4
      engine/compilers/bundle_compiler.cpp
  2. 1 1
      engine/compilers/bundle_compiler.h
  3. 13 32
      engine/crown.cpp
  4. 22 10
      engine/crown.h
  5. 3 1
      engine/main/main_android.cpp
  6. 12 11
      engine/main/main_linux.cpp
  7. 7 6
      engine/main/main_windows.cpp

+ 4 - 4
engine/compilers/bundle_compiler.cpp

@@ -135,12 +135,12 @@ void BundleCompiler::scan(const char* cur_dir, Vector<DynamicString>& files)
 
 
 namespace bundle_compiler
 namespace bundle_compiler
 {
 {
-	bool main(const CommandLineSettings& cls)
+	bool main(const ConfigSettings& cs)
 	{
 	{
-		if (cls.do_compile)
+		if (cs.do_compile)
 		{
 		{
-			bool ok = bundle_compiler_globals::compiler()->compile_all(cls.platform);
-			if (!ok || !cls.do_continue)
+			bool ok = bundle_compiler_globals::compiler()->compile_all(cs.platform);
+			if (!ok || !cs.do_continue)
 			{
 			{
 				return false;
 				return false;
 			}
 			}

+ 1 - 1
engine/compilers/bundle_compiler.h

@@ -55,7 +55,7 @@ private:
 
 
 namespace bundle_compiler
 namespace bundle_compiler
 {
 {
-	bool main(const CommandLineSettings& cls);
+	bool main(const ConfigSettings& cls);
 } // namespace bundle_compiler
 } // namespace bundle_compiler
 
 
 namespace bundle_compiler_globals
 namespace bundle_compiler_globals

+ 13 - 32
engine/crown.cpp

@@ -84,6 +84,7 @@ static void help(const char* msg = NULL)
 
 
 		"  -h --help                  Show this help.\n"
 		"  -h --help                  Show this help.\n"
 		"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
 		"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
+		"  --console-port <port>      Set port of the console.\n"
 		"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
 		"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
 		"                             Used only by tools.\n"
 		"                             Used only by tools.\n"
 
 
@@ -102,17 +103,8 @@ static void help(const char* msg = NULL)
 	);
 	);
 }
 }
 
 
-CommandLineSettings parse_command_line(int argc, char** argv)
+void parse_command_line(int argc, char** argv, ConfigSettings& cs)
 {
 {
-	CommandLineSettings cls;
-	cls.source_dir = NULL;
-	cls.bundle_dir = NULL;
-	cls.platform = Platform::COUNT;
-	cls.wait_console = false;
-	cls.do_compile = false;
-	cls.do_continue = false;
-	cls.parent_window = 0;
-
 	CommandLine cmd(argc, argv);
 	CommandLine cmd(argc, argv);
 
 
 	if (cmd.has_argument("help", 'h'))
 	if (cmd.has_argument("help", 'h'))
@@ -121,26 +113,26 @@ CommandLineSettings parse_command_line(int argc, char** argv)
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
 	}
 	}
 
 
-	cls.source_dir = cmd.get_parameter("source-dir");
-	if (!cls.source_dir)
+	cs.source_dir = cmd.get_parameter("source-dir");
+	if (!cs.source_dir)
 	{
 	{
 		help("Source directory must be specified.");
 		help("Source directory must be specified.");
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
 	}
 	}
 	
 	
-	cls.bundle_dir = cmd.get_parameter("bundle-dir");
-	if (!cls.bundle_dir)
+	cs.bundle_dir = cmd.get_parameter("bundle-dir");
+	if (!cs.bundle_dir)
 	{
 	{
 		help("Bundle directory must be specified.");
 		help("Bundle directory must be specified.");
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
 	}
 	}
 
 
-	cls.wait_console = cmd.has_argument("wait-console");
-	cls.do_compile = cmd.has_argument("compile");
-	cls.do_continue = cmd.has_argument("continue");
+	cs.wait_console = cmd.has_argument("wait-console");
+	cs.do_compile = cmd.has_argument("compile");
+	cs.do_continue = cmd.has_argument("continue");
 
 
-	cls.platform = string_to_platform(cmd.get_parameter("platform"));
-	if (cls.do_compile && cls.platform == Platform::COUNT)
+	cs.platform = string_to_platform(cmd.get_parameter("platform"));
+	if (cs.do_compile && cs.platform == Platform::COUNT)
 	{
 	{
 		help("Platform must be specified.");
 		help("Platform must be specified.");
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
@@ -149,21 +141,12 @@ CommandLineSettings parse_command_line(int argc, char** argv)
 	const char* parent = cmd.get_parameter("parent-window");
 	const char* parent = cmd.get_parameter("parent-window");
 	if (parent)
 	if (parent)
 	{
 	{
-		cls.parent_window = string::parse_uint(parent);
+		cs.parent_window = string::parse_uint(parent);
 	}
 	}
-
-	return cls;
 }
 }
 
 
-ConfigSettings parse_config_file(Filesystem& fs)
+void parse_config_file(Filesystem& fs, ConfigSettings& cs)
 {
 {
-	ConfigSettings cs;
-	cs.console_port = 10001;
-	cs.boot_package = 0;
-	cs.boot_script = 0;
-	cs.window_width = CROWN_DEFAULT_WINDOW_WIDTH;
-	cs.window_height = CROWN_DEFAULT_WINDOW_HEIGHT;
-
 	File* tmpfile = fs.open("crown.config", FOM_READ);
 	File* tmpfile = fs.open("crown.config", FOM_READ);
 	JSONParser config(*tmpfile);
 	JSONParser config(*tmpfile);
 	fs.close(tmpfile);
 	fs.close(tmpfile);
@@ -189,8 +172,6 @@ ConfigSettings parse_config_file(Filesystem& fs)
 
 
 	cs.boot_script = root.key("boot_script").to_resource_id("lua").name;
 	cs.boot_script = root.key("boot_script").to_resource_id("lua").name;
 	cs.boot_package = root.key("boot_package").to_resource_id("package").name;
 	cs.boot_package = root.key("boot_package").to_resource_id("package").name;
-
-	return cs;
 }
 }
 
 
 bool init(Filesystem& fs, const ConfigSettings& cs)
 bool init(Filesystem& fs, const ConfigSettings& cs)

+ 22 - 10
engine/crown.h

@@ -44,15 +44,22 @@ namespace crown
 
 
 	struct ConfigSettings
 	struct ConfigSettings
 	{
 	{
-		uint16_t console_port;
-		StringId64 boot_package;
-		StringId64 boot_script;
-		uint16_t window_width;
-		uint16_t window_height;
-	};
+		ConfigSettings()
+			: source_dir(NULL)
+			, bundle_dir(NULL)
+			, platform(Platform::COUNT)
+			, wait_console(false)
+			, do_compile(false)
+			, do_continue(false)
+			, parent_window(0)
+			, console_port(10001)
+			, boot_package(0)
+			, boot_script(0)
+			, window_width(CROWN_DEFAULT_WINDOW_WIDTH)
+			, window_height(CROWN_DEFAULT_WINDOW_HEIGHT)
+		{
+		}
 
 
-	struct CommandLineSettings
-	{
 		const char* source_dir;
 		const char* source_dir;
 		const char* bundle_dir;
 		const char* bundle_dir;
 		Platform::Enum platform;
 		Platform::Enum platform;
@@ -60,12 +67,17 @@ namespace crown
 		bool do_compile;
 		bool do_compile;
 		bool do_continue;
 		bool do_continue;
 		uint32_t parent_window;
 		uint32_t parent_window;
+		uint16_t console_port;
+		StringId64 boot_package;
+		StringId64 boot_script;
+		uint16_t window_width;
+		uint16_t window_height;
 	};
 	};
 
 
-	CommandLineSettings parse_command_line(int argc, char** argv);
+	void parse_command_line(int argc, char** argv, ConfigSettings& cs);
 
 
 	/// Read configuration file from @a fs.
 	/// Read configuration file from @a fs.
-	ConfigSettings parse_config_file(Filesystem& fs);
+	void parse_config_file(Filesystem& fs, ConfigSettings& cs);
 
 
 	/// Initializes the engine.
 	/// Initializes the engine.
 	bool init(Filesystem& fs, const ConfigSettings& cs);
 	bool init(Filesystem& fs, const ConfigSettings& cs);

+ 3 - 1
engine/main/main_android.cpp

@@ -250,10 +250,12 @@ void android_main(struct android_app* app)
 	// Make sure glue isn't stripped.
 	// Make sure glue isn't stripped.
 	app_dummy();
 	app_dummy();
 
 
+	ConfigSettings cs;
+
 	memory_globals::init();
 	memory_globals::init();
 	// DiskFilesystem src_fs(cls.source_dir);
 	// DiskFilesystem src_fs(cls.source_dir);
 	ApkFilesystem src_fs(app->activity->assetManager);
 	ApkFilesystem src_fs(app->activity->assetManager);
-	ConfigSettings cs = parse_config_file(src_fs);
+	parse_config_file(src_fs, cs);
 
 
 	console_server_globals::init(cs.console_port, false);
 	console_server_globals::init(cs.console_port, false);
 
 

+ 12 - 11
engine/main/main_linux.cpp

@@ -216,7 +216,7 @@ struct LinuxDevice
 	{
 	{
 	}
 	}
 
 
-	int32_t run(Filesystem* fs, ConfigSettings* cs, CommandLineSettings* cls)
+	int32_t run(Filesystem* fs, ConfigSettings* cs)
 	{
 	{
 		// Create main window
 		// Create main window
 		XInitThreads();
 		XInitThreads();
@@ -229,8 +229,8 @@ struct LinuxDevice
 		int depth = DefaultDepth(_x11_display, screen);
 		int depth = DefaultDepth(_x11_display, screen);
 		Visual* visual = DefaultVisual(_x11_display, screen);
 		Visual* visual = DefaultVisual(_x11_display, screen);
 
 
-		_x11_parent_window = (cls->parent_window == 0) ? RootWindow(_x11_display, screen) :
-			(Window) cls->parent_window;
+		_x11_parent_window = (cs->parent_window == 0) ? RootWindow(_x11_display, screen) :
+			(Window) cs->parent_window;
 
 
 		// Create main window
 		// Create main window
 		XSetWindowAttributes win_attribs;
 		XSetWindowAttributes win_attribs;
@@ -431,25 +431,26 @@ int main(int argc, char** argv)
 {
 {
 	using namespace crown;
 	using namespace crown;
 
 
-	CommandLineSettings cls = parse_command_line(argc, argv);
+	ConfigSettings cs;
+	parse_command_line(argc, argv, cs);
 
 
 	memory_globals::init();
 	memory_globals::init();
-	DiskFilesystem src_fs(cls.source_dir);
-	ConfigSettings cs = parse_config_file(src_fs);
+	DiskFilesystem src_fs(cs.source_dir);
+	parse_config_file(src_fs, cs);
 
 
-	console_server_globals::init(cs.console_port, cls.wait_console);
+	console_server_globals::init(cs.console_port, cs.wait_console);
 
 
-	bundle_compiler_globals::init(cls.source_dir, cls.bundle_dir);
+	bundle_compiler_globals::init(cs.source_dir, cs.bundle_dir);
 
 
 	bool do_continue = true;
 	bool do_continue = true;
 	int exitcode = EXIT_SUCCESS;
 	int exitcode = EXIT_SUCCESS;
 
 
-	do_continue = bundle_compiler::main(cls);
+	do_continue = bundle_compiler::main(cs);
 
 
 	if (do_continue)
 	if (do_continue)
 	{
 	{
-		DiskFilesystem dst_fs(cls.bundle_dir);
-		exitcode = crown::s_ldvc.run(&dst_fs, &cs, &cls);
+		DiskFilesystem dst_fs(cs.bundle_dir);
+		exitcode = crown::s_ldvc.run(&dst_fs, &cs);
 	}
 	}
 
 
 	bundle_compiler_globals::shutdown();
 	bundle_compiler_globals::shutdown();

+ 7 - 6
engine/main/main_windows.cpp

@@ -348,15 +348,16 @@ int main(int argc, char** argv)
 	CE_UNUSED(WsaData);
 	CE_UNUSED(WsaData);
 	CE_UNUSED(res);
 	CE_UNUSED(res);
 
 
-	CommandLineSettings cls = parse_command_line(argc, argv);
+	ConfigSettings cs;
+	parse_command_line(argc, argv, cs);
 
 
 	memory_globals::init();
 	memory_globals::init();
-	DiskFilesystem src_fs(cls.source_dir);
-	ConfigSettings cs = parse_config_file(src_fs);
+	DiskFilesystem src_fs(cs.source_dir);
+	parse_config_file(src_fs, cs);
 
 
-	console_server_globals::init(cs.console_port, cls.wait_console);
+	console_server_globals::init(cs.console_port, cs.wait_console);
 
 
-	bundle_compiler_globals::init(cls.source_dir, cls.bundle_dir);
+	bundle_compiler_globals::init(cs.source_dir, cs.bundle_dir);
 
 
 	bool do_continue = true;
 	bool do_continue = true;
 	int exitcode = EXIT_SUCCESS;
 	int exitcode = EXIT_SUCCESS;
@@ -365,7 +366,7 @@ int main(int argc, char** argv)
 
 
 	if (do_continue)
 	if (do_continue)
 	{
 	{
-		DiskFilesystem dst_fs(cls.bundle_dir);
+		DiskFilesystem dst_fs(cs.bundle_dir);
 		exitcode = crown::s_wdvc.run(&dst_fs, &cs);
 		exitcode = crown::s_wdvc.run(&dst_fs, &cs);
 	}
 	}