Explorar el Código

resource: add console command to gracefully shut down the data compiler server

Daniele Bartolini hace 6 años
padre
commit
40c9cfb7d4

+ 9 - 1
src/resource/data_compiler.cpp

@@ -106,6 +106,13 @@ static void console_command_compile(ConsoleServer& cs, TCPSocket client, const c
 	}
 	}
 }
 }
 
 
+static bool _quit = false;
+
+static void console_command_quit(ConsoleServer& /*cs*/, TCPSocket /*client*/, const char* /*json*/, void* /*user_data*/)
+{
+	_quit = true;
+}
+
 static Buffer read(FilesystemDisk& data_fs, const char* filename)
 static Buffer read(FilesystemDisk& data_fs, const char* filename)
 {
 {
 	Buffer buffer(default_allocator());
 	Buffer buffer(default_allocator());
@@ -367,6 +374,7 @@ DataCompiler::DataCompiler(ConsoleServer& cs)
 	, _file_monitor(default_allocator())
 	, _file_monitor(default_allocator())
 {
 {
 	cs.register_command("compile", console_command_compile, this);
 	cs.register_command("compile", console_command_compile, this);
+	cs.register_command("quit", console_command_quit, this);
 }
 }
 
 
 DataCompiler::~DataCompiler()
 DataCompiler::~DataCompiler()
@@ -1043,7 +1051,7 @@ int main_data_compiler(const DeviceOptions& opts)
 
 
 	if (opts._server)
 	if (opts._server)
 	{
 	{
-		while (true)
+		while (!_quit)
 		{
 		{
 			console_server()->update();
 			console_server()->update();
 			os::sleep(60);
 			os::sleep(60);

+ 5 - 0
tools/api/engine_api.vala

@@ -40,6 +40,11 @@ namespace Crown
 				);
 				);
 		}
 		}
 
 
+		public string quit()
+		{
+			return "{\"type\":\"quit\"}";
+		}
+
 	}
 	}
 
 
 	namespace DeviceApi
 	namespace DeviceApi

+ 2 - 1
tools/level_editor/level_editor.vala

@@ -562,6 +562,7 @@ namespace Crown
 			{
 			{
 				ENGINE_EXE,
 				ENGINE_EXE,
 				"--source-dir", _project.source_dir(),
 				"--source-dir", _project.source_dir(),
+				"--data-dir", _project.data_dir(),
 				"--map-source-dir", "core", _project.toolchain_dir(),
 				"--map-source-dir", "core", _project.toolchain_dir(),
 				"--server",
 				"--server",
 				"--wait-console",
 				"--wait-console",
@@ -605,11 +606,11 @@ namespace Crown
 
 
 		private void stop_compiler()
 		private void stop_compiler()
 		{
 		{
+			_compiler.send(DataCompilerApi.quit());
 			_compiler.close();
 			_compiler.close();
 
 
 			if (_compiler_process != null)
 			if (_compiler_process != null)
 			{
 			{
-				_compiler_process.force_exit();
 				try
 				try
 				{
 				{
 					_compiler_process.wait();
 					_compiler_process.wait();