Skip to content

Commit

Permalink
Merge pull request godotengine#30 from JiepengTan/spx4.2.2
Browse files Browse the repository at this point in the history
Fix dynamic animation mode
  • Loading branch information
JiepengTan authored Dec 12, 2024
2 parents 988c544 + fce7bcd commit 5e11488
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/extension/gdextension_spx_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ static void gdextension_spx_platform_get_time_scale(GdFloat* ret_val) {
static void gdextension_spx_platform_set_time_scale(GdFloat time_scale) {
platformMgr->set_time_scale(time_scale);
}
static void gdextension_spx_res_create_animation(GdString sprite_type_name,GdString anim_name,GdString context,GdInt fps,GdBool is_altas,GdInt* ret_val) {
*ret_val = resMgr->create_animation(sprite_type_name, anim_name, context, fps, is_altas);
static void gdextension_spx_res_create_animation(GdString sprite_type_name,GdString anim_name,GdString context,GdInt fps,GdBool is_altas) {
resMgr->create_animation(sprite_type_name, anim_name, context, fps, is_altas);
}
static void gdextension_spx_res_set_load_mode(GdBool is_direct_mode) {
resMgr->set_load_mode(is_direct_mode);
Expand Down
2 changes: 1 addition & 1 deletion core/extension/gdextension_spx_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ typedef void (*GDExtensionSpxPlatformIsDebugMode)(GdBool* ret_value);
typedef void (*GDExtensionSpxPlatformGetTimeScale)(GdFloat* ret_value);
typedef void (*GDExtensionSpxPlatformSetTimeScale)(GdFloat time_scale);
// SpxRes
typedef void (*GDExtensionSpxResCreateAnimation)(GdString sprite_type_name,GdString anim_name, GdString context, GdInt fps, GdBool is_altas, GdInt* ret_value);
typedef void (*GDExtensionSpxResCreateAnimation)(GdString sprite_type_name,GdString anim_name, GdString context, GdInt fps, GdBool is_altas);
typedef void (*GDExtensionSpxResSetLoadMode)(GdBool is_direct_mode);
typedef void (*GDExtensionSpxResGetLoadMode)(GdBool* ret_value);
typedef void (*GDExtensionSpxResGetBoundFromAlpha)(GdString p_path, GdRect2* ret_value);
Expand Down
13 changes: 6 additions & 7 deletions core/extension/spx_res_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ String SpxResMgr::get_anim_key_name(const String &sprite_type_name, const String
return sprite_type_name + "::" + anim_name;
}

GdInt SpxResMgr::create_animation(GdString p_sprite_type_name, GdString p_anim_name, GdString p_context,GdInt fps, GdBool is_altas) {
void SpxResMgr::create_animation(GdString p_sprite_type_name, GdString p_anim_name, GdString p_context,GdInt fps, GdBool is_altas) {
is_dynamic_anim = true;
auto sprite_type_name = SpxStr(p_sprite_type_name);
auto clip_name = SpxStr(p_anim_name);
Expand All @@ -169,7 +169,7 @@ GdInt SpxResMgr::create_animation(GdString p_sprite_type_name, GdString p_anim_n
auto frames = anim_frames;
if (frames->has_animation(anim_key)) {
print_error("animation is already exist " + sprite_type_name + " " + clip_name);
return 1;
return ;
}
frames->add_animation(anim_key);
frames->set_animation_speed(anim_key,fps);
Expand All @@ -179,28 +179,28 @@ GdInt SpxResMgr::create_animation(GdString p_sprite_type_name, GdString p_anim_n
Ref<Texture2D> texture = load_texture(path);
if (!texture.is_valid()) {
print_error("animation parse error" + sprite_type_name + " " + anim_key + " can not find path " + path);
return 1;
return ;
}
frames->add_frame(anim_key, texture);
}
} else {
auto strs = context.split(";");
if (strs.size() < 2) {
print_error("create_animation context error missing \";\"? : " + context);
return 1;
return ;
}
auto path = strs[0];
Ref<Texture2D> altas_texture = load_texture(path);
if (!altas_texture.is_valid()) {
print_error("animation parse error" + sprite_type_name + " " + anim_key + " can not find path " + path);
return 1;
return ;
}

auto paramStrs = strs[1].split(",");

if (paramStrs.size() % 4 != 0) {
print_error("create_animation context error, params count % 4 != 0: " + context +" size = "+ paramStrs.size() );
return 1;
return ;
}
Vector<double> params;
for (const String &str : paramStrs) {
Expand All @@ -219,7 +219,6 @@ GdInt SpxResMgr::create_animation(GdString p_sprite_type_name, GdString p_anim_n
frames->add_frame(anim_key, texture);
}
}
return 0;
}
void SpxResMgr::set_load_mode(GdBool is_direct_mode) {
is_load_direct = is_direct_mode;
Expand Down
2 changes: 1 addition & 1 deletion core/extension/spx_res_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SpxResMgr : SpxBaseMgr {
bool is_dynamic_anim_mode() const;

public:
GdInt create_animation(GdString sprite_type_name,GdString anim_name, GdString context, GdInt fps, GdBool is_altas);
void create_animation(GdString sprite_type_name,GdString anim_name, GdString context, GdInt fps, GdBool is_altas);

void set_load_mode(GdBool is_direct_mode);
GdBool get_load_mode();
Expand Down
5 changes: 2 additions & 3 deletions core/extension/spx_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ void SpxSprite::_draw() {
void SpxSprite::on_start() {
collider2d = (get_component<CollisionShape2D>());
anim2d = (get_component<AnimatedSprite2D>());
if (resMgr->is_dynamic_anim_mode()) {
default_sprite_frames = anim2d->get_sprite_frames();
if(default_sprite_frames.is_null() || resMgr->is_dynamic_anim_mode()) {
default_sprite_frames.instantiate();
anim2d->set_sprite_frames(default_sprite_frames);
}else {
default_sprite_frames = anim2d->get_sprite_frames();
}

visible_notifier = (get_component<VisibleOnScreenNotifier2D>());
Expand Down
4 changes: 2 additions & 2 deletions platform/web/godot_js_spx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ void gdspx_platform_set_time_scale(GdFloat* time_scale) {
platformMgr->set_time_scale(*time_scale);
}
EMSCRIPTEN_KEEPALIVE
void gdspx_res_create_animation(GdString* sprite_type_name,GdString* anim_name,GdString* context,GdInt* fps,GdBool* is_altas,GdInt* ret_val) {
*ret_val = resMgr->create_animation(*sprite_type_name, *anim_name, *context, *fps, *is_altas);
void gdspx_res_create_animation(GdString* sprite_type_name,GdString* anim_name,GdString* context,GdInt* fps,GdBool* is_altas) {
resMgr->create_animation(*sprite_type_name, *anim_name, *context, *fps, *is_altas);
}
EMSCRIPTEN_KEEPALIVE
void gdspx_res_set_load_mode(GdBool* is_direct_mode) {
Expand Down
8 changes: 3 additions & 5 deletions platform/web/js/engine/gdspx.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,19 @@ function gdspx_platform_set_time_scale(time_scale) {
}
function gdspx_res_create_animation(sprite_type_name,anim_name,context,fps,is_altas) {
_gdFuncPtr = GodotEngine.rtenv['_gdspx_res_create_animation'];
_retValue = AllocGdInt();

_arg0 = ToGdString(sprite_type_name);
_arg1 = ToGdString(anim_name);
_arg2 = ToGdString(context);
_arg3 = ToGdInt(fps);
_arg4 = ToGdBool(is_altas);
_gdFuncPtr(_arg0, _arg1, _arg2, _arg3, _arg4, _retValue);
_gdFuncPtr(_arg0, _arg1, _arg2, _arg3, _arg4);
FreeGdString(_arg0);
FreeGdString(_arg1);
FreeGdString(_arg2);
FreeGdInt(_arg3);
FreeGdBool(_arg4);
_finalRetValue = ToJsInt(_retValue);
FreeGdInt(_retValue);
return _finalRetValue

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

0 comments on commit 5e11488

Please sign in to comment.