From 4af7bc03862190ee0357b981b3d10c980b917fff Mon Sep 17 00:00:00 2001 From: gez Date: Sun, 2 Jun 2013 11:43:27 +0000 Subject: [PATCH] * Updated to ZDoom r4318: - Added more string functions to ACS: strcmp, stricmp (aka strcasecmp), strleft, strright, and strmid. - Clean up excess code around a few calls to SingleActorFromTID(), since that function is already designed specifically to handle the case where tid is 0. - Added GetActorClass and GetWeapon functions to ACS. - Added S_ChangeSoundVolume() to change the volume of an already playing sound, accessible through the new ACS function SoundVolume. git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@1587 b0f79afe-0144-0410-b225-9a4edf0717df --- src/p_acs.cpp | 123 +++++++++++++++++++++++++++++++++++++++- src/s_sound.cpp | 24 +++++++- src/s_sound.h | 3 + src/sound/fmodsound.cpp | 14 +++++ src/sound/fmodsound.h | 3 + src/sound/i_sound.cpp | 3 + src/sound/i_sound.h | 3 + src/svnrevision.h | 4 +- 8 files changed, 171 insertions(+), 6 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 6ccf7339..99ddf778 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4127,6 +4127,14 @@ enum EACSFunctions ACSF_LineAttack, ACSF_PlaySound, ACSF_StopSound, + ACSF_strcmp, + ACSF_stricmp, + ACSF_StrLeft, + ACSF_StrRight, + ACSF_StrMid, + ACSF_GetActorClass, + ACSF_GetWeapon, + ACSF_SoundVolume, // ZDaemon ACSF_GetTeamScore = 19620, // (int team) @@ -4593,7 +4601,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) FName varname(FBehavior::StaticLookupString(args[1]), true); if (varname != NAME_None) { - AActor *a = args[0] == 0 ? (AActor *)activator : SingleActorFromTID(args[0], NULL); + AActor *a = SingleActorFromTID(args[0], activator); return a != NULL ? GetUserVariable(a, varname, 0) : 0; } return 0; @@ -4632,7 +4640,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) FName varname(FBehavior::StaticLookupString(args[1]), true); if (varname != NAME_None) { - AActor *a = args[0] == 0 ? (AActor *)activator : SingleActorFromTID(args[0], NULL); + AActor *a = SingleActorFromTID(args[0], activator); return a != NULL ? GetUserVariable(a, varname, args[2]) : 0; } return 0; @@ -4644,10 +4652,16 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) case ACSF_CheckActorClass: { - AActor *a = args[0] == 0 ? (AActor *)activator : SingleActorFromTID(args[0], NULL); + AActor *a = SingleActorFromTID(args[0], activator); return a == NULL ? false : a->GetClass()->TypeName == FName(FBehavior::StaticLookupString(args[1])); } + case ACSF_GetActorClass: + { + AActor *a = SingleActorFromTID(args[0], activator); + return GlobalACSStrings.AddString(a == NULL ? "None" : a->GetClass()->TypeName.GetChars()); + } + case ACSF_SoundSequenceOnActor: { const char *seqname = FBehavior::StaticLookupString(args[1]); @@ -4951,6 +4965,109 @@ doplaysound: if (!looping) } break; + case ACSF_SoundVolume: + // SoundVolume(int tid, int channel, fixed volume) + { + int chan = args[1]; + float volume = FIXED2FLOAT(args[2]); + + if (args[0] == 0) + { + S_ChangeSoundVolume(activator, chan, volume); + } + else + { + FActorIterator it(args[0]); + AActor *spot; + + while ((spot = it.Next()) != NULL) + { + S_ChangeSoundVolume(spot, chan, volume); + } + } + } + break; + + case ACSF_strcmp: + case ACSF_stricmp: + if (argCount >= 2) + { + const char *a, *b; + a = FBehavior::StaticLookupString(args[0]); + b = FBehavior::StaticLookupString(args[1]); + + // Don't crash on invalid strings. + if (a == NULL) a = ""; + if (b == NULL) b = ""; + + if (argCount > 2) + { + int n = args[2]; + return (funcIndex == ACSF_strcmp) ? strncmp(a, b, n) : strnicmp(a, b, n); + } + else + { + return (funcIndex == ACSF_strcmp) ? strcmp(a, b) : stricmp(a, b); + } + } + break; + + case ACSF_StrLeft: + case ACSF_StrRight: + if (argCount >= 2) + { + const char *oldstr = FBehavior::StaticLookupString(args[0]); + if (oldstr == NULL || *oldstr == '\0') + { + return GlobalACSStrings.AddString(""); + } + size_t oldlen = strlen(oldstr); + size_t newlen = args[1]; + + if (oldlen < newlen) + { + newlen = oldlen; + } + FString newstr(funcIndex == ACSF_StrLeft ? oldstr : oldstr + oldlen - newlen, newlen); + return GlobalACSStrings.AddString(newstr); + } + break; + + case ACSF_StrMid: + if (argCount >= 3) + { + const char *oldstr = FBehavior::StaticLookupString(args[0]); + if (oldstr == NULL || *oldstr == '\0') + { + return GlobalACSStrings.AddString(""); + } + size_t oldlen = strlen(oldstr); + size_t pos = args[1]; + size_t newlen = args[2]; + + if (pos >= oldlen) + { + return GlobalACSStrings.AddString(""); + } + if (pos + newlen > oldlen || pos + newlen < pos) + { + newlen = oldlen - pos; + } + return GlobalACSStrings.AddString(FString(oldstr + pos, newlen)); + } + break; + + case ACSF_GetWeapon: + if (activator == NULL || activator->player == NULL || // Non-players do not have weapons + activator->player->ReadyWeapon == NULL) + { + return GlobalACSStrings.AddString("None"); + } + else + { + return GlobalACSStrings.AddString(activator->player->ReadyWeapon->GetClass()->TypeName.GetChars()); + } + default: break; } diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 3da346bf..2626c2b8 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1592,6 +1592,29 @@ void S_RelinkSound (AActor *from, AActor *to) } } + +//========================================================================== +// +// S_ChangeSoundVolume +// +//========================================================================== + +bool S_ChangeSoundVolume(AActor *actor, int channel, float volume) +{ + for (FSoundChan *chan = Channels; chan != NULL; chan = chan->NextChan) + { + if (chan->SourceType == SOURCE_Actor && + chan->Actor == actor && + (chan->EntChannel == channel || (i_compatflags & COMPATF_MAGICSILENCE))) + { + GSnd->ChannelVolume(chan, volume); + chan->Volume = volume; + return true; + } + } + return false; +} + //========================================================================== // // S_GetSoundPlayingInfo @@ -2136,7 +2159,6 @@ void S_StopChannel(FSoundChan *chan) } } - //========================================================================== // // (FArchive &) << (FSoundID &) diff --git a/src/s_sound.h b/src/s_sound.h index 2f4f6864..346e51ce 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -303,6 +303,9 @@ bool S_GetSoundPlayingInfo (const FPolyObj *poly, int sound_id); bool S_IsActorPlayingSomething (AActor *actor, int channel, int sound_id); +// Change a playing sound's volume +bool S_ChangeSoundVolume(AActor *actor, int channel, float volume); + // Moves all sounds from one mobj to another void S_RelinkSound (AActor *from, AActor *to); diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index 5abb67e7..133fc240 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -2053,6 +2053,20 @@ void FMODSoundRenderer::StopChannel(FISoundChannel *chan) } } +//========================================================================== +// +// FMODSoundRenderer :: ChannelVolume +// +//========================================================================== + +void FMODSoundRenderer::ChannelVolume(FISoundChannel *chan, float volume) +{ + if (chan != NULL && chan->SysChannel != NULL) + { + ((FMOD::Channel *)chan->SysChannel)->setVolume(volume); + } +} + //========================================================================== // // FMODSoundRenderer :: GetPosition diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index 99d627e5..93b70ce8 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -33,6 +33,9 @@ public: // Stops a sound channel. void StopChannel (FISoundChannel *chan); + // Changes a channel's volume. + void ChannelVolume (FISoundChannel *chan, float volume); + // Marks a channel's start time without actually playing it. void MarkStartTime (FISoundChannel *chan); diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 0fe68a25..c95b0221 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -150,6 +150,9 @@ public: void StopChannel(FISoundChannel *chan) { } + void ChannelVolume(FISoundChannel *, float) + { + } // Streaming sounds. SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index c905678a..adce8796 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -110,6 +110,9 @@ public: // Stops a sound channel. virtual void StopChannel (FISoundChannel *chan) = 0; + // Changes a channel's volume. + virtual void ChannelVolume (FISoundChannel *chan, float volume) = 0; + // Marks a channel's start time without actually playing it. virtual void MarkStartTime (FISoundChannel *chan) = 0; diff --git a/src/svnrevision.h b/src/svnrevision.h index 22b46895..1ecbc2ad 100644 --- a/src/svnrevision.h +++ b/src/svnrevision.h @@ -3,5 +3,5 @@ // This file was automatically generated by the // updaterevision tool. Do not edit by hand. -#define ZD_SVN_REVISION_STRING "4310" -#define ZD_SVN_REVISION_NUMBER 4310 +#define ZD_SVN_REVISION_STRING "4318" +#define ZD_SVN_REVISION_NUMBER 4318