diff --git a/include/SFML/Audio/Sound.hpp b/include/SFML/Audio/Sound.hpp index c0d7d8b6..47ce6454 100644 --- a/include/SFML/Audio/Sound.hpp +++ b/include/SFML/Audio/Sound.hpp @@ -29,7 +29,6 @@ // Headers //////////////////////////////////////////////////////////// #include -#include #include @@ -214,7 +213,7 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - ResourcePtr myBuffer; ///< Sound buffer bound to the source + const SoundBuffer* myBuffer; ///< Sound buffer bound to the source }; } // namespace sf diff --git a/include/SFML/Audio/SoundBuffer.hpp b/include/SFML/Audio/SoundBuffer.hpp index 31c29194..2e8fe699 100644 --- a/include/SFML/Audio/SoundBuffer.hpp +++ b/include/SFML/Audio/SoundBuffer.hpp @@ -29,7 +29,6 @@ // Headers //////////////////////////////////////////////////////////// #include -#include #include #include #include @@ -49,7 +48,7 @@ class InputStream; /// \brief Storage for audio samples defining a sound /// //////////////////////////////////////////////////////////// -class SFML_API SoundBuffer : public Resource +class SFML_API SoundBuffer { public : diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index d846f5ac..dd33432c 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -28,7 +28,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include #include @@ -47,7 +46,7 @@ class InputStream; /// \brief Class for loading and manipulating character fonts /// //////////////////////////////////////////////////////////// -class SFML_API Font : public Resource +class SFML_API Font { public : diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index cb754797..38af302a 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -28,7 +28,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include @@ -204,10 +203,10 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - ResourcePtr myTexture; ///< Texture used to draw the sprite - IntRect mySubRect; ///< Sub-rectangle of source texture to assign to the sprite - bool myIsFlippedX; ///< Is the sprite flipped on the X axis ? - bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ? + const Texture* myTexture; ///< Texture used to draw the sprite + IntRect mySubRect; ///< Sub-rectangle of source texture to assign to the sprite + bool myIsFlippedX; ///< Is the sprite flipped on the X axis ? + bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ? }; } // namespace sf diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 1aa45aa7..b3d97c7e 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -28,7 +28,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include #include @@ -239,7 +238,7 @@ private : // Member data //////////////////////////////////////////////////////////// String myString; ///< String to display - ResourcePtr myFont; ///< Font used to display the string + const Font* myFont; ///< Font used to display the string unsigned int myCharacterSize; ///< Base size of characters, in pixels unsigned long myStyle; ///< Text style (see Style enum) mutable FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index f4a2a276..6f4d20a1 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -28,9 +28,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include -#include #include +#include namespace sf @@ -44,7 +43,7 @@ class InputStream; /// \brief Image living on the graphics card that can be used for drawing /// //////////////////////////////////////////////////////////// -class SFML_API Texture : public Resource, GlResource +class SFML_API Texture : GlResource { public : diff --git a/include/SFML/System/Resource.hpp b/include/SFML/System/Resource.hpp deleted file mode 100644 index b3159794..00000000 --- a/include/SFML/System/Resource.hpp +++ /dev/null @@ -1,288 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_RESOURCE_HPP -#define SFML_RESOURCE_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -namespace sf -{ -//////////////////////////////////////////////////////////// -// These two classes are defined in the same header because -// they depend on each other. And as they're template classes, -// they must be entirely defined in header files, which -// prevents from proper separate compiling -//////////////////////////////////////////////////////////// - -template class ResourcePtr; - -//////////////////////////////////////////////////////////// -/// \brief Base class for resources that need to notify -/// dependent classes about their destruction -/// -//////////////////////////////////////////////////////////// -template -class Resource -{ -protected : - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - //////////////////////////////////////////////////////////// - Resource(); - - //////////////////////////////////////////////////////////// - /// \brief Copy constructor - /// - /// \param copy Instance to copy - /// - //////////////////////////////////////////////////////////// - Resource(const Resource& copy); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~Resource(); - - //////////////////////////////////////////////////////////// - /// \brief Assignment operator - /// - /// \param right Instance to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - Resource& operator =(const Resource& right); - -private : - - friend class ResourcePtr; - - //////////////////////////////////////////////////////////// - /// \brief Connect a ResourcePtr to this resource - /// - /// A connected ResourcePtr will be notified of the - /// destruction of this instance. - /// - /// \param observer ResourcePtr to connect - /// - //////////////////////////////////////////////////////////// - void Connect(ResourcePtr& observer) const; - - //////////////////////////////////////////////////////////// - /// \brief Disconnect a ResourcePtr from this resource - /// - /// The disconnected ResourcePtr will no longer be notified - /// if this instance is destroyed. - /// - /// \param observer ResourcePtr to disconnect - /// - //////////////////////////////////////////////////////////// - void Disconnect(ResourcePtr& observer) const; - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - mutable std::set*> myObservers; ///< List of pointers to this resource - mutable Mutex myMutex; ///< Mutex for preventing concurrent access to the pointer list -}; - - -//////////////////////////////////////////////////////////// -/// \brief Safe pointer to a sf::Resource -/// -//////////////////////////////////////////////////////////// -template -class ResourcePtr -{ -public : - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// A default constructed ResourcePtr is empty (null). - /// - //////////////////////////////////////////////////////////// - ResourcePtr(); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a raw pointer - /// - /// \param resource Raw pointer to the resource to wrap - /// - //////////////////////////////////////////////////////////// - ResourcePtr(const T* resource); - - //////////////////////////////////////////////////////////// - /// \brief Copy constructor - /// - /// The new ResourcePtr will share the same resource as \a copy. - /// - /// \param copy Instance to copy - /// - //////////////////////////////////////////////////////////// - ResourcePtr(const ResourcePtr& copy); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~ResourcePtr(); - - //////////////////////////////////////////////////////////// - /// \brief Assignment operator for a ResourcePtr parameter - /// - /// \param right Instance to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - ResourcePtr& operator =(const ResourcePtr& right); - - //////////////////////////////////////////////////////////// - /// \brief Assignment operator for a raw pointer parameter - /// - /// \param resource Resource to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - ResourcePtr& operator =(const T* resource); - - //////////////////////////////////////////////////////////// - /// \brief Cast operator to implicitely convert the resource - /// pointer to its raw pointer type (T*) - /// - /// This might be dangerous in the general case, but in this context - /// it is safe enough to define this operator. - /// - /// \return Read-only pointer to the actual resource - /// - //////////////////////////////////////////////////////////// - operator const T*() const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of unary operator * - /// - /// Like raw pointers, applying the * operator returns a - /// reference to the pointed object. - /// - /// \return Reference to the pointed resource - /// - //////////////////////////////////////////////////////////// - const T& operator *() const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of operator -> - /// - /// Like raw pointers, applying the -> operator returns the - /// pointed object. - /// - /// \return Pointed resource - /// - //////////////////////////////////////////////////////////// - const T* operator ->() const; - - //////////////////////////////////////////////////////////// - /// \brief Function called when the observed resource - /// is about to be destroyed - /// - /// This functions is called by the destructor of the pointed - /// resource. It allows this instance to reset its internal pointer - /// when the resource is destroyed, and avoid dangling pointers. - /// - //////////////////////////////////////////////////////////// - void OnResourceDestroyed(); - -private : - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - const T* myResource; /// Pointer to the actual resource -}; - -#include -#include - -} // namespace sf - - -#endif // SFML_RESOURCE_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::Resource -/// \ingroup system -/// -/// sf::Resource is a base for classes that want to be -/// compatible with the sf::ResourcePtr safe pointer. -/// -/// See sf::ResourcePtr for a complete explanation. -/// -/// \see sf::ResourcePtr -/// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -/// \class sf::ResourcePtr -/// \ingroup system -/// -/// sf::ResourcePtr is a special kind of smart pointer for -/// resources. Its main feature is to automatically -/// reset its internal pointer to 0 when the resource -/// gets destroyed, so that pointers to a resource never -/// become invalid when the resource is destroyed. Instead, -/// it properly returns 0 when the resource no longer exists. -/// -/// Its usage is completely transparent, so that it is similar -/// to manipulating the raw resource directly (like any smart pointer). -/// -/// For sf::ResourcePtr to work, T must inherit from -/// the sf::Resource class. -/// -/// These two classes are heavily used internally in SFML -/// to safely handle resources and the classes that use them: -/// \li sf::Texture / sf::Sprite -/// \li sf::Font / sf::Text -/// \li sf::SoundBuffer / sf::Sound -/// -/// sf::Resource and sf::ResourcePtr are designed for internal use, -/// but if you feel like they would fit well in your implementation -/// there's no problem to use them. -/// -/// \see sf::Resource -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Resource.inl b/include/SFML/System/Resource.inl deleted file mode 100644 index 0582e562..00000000 --- a/include/SFML/System/Resource.inl +++ /dev/null @@ -1,78 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -template -Resource::Resource() -{ - // Nothing to do -} - - -//////////////////////////////////////////////////////////// -template -Resource::Resource(const Resource&) -{ - // Nothing to do, we don't want to copy observers -} - - -//////////////////////////////////////////////////////////// -template -Resource::~Resource() -{ - // Notify all observers - for (typename std::set*>::iterator i = myObservers.begin(); i != myObservers.end(); ++i) - { - (*i)->OnResourceDestroyed(); - } -} - - -//////////////////////////////////////////////////////////// -template -Resource& Resource::operator =(const Resource&) -{ - // Nothing to do, we don't want to copy observers - return *this; -} - - -//////////////////////////////////////////////////////////// -template -void Resource::Connect(ResourcePtr& observer) const -{ - sf::Lock lock(myMutex); - myObservers.insert(&observer); -} - - -//////////////////////////////////////////////////////////// -template -void Resource::Disconnect(ResourcePtr& observer) const -{ - sf::Lock lock(myMutex); - myObservers.erase(&observer); -} diff --git a/include/SFML/System/ResourcePtr.inl b/include/SFML/System/ResourcePtr.inl deleted file mode 100644 index 3aa5f363..00000000 --- a/include/SFML/System/ResourcePtr.inl +++ /dev/null @@ -1,125 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -template -ResourcePtr::ResourcePtr() : -myResource(NULL) -{ - -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr::ResourcePtr(const T* resource) : -myResource(resource) -{ - if (myResource) - myResource->Connect(*this); -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr::ResourcePtr(const ResourcePtr& copy) : -myResource(copy.myResource) -{ - if (myResource) - myResource->Connect(*this); -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr::~ResourcePtr() -{ - if (myResource) - myResource->Disconnect(*this); -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr& ResourcePtr::operator =(const ResourcePtr& right) -{ - if (myResource) - myResource->Disconnect(*this); - - myResource = right.myResource; - - if (myResource) - myResource->Connect(*this); - - return *this; -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr& ResourcePtr::operator =(const T* resource) -{ - if (myResource) - myResource->Disconnect(*this); - - myResource = resource; - - if (myResource) - myResource->Connect(*this); - - return *this; -} - - -//////////////////////////////////////////////////////////// -template -ResourcePtr::operator const T*() const -{ - return myResource; -} - - -//////////////////////////////////////////////////////////// -template -const T& ResourcePtr::operator *() const -{ - return *myResource; -} - - -//////////////////////////////////////////////////////////// -template -const T* ResourcePtr::operator ->() const -{ - return myResource; -} - - -//////////////////////////////////////////////////////////// -template -void ResourcePtr::OnResourceDestroyed() -{ - myResource = NULL; -} diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index dc1978a9..961fd2f1 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -33,7 +33,8 @@ namespace sf { //////////////////////////////////////////////////////////// -Sound::Sound() +Sound::Sound() : +myBuffer(NULL) { } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index d5e09a8d..5f529591 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -50,11 +50,10 @@ myDuration(0) //////////////////////////////////////////////////////////// SoundBuffer::SoundBuffer(const SoundBuffer& copy) : -Resource(), -myBuffer (0), -mySamples (copy.mySamples), -myDuration (copy.myDuration), -mySounds () // don't copy the attached sounds +myBuffer (0), +mySamples (copy.mySamples), +myDuration(copy.myDuration), +mySounds () // don't copy the attached sounds { // Create the buffer ALCheck(alGenBuffers(1, &myBuffer)); diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 59e1e6dc..b16e254e 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -77,7 +77,6 @@ myRefCount (NULL) //////////////////////////////////////////////////////////// Font::Font(const Font& copy) : -Resource(), myLibrary (copy.myLibrary), myFace (copy.myFace), myStreamRec (copy.myStreamRec), diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 19405a7b..6518dc46 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -36,6 +36,7 @@ namespace sf //////////////////////////////////////////////////////////// Sprite::Sprite() : Drawable (), +myTexture (NULL), mySubRect (0, 0, 1, 1), myIsFlippedX(false), myIsFlippedY(false) @@ -47,6 +48,7 @@ myIsFlippedY(false) //////////////////////////////////////////////////////////// Sprite::Sprite(const Texture& texture) : Drawable (), +myTexture (NULL), mySubRect (0, 0, 1, 1), myIsFlippedX(false), myIsFlippedY(false) diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 202b1968..0517927f 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -52,7 +52,6 @@ myPixelsFlipped(false) //////////////////////////////////////////////////////////// Texture::Texture(const Texture& copy) : -Resource(), myWidth (0), myHeight (0), myTextureWidth (0), diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index dc1a8b2c..8cc3a26f 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -14,9 +14,6 @@ set(SRC ${INCROOT}/Mutex.hpp ${INCROOT}/NonCopyable.hpp ${SRCROOT}/Platform.hpp - ${INCROOT}/Resource.hpp - ${INCROOT}/Resource.inl - ${INCROOT}/ResourcePtr.inl ${SRCROOT}/Sleep.cpp ${INCROOT}/Sleep.hpp ${SRCROOT}/String.cpp