Created new Engine singleton, and moved engine related OS functions to it.

This commit is contained in:
Juan Linietsky 2017-01-13 12:51:14 -03:00
parent 0ad9939603
commit e53c247cb1
17 changed files with 393 additions and 186 deletions

View file

@ -340,24 +340,6 @@ Array _OS::get_fullscreen_mode_list(int p_screen) const {
return vmarr; return vmarr;
} }
void _OS::set_iterations_per_second(int p_ips) {
OS::get_singleton()->set_iterations_per_second(p_ips);
}
int _OS::get_iterations_per_second() const {
return OS::get_singleton()->get_iterations_per_second();
}
void _OS::set_target_fps(int p_fps) {
OS::get_singleton()->set_target_fps(p_fps);
}
float _OS::get_target_fps() const {
return OS::get_singleton()->get_target_fps();
}
void _OS::set_low_processor_usage_mode(bool p_enabled) { void _OS::set_low_processor_usage_mode(bool p_enabled) {
OS::get_singleton()->set_low_processor_usage_mode(p_enabled); OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
@ -452,19 +434,7 @@ String _OS::get_model_name() const {
return OS::get_singleton()->get_model_name(); return OS::get_singleton()->get_model_name();
} }
MainLoop *_OS::get_main_loop() const {
return OS::get_singleton()->get_main_loop();
}
void _OS::set_time_scale(float p_scale) {
OS::get_singleton()->set_time_scale(p_scale);
}
float _OS::get_time_scale() {
return OS::get_singleton()->get_time_scale();
}
bool _OS::is_ok_left_and_cancel_right() const { bool _OS::is_ok_left_and_cancel_right() const {
@ -804,10 +774,6 @@ bool _OS::can_draw() const {
return OS::get_singleton()->can_draw(); return OS::get_singleton()->can_draw();
} }
int _OS::get_frames_drawn() {
return OS::get_singleton()->get_frames_drawn();
}
int _OS::get_processor_count() const { int _OS::get_processor_count() const {
@ -936,11 +902,6 @@ String _OS::get_data_dir() const {
return OS::get_singleton()->get_data_dir(); return OS::get_singleton()->get_data_dir();
}; };
float _OS::get_frames_per_second() const {
return OS::get_singleton()->get_frames_per_second();
}
Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track); return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
@ -1005,10 +966,7 @@ String _OS::get_system_dir(SystemDir p_dir) const {
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir)); return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
} }
String _OS::get_custom_level() const {
return OS::get_singleton()->get_custom_level();
}
String _OS::get_scancode_string(uint32_t p_code) const { String _OS::get_scancode_string(uint32_t p_code) const {
@ -1079,13 +1037,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on); ClassDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
ClassDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on); ClassDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
ClassDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second);
ClassDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second);
ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_OS::set_target_fps);
ClassDB::bind_method(_MD("get_target_fps"),&_OS::get_target_fps);
ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_OS::set_time_scale);
ClassDB::bind_method(_MD("get_time_scale"),&_OS::get_time_scale);
ClassDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint); ClassDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
@ -1107,7 +1058,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(_MD("get_name"),&_OS::get_name); ClassDB::bind_method(_MD("get_name"),&_OS::get_name);
ClassDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args); ClassDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
ClassDB::bind_method(_MD("get_main_loop"),&_OS::get_main_loop);
ClassDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false)); ClassDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
ClassDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false)); ClassDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
@ -1133,10 +1083,8 @@ void _OS::_bind_methods() {
ClassDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant); ClassDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
ClassDB::bind_method(_MD("get_model_name"),&_OS::get_model_name); ClassDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
ClassDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level);
ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw); ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw);
ClassDB::bind_method(_MD("get_frames_drawn"),&_OS::get_frames_drawn);
ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose); ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads); ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
@ -1163,7 +1111,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right); ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
ClassDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
ClassDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size); ClassDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
ClassDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type); ClassDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
@ -2596,3 +2543,128 @@ _ClassDB::~_ClassDB(){
} }
///////////////////////////////
void _Engine::set_iterations_per_second(int p_ips) {
Engine::get_singleton()->set_iterations_per_second(p_ips);
}
int _Engine::get_iterations_per_second() const {
return Engine::get_singleton()->get_iterations_per_second();
}
void _Engine::set_target_fps(int p_fps) {
Engine::get_singleton()->set_target_fps(p_fps);
}
float _Engine::get_target_fps() const {
return Engine::get_singleton()->get_target_fps();
}
float _Engine::get_frames_per_second() const {
return Engine::get_singleton()->get_frames_per_second();
}
String _Engine::get_custom_level() const {
return Engine::get_singleton()->get_custom_level();
}
void _Engine::set_time_scale(float p_scale) {
Engine::get_singleton()->set_time_scale(p_scale);
}
float _Engine::get_time_scale() {
return Engine::get_singleton()->get_time_scale();
}
int _Engine::get_frames_drawn() {
return Engine::get_singleton()->get_frames_drawn();
}
MainLoop *_Engine::get_main_loop() const {
//needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
return OS::get_singleton()->get_main_loop();
}
String _Engine::get_version() const {
return Engine::get_singleton()->get_version();
}
String _Engine::get_version_name() const{
return Engine::get_singleton()->get_version_name();
}
String _Engine::get_version_short_name() const{
return Engine::get_singleton()->get_version_short_name();
}
int _Engine::get_version_major() const{
return Engine::get_singleton()->get_version_major();
}
int _Engine::get_version_minor() const{
return Engine::get_singleton()->get_version_minor();
}
String _Engine::get_version_revision() const{
return Engine::get_singleton()->get_version_revision();
}
String _Engine::get_version_status() const{
return Engine::get_singleton()->get_version_status();
}
int _Engine::get_version_year() const{
return Engine::get_singleton()->get_version_year();
}
void _Engine::_bind_methods() {
ClassDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_Engine::set_iterations_per_second);
ClassDB::bind_method(_MD("get_iterations_per_second"),&_Engine::get_iterations_per_second);
ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_Engine::set_target_fps);
ClassDB::bind_method(_MD("get_target_fps"),&_Engine::get_target_fps);
ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_Engine::set_time_scale);
ClassDB::bind_method(_MD("get_time_scale"),&_Engine::get_time_scale);
ClassDB::bind_method(_MD("get_custom_level"),&_Engine::get_custom_level);
ClassDB::bind_method(_MD("get_frames_drawn"),&_Engine::get_frames_drawn);
ClassDB::bind_method(_MD("get_frames_per_second"),&_Engine::get_frames_per_second);
ClassDB::bind_method(_MD("get_main_loop:MainLoop"),&_Engine::get_main_loop);
ClassDB::bind_method(_MD("get_version"),&_Engine::get_version);
ClassDB::bind_method(_MD("get_version_name"),&_Engine::get_version_name);
ClassDB::bind_method(_MD("get_version_short_name"),&_Engine::get_version_short_name);
ClassDB::bind_method(_MD("get_version_major"),&_Engine::get_version_major);
ClassDB::bind_method(_MD("get_version_minor"),&_Engine::get_version_minor);
ClassDB::bind_method(_MD("get_version_revision"),&_Engine::get_version_revision);
ClassDB::bind_method(_MD("get_version_status"),&_Engine::get_version_status);
ClassDB::bind_method(_MD("get_version_year"),&_Engine::get_version_year);
}
_Engine *_Engine::singleton = NULL;
_Engine::_Engine() {
singleton=this;
}

View file

@ -169,12 +169,6 @@ public:
void native_video_unpause(); void native_video_unpause();
void native_video_stop(); void native_video_stop();
void set_iterations_per_second(int p_ips);
int get_iterations_per_second() const;
void set_target_fps(int p_fps);
float get_target_fps() const;
void set_low_processor_usage_mode(bool p_enabled); void set_low_processor_usage_mode(bool p_enabled);
bool is_in_low_processor_usage_mode() const; bool is_in_low_processor_usage_mode() const;
@ -196,11 +190,7 @@ public:
String get_latin_keyboard_variant() const; String get_latin_keyboard_variant() const;
String get_model_name() const; String get_model_name() const;
MainLoop *get_main_loop() const;
String get_custom_level() const;
float get_frames_per_second() const;
void dump_memory_to_file(const String& p_file); void dump_memory_to_file(const String& p_file);
void dump_resources_to_file(const String& p_file); void dump_resources_to_file(const String& p_file);
@ -271,8 +261,6 @@ public:
bool can_draw() const; bool can_draw() const;
int get_frames_drawn();
bool is_stdout_verbose() const; bool is_stdout_verbose() const;
int get_processor_count() const; int get_processor_count() const;
@ -313,8 +301,6 @@ public:
void set_keep_screen_on(bool p_enabled); void set_keep_screen_on(bool p_enabled);
bool is_keep_screen_on() const; bool is_keep_screen_on() const;
void set_time_scale(float p_scale);
float get_time_scale();
bool is_ok_left_and_cancel_right() const; bool is_ok_left_and_cancel_right() const;
@ -632,4 +618,47 @@ public:
~_ClassDB(); ~_ClassDB();
}; };
class _Engine : public Object {
GDCLASS(_Engine,Object);
protected:
static void _bind_methods();
static _Engine *singleton;
public:
static _Engine* get_singleton() { return singleton; }
void set_iterations_per_second(int p_ips);
int get_iterations_per_second() const;
void set_target_fps(int p_fps);
float get_target_fps() const;
float get_frames_per_second() const;
int get_frames_drawn();
void set_time_scale(float p_scale);
float get_time_scale();
String get_custom_level() const;
MainLoop *get_main_loop() const;
String get_version() const;
String get_version_name() const;
String get_version_short_name() const;
int get_version_major() const;
int get_version_minor() const;
String get_version_revision() const;
String get_version_status() const;
int get_version_year() const;
_Engine();
};
#endif // CORE_BIND_H #endif // CORE_BIND_H

102
core/engine.cpp Normal file
View file

@ -0,0 +1,102 @@
#include "engine.h"
#include "version.h"
void Engine::set_iterations_per_second(int p_ips) {
ips=p_ips;
}
int Engine::get_iterations_per_second() const {
return ips;
}
void Engine::set_target_fps(int p_fps) {
_target_fps=p_fps>0? p_fps : 0;
}
float Engine::get_target_fps() const {
return _target_fps;
}
uint64_t Engine::get_frames_drawn() {
return frames_drawn;
}
void Engine::set_frame_delay(uint32_t p_msec) {
_frame_delay=p_msec;
}
uint32_t Engine::get_frame_delay() const {
return _frame_delay;
}
void Engine::set_time_scale(float p_scale) {
_time_scale=p_scale;
}
float Engine::get_time_scale() const {
return _time_scale;
}
String Engine::get_version() const {
return VERSION_FULL_NAME;
}
String Engine::get_version_name() const{
return _MKSTR(VERSION_NAME);
}
String Engine::get_version_short_name() const{
return _MKSTR(VERSION_SHORT_NAME);
}
int Engine::get_version_major() const{
return VERSION_MAJOR;
}
int Engine::get_version_minor() const{
return VERSION_MINOR;
}
String Engine::get_version_revision() const{
return _MKSTR(VERSION_REVISION);
}
String Engine::get_version_status() const{
return _MKSTR(VERSION_STATUS);
}
int Engine::get_version_year() const{
return VERSION_YEAR;
}
Engine *Engine::singleton=NULL;
Engine *Engine::get_singleton() {
return singleton;
}
Engine::Engine()
{
singleton=this;
frames_drawn=0;
ips=60;
_frame_delay=0;
_fps=1;
_target_fps=0;
_time_scale=1.0;
_pixel_snap=false;
_fixed_frames=0;
_idle_frames=0;
_in_fixed=false;
}

67
core/engine.h Normal file
View file

@ -0,0 +1,67 @@
#ifndef ENGINE_H
#define ENGINE_H
#include "ustring.h"
#include "list.h"
#include "vector.h"
#include "os/main_loop.h"
class Engine {
friend class Main;
String _custom_level;
uint64_t frames_drawn;
uint32_t _frame_delay;
int ips;
float _fps;
int _target_fps;
float _time_scale;
bool _pixel_snap;
uint64_t _fixed_frames;
uint64_t _idle_frames;
bool _in_fixed;
static Engine *singleton;
public:
static Engine *get_singleton();
virtual void set_iterations_per_second(int p_ips);
virtual int get_iterations_per_second() const;
virtual void set_target_fps(int p_fps);
virtual float get_target_fps() const;
virtual float get_frames_per_second() const { return _fps; }
String get_custom_level() const { return _custom_level; }
uint64_t get_frames_drawn();
uint64_t get_fixed_frames() const { return _fixed_frames; }
uint64_t get_idle_frames() const { return _idle_frames; }
bool is_in_fixed_frame() const { return _in_fixed; }
void set_time_scale(float p_scale);
float get_time_scale() const;
void set_frame_delay(uint32_t p_msec);
uint32_t get_frame_delay() const;
_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
String get_version() const;
String get_version_name() const;
String get_version_short_name() const;
int get_version_major() const;
int get_version_minor() const;
String get_version_revision() const;
String get_version_status() const;
int get_version_year() const;
Engine();
};
#endif // ENGINE_H

View file

@ -98,23 +98,6 @@ void OS::printerr(const char* p_format, ...) {
}; };
void OS::set_iterations_per_second(int p_ips) {
ips=p_ips;
}
int OS::get_iterations_per_second() const {
return ips;
}
void OS::set_target_fps(int p_fps) {
_target_fps=p_fps>0? p_fps : 0;
}
float OS::get_target_fps() const {
return _target_fps;
}
void OS::set_keep_screen_on(bool p_enabled) { void OS::set_keep_screen_on(bool p_enabled) {
_keep_screen_on=p_enabled; _keep_screen_on=p_enabled;
} }
@ -152,10 +135,6 @@ int OS::get_process_ID() const {
return -1; return -1;
}; };
uint64_t OS::get_frames_drawn() {
return frames_drawn;
}
bool OS::is_stdout_verbose() const { bool OS::is_stdout_verbose() const {
@ -261,15 +240,7 @@ void OS::clear_last_error() {
memfree(last_error); memfree(last_error);
last_error=NULL; last_error=NULL;
} }
void OS::set_frame_delay(uint32_t p_msec) {
_frame_delay=p_msec;
}
uint32_t OS::get_frame_delay() const {
return _frame_delay;
}
void OS::set_no_window_mode(bool p_enable) { void OS::set_no_window_mode(bool p_enable) {
@ -513,20 +484,13 @@ OS::MouseMode OS::get_mouse_mode() const{
return MOUSE_MODE_VISIBLE; return MOUSE_MODE_VISIBLE;
} }
void OS::set_time_scale(float p_scale) {
_time_scale=p_scale;
}
OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const { OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const {
return LATIN_KEYBOARD_QWERTY; return LATIN_KEYBOARD_QWERTY;
} }
float OS::get_time_scale() const {
return _time_scale;
}
bool OS::is_joy_known(int p_device) { bool OS::is_joy_known(int p_device) {
return true; return true;
@ -572,25 +536,18 @@ Dictionary OS::get_engine_version() const {
OS::OS() { OS::OS() {
last_error=NULL; last_error=NULL;
frames_drawn=0;
singleton=this; singleton=this;
ips=60;
_keep_screen_on=true; // set default value to true, because this had been true before godot 2.0. _keep_screen_on=true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode=false; low_processor_usage_mode=false;
_verbose_stdout=false; _verbose_stdout=false;
_frame_delay=0;
_no_window=false; _no_window=false;
_exit_code=0; _exit_code=0;
_orientation=SCREEN_LANDSCAPE; _orientation=SCREEN_LANDSCAPE;
_fps=1;
_target_fps=0;
_render_thread_mode=RENDER_THREAD_SAFE; _render_thread_mode=RENDER_THREAD_SAFE;
_time_scale=1.0;
_pixel_snap=false;
_allow_hidpi=true; _allow_hidpi=true;
_fixed_frames=0;
_idle_frames=0;
_in_fixed=false;
Math::seed(1234567); Math::seed(1234567);
} }

View file

@ -32,6 +32,7 @@
#include "ustring.h" #include "ustring.h"
#include "list.h" #include "list.h"
#include "vector.h" #include "vector.h"
#include "engine.h"
#include "os/main_loop.h" #include "os/main_loop.h"
#include <stdarg.h> #include <stdarg.h>
@ -43,28 +44,17 @@ class OS {
static OS* singleton; static OS* singleton;
String _execpath; String _execpath;
String _custom_level;
List<String> _cmdline; List<String> _cmdline;
int ips;
bool _keep_screen_on; bool _keep_screen_on;
bool low_processor_usage_mode; bool low_processor_usage_mode;
bool _verbose_stdout; bool _verbose_stdout;
String _local_clipboard; String _local_clipboard;
uint64_t frames_drawn;
uint32_t _frame_delay;
uint64_t _msec_splash; uint64_t _msec_splash;
bool _no_window; bool _no_window;
int _exit_code; int _exit_code;
int _orientation; int _orientation;
float _fps;
int _target_fps;
float _time_scale;
bool _pixel_snap;
bool _allow_hidpi; bool _allow_hidpi;
uint64_t _fixed_frames;
uint64_t _idle_frames;
bool _in_fixed;
char *last_error; char *last_error;
@ -185,15 +175,6 @@ public:
virtual bool get_borderless_window() { return 0; } virtual bool get_borderless_window() { return 0; }
virtual void set_iterations_per_second(int p_ips);
virtual int get_iterations_per_second() const;
virtual void set_target_fps(int p_fps);
virtual float get_target_fps() const;
virtual float get_frames_per_second() const { return _fps; }
virtual void set_keep_screen_on(bool p_enabled); virtual void set_keep_screen_on(bool p_enabled);
virtual bool is_keep_screen_on() const; virtual bool is_keep_screen_on() const;
virtual void set_low_processor_usage_mode(bool p_enabled); virtual void set_low_processor_usage_mode(bool p_enabled);
@ -217,7 +198,6 @@ public:
virtual MainLoop *get_main_loop() const=0; virtual MainLoop *get_main_loop() const=0;
String get_custom_level() const { return _custom_level; }
virtual void yield(); virtual void yield();
@ -280,17 +260,9 @@ public:
uint32_t get_ticks_msec() const; uint32_t get_ticks_msec() const;
uint64_t get_splash_tick_msec() const; uint64_t get_splash_tick_msec() const;
void set_frame_delay(uint32_t p_msec);
uint32_t get_frame_delay() const;
virtual bool can_draw() const = 0; virtual bool can_draw() const = 0;
uint64_t get_frames_drawn();
uint64_t get_fixed_frames() const { return _fixed_frames; }
uint64_t get_idle_frames() const { return _idle_frames; }
bool is_in_fixed_frame() const { return _in_fixed; }
bool is_stdout_verbose() const; bool is_stdout_verbose() const;
enum CursorShape { enum CursorShape {
@ -416,10 +388,6 @@ public:
virtual LatinKeyboardVariant get_latin_keyboard_variant() const; virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
void set_time_scale(float p_scale);
float get_time_scale() const;
_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
virtual bool is_joy_known(int p_device); virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device)const; virtual String get_joy_guid(int p_device)const;

View file

@ -62,6 +62,7 @@ static ResourceFormatLoaderBinary *resource_loader_binary=NULL;
static _ResourceLoader *_resource_loader=NULL; static _ResourceLoader *_resource_loader=NULL;
static _ResourceSaver *_resource_saver=NULL; static _ResourceSaver *_resource_saver=NULL;
static _OS *_os=NULL; static _OS *_os=NULL;
static _Engine *_engine=NULL;
static _ClassDB *_classdb=NULL; static _ClassDB *_classdb=NULL;
static _Marshalls *_marshalls = NULL; static _Marshalls *_marshalls = NULL;
static TranslationLoaderPO *resource_format_po=NULL; static TranslationLoaderPO *resource_format_po=NULL;
@ -156,6 +157,7 @@ void register_core_types() {
_resource_loader=memnew(_ResourceLoader); _resource_loader=memnew(_ResourceLoader);
_resource_saver=memnew(_ResourceSaver); _resource_saver=memnew(_ResourceSaver);
_os=memnew(_OS); _os=memnew(_OS);
_engine=memnew(_Engine);
_classdb=memnew(_ClassDB); _classdb=memnew(_ClassDB);
_marshalls = memnew(_Marshalls); _marshalls = memnew(_Marshalls);
@ -179,6 +181,7 @@ void register_core_singletons() {
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Engine",_Engine::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Marshalls",_Marshalls::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Marshalls",_Marshalls::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TranslationServer",TranslationServer::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TranslationServer",TranslationServer::get_singleton() ) );
@ -196,6 +199,7 @@ void unregister_core_types() {
memdelete( _resource_loader ); memdelete( _resource_loader );
memdelete( _resource_saver ); memdelete( _resource_saver );
memdelete( _os); memdelete( _os);
memdelete( _engine );
memdelete( _classdb ); memdelete( _classdb );
memdelete( _marshalls ); memdelete( _marshalls );

View file

@ -778,7 +778,7 @@ void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
} }
packet_peer_stream->put_var(OS::get_singleton()->get_frames_drawn()); //total frame time packet_peer_stream->put_var(Engine::get_singleton()->get_frames_drawn()); //total frame time
packet_peer_stream->put_var(frame_time); //total frame time packet_peer_stream->put_var(frame_time); //total frame time
packet_peer_stream->put_var(idle_time); //idle frame time packet_peer_stream->put_var(idle_time); //idle frame time
packet_peer_stream->put_var(fixed_time); //fixed frame time packet_peer_stream->put_var(fixed_time); //fixed frame time

View file

@ -158,10 +158,10 @@ bool InputDefault::is_action_just_pressed(const StringName& p_action) const {
if (!E) if (!E)
return false; return false;
if (OS::get_singleton()->is_in_fixed_frame()) { if (Engine::get_singleton()->is_in_fixed_frame()) {
return E->get().pressed && E->get().fixed_frame==OS::get_singleton()->get_fixed_frames(); return E->get().pressed && E->get().fixed_frame==Engine::get_singleton()->get_fixed_frames();
} else { } else {
return E->get().pressed && E->get().idle_frame==OS::get_singleton()->get_idle_frames(); return E->get().pressed && E->get().idle_frame==Engine::get_singleton()->get_idle_frames();
} }
} }
@ -171,10 +171,10 @@ bool InputDefault::is_action_just_released(const StringName& p_action) const{
if (!E) if (!E)
return false; return false;
if (OS::get_singleton()->is_in_fixed_frame()) { if (Engine::get_singleton()->is_in_fixed_frame()) {
return !E->get().pressed && E->get().fixed_frame==OS::get_singleton()->get_fixed_frames(); return !E->get().pressed && E->get().fixed_frame==Engine::get_singleton()->get_fixed_frames();
} else { } else {
return !E->get().pressed && E->get().idle_frame==OS::get_singleton()->get_idle_frames(); return !E->get().pressed && E->get().idle_frame==Engine::get_singleton()->get_idle_frames();
} }
} }
@ -379,8 +379,8 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
if(is_action_pressed(E->key()) != p_event.is_pressed()) { if(is_action_pressed(E->key()) != p_event.is_pressed()) {
Action action; Action action;
action.fixed_frame=OS::get_singleton()->get_fixed_frames(); action.fixed_frame=Engine::get_singleton()->get_fixed_frames();
action.idle_frame=OS::get_singleton()->get_idle_frames(); action.idle_frame=Engine::get_singleton()->get_idle_frames();
action.pressed=p_event.is_pressed(); action.pressed=p_event.is_pressed();
action_state[E->key()]=action; action_state[E->key()]=action;
} }
@ -490,8 +490,8 @@ void InputDefault::action_press(const StringName& p_action) {
Action action; Action action;
action.fixed_frame=OS::get_singleton()->get_fixed_frames(); action.fixed_frame=Engine::get_singleton()->get_fixed_frames();
action.idle_frame=OS::get_singleton()->get_idle_frames(); action.idle_frame=Engine::get_singleton()->get_idle_frames();
action.pressed=true; action.pressed=true;
action_state[p_action]=action; action_state[p_action]=action;
@ -502,8 +502,8 @@ void InputDefault::action_release(const StringName& p_action){
Action action; Action action;
action.fixed_frame=OS::get_singleton()->get_fixed_frames(); action.fixed_frame=Engine::get_singleton()->get_fixed_frames();
action.idle_frame=OS::get_singleton()->get_idle_frames(); action.idle_frame=Engine::get_singleton()->get_idle_frames();
action.pressed=false; action.pressed=false;
action_state[p_action]=action; action_state[p_action]=action;

View file

@ -79,6 +79,7 @@
#include "performance.h" #include "performance.h"
static GlobalConfig *globals=NULL; static GlobalConfig *globals=NULL;
static Engine *engine=NULL;
static InputMap *input_map=NULL; static InputMap *input_map=NULL;
static bool _start_success=false; static bool _start_success=false;
static ScriptDebugger *script_debugger=NULL; static ScriptDebugger *script_debugger=NULL;
@ -195,6 +196,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
RID_OwnerBase::init_rid(); RID_OwnerBase::init_rid();
OS::get_singleton()->initialize_core(); OS::get_singleton()->initialize_core();
engine = memnew( Engine );
ClassDB::init(); ClassDB::init();
MAIN_PRINT("Main: Initialize CORE"); MAIN_PRINT("Main: Initialize CORE");
@ -499,7 +503,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
if (I->next()) { if (I->next()) {
OS::get_singleton()->set_time_scale(I->next()->get().to_double()); Engine::get_singleton()->set_time_scale(I->next()->get().to_double());
N=I->next()->next(); N=I->next()->next();
} else { } else {
goto error; goto error;
@ -742,7 +746,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
use_vsync = GLOBAL_DEF("display/window/use_vsync", use_vsync); use_vsync = GLOBAL_DEF("display/window/use_vsync", use_vsync);
GLOBAL_DEF("display/window/test_width",0); GLOBAL_DEF("display/window/test_width",0);
GLOBAL_DEF("display/window/test_height",0); GLOBAL_DEF("display/window/test_height",0);
OS::get_singleton()->_pixel_snap=GLOBAL_DEF("rendering/2d/use_pixel_snap",false); Engine::get_singleton()->_pixel_snap=GLOBAL_DEF("rendering/2d/use_pixel_snap",false);
OS::get_singleton()->_keep_screen_on=GLOBAL_DEF("display/energy_saving/keep_screen_on",true); OS::get_singleton()->_keep_screen_on=GLOBAL_DEF("display/energy_saving/keep_screen_on",true);
if (rtm==-1) { if (rtm==-1) {
rtm=GLOBAL_DEF("rendering/threads/thread_model",OS::RENDER_THREAD_SAFE); rtm=GLOBAL_DEF("rendering/threads/thread_model",OS::RENDER_THREAD_SAFE);
@ -819,8 +823,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} }
OS::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/fixed_fps",60)); Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/fixed_fps",60));
OS::get_singleton()->set_target_fps(GLOBAL_DEF("debug/fps/force_fps",0)); Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/fps/force_fps",0));
GLOBAL_DEF("debug/stdout/print_fps", OS::get_singleton()->is_stdout_verbose()); GLOBAL_DEF("debug/stdout/print_fps", OS::get_singleton()->is_stdout_verbose());
@ -831,7 +835,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
frame_delay=GLOBAL_DEF("application/frame_delay_msec",0); frame_delay=GLOBAL_DEF("application/frame_delay_msec",0);
} }
OS::get_singleton()->set_frame_delay(frame_delay); Engine::get_singleton()->set_frame_delay(frame_delay);
message_queue = memnew( MessageQueue ); message_queue = memnew( MessageQueue );
@ -862,6 +866,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
memdelete( translation_server ); memdelete( translation_server );
if (globals) if (globals)
memdelete(globals); memdelete(globals);
if (engine)
memdelete(engine);
if (script_debugger) if (script_debugger)
memdelete(script_debugger); memdelete(script_debugger);
if (packed_data) if (packed_data)
@ -1096,7 +1102,7 @@ bool Main::start() {
} else if (args[i]=="-script" || args[i]=="-s") { } else if (args[i]=="-script" || args[i]=="-s") {
script=args[i+1]; script=args[i+1];
} else if (args[i]=="-level" || args[i]=="-l") { } else if (args[i]=="-level" || args[i]=="-l") {
OS::get_singleton()->_custom_level=args[i+1]; Engine::get_singleton()->_custom_level=args[i+1];
} else if (args[i]=="-test") { } else if (args[i]=="-test") {
test=args[i+1]; test=args[i+1];
} else if (args[i]=="-optimize") { } else if (args[i]=="-optimize") {
@ -1579,7 +1585,7 @@ bool Main::iteration() {
uint64_t ticks_elapsed=ticks-last_ticks; uint64_t ticks_elapsed=ticks-last_ticks;
double step=(double)ticks_elapsed / 1000000.0; double step=(double)ticks_elapsed / 1000000.0;
float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second(); float frame_slice=1.0/Engine::get_singleton()->get_iterations_per_second();
// if (time_accum+step < frame_slice) // if (time_accum+step < frame_slice)
// return false; // return false;
@ -1597,13 +1603,13 @@ bool Main::iteration() {
time_accum+=step; time_accum+=step;
float time_scale = OS::get_singleton()->get_time_scale(); float time_scale = Engine::get_singleton()->get_time_scale();
bool exit=false; bool exit=false;
int iters = 0; int iters = 0;
OS::get_singleton()->_in_fixed=true; Engine::get_singleton()->_in_fixed=true;
while(time_accum>frame_slice) { while(time_accum>frame_slice) {
@ -1635,10 +1641,10 @@ bool Main::iteration() {
fixed_process_ticks=MAX(fixed_process_ticks,OS::get_singleton()->get_ticks_usec()-fixed_begin); // keep the largest one for reference fixed_process_ticks=MAX(fixed_process_ticks,OS::get_singleton()->get_ticks_usec()-fixed_begin); // keep the largest one for reference
fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max); fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max);
iters++; iters++;
OS::get_singleton()->_fixed_frames++; Engine::get_singleton()->_fixed_frames++;
} }
OS::get_singleton()->_in_fixed=false; Engine::get_singleton()->_in_fixed=false;
uint64_t idle_begin = OS::get_singleton()->get_ticks_usec(); uint64_t idle_begin = OS::get_singleton()->get_ticks_usec();
@ -1658,11 +1664,11 @@ bool Main::iteration() {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) { if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
if (VisualServer::get_singleton()->has_changed()) { if (VisualServer::get_singleton()->has_changed()) {
VisualServer::get_singleton()->draw(); // flush visual commands VisualServer::get_singleton()->draw(); // flush visual commands
OS::get_singleton()->frames_drawn++; Engine::get_singleton()->frames_drawn++;
} }
} else { } else {
VisualServer::get_singleton()->draw(); // flush visual commands VisualServer::get_singleton()->draw(); // flush visual commands
OS::get_singleton()->frames_drawn++; Engine::get_singleton()->frames_drawn++;
force_redraw_requested = false; force_redraw_requested = false;
} }
} }
@ -1688,7 +1694,7 @@ bool Main::iteration() {
// x11_delay_usec(10000); // x11_delay_usec(10000);
frames++; frames++;
OS::get_singleton()->_idle_frames++; Engine::get_singleton()->_idle_frames++;
if (frame>1000000) { if (frame>1000000) {
@ -1696,7 +1702,7 @@ bool Main::iteration() {
print_line("FPS: "+itos(frames)); print_line("FPS: "+itos(frames));
}; };
OS::get_singleton()->_fps=frames; Engine::get_singleton()->_fps=frames;
performance->set_process_time(USEC_TO_SEC(idle_process_max)); performance->set_process_time(USEC_TO_SEC(idle_process_max));
performance->set_fixed_process_time(USEC_TO_SEC(fixed_process_max)); performance->set_fixed_process_time(USEC_TO_SEC(fixed_process_max));
idle_process_max=0; idle_process_max=0;
@ -1710,12 +1716,12 @@ bool Main::iteration() {
if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw()) if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw())
OS::get_singleton()->delay_usec(16600); //apply some delay to force idle time (results in about 60 FPS max) OS::get_singleton()->delay_usec(16600); //apply some delay to force idle time (results in about 60 FPS max)
else { else {
uint32_t frame_delay = OS::get_singleton()->get_frame_delay(); uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
if (frame_delay) if (frame_delay)
OS::get_singleton()->delay_usec( OS::get_singleton()->get_frame_delay()*1000 ); OS::get_singleton()->delay_usec( Engine::get_singleton()->get_frame_delay()*1000 );
} }
int target_fps = OS::get_singleton()->get_target_fps(); int target_fps = Engine::get_singleton()->get_target_fps();
if (target_fps>0) { if (target_fps>0) {
uint64_t time_step = 1000000L/target_fps; uint64_t time_step = 1000000L/target_fps;
target_ticks += time_step; target_ticks += time_step;
@ -1777,6 +1783,8 @@ void Main::cleanup() {
memdelete(path_remap); memdelete(path_remap);
if (globals) if (globals)
memdelete(globals); memdelete(globals);
if (engine)
memdelete(engine);

View file

@ -118,7 +118,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
float Performance::get_monitor(Monitor p_monitor) const { float Performance::get_monitor(Monitor p_monitor) const {
switch(p_monitor) { switch(p_monitor) {
case TIME_FPS: return OS::get_singleton()->get_frames_per_second(); case TIME_FPS: return Engine::get_singleton()->get_frames_per_second();
case TIME_PROCESS: return _process_time; case TIME_PROCESS: return _process_time;
case TIME_FIXED_PROCESS: return _fixed_process_time; case TIME_FIXED_PROCESS: return _fixed_process_time;
case MEMORY_STATIC: return Memory::get_mem_usage(); case MEMORY_STATIC: return Memory::get_mem_usage();

View file

@ -417,7 +417,7 @@ void AnimatedSprite::_notification(int p_what) {
if (centered) if (centered)
ofs-=s/2; ofs-=s/2;
if (OS::get_singleton()->get_use_pixel_snap()) { if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs=ofs.floor(); ofs=ofs.floor();
} }
Rect2 dst_rect(ofs,s); Rect2 dst_rect(ofs,s);

View file

@ -86,7 +86,7 @@ void Sprite::_notification(int p_what) {
Point2 ofs=offset; Point2 ofs=offset;
if (centered) if (centered)
ofs-=s/2; ofs-=s/2;
if (OS::get_singleton()->get_use_pixel_snap()) { if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs=ofs.floor(); ofs=ofs.floor();
} }

View file

@ -1883,7 +1883,7 @@ void Control::show_modal(bool p_exclusive) {
raise(); raise();
data.modal_exclusive=p_exclusive; data.modal_exclusive=p_exclusive;
data.MI=get_viewport()->_gui_show_modal(this); data.MI=get_viewport()->_gui_show_modal(this);
data.modal_frame=OS::get_singleton()->get_frames_drawn(); data.modal_frame=Engine::get_singleton()->get_frames_drawn();
} }

View file

@ -1830,7 +1830,7 @@ void Viewport::_gui_input_event(InputEvent p_event) {
Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos);
if (!top->has_point(pos)) { if (!top->has_point(pos)) {
if (top->data.modal_exclusive || top->data.modal_frame==OS::get_singleton()->get_frames_drawn()) { if (top->data.modal_exclusive || top->data.modal_frame==Engine::get_singleton()->get_frames_drawn()) {
//cancel event, sorry, modal exclusive EATS UP ALL //cancel event, sorry, modal exclusive EATS UP ALL
//alternative, you can't pop out a window the same frame it was made modal (fixes many issues) //alternative, you can't pop out a window the same frame it was made modal (fixes many issues)
get_tree()->set_input_as_handled(); get_tree()->set_input_as_handled();

View file

@ -3289,14 +3289,14 @@ bool AnimationKeyEditor::has_keying() const {
void AnimationKeyEditor::_query_insert(const InsertData& p_id) { void AnimationKeyEditor::_query_insert(const InsertData& p_id) {
if (insert_frame!=OS::get_singleton()->get_frames_drawn()) { if (insert_frame!=Engine::get_singleton()->get_frames_drawn()) {
//clear insert list for the frame if frame changed //clear insert list for the frame if frame changed
if (insert_confirm->is_visible_in_tree()) if (insert_confirm->is_visible_in_tree())
return; //do nothing return; //do nothing
insert_data.clear(); insert_data.clear();
insert_query=false; insert_query=false;
} }
insert_frame=OS::get_singleton()->get_frames_drawn(); insert_frame=Engine::get_singleton()->get_frames_drawn();
for (List<InsertData>::Element *E=insert_data.front();E;E=E->next()) { for (List<InsertData>::Element *E=insert_data.front();E;E=E->next()) {
//prevent insertion of multiple tracks //prevent insertion of multiple tracks

View file

@ -258,7 +258,7 @@ void EditorNode::_notification(int p_what) {
//get_root_node()->set_rect(viewport->get_global_rect()); //get_root_node()->set_rect(viewport->get_global_rect());
//update the circle //update the circle
uint64_t frame = OS::get_singleton()->get_frames_drawn(); uint64_t frame = Engine::get_singleton()->get_frames_drawn();
uint32_t tick = OS::get_singleton()->get_ticks_msec(); uint32_t tick = OS::get_singleton()->get_ticks_msec();
if (frame!=circle_step_frame && (tick-circle_step_msec)>(1000/8)) { if (frame!=circle_step_frame && (tick-circle_step_msec)>(1000/8)) {
@ -6614,7 +6614,7 @@ EditorNode::EditorNode() {
circle_step_msec=OS::get_singleton()->get_ticks_msec(); circle_step_msec=OS::get_singleton()->get_ticks_msec();
circle_step_frame=OS::get_singleton()->get_frames_drawn(); circle_step_frame=Engine::get_singleton()->get_frames_drawn();
circle_step=0; circle_step=0;
_rebuild_import_menu(); _rebuild_import_menu();