summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-23 22:13:28 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-23 22:13:28 +0100
commit1dfd236f15d8553e0ad0c976eab93b70665c3b78 (patch)
tree31bff419971f61abdc4d0a1650778e511d4d258b /main/main.cpp
parentf963202b7c81f3304563b9d52eb08be75a82436e (diff)
parent74458b6e9bed0f28db3374c7406eacbcf4b09b9d (diff)
Merge pull request #70377 from dsnopek/server-export-mk2
Add "dedicated server" export mode which can strip unneeded visual resources
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/main/main.cpp b/main/main.cpp
index eff30bee9b..c5a9f94417 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -208,6 +208,11 @@ static bool dump_extension_api = false;
#endif
bool profile_gpu = false;
+// Constants.
+
+static const String NULL_DISPLAY_DRIVER("headless");
+static const String NULL_AUDIO_DRIVER("Dummy");
+
/* Helper methods */
bool Main::is_cmdline_tool() {
@@ -1003,8 +1008,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--headless") { // enable headless mode (no audio, no rendering).
- audio_driver = "Dummy";
- display_driver = "headless";
+ audio_driver = NULL_AUDIO_DRIVER;
+ display_driver = NULL_DISPLAY_DRIVER;
} else if (I->get() == "--profiling") { // enable profiling
@@ -1139,8 +1144,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// `--doctool` implies `--headless` to avoid spawning an unnecessary window
// and speed up class reference generation.
- audio_driver = "Dummy";
- display_driver = "headless";
+ audio_driver = NULL_AUDIO_DRIVER;
+ display_driver = NULL_DISPLAY_DRIVER;
main_args.push_back(I->get());
#endif
} else if (I->get() == "--path") { // set path of project to start or edit
@@ -1377,6 +1382,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
ResourceUID::get_singleton()->load_from_cache(); // load UUIDs from cache.
+ if (ProjectSettings::get_singleton()->has_custom_feature("dedicated_server")) {
+ audio_driver = NULL_AUDIO_DRIVER;
+ display_driver = NULL_DISPLAY_DRIVER;
+ }
+
GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater"), 32768);
GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_queued_messages", PROPERTY_HINT_RANGE, "0, 8192, 1, or_greater"), 2048);
GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater"), 400);
@@ -1730,7 +1740,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// Display driver, e.g. X11, Wayland.
// Make sure that headless is the last one, which it is assumed to be by design.
- DEV_ASSERT(String("headless") == DisplayServer::get_create_function_name(DisplayServer::get_create_function_count() - 1));
+ DEV_ASSERT(NULL_DISPLAY_DRIVER == DisplayServer::get_create_function_name(DisplayServer::get_create_function_count() - 1));
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
String name = DisplayServer::get_create_function_name(i);
if (display_driver == name) {
@@ -1755,7 +1765,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
// Make sure that dummy is the last one, which it is assumed to be by design.
- DEV_ASSERT(String("Dummy") == AudioDriverManager::get_driver(AudioDriverManager::get_driver_count() - 1)->get_name());
+ DEV_ASSERT(NULL_AUDIO_DRIVER == AudioDriverManager::get_driver(AudioDriverManager::get_driver_count() - 1)->get_name());
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
audio_driver_idx = i;