2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os_server.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2019-01-01 12:46:36 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "os_server.h"
|
2018-07-20 08:37:10 +02:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/string/print_string.h"
|
2017-12-27 01:31:51 +01:00
|
|
|
#include "drivers/dummy/rasterizer_dummy.h"
|
2018-05-07 14:56:47 +02:00
|
|
|
#include "drivers/dummy/texture_loader_dummy.h"
|
2020-12-03 22:09:47 +01:00
|
|
|
#include "servers/rendering/rendering_server_default.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#include "main/main.h"
|
|
|
|
|
2018-07-20 08:37:10 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-02-10 02:10:30 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int OS_Server::get_video_driver_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *OS_Server::get_video_driver_name(int p_driver) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return "Dummy";
|
|
|
|
}
|
|
|
|
|
2018-07-20 08:37:10 +02:00
|
|
|
int OS_Server::get_current_video_driver() const {
|
|
|
|
return video_driver_index;
|
|
|
|
}
|
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
void OS_Server::initialize_core() {
|
|
|
|
crash_handler.initialize();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
OS_Unix::initialize_core();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-09 11:08:10 +01:00
|
|
|
Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2017-12-27 01:31:51 +01:00
|
|
|
args = OS::get_singleton()->get_cmdline_args();
|
|
|
|
current_videomode = p_desired;
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2017-12-27 01:31:51 +01:00
|
|
|
|
|
|
|
RasterizerDummy::make_current();
|
|
|
|
|
2018-07-20 08:37:10 +02:00
|
|
|
video_driver_index = p_video_driver; // unused in server platform, but should still be initialized
|
|
|
|
|
2020-12-03 22:09:47 +01:00
|
|
|
rendering_server = memnew(RenderingServerDefault);
|
2020-03-27 19:21:27 +01:00
|
|
|
rendering_server->init();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
AudioDriverManager::initialize(p_audio_driver);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
input = memnew(InputDefault);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
_ensure_user_data_dir();
|
2018-01-09 11:08:10 +01:00
|
|
|
|
2018-06-11 02:59:53 +02:00
|
|
|
resource_loader_dummy.instance();
|
2018-05-07 14:56:47 +02:00
|
|
|
ResourceLoader::add_resource_format_loader(resource_loader_dummy);
|
|
|
|
|
2018-01-09 11:08:10 +01:00
|
|
|
return OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-01-09 11:08:10 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OS_Server::finalize() {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (main_loop)
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(main_loop);
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
rendering_server->finish();
|
|
|
|
memdelete(rendering_server);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(input);
|
|
|
|
|
2018-06-11 02:59:53 +02:00
|
|
|
ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
|
|
|
|
resource_loader_dummy.unref();
|
2018-05-07 14:56:47 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
args.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Server::set_mouse_show(bool p_show) {
|
|
|
|
}
|
2018-01-09 11:08:10 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OS_Server::set_mouse_grab(bool p_grab) {
|
2017-03-05 16:44:50 +01:00
|
|
|
grab = p_grab;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-01-09 11:08:10 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool OS_Server::is_mouse_grab_enabled() const {
|
|
|
|
return grab;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Server::get_mouse_button_state() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
Point2 OS_Server::get_mouse_position() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return Point2();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS_Server::set_window_title(const String &p_title) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS_Server::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-01-09 11:08:10 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
OS::VideoMode OS_Server::get_video_mode(int p_screen) const {
|
|
|
|
return current_videomode;
|
|
|
|
}
|
2015-04-02 17:59:23 +02:00
|
|
|
|
|
|
|
Size2 OS_Server::get_window_size() const {
|
2017-03-05 16:44:50 +01:00
|
|
|
return Vector2(current_videomode.width, current_videomode.height);
|
2015-04-02 17:59:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS_Server::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainLoop *OS_Server::get_main_loop() const {
|
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Server::delete_main_loop() {
|
|
|
|
if (main_loop)
|
|
|
|
memdelete(main_loop);
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS_Server::set_main_loop(MainLoop *p_main_loop) {
|
|
|
|
main_loop = p_main_loop;
|
2014-02-10 02:10:30 +01:00
|
|
|
input->set_main_loop(p_main_loop);
|
|
|
|
}
|
|
|
|
|
2019-05-20 19:36:24 +02:00
|
|
|
String OS_Server::get_name() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return "Server";
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Server::move_window_to_foreground() {
|
|
|
|
}
|
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
bool OS_Server::_check_internal_feature_support(const String &p_feature) {
|
|
|
|
return p_feature == "pc";
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OS_Server::run() {
|
|
|
|
force_quit = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!main_loop)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
main_loop->init();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
while (!force_quit) {
|
2018-10-03 19:40:37 +02:00
|
|
|
if (Main::iteration())
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
2017-12-27 01:31:51 +01:00
|
|
|
String OS_Server::get_config_path() const {
|
|
|
|
if (has_environment("XDG_CONFIG_HOME")) {
|
|
|
|
return get_environment("XDG_CONFIG_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".config");
|
|
|
|
} else {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Server::get_data_path() const {
|
|
|
|
if (has_environment("XDG_DATA_HOME")) {
|
|
|
|
return get_environment("XDG_DATA_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".local/share");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Server::get_cache_path() const {
|
|
|
|
if (has_environment("XDG_CACHE_HOME")) {
|
|
|
|
return get_environment("XDG_CACHE_HOME");
|
|
|
|
} else if (has_environment("HOME")) {
|
|
|
|
return get_environment("HOME").plus_file(".cache");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Server::get_system_dir(SystemDir p_dir) const {
|
|
|
|
String xdgparam;
|
|
|
|
|
|
|
|
switch (p_dir) {
|
|
|
|
case SYSTEM_DIR_DESKTOP: {
|
|
|
|
xdgparam = "DESKTOP";
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DCIM: {
|
|
|
|
xdgparam = "PICTURES";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOCUMENTS: {
|
|
|
|
xdgparam = "DOCUMENTS";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOWNLOADS: {
|
|
|
|
xdgparam = "DOWNLOAD";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MOVIES: {
|
|
|
|
xdgparam = "VIDEOS";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MUSIC: {
|
|
|
|
xdgparam = "MUSIC";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_PICTURES: {
|
|
|
|
xdgparam = "PICTURES";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_RINGTONES: {
|
|
|
|
xdgparam = "MUSIC";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
String pipe;
|
|
|
|
List<String> arg;
|
|
|
|
arg.push_back(xdgparam);
|
2020-04-02 01:20:12 +02:00
|
|
|
Error err = const_cast<OS_Server *>(this)->execute("xdg-user-dir", arg, true, nullptr, &pipe);
|
2017-12-27 01:31:51 +01:00
|
|
|
if (err != OK)
|
|
|
|
return ".";
|
|
|
|
return pipe.strip_edges();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Server::disable_crash_handler() {
|
|
|
|
crash_handler.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_Server::is_disable_crash_handler() const {
|
|
|
|
return crash_handler.is_disabled();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
OS_Server::OS_Server() {
|
|
|
|
//adriver here
|
2017-03-05 16:44:50 +01:00
|
|
|
grab = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|