Remove GDScript bindings for OS.get/set_exit_code, SceneTree.quit(<exit_code>) should be used instead

This commit is contained in:
Emmanuel Leblond 2020-06-04 22:03:45 +02:00
parent 0e4abcb77f
commit 60d2c1fd47
No known key found for this signature in database
GPG Key ID: C360860E645EFFC0
9 changed files with 8 additions and 43 deletions

View File

@ -322,18 +322,6 @@ uint64_t _OS::get_static_memory_peak_usage() const {
return OS::get_singleton()->get_static_memory_peak_usage(); return OS::get_singleton()->get_static_memory_peak_usage();
} }
int _OS::get_exit_code() const {
return OS::get_singleton()->get_exit_code();
}
void _OS::set_exit_code(int p_code) {
if (p_code < 0 || p_code > 125) {
WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive).");
}
OS::get_singleton()->set_exit_code(p_code);
}
/** /**
* Get current datetime with consideration for utc and * Get current datetime with consideration for utc and
* dst * dst
@ -730,9 +718,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time); ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime); ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &_OS::delay_usec); ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &_OS::delay_usec);
ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &_OS::delay_msec); ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &_OS::delay_msec);
ClassDB::bind_method(D_METHOD("get_ticks_msec"), &_OS::get_ticks_msec); ClassDB::bind_method(D_METHOD("get_ticks_msec"), &_OS::get_ticks_msec);
@ -777,7 +762,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions); ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions); ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions);
ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec"); ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec");

View File

@ -199,8 +199,6 @@ public:
void set_use_file_access_save_and_swap(bool p_enable); void set_use_file_access_save_and_swap(bool p_enable);
int get_exit_code() const;
void set_exit_code(int p_code);
Dictionary get_date(bool utc) const; Dictionary get_date(bool utc) const;
Dictionary get_time(bool utc) const; Dictionary get_time(bool utc) const;
Dictionary get_datetime(bool utc) const; Dictionary get_datetime(bool utc) const;

View File

@ -226,11 +226,6 @@ int OS::get_exit_code() const {
void OS::set_exit_code(int p_code) { void OS::set_exit_code(int p_code) {
_exit_code = p_code; _exit_code = p_code;
_is_custom_exit_code = true;
}
bool OS::is_custom_exit_code() {
return _is_custom_exit_code;
} }
String OS::get_locale() const { String OS::get_locale() const {

View File

@ -55,7 +55,6 @@ class OS {
String _local_clipboard; String _local_clipboard;
bool _no_window = false; bool _no_window = false;
int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
bool _is_custom_exit_code = false;
int _orientation; int _orientation;
bool _allow_hidpi = false; bool _allow_hidpi = false;
bool _allow_layered = false; bool _allow_layered = false;
@ -270,7 +269,6 @@ public:
virtual int get_exit_code() const; virtual int get_exit_code() const;
virtual void set_exit_code(int p_code); virtual void set_exit_code(int p_code);
virtual bool is_custom_exit_code();
virtual int get_processor_count() const; virtual int get_processor_count() const;

View File

@ -549,10 +549,6 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="exit_code" type="int" setter="set_exit_code" getter="get_exit_code" default="0">
The exit code passed to the OS when the main loop exits. By convention, an exit code of [code]0[/code] indicates success whereas a non-zero exit code indicates an error. For portability reasons, the exit code should be set between 0 and 125 (inclusive).
[b]Note:[/b] This value will be ignored if using [method SceneTree.quit] with an [code]exit_code[/code] argument passed.
</member>
<member name="low_processor_usage_mode" type="bool" setter="set_low_processor_usage_mode" getter="is_in_low_processor_usage_mode" default="false"> <member name="low_processor_usage_mode" type="bool" setter="set_low_processor_usage_mode" getter="is_in_low_processor_usage_mode" default="false">
If [code]true[/code], the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile. If [code]true[/code], the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.
</member> </member>

View File

@ -181,10 +181,12 @@
<method name="quit"> <method name="quit">
<return type="void"> <return type="void">
</return> </return>
<argument index="0" name="exit_code" type="int" default="-1"> <argument index="0" name="exit_code" type="int" default="0">
</argument> </argument>
<description> <description>
Quits the application at the end of the current iteration. A process [code]exit_code[/code] can optionally be passed as an argument. If this argument is [code]0[/code] or greater, it will override the [member OS.exit_code] defined before quitting the application. Quits the application at the end of the current iteration. Argument [code]exit_code[/code] can optionally be given (defaulting to 0) to customize the exit status code.
By convention, an exit code of [code]0[/code] indicates success whereas a non-zero exit code indicates an error.
For portability reasons, the exit code should be set between 0 and 125 (inclusive).
</description> </description>
</method> </method>
<method name="reload_current_scene"> <method name="reload_current_scene">

View File

@ -1992,7 +1992,7 @@ bool Main::start() {
if (check_only) { if (check_only) {
if (!script_res->is_valid()) { if (!script_res->is_valid()) {
OS::get_singleton()->set_exit_code(1); OS::get_singleton()->set_exit_code(EXIT_FAILURE);
} }
return false; return false;
} }

View File

@ -535,15 +535,7 @@ void SceneTree::finalize() {
} }
void SceneTree::quit(int p_exit_code) { void SceneTree::quit(int p_exit_code) {
if (p_exit_code >= 0) { OS::get_singleton()->set_exit_code(p_exit_code);
// Override the exit code if a positive argument is given (the default is `-1`).
// This is a shorthand for calling `set_exit_code()` on the OS singleton then quitting.
OS::get_singleton()->set_exit_code(p_exit_code);
} else if (!OS::get_singleton()->is_custom_exit_code()) {
// Must customize exit code, otherwise it will default to a non-zero value
OS::get_singleton()->set_exit_code(EXIT_SUCCESS);
}
_quit = true; _quit = true;
} }
@ -1209,7 +1201,7 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count); ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count);
ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame); ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame);
ClassDB::bind_method(D_METHOD("quit", "exit_code"), &SceneTree::quit, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("quit", "exit_code"), &SceneTree::quit, DEFVAL(EXIT_SUCCESS));
ClassDB::bind_method(D_METHOD("queue_delete", "obj"), &SceneTree::queue_delete); ClassDB::bind_method(D_METHOD("queue_delete", "obj"), &SceneTree::queue_delete);

View File

@ -245,7 +245,7 @@ public:
void set_auto_accept_quit(bool p_enable); void set_auto_accept_quit(bool p_enable);
void set_quit_on_go_back(bool p_enable); void set_quit_on_go_back(bool p_enable);
void quit(int p_exit_code = -1); void quit(int p_exit_code = EXIT_SUCCESS);
_FORCE_INLINE_ float get_physics_process_time() const { return physics_process_time; } _FORCE_INLINE_ float get_physics_process_time() const { return physics_process_time; }
_FORCE_INLINE_ float get_process_time() const { return process_time; } _FORCE_INLINE_ float get_process_time() const { return process_time; }