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

Author Topic: sf::NonCopyable - Issue - Sound Manager  (Read 1670 times)

0 Members and 1 Guest are viewing this topic.

RumpNissen

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::NonCopyable - Issue - Sound Manager
« on: February 19, 2014, 04:00:49 pm »
Greetings, I don't have much experience with SFML and I started programming with C++ just last autumn.

I used an open source sound manager for my project:
https://thunked.org/p/view/pub/ao7lc3kqg

However, the author made the mistake of setting values for the sf::Time variables in the header:

sf::Time startingPoint = sf::seconds(0);
sf::Time endPoint = sf::seconds(0);

I changed this and set the values in the .cpp instead. That's when the "sf::NonCopyable" issue showed up:

Error   2   error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'


The Sound Manager looks like this:

Header
#pragma once
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>

class SoundEntity
{
public:
        sf::Time startingPoint;
        sf::Time endPoint;
        sf::Sound Sound;
        sf::SoundBuffer Buffer;
        sf::Music Music;
        void Loop();
        SoundEntity();
        void Play(bool stop);
        void Init(std::string filename);
        void Update();
};

class SoundManager
{
public:
        std::vector<SoundEntity> Sounds;
        int newSound(std::string filename, bool Looping);
        void Update();
};

CPP
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>
#include <iostream>
#include "SoundManager.h"


void SoundEntity::Loop()
{
        startingPoint = sf::seconds(0);
        endPoint = sf::seconds(0);
        Sound.setPlayingOffset(startingPoint);
}

void SoundEntity::Play(bool stop = true)        // stops the sound, then starts it from the beginning of the loop, then starts it
{
        if (stop)
                Sound.stop();
        Sound.setPlayingOffset(startingPoint);
        Sound.play();
}

void SoundEntity::Init(std::string filename)
{
        //Buffer = new sf::SoundBuffer;
        Buffer.loadFromFile(filename);
        //Sound = new sf::Sound;
        Sound.setBuffer(Buffer);
        startingPoint = sf::microseconds(0);
        endPoint = Buffer.getDuration();
}

SoundEntity::SoundEntity()
{
        std::cout << "Hi\n";
}

void SoundEntity::Update()
{
        if (Sound.getPlayingOffset() >= endPoint && Sound.getLoop())
        {
                Loop();
        }
        else if (Sound.getPlayingOffset() >= endPoint)
        {
                Sound.stop();
        }
}


int SoundManager::newSound(std::string filename, bool Looping)
{
        SoundEntity newSoundEntity;
        Sounds.push_back(newSoundEntity);
        Sounds[Sounds.size() - 1].Init(filename);
        Sounds[Sounds.size() - 1].Sound.setLoop(Looping);
        return Sounds.size() - 1;
}

void SoundManager::Update()
{
        for (int i = 0; i < Sounds.size(); i++)
        {
                Sounds[i].Update();
        }

}

So what did I miss? Or is it something the original author missed?

Any help would be much appreciated

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: sf::NonCopyable - Issue - Sound Manager
« Reply #1 on: February 19, 2014, 07:03:38 pm »
Yeah I think there is something that both you and the original author missed. The functionality that you want to implement is already provided by SFML. Take a look at the documentation.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::NonCopyable - Issue - Sound Manager
« Reply #2 on: February 19, 2014, 07:52:49 pm »
I think this code is meant to be compiled with a C++11 compiler.

sf::Music instances can't be copied, that's why you get this error (std::vector copies its elements internally -- unless you're in C++11, in which case it only moves them). You'll have to adapt this to avoid copies of sf::Music instances. Or simply remove them, since they don't seem to be used at all? :P
Laurent Gomila - SFML developer

 

anything