Removed the sf::Randomizer class from the system module
This commit is contained in:
parent
e3c8fd6586
commit
a4f6e915a0
@ -1,74 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2009 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_H
|
|
||||||
#define SFML_RANDOMIZER_H
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.h>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Set the seed for the random numbers generator. Using a known seed
|
|
||||||
/// allows you to reproduce the same sequence of random numbers
|
|
||||||
///
|
|
||||||
/// \param seed : Number to use as the seed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_API void sfRandom_SetSeed(unsigned int seed);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get the seed used to generate random numbers the generator
|
|
||||||
///
|
|
||||||
/// \return Current seed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_API unsigned int sfRandom_GetSeed(void);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get a random float number in a given range
|
|
||||||
///
|
|
||||||
/// \return begin : Start of the range
|
|
||||||
/// \return end : End of the range
|
|
||||||
///
|
|
||||||
/// \return Random number in [begin, end]
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_API float sfRandom_Float(float begin, float end);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get a random integer number in a given range
|
|
||||||
///
|
|
||||||
/// \return begin : Start of the range
|
|
||||||
/// \return end : End of the range
|
|
||||||
///
|
|
||||||
/// \return Random number in [begin, end]
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_API int sfRandom_Int(int begin, int end);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RANDOMIZER_H
|
|
@ -10,8 +10,6 @@ set(SRC
|
|||||||
${SRCROOT}/Mutex.cpp
|
${SRCROOT}/Mutex.cpp
|
||||||
${SRCROOT}/MutexStruct.h
|
${SRCROOT}/MutexStruct.h
|
||||||
${INCROOT}/Mutex.h
|
${INCROOT}/Mutex.h
|
||||||
${SRCROOT}/Randomizer.cpp
|
|
||||||
${INCROOT}/Randomizer.h
|
|
||||||
${SRCROOT}/Sleep.cpp
|
${SRCROOT}/Sleep.cpp
|
||||||
${INCROOT}/Sleep.h
|
${INCROOT}/Sleep.h
|
||||||
${SRCROOT}/Thread.cpp
|
${SRCROOT}/Thread.cpp
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2009 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.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Randomizer.h>
|
|
||||||
#include <SFML/System/Randomizer.hpp>
|
|
||||||
#include <SFML/Internal.h>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Set the seed for the random numbers generator. Using a known seed
|
|
||||||
/// allows you to reproduce the same sequence of random numbers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void sfRandom_SetSeed(unsigned int seed)
|
|
||||||
{
|
|
||||||
sf::Randomizer::SetSeed(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get the seed used to generate random numbers the generator
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int sfRandom_GetSeed(void)
|
|
||||||
{
|
|
||||||
return sf::Randomizer::GetSeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get a random float number in a given range
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float sfRandom_Float(float begin, float end)
|
|
||||||
{
|
|
||||||
return sf::Randomizer::Random(begin, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get a random integer number in a given range
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
int sfRandom_Int(int begin, int end)
|
|
||||||
{
|
|
||||||
return sf::Randomizer::Random(begin, end);
|
|
||||||
}
|
|
@ -5,6 +5,8 @@
|
|||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -15,6 +17,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
// Defines PI
|
// Defines PI
|
||||||
const float PI = 3.14159f;
|
const float PI = 3.14159f;
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ int main()
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Make sure the ball initial angle is not too much vertical
|
// Make sure the ball initial angle is not too much vertical
|
||||||
ballAngle = sf::Randomizer::Random(0.f, 2 * PI);
|
ballAngle = std::rand() * 2 * PI / RAND_MAX;
|
||||||
} while (std::abs(std::cos(ballAngle)) < 0.7f);
|
} while (std::abs(std::cos(ballAngle)) < 0.7f);
|
||||||
|
|
||||||
bool isPlaying = true;
|
bool isPlaying = true;
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <SFML/System/Lock.hpp>
|
#include <SFML/System/Lock.hpp>
|
||||||
#include <SFML/System/Mutex.hpp>
|
#include <SFML/System/Mutex.hpp>
|
||||||
#include <SFML/System/Randomizer.hpp>
|
|
||||||
#include <SFML/System/Sleep.hpp>
|
#include <SFML/System/Sleep.hpp>
|
||||||
#include <SFML/System/String.hpp>
|
#include <SFML/System/String.hpp>
|
||||||
#include <SFML/System/Thread.hpp>
|
#include <SFML/System/Thread.hpp>
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2009 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
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class for generating pseudo-random numbers
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_API Randomizer
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set a new seed for the generator
|
|
||||||
///
|
|
||||||
/// Using a known seed allows you to reproduce the same
|
|
||||||
/// sequence of random numbers.
|
|
||||||
///
|
|
||||||
/// \param seed Number to use as the seed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void SetSeed(unsigned int seed);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current seed of the generator
|
|
||||||
///
|
|
||||||
/// \return Current seed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static unsigned int GetSeed();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a random float number in a given range
|
|
||||||
///
|
|
||||||
/// \param begin Beginning of the range
|
|
||||||
/// \param end End of the range
|
|
||||||
///
|
|
||||||
/// \return Random number in [begin, end]
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static float Random(float begin, float end);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a random integer number in a given range
|
|
||||||
///
|
|
||||||
/// \param begin Beginning of the range
|
|
||||||
/// \param end End of the range
|
|
||||||
///
|
|
||||||
/// \return Random number in [begin, end]
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static int Random(int begin, int end);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RANDOMIZER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Randomizer
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// sf::Randomizer generates pseudo-random numbers using the
|
|
||||||
/// standard library.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// int x1 = sf::Randomizer::Random(0, 6);
|
|
||||||
/// float x2 = sf::Randomizer::Random(0.f, 1.f);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Note that, unlike the standard rand() function, you don't
|
|
||||||
/// have to initialize the seed before using this class. SFML does
|
|
||||||
/// it for you, so that you will automatically get different results
|
|
||||||
/// for every execution of the program.
|
|
||||||
///
|
|
||||||
/// The SetSeed and GetSeed functions are provided mainly for being
|
|
||||||
/// able to reproduce the same set of numbers in a recorded
|
|
||||||
/// sequence. This is useful when implementing replays, for example.
|
|
||||||
///
|
|
||||||
/// The technique used by sf::Randomizer for getting random numbers
|
|
||||||
/// is not the most accurate: some numbers may have a slightly higher
|
|
||||||
/// probability than others, under certain circumstancies.
|
|
||||||
/// This doesn't matter in 99.9% of situations, but if you really
|
|
||||||
/// need a generator which is mathematically more robust
|
|
||||||
/// you should use another library for that part (see boost.random).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -14,8 +14,6 @@ set(SRC
|
|||||||
${INCROOT}/Mutex.hpp
|
${INCROOT}/Mutex.hpp
|
||||||
${INCROOT}/NonCopyable.hpp
|
${INCROOT}/NonCopyable.hpp
|
||||||
${SRCROOT}/Platform.hpp
|
${SRCROOT}/Platform.hpp
|
||||||
${SRCROOT}/Randomizer.cpp
|
|
||||||
${INCROOT}/Randomizer.hpp
|
|
||||||
${INCROOT}/Resource.hpp
|
${INCROOT}/Resource.hpp
|
||||||
${INCROOT}/Resource.inl
|
${INCROOT}/Resource.inl
|
||||||
${INCROOT}/ResourcePtr.inl
|
${INCROOT}/ResourcePtr.inl
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2009 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.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Randomizer.hpp>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Private data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// Initialize the generator's seed with the current system time
|
|
||||||
// in milliseconds, so that it is always different
|
|
||||||
unsigned int InitializeSeed()
|
|
||||||
{
|
|
||||||
unsigned int seed = static_cast<unsigned int>(std::time(NULL));
|
|
||||||
std::srand(seed);
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global variable storing the current seed
|
|
||||||
unsigned int globalSeed = InitializeSeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Randomizer::SetSeed(unsigned int seed)
|
|
||||||
{
|
|
||||||
std::srand(seed);
|
|
||||||
globalSeed = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int Randomizer::GetSeed()
|
|
||||||
{
|
|
||||||
return globalSeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float Randomizer::Random(float begin, float end)
|
|
||||||
{
|
|
||||||
// This is not the best algorithm, but it is fast and will be enough in most cases
|
|
||||||
|
|
||||||
return static_cast<float>(std::rand()) / RAND_MAX * (end - begin) + begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get a random integer number in a given range
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
int Randomizer::Random(int begin, int end)
|
|
||||||
{
|
|
||||||
// This is not the best algorithm, but it is fast and will be enough in most cases
|
|
||||||
|
|
||||||
return std::rand() % (end - begin + 1) + begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sf
|
|
Loading…
Reference in New Issue
Block a user