I am making a C++ SDL based game engine, currently finalising everything, I already have…
- User
I am making a C++ SDL based game engine, currently finalising everything, I already have the AudioManager, the SoundEffect and the Music classes done and probably working, and I am about to close the commit, but something crossed my mind, both the SoundEffect and the Music have method in common only by name, the implementation is different, should I add an interface class to join them together or not needed?
SoundEffect common with Music: int GetVolume() const; void SetVolume(int volume); void Play(int loops = 0); void PlayFadeIn(int ms, int loops = 0); //inverted parameter order because of loops being optional void Pause(); void Resume(); void Stop(); void StopFadeOut(int ms);
SoundEffect specifics: int GetChannel() const; void SetChannel(int channel);
Music common with SoundEffect int GetVolume() const; void SetVolume(int volume); void Play(int loops = -1); void PlayFadeIn(int loops, int ms); void Pause(); void Resume(); void Stop(); void StopFadeOut(int ms);
Music specifics: double GetTempo() const; void SetTempo(double tempo); double GetSpeed() const; void SetSpeed(double speed); double GetPitch() const; void SetPitch(double pitch); double GetDuration() const; bool IsPlaying() const; bool IsFading() const; std::string GetTitleTag() const; std::string GetArtistTag() const; std::string GetAlbumTag() const; void SetEffectPanning(uint8_t left, uint8_t right); void SetEffectDistance(uint8_t distance); void SetEffectPosition(int16_t angle, uint8_t distance); void RemoveEffects();
- Assistant
- User
Well I have some concerns about this:
- I designed everything to be separated, that means in my AudioManager I store them separately, I deal with them separately even the play function i only have for the sound effect and not the music, in the case that I deal with everything in different ways and never use them joined, should I implement this abstract class or not? Maybe I should have done it differently but I found out that sound effect needed a channel to play while the music don't was my main point on my decision to separate and only make the play for the sound and not the music, and let the music get the play from its own object.
- Assistant
- User
I see and I understand your point, now isn't a bit wrong or weird that the audiomanager only offers a way to play sounds but not music and to play music you have to make a different strategy?
Usage:
-
- To play a sound effect, use AudioManager::PlaySound().
-
- To play a music, use AudioManager::GetMusic() and Music::Play().
This is my current usage, I don't know if this is correct, or maybe I am missing something here.
-
- Assistant
- User
I see, but the things is I initially took them out because I had like 100 functions all dealing with the same thing, and I only left the PlaySound because I need to give it a channel to play on, if it wasn't for that I would have taken that out, but now leaving only one seems strange but I guess It can't be helped, I already have other Manager classes that do this philosophy of giving the caller the object to work with and they deal with the way they see fit. Maybe I am in the wrong here from the start.
- Assistant
- User
I will keep this in mind, for a moment I am doing this for myself only but I will keep this in mind if I ever encounter the problem myself or if I ever open-source my engine. With that said and done, I will close this commit and we can start working on the EventManager.
- Assistant
- User
- Assistant
- User
I think I like the Push model more, yeah it will be more complex but the pors ouy weights the cons here, the problem with starting simpler is that refactoring into the other would be a nightmare compared to refactor from a more complex to a simpler. Is the queue management really that difficult? I think the Push model flexility could be a good deal for example if I add new events of if the user add new events by themselves and want to use the EventManager to subscribe events outside the basic SDL events received by the SDL_PollEvent method. what do you think about this?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.