Skip to content

Commit

Permalink
Export function: get_time_scale set_time_scale
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan committed Nov 27, 2024
1 parent 79c844f commit 5085b5b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/extension/gdextension_spx_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ static void gdextension_spx_platform_set_debug_mode(GdBool enable) {
static void gdextension_spx_platform_is_debug_mode(GdBool* ret_val) {
*ret_val = platformMgr->is_debug_mode();
}
static void gdextension_spx_platform_get_time_scale(GdFloat* ret_val) {
*ret_val = platformMgr->get_time_scale();
}
static void gdextension_spx_platform_set_time_scale(GdFloat time_scale) {
platformMgr->set_time_scale(time_scale);
}
static void gdextension_spx_res_set_load_mode(GdBool is_direct_mode) {
resMgr->set_load_mode(is_direct_mode);
}
Expand Down Expand Up @@ -648,6 +654,8 @@ void gdextension_spx_setup_interface() {
REGISTER_SPX_INTERFACE_FUNC(spx_platform_is_window_fullscreen);
REGISTER_SPX_INTERFACE_FUNC(spx_platform_set_debug_mode);
REGISTER_SPX_INTERFACE_FUNC(spx_platform_is_debug_mode);
REGISTER_SPX_INTERFACE_FUNC(spx_platform_get_time_scale);
REGISTER_SPX_INTERFACE_FUNC(spx_platform_set_time_scale);
REGISTER_SPX_INTERFACE_FUNC(spx_res_set_load_mode);
REGISTER_SPX_INTERFACE_FUNC(spx_res_get_load_mode);
REGISTER_SPX_INTERFACE_FUNC(spx_res_get_bound_from_alpha);
Expand Down
2 changes: 2 additions & 0 deletions core/extension/gdextension_spx_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ typedef void (*GDExtensionSpxPlatformSetWindowFullscreen)(GdBool enable);
typedef void (*GDExtensionSpxPlatformIsWindowFullscreen)(GdBool* ret_value);
typedef void (*GDExtensionSpxPlatformSetDebugMode)(GdBool enable);
typedef void (*GDExtensionSpxPlatformIsDebugMode)(GdBool* ret_value);
typedef void (*GDExtensionSpxPlatformGetTimeScale)(GdFloat* ret_value);
typedef void (*GDExtensionSpxPlatformSetTimeScale)(GdFloat time_scale);
// SpxRes
typedef void (*GDExtensionSpxResSetLoadMode)(GdBool is_direct_mode);
typedef void (*GDExtensionSpxResGetLoadMode)(GdBool* ret_value);
Expand Down
12 changes: 10 additions & 2 deletions core/extension/spx_platform_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "spx_platform_mgr.h"
#include "core/config/engine.h"
#include "scene/main/window.h"
#include "spx.h"

Expand Down Expand Up @@ -60,19 +61,26 @@ GdString SpxPlatformMgr::get_window_title() {

void SpxPlatformMgr::set_window_fullscreen(GdBool enable) {
print_line("SpxPlatformMgr::set_window_fullscreen", enable);
auto mode = enable? DisplayServer::WINDOW_MODE_FULLSCREEN : DisplayServer::WINDOW_MODE_WINDOWED;
auto mode = enable ? DisplayServer::WINDOW_MODE_FULLSCREEN : DisplayServer::WINDOW_MODE_WINDOWED;
DisplayServer::get_singleton()->window_set_mode(mode);
}

GdBool SpxPlatformMgr::is_window_fullscreen() {
return get_root()->get_mode() == Window::MODE_FULLSCREEN;
}


void SpxPlatformMgr::set_debug_mode(GdBool enable) {
Spx::debug_mode = enable;
}

GdBool SpxPlatformMgr::is_debug_mode() {
return Spx::debug_mode;
}

void SpxPlatformMgr::set_time_scale(GdFloat time_scale) {
Engine::get_singleton()->set_time_scale(time_scale);
}

GdFloat SpxPlatformMgr::get_time_scale() {
return Engine::get_singleton()->get_time_scale();
}
3 changes: 3 additions & 0 deletions core/extension/spx_platform_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class SpxPlatformMgr : SpxBaseMgr {
GdBool is_window_fullscreen();
void set_debug_mode(GdBool enable);
GdBool is_debug_mode();

GdFloat get_time_scale();
void set_time_scale(GdFloat time_scale);
};

#endif // SPX_OS_MGR_H
8 changes: 8 additions & 0 deletions platform/web/godot_js_spx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ void gdspx_platform_is_debug_mode(GdBool* ret_val) {
*ret_val = platformMgr->is_debug_mode();
}
EMSCRIPTEN_KEEPALIVE
void gdspx_platform_get_time_scale(GdFloat* ret_val) {
*ret_val = platformMgr->get_time_scale();
}
EMSCRIPTEN_KEEPALIVE
void gdspx_platform_set_time_scale(GdFloat* time_scale) {
platformMgr->set_time_scale(*time_scale);
}
EMSCRIPTEN_KEEPALIVE
void gdspx_res_set_load_mode(GdBool* is_direct_mode) {
resMgr->set_load_mode(*is_direct_mode);
}
Expand Down
16 changes: 16 additions & 0 deletions platform/web/js/engine/gdspx.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ function gdspx_platform_is_debug_mode() {
FreeGdBool(_retValue);
return _finalRetValue
}
function gdspx_platform_get_time_scale() {
_gdFuncPtr = GodotEngine.rtenv['_gdspx_platform_get_time_scale'];
_retValue = AllocGdFloat();
_gdFuncPtr(_retValue);
_finalRetValue = ToJsFloat(_retValue);
FreeGdFloat(_retValue);
return _finalRetValue
}
function gdspx_platform_set_time_scale(time_scale) {
_gdFuncPtr = GodotEngine.rtenv['_gdspx_platform_set_time_scale'];

_arg0 = ToGdFloat(time_scale);
_gdFuncPtr(_arg0);
FreeGdFloat(_arg0);

}
function gdspx_res_set_load_mode(is_direct_mode) {
_gdFuncPtr = GodotEngine.rtenv['_gdspx_res_set_load_mode'];

Expand Down

0 comments on commit 5085b5b

Please sign in to comment.