mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-09-10 12:02:53 +02:00
Fix setting animated bitmap FPS from Ruby
This commit is contained in:
parent
f98b91ff9a
commit
2c188f944a
3 changed files with 13 additions and 11 deletions
|
@ -521,12 +521,17 @@ RB_METHOD(bitmapCurrentFrame){
|
|||
RB_METHOD(bitmapSetFPS){
|
||||
RB_UNUSED_PARAM;
|
||||
|
||||
float fps;
|
||||
rb_get_args(argc, argv, "f", &fps RB_ARG_END);
|
||||
VALUE fps;
|
||||
rb_scan_args(argc, argv, "1", &fps);
|
||||
|
||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||
|
||||
b->setAnimationFPS(fps);
|
||||
if (RB_TYPE_P(fps, RUBY_T_FLOAT)) {
|
||||
b->setAnimationFPS(RFLOAT_VALUE(fps));
|
||||
}
|
||||
else {
|
||||
b->setAnimationFPS(NUM2INT(fps));
|
||||
}
|
||||
|
||||
return RUBY_Qnil;
|
||||
}
|
||||
|
@ -549,7 +554,7 @@ RB_METHOD(bitmapSetLooping){
|
|||
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||
b->setLooping(loop);
|
||||
|
||||
return Qnil;
|
||||
return RUBY_Qnil;
|
||||
}
|
||||
|
||||
RB_METHOD(bitmapGetLooping){
|
||||
|
@ -636,7 +641,7 @@ void bitmapBindingInit() {
|
|||
_rb_define_method(klass, "frame_rate", bitmapGetFPS);
|
||||
|
||||
// For some reason Ruby says "screw this function in particular"
|
||||
//_rb_define_method(klass, "frame_rate=", bitmapSetFPS);
|
||||
_rb_define_method(klass, "frame_rate=", bitmapSetFPS);
|
||||
_rb_define_method(klass, "looping", bitmapGetLooping);
|
||||
_rb_define_method(klass, "looping=", bitmapSetLooping);
|
||||
|
||||
|
|
|
@ -900,7 +900,6 @@
|
|||
3B10EDE02568E96A00372D13 /* sceneelement-binding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "sceneelement-binding.h"; sourceTree = "<group>"; };
|
||||
3B10EDE12568E96A00372D13 /* tilemapvx-binding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "tilemapvx-binding.cpp"; sourceTree = "<group>"; };
|
||||
3B10EDE22568E96A00372D13 /* module_rpg2.rb.xxd */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = module_rpg2.rb.xxd; sourceTree = "<group>"; };
|
||||
3B10EDE32568E96A00372D13 /* meson.build */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = meson.build; sourceTree = "<group>"; };
|
||||
3B10EDE42568E96A00372D13 /* bitmap-binding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "bitmap-binding.cpp"; sourceTree = "<group>"; };
|
||||
3B10EDE52568E96A00372D13 /* table-binding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "table-binding.cpp"; sourceTree = "<group>"; };
|
||||
3B10EDE62568E96A00372D13 /* etc-binding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "etc-binding.cpp"; sourceTree = "<group>"; };
|
||||
|
@ -1500,7 +1499,6 @@
|
|||
3B10EDE02568E96A00372D13 /* sceneelement-binding.h */,
|
||||
3B10EDE12568E96A00372D13 /* tilemapvx-binding.cpp */,
|
||||
3B10EDE22568E96A00372D13 /* module_rpg2.rb.xxd */,
|
||||
3B10EDE32568E96A00372D13 /* meson.build */,
|
||||
3B10EDE42568E96A00372D13 /* bitmap-binding.cpp */,
|
||||
3B10EDE52568E96A00372D13 /* table-binding.cpp */,
|
||||
3B10EDE62568E96A00372D13 /* etc-binding.cpp */,
|
||||
|
|
|
@ -60,7 +60,7 @@ extern "C" {
|
|||
{ \
|
||||
if (p->megaSurface) \
|
||||
throw Exception(Exception::MKXPError, \
|
||||
"Operation not supported for mega surfaces / animated bitmaps"); \
|
||||
"Operation not supported for mega surfaces"); \
|
||||
}
|
||||
|
||||
#define GUARD_ANIMATED \
|
||||
|
@ -168,8 +168,7 @@ struct BitmapPrivate
|
|||
inline int currentFrameI() {
|
||||
if (!playing) return lastFrame;
|
||||
int i = lastFrame + ((shState->runTime() - startTime) / ((1 / fps) * 1000000));
|
||||
int r = (loop) ? fmod(i, frames.size()) : (i > frames.size() - 1) ? frames.size() - 1 : i;
|
||||
return r;
|
||||
return (loop) ? fmod(i, frames.size()) : (i > frames.size() - 1) ? frames.size() - 1 : i;
|
||||
}
|
||||
|
||||
TEXFBO ¤tFrame() {
|
||||
|
@ -1774,7 +1773,7 @@ void Bitmap::setAnimationFPS(float FPS)
|
|||
|
||||
bool restart = p->animation.playing;
|
||||
p->animation.stop();
|
||||
p->animation.fps = FPS;
|
||||
p->animation.fps = (FPS < 0) ? 0 : FPS;
|
||||
if (restart) p->animation.play();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue