Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
74
include/SFML/System/Clock.hpp
Normal file
74
include/SFML/System/Clock.hpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_CLOCK_HPP
|
||||
#define SFML_CLOCK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Clock is an utility class for manipulating time
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Clock
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Clock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the time elapsed since last reset
|
||||
///
|
||||
/// \return Time elapsed, in seconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float GetElapsedTime() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Restart the timer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Reset();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
double myStartTime; ///< Time of last reset
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_CLOCK_HPP
|
71
include/SFML/System/Lock.hpp
Normal file
71
include/SFML/System/Lock.hpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_LOCK_HPP
|
||||
#define SFML_LOCK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Mutex;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Lock is an exception-safe automatic wrapper for
|
||||
/// locking and unlocking mutexes
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Lock : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the lock with a target mutex (lock it)
|
||||
///
|
||||
/// @param Mutex : Mutex to lock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Lock(Mutex& Mutex);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor (unlocks the mutex)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Lock();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Mutex& myMutex; ///< Mutex to lock / unlock
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_LOCK_HPP
|
45
include/SFML/System/Mutex.hpp
Normal file
45
include/SFML/System/Mutex.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_MUTEX_HPP
|
||||
#define SFML_MUTEX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
#ifdef SFML_SYSTEM_WINDOWS
|
||||
|
||||
#include <SFML/System/Win32/Mutex.hpp>
|
||||
|
||||
#else
|
||||
|
||||
#include <SFML/System/Unix/Mutex.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_MUTEX_HPP
|
70
include/SFML/System/NonCopyable.hpp
Normal file
70
include/SFML/System/NonCopyable.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_NONCOPYABLE_HPP
|
||||
#define SFML_NONCOPYABLE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Utility base class to easily declare non-copyable classes.
|
||||
/// Just inherit from NonCopyable to get a non-copyable class
|
||||
////////////////////////////////////////////////////////////
|
||||
struct SFML_API NonCopyable
|
||||
{
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// The default constructor won't be generated, so provide it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable() {}
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy constructor : declare it private and don't implement
|
||||
/// it to prevent from calling it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable(const NonCopyable&);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator : declare it private and don't implement
|
||||
/// it to prevent from calling it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable& operator =(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_NONCOPYABLE_HPP
|
94
include/SFML/System/Randomizer.hpp
Normal file
94
include/SFML/System/Randomizer.hpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_RANDOMIZER_HPP
|
||||
#define SFML_RANDOMIZER_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Randomizer is an utility class for generating pseudo-random
|
||||
/// numbers
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Randomizer
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the seed for the generator. Using a known seed
|
||||
/// allows you to reproduce the same sequence of random number
|
||||
///
|
||||
/// \param Seed : Number to use as the seed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetSeed(unsigned int Seed);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the seed used to generate random numbers the generator.
|
||||
///
|
||||
/// \return Current seed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int GetSeed();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a random float number in a given range
|
||||
///
|
||||
/// \return Start : Start of the range
|
||||
/// \return End : End of the range
|
||||
///
|
||||
/// \return Random number in [Begin, End]
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static float Random(float Begin, float End);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a random integer number in a given range
|
||||
///
|
||||
/// \return Start : Start of the range
|
||||
/// \return End : End of the range
|
||||
///
|
||||
/// \return Random number in [Begin, End]
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static int Random(int Begin, int End);
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member variables
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int ourSeed;
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RANDOMIZER_HPP
|
216
include/SFML/System/Resource.hpp
Normal file
216
include/SFML/System/Resource.hpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <set>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Base class for every resource that needs to notify
|
||||
/// dependent classes about its destruction
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Resource
|
||||
{
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy constructor
|
||||
///
|
||||
/// \param Copy : Resource to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource(const Resource<T>& Copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Resource();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator
|
||||
///
|
||||
/// \param Other : Resource to copy
|
||||
///
|
||||
/// \return Reference to this
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Resource<T>& operator =(const Resource<T>& Other);
|
||||
|
||||
private :
|
||||
|
||||
friend class ResourcePtr<T>;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Connect a ResourcePtr to this resource
|
||||
///
|
||||
/// \param Observer : Observer to add
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Connect(ResourcePtr<T>& Observer) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Disconnect a ResourcePtr from this resource
|
||||
///
|
||||
/// \param Observer : Observer to remove
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Disconnect(ResourcePtr<T>& Observer) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
mutable std::set<ResourcePtr<T>*> myObservers;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Safe pointer to a T resource (inheriting from sf::Resource<T>),
|
||||
/// its pointer is automatically reseted when the resource is destroyed
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class ResourcePtr
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct from a raw resource
|
||||
///
|
||||
/// \param Resource : Internal resource
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr(const T* Resource);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy constructor
|
||||
///
|
||||
/// \param Copy : Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr(const ResourcePtr<T>& Copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~ResourcePtr();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator from another ResourcePtr
|
||||
///
|
||||
/// \param Other : Resource pointer to assign
|
||||
///
|
||||
/// \return Reference to this
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr<T>& operator =(const ResourcePtr<T>& Other);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator from a raw resource
|
||||
///
|
||||
/// \param Resource : Resource to assign
|
||||
///
|
||||
/// \return Reference to this
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ResourcePtr<T>& operator =(const T* Resource);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Cast operator to implicitely convert the resource pointer to
|
||||
/// its raw pointer type.
|
||||
/// This might be dangerous in the general case, but in this context
|
||||
/// it is safe enough to define this operator
|
||||
///
|
||||
/// \return Pointer to the actual resource
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator const T*() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload to return a reference to the actual resource
|
||||
///
|
||||
/// \return Reference to the internal resource
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const T& operator *() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -> overload to return a pointer to the actual resource
|
||||
///
|
||||
/// \return Pointer to the internal resource
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const T* operator ->() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Function called when the observed resource is about to be
|
||||
/// destroyed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
88
include/SFML/System/Resource.inl
Normal file
88
include/SFML/System/Resource.inl
Normal file
|
@ -0,0 +1,88 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>::Resource()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>::Resource(const Resource<T>&)
|
||||
{
|
||||
// Nothing to do, we don't want to copy observers
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Resource<T>& Resource<T>::operator =(const Resource<T>&)
|
||||
{
|
||||
// Nothing to do, we don't want to copy observers
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Connect a ResourcePtr to this resource
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void Resource<T>::Connect(ResourcePtr<T>& Observer) const
|
||||
{
|
||||
myObservers.insert(&Observer);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Disconnect a ResourcePtr from this resource
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void Resource<T>::Disconnect(ResourcePtr<T>& Observer) const
|
||||
{
|
||||
myObservers.erase(&Observer);
|
||||
}
|
149
include/SFML/System/ResourcePtr.inl
Normal file
149
include/SFML/System/ResourcePtr.inl
Normal file
|
@ -0,0 +1,149 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::ResourcePtr() :
|
||||
myResource(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct from a raw resource
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::ResourcePtr(const T* Resource) :
|
||||
myResource(Resource)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) :
|
||||
myResource(Copy.myResource)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::~ResourcePtr()
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Disconnect(*this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator from another ResourcePtr
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other)
|
||||
{
|
||||
if (myResource)
|
||||
myResource->Disconnect(*this);
|
||||
|
||||
myResource = Other.myResource;
|
||||
|
||||
if (myResource)
|
||||
myResource->Connect(*this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Assignment operator from a raw resource
|
||||
////////////////////////////////////////////////////////////
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Cast operator to implicitely convert the resource pointer to
|
||||
/// its raw pointer type.
|
||||
/// This might be dangerous in the general case, but in this context
|
||||
/// it is safe enough to define this operator
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ResourcePtr<T>::operator const T*() const
|
||||
{
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload to return a reference to the actual resource
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
const T& ResourcePtr<T>::operator *() const
|
||||
{
|
||||
return *myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -> overload to return a pointer to the actual resource
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
const T* ResourcePtr<T>::operator ->() const
|
||||
{
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Function called when the observed resource is about to be
|
||||
/// destroyed
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void ResourcePtr<T>::OnResourceDestroyed()
|
||||
{
|
||||
myResource = NULL;
|
||||
}
|
47
include/SFML/System/Sleep.hpp
Normal file
47
include/SFML/System/Sleep.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_SLEEP_HPP
|
||||
#define SFML_SLEEP_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make the current thread sleep for a given time
|
||||
///
|
||||
/// \param Duration : Time to sleep, in seconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_API Sleep(float Duration);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SLEEP_HPP
|
45
include/SFML/System/Thread.hpp
Normal file
45
include/SFML/System/Thread.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_THREAD_HPP
|
||||
#define SFML_THREAD_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
#ifdef SFML_SYSTEM_WINDOWS
|
||||
|
||||
#include <SFML/System/Win32/Thread.hpp>
|
||||
|
||||
#else
|
||||
|
||||
#include <SFML/System/Unix/Thread.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_THREAD_HPP
|
290
include/SFML/System/Unicode.hpp
Normal file
290
include/SFML/System/Unicode.hpp
Normal file
|
@ -0,0 +1,290 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_UNICODE_HPP
|
||||
#define SFML_UNICODE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Provides utility functions to convert from and to
|
||||
/// any unicode and ASCII encoding
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Unicode
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Define a string type for each encoding
|
||||
/// Warning : in UTF8 and UTF16 strings, one element doesn't
|
||||
/// necessarily maps to one character ; only an UTF32 element
|
||||
/// is wide enough to hold all possible unicode values
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::basic_string<Uint8> UTF8String;
|
||||
typedef std::basic_string<Uint16> UTF16String;
|
||||
typedef std::basic_string<Uint32> UTF32String;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// This class is an abstract definition of a unicode text,
|
||||
/// it can be converted from and to any kind of string
|
||||
/// and encoding
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Text
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor (empty text)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the unicode text from any type of string
|
||||
///
|
||||
/// \param Str : String to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text(const char* Str);
|
||||
Text(const wchar_t* Str);
|
||||
Text(const Uint8* Str);
|
||||
Text(const Uint16* Str);
|
||||
Text(const Uint32* Str);
|
||||
Text(const std::string& Str);
|
||||
Text(const std::wstring& Str);
|
||||
Text(const Unicode::UTF8String& Str);
|
||||
Text(const Unicode::UTF16String& Str);
|
||||
Text(const Unicode::UTF32String& Str);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator to cast the text to any type of string
|
||||
///
|
||||
/// \return Converted string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::string () const;
|
||||
operator std::wstring () const;
|
||||
operator Unicode::UTF8String () const;
|
||||
operator Unicode::UTF16String () const;
|
||||
operator const Unicode::UTF32String&() const;
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Data member
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Unicode::UTF32String myUTF32String; ///< UTF-32 unicode text
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an ANSI characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
/// \param Locale : Locale to use for conversion (uses the current one by default)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement = '?', const std::locale& Locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an ANSI characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Locale : Locale to use for conversion (uses the current one by default)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
/// \param Output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-8 string
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF8Length(In Begin, In End);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-16 string
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF16Length(In Begin, In End);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-32 string
|
||||
///
|
||||
/// \param Begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param End : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF32Length(In Begin, In End);
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default system locale
|
||||
///
|
||||
/// \return Reference to the default system locale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static const std::locale& GetDefaultLocale();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const char UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
|
||||
static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions
|
||||
static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences
|
||||
};
|
||||
|
||||
#include <SFML/System/Unicode.inl>
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_UNICODE_HPP
|
474
include/SFML/System/Unicode.inl
Normal file
474
include/SFML/System/Unicode.inl
Normal file
|
@ -0,0 +1,474 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an ANSI characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToANSI(In Begin, In End, Out Output, char Replacement, const std::locale& Locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has a almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
while (Begin < End)
|
||||
{
|
||||
char Char = 0;
|
||||
if (wctomb(&Char, static_cast<wchar_t>(*Begin++)) >= 0)
|
||||
*Output++ = Char;
|
||||
else if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
while (Begin < End)
|
||||
*Output++ = Facet.narrow(static_cast<wchar_t>(*Begin++), Replacement);
|
||||
|
||||
#endif
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an ANSI characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has a almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
while (Begin < End)
|
||||
{
|
||||
wchar_t Char = 0;
|
||||
mbtowc(&Char, &*Begin, 1);
|
||||
Begin++;
|
||||
*Output++ = static_cast<Uint32>(Char);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
while (Begin < End)
|
||||
*Output++ = static_cast<Uint32>(Facet.widen(*Begin++));
|
||||
|
||||
#endif
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = 0;
|
||||
int TrailingBytes = UTF8TrailingBytes[*Begin];
|
||||
if (Begin + TrailingBytes < End)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
switch (TrailingBytes)
|
||||
{
|
||||
case 5 : c += *Begin++; c <<= 6;
|
||||
case 4 : c += *Begin++; c <<= 6;
|
||||
case 3 : c += *Begin++; c <<= 6;
|
||||
case 2 : c += *Begin++; c <<= 6;
|
||||
case 1 : c += *Begin++; c <<= 6;
|
||||
case 0 : c += *Begin++;
|
||||
}
|
||||
c -= UTF8Offsets[TrailingBytes];
|
||||
|
||||
// Then encode it in UTF-16
|
||||
if (c < 0xFFFF)
|
||||
{
|
||||
// Character can be converted directly to 16 bits, just need to check it's in the valid range
|
||||
if ((c >= 0xD800) && (c <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to 16 bits
|
||||
*Output++ = static_cast<Uint16>(c);
|
||||
}
|
||||
}
|
||||
else if (c > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Character will be converted to 2 UTF-16 elements
|
||||
c -= 0x0010000;
|
||||
*Output++ = static_cast<Uint16>((c >> 10) + 0xD800);
|
||||
*Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = 0;
|
||||
int TrailingBytes = UTF8TrailingBytes[*Begin];
|
||||
if (Begin + TrailingBytes < End)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
switch (TrailingBytes)
|
||||
{
|
||||
case 5 : c += *Begin++; c <<= 6;
|
||||
case 4 : c += *Begin++; c <<= 6;
|
||||
case 3 : c += *Begin++; c <<= 6;
|
||||
case 2 : c += *Begin++; c <<= 6;
|
||||
case 1 : c += *Begin++; c <<= 6;
|
||||
case 0 : c += *Begin++;
|
||||
}
|
||||
c -= UTF8Offsets[TrailingBytes];
|
||||
|
||||
// Then write it if valid
|
||||
if ((c < 0xD800) || (c > 0xDFFF))
|
||||
{
|
||||
// Valid UTF-32 character
|
||||
*Output++ = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid UTF-32 character
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = *Begin++;
|
||||
|
||||
// If it's a surrogate pair, first convert to a single UTF-32 character
|
||||
if ((c >= 0xD800) && (c <= 0xDBFF))
|
||||
{
|
||||
if (Begin < End)
|
||||
{
|
||||
// The second element is valid : convert the two elements to a UTF-32 character
|
||||
Uint32 d = *Begin++;
|
||||
if ((d >= 0xDC00) && (d <= 0xDFFF))
|
||||
c = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid second element
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
}
|
||||
|
||||
// Then convert to UTF-8
|
||||
if (c > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get number of bytes to write
|
||||
int BytesToWrite = 1;
|
||||
if (c < 0x80) BytesToWrite = 1;
|
||||
else if (c < 0x800) BytesToWrite = 2;
|
||||
else if (c < 0x10000) BytesToWrite = 3;
|
||||
else if (c <= 0x0010FFFF) BytesToWrite = 4;
|
||||
|
||||
// Extract bytes to write
|
||||
Uint8 Bytes[4];
|
||||
switch (BytesToWrite)
|
||||
{
|
||||
case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
const Uint8* CurByte = Bytes;
|
||||
switch (BytesToWrite)
|
||||
{
|
||||
case 4 : *Output++ = *CurByte++;
|
||||
case 3 : *Output++ = *CurByte++;
|
||||
case 2 : *Output++ = *CurByte++;
|
||||
case 1 : *Output++ = *CurByte++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint16 c = *Begin++;
|
||||
if ((c >= 0xD800) && (c <= 0xDBFF))
|
||||
{
|
||||
// We have a surrogate pair, ie. a character composed of two elements
|
||||
if (Begin < End)
|
||||
{
|
||||
Uint16 d = *Begin++;
|
||||
if ((d >= 0xDC00) && (d <= 0xDFFF))
|
||||
{
|
||||
// The second element is valid : convert the two elements to a UTF-32 character
|
||||
*Output++ = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid second element
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((c >= 0xDC00) && (c <= 0xDFFF))
|
||||
{
|
||||
// Invalid character
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to UTF-32
|
||||
*Output++ = static_cast<Uint32>(c);
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = *Begin++;
|
||||
if (c > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get number of bytes to write
|
||||
int BytesToWrite = 1;
|
||||
if (c < 0x80) BytesToWrite = 1;
|
||||
else if (c < 0x800) BytesToWrite = 2;
|
||||
else if (c < 0x10000) BytesToWrite = 3;
|
||||
else if (c <= 0x0010FFFF) BytesToWrite = 4;
|
||||
|
||||
// Extract bytes to write
|
||||
Uint8 Bytes[4];
|
||||
switch (BytesToWrite)
|
||||
{
|
||||
case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
|
||||
case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
const Uint8* CurByte = Bytes;
|
||||
switch (BytesToWrite)
|
||||
{
|
||||
case 4 : *Output++ = *CurByte++;
|
||||
case 3 : *Output++ = *CurByte++;
|
||||
case 2 : *Output++ = *CurByte++;
|
||||
case 1 : *Output++ = *CurByte++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)
|
||||
{
|
||||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = *Begin++;
|
||||
if (c < 0xFFFF)
|
||||
{
|
||||
// Character can be converted directly to 16 bits, just need to check it's in the valid range
|
||||
if ((c >= 0xD800) && (c <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to 16 bits
|
||||
*Output++ = static_cast<Uint16>(c);
|
||||
}
|
||||
}
|
||||
else if (c > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (Replacement)
|
||||
*Output++ = Replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Character will be converted to 2 UTF-16 elements
|
||||
c -= 0x0010000;
|
||||
*Output++ = static_cast<Uint16>((c >> 10) + 0xD800);
|
||||
*Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-8 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF8Length(In Begin, In End)
|
||||
{
|
||||
std::size_t Length = 0;
|
||||
while (Begin < End)
|
||||
{
|
||||
int NbBytes = UTF8TrailingBytes[*Begin];
|
||||
if (Begin + NbBytes < End)
|
||||
++Length;
|
||||
|
||||
Begin += NbBytes + 1;
|
||||
}
|
||||
|
||||
return Length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-16 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF16Length(In Begin, In End)
|
||||
{
|
||||
std::size_t Length = 0;
|
||||
while (Begin < End)
|
||||
{
|
||||
if ((*Begin >= 0xD800) && (*Begin <= 0xDBFF))
|
||||
{
|
||||
++Begin;
|
||||
if ((Begin < End) && ((*Begin >= 0xDC00) && (*Begin <= 0xDFFF)))
|
||||
{
|
||||
++Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++Length;
|
||||
}
|
||||
|
||||
++Begin;
|
||||
}
|
||||
|
||||
return Length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-32 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF32Length(In Begin, In End)
|
||||
{
|
||||
return End - Begin;
|
||||
}
|
82
include/SFML/System/Unix/Mutex.hpp
Normal file
82
include/SFML/System/Unix/Mutex.hpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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_MUTEXUNIX_HPP
|
||||
#define SFML_MUTEXUNIX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Mutex defines a mutex (MUTual EXclusion) object,
|
||||
/// that allows a thread to lock critical instructions
|
||||
/// to avoid simultaneous access with other threads.
|
||||
/// See Lock for an efficient way of using it.
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Mutex : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Lock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Lock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Unlock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Unlock();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
pthread_mutex_t myMutex; ///< pthread instance of the mutex
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_MUTEXUNIX_HPP
|
124
include/SFML/System/Unix/Thread.hpp
Normal file
124
include/SFML/System/Unix/Thread.hpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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_THREADUNIX_HPP
|
||||
#define SFML_THREADUNIX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Thread defines a thread.
|
||||
/// There is two ways to use Thread :
|
||||
/// - Inherit from it and override the Run() virtual function
|
||||
/// - Construct a sfThread instance and pass it a function
|
||||
/// pointer to call
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Thread : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
typedef void (*FuncType)(void*);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the thread from a function pointer
|
||||
///
|
||||
/// \param Function : Entry point of the thread
|
||||
/// \param UserData : Data to pass to the thread function (NULL by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Thread(FuncType Function, void* UserData = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Thread();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create and run the thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Launch();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Wait until the thread finishes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Wait();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Terminate the thread
|
||||
/// Terminating a thread with this function is not safe,
|
||||
/// you should rather try to make the thread function
|
||||
/// terminate by itself
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Terminate();
|
||||
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Thread();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Function called as the thread entry point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void Run();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Actual thread entry point, dispatches to instances
|
||||
///
|
||||
/// \param UserData : Data to pass to the thread function
|
||||
///
|
||||
/// \return Error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void* ThreadFunc(void* UserData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
pthread_t myThread; ///< Unix thread instance
|
||||
bool myIsActive; ///< Thread state (active or inactive)
|
||||
FuncType myFunction; ///< Function to call as the thread entry point
|
||||
void* myUserData; ///< Data to pass to the thread function
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_THREADUNIX_HPP
|
215
include/SFML/System/Vector2.hpp
Normal file
215
include/SFML/System/Vector2.hpp
Normal file
|
@ -0,0 +1,215 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_VECTOR2_HPP
|
||||
#define SFML_VECTOR2_HPP
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Vector2 is an utility class for manipulating 2 dimensional
|
||||
/// vectors. Template parameter defines the type of coordinates
|
||||
/// (integer, float, ...)
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Vector2
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the vector from its coordinates
|
||||
///
|
||||
/// \param X : X coordinate
|
||||
/// \param Y : Y coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2(T X, T Y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
T x; ///< X coordinate of the vector
|
||||
T y; ///< Y coordinate of the vector
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
///
|
||||
/// \param V : Vector to negate
|
||||
///
|
||||
/// \return -V
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& V);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator += overload ; add two vectors and assign to the first op
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 + V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -= overload ; subtract two vectors and assign to the first op
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 - V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator + overload ; adds two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 + V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 - V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V * X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(const Vector2<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
///
|
||||
/// \param X : Scalar value
|
||||
/// \param V : Vector
|
||||
///
|
||||
/// \return X * V
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(T X, const Vector2<T>& V);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator *= overload ; multiply-assign a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V * X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator *=(Vector2<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V / X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator /(const Vector2<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator /= overload ; divide-assign a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V / X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator /=(Vector2<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator == overload ; compares the equality of two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return True if V1 is equal to V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator != overload ; compares the difference of two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return True if V1 is different than V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2);
|
||||
|
||||
#include <SFML/System/Vector2.inl>
|
||||
|
||||
// Define the most common types
|
||||
typedef Vector2<int> Vector2i;
|
||||
typedef Vector2<float> Vector2f;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VECTOR2_HPP
|
179
include/SFML/System/Vector2.inl
Normal file
179
include/SFML/System/Vector2.inl
Normal file
|
@ -0,0 +1,179 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>::Vector2() :
|
||||
x(0),
|
||||
y(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the color from its coordinates
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>::Vector2(T X, T Y) :
|
||||
x(X),
|
||||
y(Y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& V)
|
||||
{
|
||||
return Vector2<T>(-V.x, -V.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator += overload ; add two vectors and assign to the first op
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
V1.x += V2.x;
|
||||
V1.y += V2.y;
|
||||
|
||||
return V1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -= overload ; subtract two vectors and assign to the first op
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
V1.x -= V2.x;
|
||||
V1.y -= V2.y;
|
||||
|
||||
return V1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator + overload ; adds two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
return Vector2<T>(V1.x + V2.x, V1.y + V2.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
return Vector2<T>(V1.x - V2.x, V1.y - V2.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(const Vector2<T>& V, T X)
|
||||
{
|
||||
return Vector2<T>(V.x * X, V.y * X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(T X, const Vector2<T>& V)
|
||||
{
|
||||
return Vector2<T>(V.x * X, V.y * X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator *= overload ; multiply-assign a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator *=(Vector2<T>& V, T X)
|
||||
{
|
||||
V.x *= X;
|
||||
V.y *= X;
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator /(const Vector2<T>& V, T X)
|
||||
{
|
||||
return Vector2<T>(V.x / X, V.y / X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator /= overload ; divide-assign a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator /=(Vector2<T>& V, T X)
|
||||
{
|
||||
V.x /= X;
|
||||
V.y /= X;
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator == overload ; compares the equality of two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
return (V1.x == V2.x) && (V1.y == V2.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator != overload ; compares the difference of two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)
|
||||
{
|
||||
return (V1.x != V2.x) || (V1.y != V2.y);
|
||||
}
|
217
include/SFML/System/Vector3.hpp
Normal file
217
include/SFML/System/Vector3.hpp
Normal file
|
@ -0,0 +1,217 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_VECTOR3_HPP
|
||||
#define SFML_VECTOR3_HPP
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Vector3 is an utility class for manipulating 3 dimensional
|
||||
/// vectors. Template parameter defines the type of coordinates
|
||||
/// (integer, float, ...)
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Vector3
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the vector from its coordinates
|
||||
///
|
||||
/// \param X : X coordinate
|
||||
/// \param Y : Y coordinate
|
||||
/// \param Z : Z coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3(T X, T Y, T Z);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
T x; ///< X coordinate of the vector
|
||||
T y; ///< Y coordinate of the vector
|
||||
T z; ///< Z coordinate of the vector
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
///
|
||||
/// \param V : Vector to negate
|
||||
///
|
||||
/// \return -V
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& V);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator += overload ; add two vectors and assign to the first op
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 + V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -= overload ; subtract two vectors and assign to the first op
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 - V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator + overload ; adds two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 + V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return V1 - V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V * X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(const Vector3<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
///
|
||||
/// \param X : Scalar value
|
||||
/// \param V : Vector
|
||||
///
|
||||
/// \return X * V
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(T X, const Vector3<T>& V);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator *= overload ; multiply-assign a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V * X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator *=(Vector3<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V / X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator /(const Vector3<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator /= overload ; divide-assign a vector by a scalar value
|
||||
///
|
||||
/// \param V : Vector
|
||||
/// \param X : Scalar value
|
||||
///
|
||||
/// \return V / X
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator /=(Vector3<T>& V, T X);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator == overload ; compares the equality of two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return True if V1 is equal to V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator != overload ; compares the difference of two vectors
|
||||
///
|
||||
/// \param V1 : First vector
|
||||
/// \param V2 : Second vector
|
||||
///
|
||||
/// \return True if V1 is different than V2
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2);
|
||||
|
||||
#include <SFML/System/Vector3.inl>
|
||||
|
||||
// Define the most common types
|
||||
typedef Vector3<int> Vector3i;
|
||||
typedef Vector3<float> Vector3f;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VECTOR3_HPP
|
185
include/SFML/System/Vector3.inl
Normal file
185
include/SFML/System/Vector3.inl
Normal file
|
@ -0,0 +1,185 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>::Vector3() :
|
||||
x(0),
|
||||
y(0),
|
||||
z(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the color from its coordinates
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>::Vector3(T X, T Y, T Z) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& V)
|
||||
{
|
||||
return Vector3<T>(-V.x, -V.y, -V.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator += overload ; add two vectors and assign to the first op
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
V1.x += V2.x;
|
||||
V1.y += V2.y;
|
||||
V1.z += V2.z;
|
||||
|
||||
return V1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator -= overload ; subtract two vectors and assign to the first op
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
V1.x -= V2.x;
|
||||
V1.y -= V2.y;
|
||||
V1.z -= V2.z;
|
||||
|
||||
return V1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator + overload ; adds two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(const Vector3<T>& V, T X)
|
||||
{
|
||||
return Vector3<T>(V.x * X, V.y * X, V.z * X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(T X, const Vector3<T>& V)
|
||||
{
|
||||
return Vector3<T>(V.x * X, V.y * X, V.z * X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator *= overload ; multiply-assign a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator *=(Vector3<T>& V, T X)
|
||||
{
|
||||
V.x *= X;
|
||||
V.y *= X;
|
||||
V.z *= X;
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator /(const Vector3<T>& V, T X)
|
||||
{
|
||||
return Vector3<T>(V.x / X, V.y / X, V.z / X);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator /= overload ; divide-assign a vector by a scalar value
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator /=(Vector3<T>& V, T X)
|
||||
{
|
||||
V.x /= X;
|
||||
V.y /= X;
|
||||
V.z /= X;
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator == overload ; compares the equality of two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator != overload ; compares the difference of two vectors
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2)
|
||||
{
|
||||
return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);
|
||||
}
|
84
include/SFML/System/Win32/Mutex.hpp
Normal file
84
include/SFML/System/Win32/Mutex.hpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_MUTEXWIN32_HPP
|
||||
#define SFML_MUTEXWIN32_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Mutex defines a mutex (MUTual EXclusion) object,
|
||||
/// that allows a thread to lock critical instructions
|
||||
/// to avoid simultaneous access with other threads.
|
||||
/// The Win32 version uses critical sections, as it is
|
||||
/// faster than mutexes.<br/>
|
||||
/// See Lock for an efficient way of using it.
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Mutex : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Lock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Lock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Unlock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Unlock();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
CRITICAL_SECTION myHandle; ///< Win32 handle of the mutex
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_MUTEXWIN32_HPP
|
123
include/SFML/System/Win32/Thread.hpp
Normal file
123
include/SFML/System/Win32/Thread.hpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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_THREADWIN32_HPP
|
||||
#define SFML_THREADWIN32_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Thread defines an easy way to manipulate a thread.
|
||||
/// There are two ways to use Thread :
|
||||
/// - Inherit from it and override the Run() virtual function
|
||||
/// - Construct a Thread instance and pass it a function
|
||||
/// pointer to call
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Thread : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
typedef void (*FuncType)(void*);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the thread from a function pointer
|
||||
///
|
||||
/// \param Function : Entry point of the thread
|
||||
/// \param UserData : Data to pass to the thread function (NULL by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Thread(FuncType Function, void* UserData = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Thread();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create and run the thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Launch();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Wait until the thread finishes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Wait();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Terminate the thread
|
||||
/// Terminating a thread with this function is not safe,
|
||||
/// you should rather try to make the thread function
|
||||
/// terminate by itself
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Terminate();
|
||||
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Thread();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Function called as the thread entry point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void Run();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Actual thread entry point, dispatches to instances
|
||||
///
|
||||
/// \param UserData : Data to pass to the thread function
|
||||
///
|
||||
/// \return Error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int __stdcall ThreadFunc(void* UserData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
HANDLE myHandle; ///< Win32 thread handle
|
||||
FuncType myFunction; ///< Function to call as the thread entry point
|
||||
void* myUserData; ///< Data to pass to the thread function
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_THREADWIN32_HPP
|
Loading…
Add table
Add a link
Reference in a new issue