It is currently 07 May 2025, 18:46
   
Text Size

[WIP] Forge Sound System

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: [WIP] Forge Sound System

Postby Agetian » 23 Nov 2012, 15:40

Well, actually, I'm done. :) All sounds use the event bus model now and are not called directly. Many events came out to be empty for now, I mean, the sound system doesn't need any specifics... Feel free to expand/merge as necessary.

P.S. Seems to work as expected thus far, though I could have accidentally broken something. ;)

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Max mtg » 23 Nov 2012, 19:53

Agetian wrote:Well, actually, I'm done. :) All sounds use the event bus model now and are not called directly. Many events came out to be empty for now, I mean, the sound system doesn't need any specifics... Feel free to expand/merge as necessary.
I think you did a great job!
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: [WIP] Forge Sound System

Postby Agetian » 24 Nov 2012, 02:14

Thanks a lot, I appreciate your feedback!

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Agetian » 24 Nov 2012, 15:10

I added two new sounds to the list of sounds supported by Forge: Block (when a blocker is assigned - "block.wav") and Token (when a token is created - "token.wav").

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Agetian » 10 Dec 2012, 07:15

OK, I have a question about implementation strategy... I'm working on implementing customizable sound effects via a card script SVar "SoundEffect". However, that brings up an important point because the enumeration SoundEffectType is a finite thing, so it's impossible to dynamically add a new enumeration element or to spawn any instances of SoundEffectType that are not elements of the enumeration.

I thought of using the getCardSpecialEffect method in EventVisualizer to play that back, but that's a part of EventVisualizer, not a part of SoundSystem, so I thought it might be a bad idea to play sounds directly from there. Anyhow, here's the code I currently have in mind:

Code: Select all
    private static boolean getSpecificCardEffect(final Card c) {
        if (null != c) {
            String effect = c.getSVar("SoundEffect");
            if (!effect.isEmpty()) {
                AudioClip specialClip = new AudioClip(effect);
                if (specialClip != null) {
                    specialClip.play();
                }
                return true;
            }
        }
        return false;
    }
I think this kind of breaks the purpose of EventVisualizer to abstract from direct calls to the sound system; however, just putting this code into SoundSystem as e.g.:

Code: Select all
    public boolean play(String resourceName) {
        if (!resourceName.isEmpty()) {
            AudioClip specialClip = new AudioClip(resourceName);
            if (specialClip != null) {
                specialClip.play();
                return true;
            }
        }
        return false;
    }
Also won't work because in that case, a dependency will have to be introduced between EventVisualizer and SoundSystem, which, once again, will defeat the original purpose of abstraction.

I'm ready to listen to your suggestions, because, honestly, I'm out of any good ones.

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Agetian » 10 Dec 2012, 09:27

UPDATE: found a (rather indirect) way of plugging in card-specific sounds without ruining the autonomous character of EventVisualizer and the event bus in general as independent entities from the SoundSystem class. Probably can be optimized in many ways, so suggestions are still highly welcome. Otherwise, the card-specific sound effects are now supported via the SoundEffect SVar. For example, if a card has a SVar specified like this:

Code: Select all
SVar:SoundEffect:my_sound.wav
then, when the card is played, the sound system will try to play back "res/sound/my_sound.wav" if it exists. If it doesn't exist, no sound will be played.
If the SVar:SoundEffect is not specified in a card script, the default sound will be played as usual.

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Max mtg » 10 Dec 2012, 11:51

Writing from a mobile phone,
Just to don't mix up the game with visualization, I suggest getting that svar value right in visualizer. It's the client - it recieved an event like "card Tezzeret has entered play" and decides how to show it to player.

Will review this thread from computer later
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: [WIP] Forge Sound System

Postby Agetian » 10 Dec 2012, 15:32

Oh, OK. Yeah, that's where it's currently taken (the SVar is taken in the visualizer). It's just that my current implementation seems unnecessarily complex, I think there should be a simpler, more elegant and effective solution but it eludes me at the moment... Thanks for your suggestions so far!

- Agetian
Agetian
Programmer
 
Posts: 3486
Joined: 14 Mar 2011, 05:58
Has thanked: 683 times
Been thanked: 568 times

Re: [WIP] Forge Sound System

Postby Rob Cashwalker » 26 Jan 2013, 21:39

I was just playing a couple rounds for the first time in a while. I only heard sound for the first time an event occurred, like playing a land, or artifact.. none afterwards.

Edit - built a jar instead of playing from eclipse, and it worked OK.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 42 guests


Who is online

In total there are 42 users online :: 0 registered, 0 hidden and 42 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 42 guests

Login Form