Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - winsett

Pages: [1]
1
Audio / [SOLVED] No sound is played but in debug mode is played
« on: April 20, 2021, 07:28:11 pm »
Hello!

I'm developing a small game and get to the point audio to be introduced to the game. But when I run the game and when sound should be played the game play no sound. The strange thing is when I'm in debug a sound is played when I go stepping through the code.  :o Nothing as error is shown to the console.

Here is a simplified scheme how I organized the audio system so far:
// singelton class for holding of all of the resources
class ResourcesManager
{
public:
    static ResourcesManager* getInstance(); // return single instance
    std::vector<sf::SoundBuffer> getSoundBuffers();
    ...
private:
    ResourcesManager() {}
    ...
    std::vector<sf::SoundBuffer> soundBuffers;
}

// another singelton class for playing the sounds
class SoundsPlayer
{
public:
        static std::shared_ptr<SoundsPlayer> getInstance();
        void play(const sf::SoundBuffer& buffer)
        {
                bool soundPlayed = false;
                // get next available sound
                for (auto sound : m_sounds)
                {
                        if (sound.getStatus() != sf::SoundSource::Status::Playing)
                        {
                                sound.setBuffer(buffer);
                                sound.play();
                                soundPlayed = true;
                                break;
                        }
                }
                if (!soundPlayed) // no sounds available
                {
                        sf::Sound sound;
                        m_sounds.push_back(sound);
                        size_t last = m_sounds.size() - 1;
                        m_sounds[last].setBuffer(buffer);
                        m_sounds[last].play();
                }
        }
private:
        SoundsPlayer() = default;
        std::vector<sf::Sound> m_sounds;
};


class PlayingCharacter
{
    ...
    void playAttackingSound()
        {
                extern ResourcesManager *resMan;

                SoundBuffersHolder soundBuffersHolder;
                std::shared_ptr<SoundsPlayer> soundsPly = SoundsPlayer::getInstance();
                bool isErr;
                soundsPly->play(resMan->getSoundBuffers().soundBuffers[0]);
        }
}
 

Some explanations on the code above:
  • ResourcesManager is taking care of holding all of the resources and it is a singelton class. So far it works the way I organized it for the textures and other resources - I invoke
    extern ResourcesManager *resMan;
    and then I get what I need from it, i.e.
    sf::texture tex = resMan->getTexture() )
  • First I simply tried to play a sound directly in the PlayingCharacter::playAttackingSound() method but there was no sound produced and I decided that probably the sf::Sound variable goes out of scope and that's why I made this SoundsPlayer singelton
  • The PlayingCharacter::playAttackingSound() is invoked on more than a seconds (timer is taking care of it) and the sound is less than a second long so no overlapping happens
  • Of course, these classes are in different files each

What am I missing?  :-\

2
Window / Errors when initializing a sf::RenderWindow variable
« on: December 12, 2016, 02:46:41 pm »
Hi there, new to this forum and with a little experience with SFML programming.

I get these 3 errors when I try to compile a VS2015 c++ project.

Quote
Error   LNK2019   unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function "protected: virtual int __thiscall CBatteryAlarmDlg::OnInitDialog(void)" (?OnInitDialog@CBatteryAlarmDlg@@MAEHXZ)   BatteryAlarm   E:\docs\programirane\BatteryAlarm\BatteryAlarm\BatteryAlarmDlg.obj   1   

Error   LNK2019   unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function "protected: virtual int __thiscall CBatteryAlarmDlg::OnInitDialog(void)" (?OnInitDialog@CBatteryAlarmDlg@@MAEHXZ)   BatteryAlarm   E:\docs\programirane\BatteryAlarm\BatteryAlarm\BatteryAlarmDlg.obj   1   

Error   LNK1120   2 unresolved externals   BatteryAlarm   E:\docs\programirane\BatteryAlarm\BatteryAlarm\Debug\BatteryAlarm.exe   1   

These errors appear only when I add this peace of code:
Quote
sf::RenderWindow testWindow(sf::VideoMode(800, 600), "test window");

Could you help me resolve what I've done wrong? Thanks! :)

Pages: [1]
anything