Daniele Bartolini пре 1 година
родитељ
комит
23843181a6
8 измењених фајлова са 148 додато и 31 уклоњено
  1. 16 0
      .github/workflows/main.yml
  2. 14 0
      makefile
  3. 53 0
      scripts/crown-launcher.lua
  4. 6 30
      scripts/dist/package.sh
  5. 1 0
      scripts/genie.lua
  6. 4 0
      src/config.h
  7. 8 1
      src/device/log.cpp
  8. 46 0
      tools/launcher/launcher.cpp

+ 16 - 0
.github/workflows/main.yml

@@ -126,6 +126,12 @@ jobs:
     - name: linux-make-crown-editor-release64
       run: |
         make MAKE_JOBS=2 crown-editor-linux-release64
+    - name: linux-make-crown-launcher-debug64
+      run: |
+        make MAKE_JOBS=2 crown-launcher-linux-debug64
+    - name: linux-make-crown-launcher-release64
+      run: |
+        make MAKE_JOBS=2 crown-launcher-linux-release64
   windows:
     runs-on: windows-2019
     steps:
@@ -188,6 +194,16 @@ jobs:
       run: |
         export MINGW=/mingw64
         make MAKE_JOBS=2 crown-editor-mingw-release64
+    - name: mingw-make-crown-launcher-debug64
+      shell: msys2 {0}
+      run: |
+        export MINGW=/mingw64
+        make MAKE_JOBS=2 crown-launcher-mingw-debug64
+    - name: mingw-make-crown-launcher-release64
+      shell: msys2 {0}
+      run: |
+        export MINGW=/mingw64
+        make MAKE_JOBS=2 crown-launcher-mingw-release64
   code-style:
     runs-on: ubuntu-20.04
     needs: [android-arm, html5, linux, windows]

+ 14 - 0
makefile

@@ -251,6 +251,20 @@ crown-editor-mingw-release64: \
 	build/projects/mingw
 	"$(MAKE)" -j$(MAKE_JOBS) -R -C build/projects/mingw crown-editor config=release64
 
+crown-launcher-linux-debug64: \
+	build/projects/linux
+	"$(MAKE)" -j$(MAKE_JOBS) -R -C build/projects/linux crown-launcher config=debug64
+crown-launcher-linux-release64: \
+	build/projects/linux
+	"$(MAKE)" -j$(MAKE_JOBS) -R -C build/projects/linux crown-launcher config=release64
+
+crown-launcher-mingw-debug64: \
+	build/projects/mingw
+	"$(MAKE)" -j$(MAKE_JOBS) -R -C build/projects/mingw crown-launcher config=debug64
+crown-launcher-mingw-release64: \
+	build/projects/mingw
+	"$(MAKE)" -j$(MAKE_JOBS) -R -C build/projects/mingw crown-launcher config=release64
+
 tools-linux-release32:       \
 	build/linux32/bin/luajit \
 	build/linux32/bin/luac

+ 53 - 0
scripts/crown-launcher.lua

@@ -0,0 +1,53 @@
+--
+-- Copyright (c) 2012-2024 Daniele Bartolini et al.
+-- SPDX-License-Identifier: MIT
+--
+
+project ("crown-launcher")
+	kind "WindowedApp"
+
+	defines {
+		"CROWN_LOG_TO_CONSOLE=0"
+	}
+
+	includedirs {
+		CROWN_DIR .. "src",
+		CROWN_DIR .. "3rdparty/stb",
+	}
+
+	configuration { "debug" }
+		defines {
+			"CROWN_DEBUG=1"
+		}
+
+	configuration { "release" }
+		defines {
+			"CROWN_DEBUG=0"
+		}
+
+	configuration { "linux-*" }
+		links {
+			"pthread",
+		}
+
+	configuration { "vs* or mingw*" }
+		links {
+			"dbghelp",
+		}
+
+	configuration {}
+
+	files {
+		CROWN_DIR .. "src/core/error/**.cpp",
+		CROWN_DIR .. "src/core/memory/globals.cpp",
+		CROWN_DIR .. "src/core/os.cpp",
+		CROWN_DIR .. "src/core/process.cpp",
+		CROWN_DIR .. "src/core/thread/mutex.cpp",
+		CROWN_DIR .. "src/device/log.cpp",
+		CROWN_DIR .. "tools/launcher/launcher.cpp",
+	}
+
+	strip()
+
+	configuration {} -- reset configuration
+

+ 6 - 30
scripts/dist/package.sh

@@ -99,6 +99,7 @@ elif [ "${PLATFORM}" = "html5" ]; then
 elif [ "${PLATFORM}" = "linux" ]; then
 	make tools-linux-release32 MAKE_JOBS="${BUILD_JOBS}"
 	make tools-linux-release64 MAKE_JOBS="${BUILD_JOBS}"
+	make crown-launcher-linux-release64 MAKE_JOBS="${BUILD_JOBS}"
 	make linux-release64 MAKE_JOBS="${BUILD_JOBS}"
 elif [ "${PLATFORM}" = "windows" ]; then
 	/c/Windows/System32/cmd.exe //C "scripts\\dist\\windows-release.bat"
@@ -107,6 +108,7 @@ elif [ "${PLATFORM}" = "windows" ]; then
 	export MINGW=/mingw64
 	export PATH="${MINGW}/bin:${PATH}"
 	make tools-mingw-release64 MAKE_JOBS="${BUILD_JOBS}"
+	make crown-launcher-mingw-release64 MAKE_JOBS="${BUILD_JOBS}"
 
 	# Copy required DLLs.
 	ldd build/mingw64/bin/crown-editor-release.exe | grep '\/mingw.*\.dll' -o | xargs -I{} cp "{}" build/mingw64/bin
@@ -199,42 +201,16 @@ if [ "${PLATFORM}" = "linux" ] || [ "${PLATFORM}" = "windows" ]; then
 	cp -r samples   "${PACKAGENAME}"
 	mv    "${PACKAGENAME}"/samples/core "${PACKAGENAME}"
 
-	# Create script that launches the editor.
 	if [ "${PLATFORM}" = "linux" ]; then
-		{
-			echo "#!/bin/sh"
-			echo "PROJECT=\$1"
-			echo "LEVEL=\$2"
-			echo "if [ ! -z \$PROJECT ]; then"
-			echo "	PROJECT=\$(readlink -f \${PROJECT})"
-			echo "fi"
-			# https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
-			echo "DIR=\"\$( cd \"\$( dirname \"\$0\" )\" >/dev/null 2>&1 && pwd )\""
-			echo "cd \${DIR}/platforms/linux64/bin"
-			echo "export UBUNTU_MENUPROXY="
-			echo "./crown-editor-release \${PROJECT} \${LEVEL}"
-		} > "${PACKAGENAME}"/crown
-		chmod +x "${PACKAGENAME}"/crown
+		# Copy crown-launcher.
+		mv "${PACKAGENAME}"/platforms/linux64/bin/crown-launcher-release "${PACKAGENAME}"/crown-launcher
 
 		# Copy app icon and .desktop file.
 		cp scripts/dist/linux/org.crownengine.Crown.desktop "${PACKAGENAME}"
 		cp tools/level_editor/resources/icons/crown-black-socket.svg "${PACKAGENAME}"/org.crownengine.Crown.svg
 	elif [ "${PLATFORM}" = "windows" ]; then
-		{
-			echo "@echo off"
-			echo "call :ABSOLUTEPATH %1"
-			echo "set PROJECT=%RETVAL%"
-			echo "set LEVEL=%2"
-			echo ""
-			echo "cd platforms\windows64\bin"
-			echo "start crown-editor-release.exe %PROJECT% %LEVEL%"
-			echo ""
-			echo "exit"
-			echo ""
-			echo ":ABSOLUTEPATH"
-			echo "  SET RETVAL=%~dpfn1"
-			echo "  EXIT /B"
-		} > "${PACKAGENAME}"/crown.bat
+		# Copy crown-launcher.
+		mv "${PACKAGENAME}"/platforms/windows64/bin/crown-launcher-release.exe "${PACKAGENAME}"/crown-launcher.exe
 	fi
 fi
 

+ 1 - 0
scripts/genie.lua

@@ -97,5 +97,6 @@ if _OPTIONS["with-tools"] then
 
 	if not _OPTIONS["no-editor"] then
 		dofile ("crown-editor.lua")
+		dofile ("crown-launcher.lua")
 	end
 end

+ 4 - 0
src/config.h

@@ -136,3 +136,7 @@
 #ifndef CROWN_USE_LUAJIT
 	#define CROWN_USE_LUAJIT 1
 #endif
+
+#ifndef CROWN_LOG_TO_CONSOLE
+	#define CROWN_LOG_TO_CONSOLE 1
+#endif

+ 8 - 1
src/device/log.cpp

@@ -3,14 +3,17 @@
  * SPDX-License-Identifier: MIT
  */
 
+#include "config.h"
 #include "core/memory/temp_allocator.inl"
 #include "core/os.h"
 #include "core/platform.h"
 #include "core/strings/string.inl"
 #include "core/strings/string_stream.inl"
 #include "core/thread/scoped_mutex.inl"
-#include "device/console_server.h"
 #include "device/log.h"
+#if CROWN_LOG_TO_CONSOLE
+	#include "device/console_server.h"
+#endif
 #include <stb_sprintf.h>
 
 namespace crown
@@ -40,6 +43,9 @@ namespace log_internal
 	/// Sends a log message to all clients.
 	static void console_log(LogSeverity::Enum sev, System system, const char *msg)
 	{
+#if !CROWN_LOG_TO_CONSOLE
+		CE_UNUSED_3(sev, system, msg);
+#else
 		if (!console_server())
 			return;
 
@@ -65,6 +71,7 @@ namespace log_internal
 		ss << "\"}";
 
 		console_server()->broadcast(string_stream::c_str(ss));
+#endif // if !CROWN_LOG_TO_CONSOLE
 	}
 
 	void vlogx(LogSeverity::Enum sev, System system, const char *msg, va_list args)

+ 46 - 0
tools/launcher/launcher.cpp

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012-2024 Daniele Bartolini et al.
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "core/memory/allocator.h"
+#include "core/memory/globals.h"
+#include "core/os.h"
+#include "core/process.h"
+#define STB_SPRINTF_IMPLEMENTATION
+#define STB_SPRINTF_NOUNALIGNED
+#define STB_SPRINTF_NOFLOAT
+#include <stb_sprintf.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+	using namespace crown;
+	memory_globals::init();
+	CE_UNUSED(argc);
+
+#if CROWN_PLATFORM_LINUX
+	os::setcwd("platforms/linux64/bin");
+	os::setenv("UBUNTU_MENUPROXY", "");
+#elif CROWN_PLATFORM_WINDOWS
+	os::setcwd("platforms/windows64/bin");
+#else
+	#error "Unsupported platform."
+#endif
+
+	char editor_exe[] = EXE_PATH("crown-editor-release");
+
+	Process pr;
+	argv[0] = editor_exe;
+
+	if (pr.spawn(argv, CROWN_PROCESS_STDOUT_PIPE | CROWN_PROCESS_STDERR_MERGE) != 0) {
+		printf("Cannot spawn %s\n", argv[0]);
+		memory_globals::shutdown();
+		return EXIT_FAILURE;
+	}
+
+	int exit_code = pr.wait();
+	memory_globals::shutdown();
+	return exit_code;
+}