Skip to content

Commit

Permalink
AGS: Use 100 as a default animation volume, as it's relative anyway
Browse files Browse the repository at this point in the history
From upstream 90a60fffd5f010e957a53721f860997835216308
Also includes upstream 951f60c4dc25aa1d4320f595e01b048b53f6bf5f
  • Loading branch information
criezy committed Jun 18, 2022
1 parent be82c63 commit 9619169
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions engines/ags/engine/ac/button.cpp
Expand Up @@ -56,7 +56,7 @@ void UpdateButtonState(const AnimatingGUIButton &abtn) {
}

void Button_AnimateEx(GUIButton *butt, int view, int loop, int speed,
int repeat, int blocking, int direction, int sframe, int volume = -1) {
int repeat, int blocking, int direction, int sframe, int volume = 100) {
int guin = butt->ParentId;
int objn = butt->Id;

Expand All @@ -83,7 +83,7 @@ void Button_AnimateEx(GUIButton *butt, int view, int loop, int speed,
if ((direction < 0) || (direction > 1))
quit("!AnimateButton: invalid direction");

volume = std::min(volume, 100); // NOTE: negative volume means use defaults
volume = Math::Clamp(volume, 0, 100);

// if it's already animating, stop it
FindAndRemoveButtonAnimation(guin, objn);
Expand Down
6 changes: 3 additions & 3 deletions engines/ags/engine/ac/character.cpp
Expand Up @@ -154,7 +154,7 @@ 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 = -1) {
int blocking, int direction, int sframe, int volume = 100) {
if (direction == FORWARDS)
direction = 0;
else if (direction == BACKWARDS)
Expand Down Expand Up @@ -2064,15 +2064,15 @@ void animate_character(CharacterInfo *chap, int loopn, int sppd, int rept,
}
chap->frame = sframe;
chap->wait = sppd + _GP(views)[chap->view].loops[loopn].frames[chap->frame].speed;
_GP(charextra)[chap->index_id].cur_anim_volume = std::min(100, volume);
_GP(charextra)[chap->index_id].cur_anim_volume = Math::Clamp(volume, 0, 100);

CheckViewFrameForCharacter(chap);
}

void stop_character_anim(CharacterInfo *chap) { // TODO: may expand with resetting more properties,
// but have to be careful to not break logic somewhere
chap->animating = 0;
_GP(charextra)[chap->index_id].cur_anim_volume = -1;
_GP(charextra)[chap->index_id].cur_anim_volume = 100;
}

void CheckViewFrameForCharacter(CharacterInfo * chi) {
Expand Down
2 changes: 1 addition & 1 deletion engines/ags/engine/ac/character.h
Expand Up @@ -177,7 +177,7 @@ class Bitmap;
using namespace AGS; // FIXME later

void animate_character(CharacterInfo *chap, int loopn, int sppd, int rept,
int noidleoverride = 0, int direction = 0, int sframe = 0, int volume = -1);
int noidleoverride = 0, int direction = 0, int sframe = 0, int volume = 100);
// Clears up animation parameters
void stop_character_anim(CharacterInfo *chap);
void walk_character(int chac, int tox, int toy, int ignwal, bool autoWalkAnims);
Expand Down
4 changes: 2 additions & 2 deletions engines/ags/engine/ac/character_extras.h
Expand Up @@ -54,8 +54,8 @@ struct CharacterExtras {
int8 process_idle_this_time = 0;
int8 slow_move_counter = 0;
short animwait = 0;
int anim_volume = -1; // default animation volume (-1 use clip default)
int cur_anim_volume = -1; // current animation sound volume (-1 = default)
int anim_volume = 100; // default animation volume (relative factor)
int cur_anim_volume = 100; // current animation sound volume (relative factor)

void ReadFromSavegame(Shared::Stream *in, int save_ver);
void WriteToSavegame(Shared::Stream *out);
Expand Down
2 changes: 1 addition & 1 deletion engines/ags/engine/ac/global_object.cpp
Expand Up @@ -258,7 +258,7 @@ void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, in
_G(objs)[obn].num = Math::InRangeOrDef<uint16_t>(pic, 0);
if (pic > UINT16_MAX)
debug_script_warn("Warning: object's (id %d) sprite %d is outside of internal range (%d), reset to 0", obn, pic, UINT16_MAX);
_G(objs)[obn].anim_volume = std::min(volume, 100); // NOTE: negative volume means use defaults
_G(objs)[obn].anim_volume = Math::Clamp(volume, 0, 100);
CheckViewFrame(_G(objs)[obn].view, loopn, _G(objs)[obn].frame, _G(objs)[obn].anim_volume);

if (blocking)
Expand Down
2 changes: 1 addition & 1 deletion engines/ags/engine/ac/global_object.h
Expand Up @@ -50,7 +50,7 @@ void SetObjectBaseline(int obn, int basel);
int GetObjectBaseline(int obn);
void AnimateObjectEx(int obn, int loopn, int spdd, int rept, int direction, int blocking);
void AnimateObject(int obn, int loopn, int spdd, int rept);
void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, int blocking, int sframe, int volume = -1);
void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, int blocking, int sframe, int volume = 100);
void MergeObject(int obn);
void StopObjectMoving(int objj);
void ObjectOff(int obn);
Expand Down
2 changes: 1 addition & 1 deletion engines/ags/engine/ac/object.cpp
Expand Up @@ -121,7 +121,7 @@ int Object_GetBaseline(ScriptObject *objj) {
}

void Object_AnimateEx(ScriptObject *objj, int loop, int delay, int repeat,
int blocking, int direction, int sframe, int volume = -1) {
int blocking, int direction, int sframe, int volume = 100) {
if (direction == FORWARDS)
direction = 0;
else if (direction == BACKWARDS)
Expand Down
6 changes: 3 additions & 3 deletions engines/ags/engine/ac/view_frame.cpp
Expand Up @@ -29,15 +29,15 @@
#include "ags/engine/ac/draw.h"
#include "ags/shared/ac/game_version.h"
#include "ags/engine/media/audio/audio_system.h"
#include "ags/shared/util/math.h"
#include "ags/shared/debugging/out.h"
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
#include "ags/globals.h"

namespace AGS3 {

using AGS::Shared::Bitmap;
using AGS::Shared::Graphics;
using namespace AGS::Shared;

int ViewFrame_GetFlipped(ScriptViewFrame *svf) {
if (_GP(views)[svf->view].loops[svf->loop].frames[svf->frame].flags & VFLG_FLIPSPRITE)
Expand Down Expand Up @@ -140,7 +140,7 @@ void CheckViewFrame(int view, int loop, int frame, int sound_volume) {
}
}
if (channel && (sound_volume >= 0)) {
sound_volume = std::min(sound_volume, 100);
sound_volume = Math::Clamp(sound_volume, 0, 100);
auto *ch = AudioChans::GetChannel(channel->id);
if (ch)
ch->set_volume100(ch->get_volume100() * sound_volume / 100);
Expand Down
5 changes: 3 additions & 2 deletions engines/ags/engine/ac/view_frame.h
Expand Up @@ -51,8 +51,9 @@ int ViewFrame_GetLoop(ScriptViewFrame *svf);
int ViewFrame_GetFrame(ScriptViewFrame *svf);

void precache_view(int view);
// Handle the new animation frame (play linked sounds, etc)
void CheckViewFrame(int view, int loop, int frame, int sound_volume = -1);
// Handle the new animation frame (play linked sounds, etc);
// sound_volume is an optional relative factor, -1 means not use
void CheckViewFrame(int view, int loop, int frame, int sound_volume = -1);
// draws a view frame, flipped if appropriate
void DrawViewFrame(Shared::Bitmap *ds, const ViewFrame *vframe, int x, int y, bool alpha_blend = false);

Expand Down

0 comments on commit 9619169

Please sign in to comment.