[Scummvm-git-logs] scummvm master -> 503e06a1a1a49d575e13ab89baf963cc8f00784e
tag2015
noreply at scummvm.org
Fri May 12 10:00:56 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
503e06a1a1 AGS: Engine: picked out basic Animate params check and warn instead of quit
Commit: 503e06a1a1a49d575e13ab89baf963cc8f00784e
https://github.com/scummvm/scummvm/commit/503e06a1a1a49d575e13ab89baf963cc8f00784e
Author: Walter Agazzi (walter.agazzi at protonmail.com)
Date: 2023-05-12T12:00:39+02:00
Commit Message:
AGS: Engine: picked out basic Animate params check and warn instead of quit
This avoids the Gobliiins5 errors.
>From upstream ecb4ae13031c32c2793d1d6a2b2af9f2af7bd911
Changed paths:
engines/ags/engine/ac/button.cpp
engines/ags/engine/ac/character.cpp
engines/ags/engine/ac/global_object.cpp
engines/ags/engine/ac/object.cpp
engines/ags/engine/ac/object.h
diff --git a/engines/ags/engine/ac/button.cpp b/engines/ags/engine/ac/button.cpp
index 3574bcee9f9..36389fed62c 100644
--- a/engines/ags/engine/ac/button.cpp
+++ b/engines/ags/engine/ac/button.cpp
@@ -60,15 +60,6 @@ void Button_AnimateEx(GUIButton *butt, int view, int loop, int speed,
int guin = butt->ParentId;
int objn = butt->Id;
- if (direction == FORWARDS)
- direction = 0;
- else if (direction == BACKWARDS)
- direction = 1;
- if (blocking == BLOCKING)
- blocking = 1;
- else if (blocking == IN_BACKGROUND)
- blocking = 0;
-
if ((view < 1) || (view > _GP(game).numviews))
quit("!AnimateButton: invalid view specified");
view--;
@@ -76,12 +67,8 @@ void Button_AnimateEx(GUIButton *butt, int view, int loop, int speed,
quit("!AnimateButton: invalid loop specified for view");
if (sframe < 0 || sframe >= _GP(views)[view].loops[loop].numFrames)
quit("!AnimateButton: invalid starting frame number specified");
- if ((repeat < 0) || (repeat > 1))
- quit("!AnimateButton: invalid repeat value");
- if ((blocking < 0) || (blocking > 1))
- quit("!AnimateButton: invalid blocking value");
- if ((direction < 0) || (direction > 1))
- quit("!AnimateButton: invalid direction");
+
+ ValidateViewAnimParams("Button.Animate", repeat, blocking, direction);
volume = Math::Clamp(volume, 0, 100);
diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index 711f60e7e39..d200722a77f 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -155,21 +155,8 @@ void Character_AddWaypoint(CharacterInfo *chaa, int x, int y) {
void Character_AnimateEx(CharacterInfo *chaa, int loop, int delay, int repeat,
int blocking, int direction, int sframe, int volume = 100) {
- if (direction == FORWARDS)
- direction = 0;
- else if (direction == BACKWARDS)
- direction = 1;
- if (blocking == BLOCKING)
- blocking = 1;
- else if (blocking == IN_BACKGROUND)
- blocking = 0;
-
- if ((repeat < 0) || (repeat > 1))
- quitprintf("!Character.Animate: invalid repeat value (%d)", repeat);
- if ((blocking < 0) || (blocking > 1))
- quitprintf("!Character.Animate: invalid blocking value (%d)", blocking);
- if ((direction < 0) || (direction > 1))
- quitprintf("!Character.Animate: invalid direction (%d)", direction);
+
+ ValidateViewAnimParams("Character.Animate", repeat, blocking, direction);
animate_character(chaa, loop, delay, repeat, 0, direction, sframe, volume);
diff --git a/engines/ags/engine/ac/global_object.cpp b/engines/ags/engine/ac/global_object.cpp
index c55b1757806..1582d639061 100644
--- a/engines/ags/engine/ac/global_object.cpp
+++ b/engines/ags/engine/ac/global_object.cpp
@@ -222,14 +222,15 @@ void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, in
quit("!AnimateObject: object has not been assigned a view");
if (loopn < 0 || loopn >= _GP(views)[_G(objs)[obn].view].numLoops)
quit("!AnimateObject: invalid loop number specified");
+ if (_GP(views)[_G(objs)[obn].view].loops[loopn].numFrames < 1)
+ quit("!AnimateObject: no frames in the specified view loop");
if (sframe < 0 || sframe >= _GP(views)[_G(objs)[obn].view].loops[loopn].numFrames)
quit("!AnimateObject: invalid starting frame number specified");
+
if ((direction < 0) || (direction > 1))
quit("!AnimateObjectEx: invalid direction");
- if ((rept < 0) || (rept > 2))
+ if (((rept + 1) < ANIM_ONCE) || ((rept + 1) > ANIM_ONCERESET)) // will convert to 1-based repeat below
quit("!AnimateObjectEx: invalid repeat value");
- if (_GP(views)[_G(objs)[obn].view].loops[loopn].numFrames < 1)
- quit("!AnimateObject: no frames in the specified view loop");
// reverse animation starts at the *previous frame*
if (direction) {
diff --git a/engines/ags/engine/ac/object.cpp b/engines/ags/engine/ac/object.cpp
index 00a3a18a10b..c3d52943c5a 100644
--- a/engines/ags/engine/ac/object.cpp
+++ b/engines/ags/engine/ac/object.cpp
@@ -122,21 +122,8 @@ int Object_GetBaseline(ScriptObject *objj) {
void Object_AnimateEx(ScriptObject *objj, int loop, int delay, int repeat,
int blocking, int direction, int sframe, int volume = 100) {
- if (direction == FORWARDS)
- direction = 0;
- else if (direction == BACKWARDS)
- direction = 1;
- if (blocking == BLOCKING)
- blocking = 1;
- else if (blocking == IN_BACKGROUND)
- blocking = 0;
- if ((repeat < 0) || (repeat > 1))
- quit("!Object.Animate: invalid repeat value");
- if ((blocking < 0) || (blocking > 1))
- quit("!Object.Animate: invalid blocking value");
- if ((direction < 0) || (direction > 1))
- quit("!Object.Animate: invalid direction");
+ ValidateViewAnimParams("Object.Animate", repeat, blocking, direction);
AnimateObjectImpl(objj->id, loop, delay, repeat, direction, blocking, sframe, volume);
}
@@ -555,6 +542,31 @@ int check_click_on_object(int roomx, int roomy, int mood) {
return 1;
}
+void ValidateViewAnimParams(const char *apiname, int &repeat, int &blocking, int &direction) {
+ if (blocking == BLOCKING)
+ blocking = 1;
+ else if (blocking == IN_BACKGROUND)
+ blocking = 0;
+
+ if (direction == FORWARDS)
+ direction = 0;
+ else if (direction == BACKWARDS)
+ direction = 1;
+
+ if ((repeat < 0) || (repeat > 1)) {
+ debug_script_warn("%s: invalid repeat value %d, will treat as REPEAT (1).", apiname, repeat);
+ repeat = 1;
+ }
+ if ((blocking < 0) || (blocking > 1)) {
+ debug_script_warn("%s: invalid blocking value %d, will treat as BLOCKING (1)", apiname, blocking);
+ blocking = 1;
+ }
+ if ((direction < 0) || (direction > 1)) {
+ debug_script_warn("%s: invalid direction value %d, will treat as BACKWARDS (1)", apiname, direction);
+ direction = 1;
+ }
+}
+
// General view animation algorithm: find next loop and frame, depending on anim settings
bool CycleViewAnim(int view, uint16_t &o_loop, uint16_t &o_frame, bool forwards, int repeat) {
// Allow multi-loop repeat: idk why, but original engine behavior
diff --git a/engines/ags/engine/ac/object.h b/engines/ags/engine/ac/object.h
index 677d693bb80..1e38ce63817 100644
--- a/engines/ags/engine/ac/object.h
+++ b/engines/ags/engine/ac/object.h
@@ -104,6 +104,10 @@ int is_pos_in_sprite(int xx, int yy, int arx, int ary, Shared::Bitmap *sprit
// X and Y co-ordinates must be in native format
// X and Y are ROOM coordinates
int check_click_on_object(int roomx, int roomy, int mood);
+// TODO: pick out some kind of "animation" struct
+// Tests if the standard animate parameters are in valid range, if not then clamps them and
+// reports a script warning.
+void ValidateViewAnimParams(const char *apiname, int &repeat, int &blocking, int &direction);
// General view animation algorithm: find next loop and frame, depending on anim settings;
// loop and frame values are passed by reference and will be updated;
// returns whether the animation should continue.
More information about the Scummvm-git-logs
mailing list