Merge branch 'master' into drawables
Conflicts: include/SFML/Graphics/Sprite.hpp include/SFML/Graphics/Text.hpp src/SFML/Graphics/Sprite.cpp
This commit is contained in:
commit
eeff685255
79 changed files with 747 additions and 892 deletions
|
@ -29,7 +29,6 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundSource.hpp>
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
|
@ -214,7 +213,7 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the source
|
||||
const SoundBuffer* myBuffer; ///< Sound buffer bound to the source
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
@ -49,7 +48,7 @@ class InputStream;
|
|||
/// \brief Storage for audio samples defining a sound
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API SoundBuffer : public Resource<SoundBuffer>
|
||||
class SFML_API SoundBuffer
|
||||
{
|
||||
public :
|
||||
|
||||
|
@ -200,7 +199,7 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of channels used by the sound
|
||||
///
|
||||
/// If the sound is mono then the number ofchannels will
|
||||
/// If the sound is mono then the number of channels will
|
||||
/// be 1, 2 for stereo, etc.
|
||||
///
|
||||
/// \return Number of channels
|
||||
|
|
|
@ -284,7 +284,7 @@ private :
|
|||
unsigned int myBuffers[BuffersCount]; ///< Sound buffers used to store temporary audio data
|
||||
unsigned int myChannelsCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
||||
unsigned int mySampleRate; ///< Frequency (samples / second)
|
||||
unsigned long myFormat; ///< Format of the internal sound buffers
|
||||
Uint32 myFormat; ///< Format of the internal sound buffers
|
||||
bool myLoop; ///< Loop flag (true to loop, false to play once)
|
||||
Uint64 mySamplesProcessed; ///< Number of buffers processed since beginning of the stream
|
||||
bool myEndBuffers[BuffersCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
|
||||
|
|
|
@ -97,32 +97,50 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Define portable import / export macros
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_SYSTEM_WINDOWS) && !defined(SFML_STATIC)
|
||||
#if !defined(SFML_STATIC)
|
||||
|
||||
#ifdef SFML_EXPORTS
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
// From DLL side, we must export
|
||||
#define SFML_API __declspec(dllexport)
|
||||
#ifdef SFML_EXPORTS
|
||||
|
||||
#else
|
||||
// From DLL side, we must export
|
||||
#define SFML_API __declspec(dllexport)
|
||||
|
||||
// From client application side, we must import
|
||||
#define SFML_API __declspec(dllimport)
|
||||
#else
|
||||
|
||||
#endif
|
||||
// From client application side, we must import
|
||||
#define SFML_API __declspec(dllimport)
|
||||
|
||||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning.
|
||||
// You can read lots ot different things about it, but the point is the code will
|
||||
// just work fine, and so the simplest way to get rid of this warning is to disable it
|
||||
#ifdef _MSC_VER
|
||||
#endif
|
||||
|
||||
#pragma warning(disable : 4251)
|
||||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning.
|
||||
// You can read lots ot different things about it, but the point is the code will
|
||||
// just work fine, and so the simplest way to get rid of this warning is to disable it
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#pragma warning(disable : 4251)
|
||||
|
||||
#endif
|
||||
|
||||
#else // Linux, FreeBSD, Mac OS X
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
// gcc 4 has special keywords for showing/hidding symbols
|
||||
#define SFML_API __attribute__ ((__visibility__ ("default")))
|
||||
|
||||
#else
|
||||
|
||||
// gcc < 4 has no mechanism to explicitely hide symbols, everything's exported
|
||||
#define SFML_API
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Other platforms and static build don't need these export macros
|
||||
// Static build doesn't need these export macros
|
||||
#define SFML_API
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
|
@ -47,7 +46,7 @@ class InputStream;
|
|||
/// \brief Class for loading and manipulating character fonts
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Font : public Resource<Font>
|
||||
class SFML_API Font
|
||||
{
|
||||
public :
|
||||
|
||||
|
|
|
@ -120,8 +120,6 @@ public :
|
|||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// The maximum size for an image depends on the graphics
|
||||
/// driver and can be retrieve with the GetMaximumSize function.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
|
|
|
@ -72,7 +72,7 @@ public :
|
|||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow(VideoMode mode, const std::string& title, unsigned long style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
RenderWindow(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the window from an existing control
|
||||
|
|
|
@ -142,7 +142,7 @@ public :
|
|||
/// \see GetStyle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetStyle(unsigned long style);
|
||||
void SetStyle(Uint32 style);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the global color of the text
|
||||
|
@ -206,7 +206,7 @@ public :
|
|||
/// \see SetStyle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned long GetStyle() const;
|
||||
Uint32 GetStyle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the global color of the text
|
||||
|
@ -286,7 +286,7 @@ private :
|
|||
String myString; ///< String to display
|
||||
const Font* myFont; ///< Font used to display the string
|
||||
unsigned int myCharacterSize; ///< Base size of characters, in pixels
|
||||
unsigned long myStyle; ///< Text style (see the Style enum)
|
||||
Uint32 myStyle; ///< Text style (see Style enum)
|
||||
Color myColor; ///< Text color
|
||||
VertexArray myVertices; ///< Vertex array containing the text's geometry
|
||||
FloatRect myBounds; ///< Bounding rectangle of the text (in local coordinates)
|
||||
|
|
|
@ -28,9 +28,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <SFML/Window/GlResource.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Window/GlResource.hpp>
|
||||
|
||||
|
||||
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<Texture>, GlResource
|
||||
class SFML_API Texture : GlResource
|
||||
{
|
||||
public :
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ public :
|
|||
Response ChangeDirectory(const std::string& directory);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Go to the parent directory of the current one
|
||||
/// \brief Go to the parent directory of the current one
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
|
|
|
@ -117,7 +117,7 @@ public :
|
|||
void SetUri(const std::string& uri);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the HTTP version fo the request
|
||||
/// \brief Set the HTTP version for the request
|
||||
///
|
||||
/// The HTTP version is 1.0 by default.
|
||||
///
|
||||
|
|
|
@ -94,7 +94,7 @@ public :
|
|||
void SetBlocking(bool blocking);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the socket is blocking or non-blocking mode
|
||||
/// \brief Tell whether the socket is in blocking or non-blocking mode
|
||||
///
|
||||
/// \return True if the socket is blocking, false otherwise
|
||||
///
|
||||
|
|
|
@ -109,7 +109,7 @@ public :
|
|||
Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, Uint32 timeout = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disconnect the connect from its remote peer
|
||||
/// \brief Disconnect the socket from its remote peer
|
||||
///
|
||||
/// This function gracefully closes the connection. If the
|
||||
/// socket is not connected, this function has no effect.
|
||||
|
|
|
@ -38,7 +38,11 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <windows.h>
|
||||
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace sf
|
|||
/// \brief Abstract class for custom file input streams
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API InputStream
|
||||
class InputStream
|
||||
{
|
||||
public :
|
||||
|
||||
|
|
|
@ -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 <SFML/System/Lock.hpp>
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
#include <set>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
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 <typename> class ResourcePtr;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Base class for resources that need to notify
|
||||
/// dependent classes about their destruction
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Resource
|
||||
{
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param copy Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource(const Resource<T>& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Resource();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource<T>& operator =(const Resource<T>& right);
|
||||
|
||||
private :
|
||||
|
||||
friend class ResourcePtr<T>;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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<T>& 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<T>& observer) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
mutable std::set<ResourcePtr<T>*> 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<T>
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
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<T>& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~ResourcePtr();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Assignment operator for a ResourcePtr parameter
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr<T>& operator =(const ResourcePtr<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Assignment operator for a raw pointer parameter
|
||||
///
|
||||
/// \param resource Resource to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr<T>& 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 <SFML/System/Resource.inl>
|
||||
#include <SFML/System/ResourcePtr.inl>
|
||||
|
||||
} // 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<T> 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
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
|
@ -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 <typename T>
|
||||
Resource<T>::Resource()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>::Resource(const Resource<T>&)
|
||||
{
|
||||
// Nothing to do, we don't want to copy observers
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>::~Resource()
|
||||
{
|
||||
// Notify all observers
|
||||
for (typename std::set<ResourcePtr<T>*>::iterator i = myObservers.begin(); i != myObservers.end(); ++i)
|
||||
{
|
||||
(*i)->OnResourceDestroyed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>& Resource<T>::operator =(const Resource<T>&)
|
||||
{
|
||||
// Nothing to do, we don't want to copy observers
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void Resource<T>::Connect(ResourcePtr<T>& observer) const
|
||||
{
|
||||
sf::Lock lock(myMutex);
|
||||
myObservers.insert(&observer);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void Resource<T>::Disconnect(ResourcePtr<T>& observer) const
|
||||
{
|
||||
sf::Lock lock(myMutex);
|
||||
myObservers.erase(&observer);
|
||||
}
|
|
@ -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 <typename T>
|
||||
ResourcePtr<T>::ResourcePtr() :
|
||||
myResource(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::ResourcePtr(const T* resource) :
|
||||
myResource(resource)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& copy) :
|
||||
myResource(copy.myResource)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::~ResourcePtr()
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Disconnect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& right)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Disconnect(*this);
|
||||
|
||||
myResource = right.myResource;
|
||||
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>& ResourcePtr<T>::operator =(const T* resource)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Disconnect(*this);
|
||||
|
||||
myResource = resource;
|
||||
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::operator const T*() const
|
||||
{
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
const T& ResourcePtr<T>::operator *() const
|
||||
{
|
||||
return *myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
const T* ResourcePtr<T>::operator ->() const
|
||||
{
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void ResourcePtr<T>::OnResourceDestroyed()
|
||||
{
|
||||
myResource = NULL;
|
||||
}
|
|
@ -66,7 +66,7 @@ public :
|
|||
/// void operator()();
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use Run().
|
||||
/// Note: this does *not* run the thread, use Launch().
|
||||
///
|
||||
/// \param function Functor or free function to use as the entry point of the thread
|
||||
///
|
||||
|
@ -93,7 +93,7 @@ public :
|
|||
/// void operator()(std::string arg);
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use Run().
|
||||
/// Note: this does *not* run the thread, use Launch().
|
||||
///
|
||||
/// \param function Functor or free function to use as the entry point of the thread
|
||||
/// \param argument argument to forward to the function
|
||||
|
@ -116,7 +116,7 @@ public :
|
|||
/// void function();
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use Run().
|
||||
/// Note: this does *not* run the thread, use Launch().
|
||||
///
|
||||
/// \param function Entry point of the thread
|
||||
/// \param object Pointer to the object to use
|
||||
|
|
|
@ -223,7 +223,7 @@ public :
|
|||
/// window.Close();
|
||||
///
|
||||
/// // The escape key was pressed
|
||||
/// if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
|
||||
/// if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
|
||||
/// window.Close();
|
||||
///
|
||||
/// // The window was resized
|
||||
|
|
|
@ -85,7 +85,7 @@ public :
|
|||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Window(VideoMode mode, const std::string& title, unsigned long style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
Window(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the window from an existing control
|
||||
|
@ -124,7 +124,7 @@ public :
|
|||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Create(VideoMode mode, const std::string& title, unsigned long style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
void Create(VideoMode mode, const std::string& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create (or recreate) the window from an existing control
|
||||
|
@ -176,7 +176,7 @@ public :
|
|||
unsigned int GetWidth() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the height of the rendering region of the window
|
||||
/// \brief Get the height of the rendering region of the window
|
||||
///
|
||||
/// The height doesn't include the titlebar and borders
|
||||
/// of the window.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue