Changed the naming convention for public member variables/functions and free functions (using lowerCase instead of UpperCase)
This commit is contained in:
parent
ff5b69d312
commit
14ac411542
200 changed files with 4302 additions and 4320 deletions
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void ALCheckError(const std::string& file, unsigned int line)
|
||||
void alCheckError(const std::string& file, unsigned int line)
|
||||
{
|
||||
// Get the last error
|
||||
ALenum errorCode = alGetError();
|
||||
|
@ -84,7 +84,7 @@ void ALCheckError(const std::string& file, unsigned int line)
|
|||
}
|
||||
|
||||
// Log the error
|
||||
Err() << "An internal OpenAL call failed in "
|
||||
err() << "An internal OpenAL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
|
@ -95,7 +95,7 @@ void ALCheckError(const std::string& file, unsigned int line)
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Make sure that OpenAL is initialized
|
||||
////////////////////////////////////////////////////////////
|
||||
void EnsureALInit()
|
||||
void ensureALInit()
|
||||
{
|
||||
// The audio device is instanciated on demand rather than at global startup,
|
||||
// which solves a lot of weird crashes and errors.
|
||||
|
|
|
@ -40,18 +40,17 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenAL
|
||||
/// API calls
|
||||
/// Let's define a macro to quickly check every OpenAL API calls
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
// If in debug mode, perform a test on every call
|
||||
#define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
|
||||
#define alCheck(Func) ((Func), priv::alCheckError(__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define ALCheck(Func) (Func)
|
||||
#define alCheck(Func) (Func)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -63,13 +62,13 @@ namespace priv
|
|||
/// \param line Line number of the source file where the call is located
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void ALCheckError(const std::string& file, unsigned int line);
|
||||
void alCheckError(const std::string& file, unsigned int line);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make sure that OpenAL is initialized
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void EnsureALInit();
|
||||
void ensureALInit();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
@ -59,12 +59,12 @@ AudioDevice::AudioDevice()
|
|||
}
|
||||
else
|
||||
{
|
||||
Err() << "Failed to create the audio context" << std::endl;
|
||||
err() << "Failed to create the audio context" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Err() << "Failed to open the audio device" << std::endl;
|
||||
err() << "Failed to open the audio device" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,9 @@ AudioDevice::~AudioDevice()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool AudioDevice::IsExtensionSupported(const std::string& extension)
|
||||
bool AudioDevice::isExtensionSupported(const std::string& extension)
|
||||
{
|
||||
EnsureALInit();
|
||||
ensureALInit();
|
||||
|
||||
if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC"))
|
||||
return alcIsExtensionPresent(audioDevice, extension.c_str()) != AL_FALSE;
|
||||
|
@ -96,9 +96,9 @@ bool AudioDevice::IsExtensionSupported(const std::string& extension)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int AudioDevice::GetFormatFromChannelCount(unsigned int channelCount)
|
||||
int AudioDevice::getFormatFromChannelCount(unsigned int channelCount)
|
||||
{
|
||||
EnsureALInit();
|
||||
ensureALInit();
|
||||
|
||||
// Find the good format according to the number of channels
|
||||
switch (channelCount)
|
||||
|
|
|
@ -70,7 +70,7 @@ public :
|
|||
/// \return True if the extension is supported, false if not
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool IsExtensionSupported(const std::string& extension);
|
||||
static bool isExtensionSupported(const std::string& extension);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OpenAL format that matches the given number of channels
|
||||
|
@ -80,7 +80,7 @@ public :
|
|||
/// \return Corresponding format
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static int GetFormatFromChannelCount(unsigned int channelCount);
|
||||
static int getFormatFromChannelCount(unsigned int channelCount);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -26,84 +26,84 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetGlobalVolume(float volume)
|
||||
void Listener::setGlobalVolume(float volume)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
ALCheck(alListenerf(AL_GAIN, volume * 0.01f));
|
||||
alCheck(alListenerf(AL_GAIN, volume * 0.01f));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Listener::GetGlobalVolume()
|
||||
float Listener::getGlobalVolume()
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
float volume = 0.f;
|
||||
ALCheck(alGetListenerf(AL_GAIN, &volume));
|
||||
alCheck(alGetListenerf(AL_GAIN, &volume));
|
||||
|
||||
return volume * 100;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetPosition(float x, float y, float z)
|
||||
void Listener::setPosition(float x, float y, float z)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
ALCheck(alListener3f(AL_POSITION, x, y, z));
|
||||
alCheck(alListener3f(AL_POSITION, x, y, z));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetPosition(const Vector3f& position)
|
||||
void Listener::setPosition(const Vector3f& position)
|
||||
{
|
||||
SetPosition(position.x, position.y, position.z);
|
||||
setPosition(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3f Listener::GetPosition()
|
||||
Vector3f Listener::getPosition()
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
Vector3f position;
|
||||
ALCheck(alGetListener3f(AL_POSITION, &position.x, &position.y, &position.z));
|
||||
alCheck(alGetListener3f(AL_POSITION, &position.x, &position.y, &position.z));
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetDirection(float x, float y, float z)
|
||||
void Listener::setDirection(float x, float y, float z)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
float orientation[] = {x, y, z, 0.f, 1.f, 0.f};
|
||||
ALCheck(alListenerfv(AL_ORIENTATION, orientation));
|
||||
alCheck(alListenerfv(AL_ORIENTATION, orientation));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetDirection(const Vector3f& direction)
|
||||
void Listener::setDirection(const Vector3f& direction)
|
||||
{
|
||||
SetDirection(direction.x, direction.y, direction.z);
|
||||
setDirection(direction.x, direction.y, direction.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3f Listener::GetDirection()
|
||||
Vector3f Listener::getDirection()
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
float orientation[6];
|
||||
ALCheck(alGetListenerfv(AL_ORIENTATION, orientation));
|
||||
alCheck(alGetListenerfv(AL_ORIENTATION, orientation));
|
||||
|
||||
return Vector3f(orientation[0], orientation[1], orientation[2]);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Music.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
@ -48,104 +48,104 @@ m_duration()
|
|||
Music::~Music()
|
||||
{
|
||||
// We must stop before destroying the file :)
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
delete m_file;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OpenFromFile(const std::string& filename)
|
||||
bool Music::openFromFile(const std::string& filename)
|
||||
{
|
||||
// First stop the music if it was already running
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
// Open the underlying sound file
|
||||
if (!m_file->OpenRead(filename))
|
||||
if (!m_file->openRead(filename))
|
||||
return false;
|
||||
|
||||
// Perform common initializations
|
||||
Initialize();
|
||||
initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
bool Music::openFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
{
|
||||
// First stop the music if it was already running
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
// Open the underlying sound file
|
||||
if (!m_file->OpenRead(data, sizeInBytes))
|
||||
if (!m_file->openRead(data, sizeInBytes))
|
||||
return false;
|
||||
|
||||
// Perform common initializations
|
||||
Initialize();
|
||||
initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OpenFromStream(InputStream& stream)
|
||||
bool Music::openFromStream(InputStream& stream)
|
||||
{
|
||||
// First stop the music if it was already running
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
// Open the underlying sound file
|
||||
if (!m_file->OpenRead(stream))
|
||||
if (!m_file->openRead(stream))
|
||||
return false;
|
||||
|
||||
// Perform common initializations
|
||||
Initialize();
|
||||
initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Music::GetDuration() const
|
||||
Time Music::getDuration() const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OnGetData(SoundStream::Chunk& data)
|
||||
bool Music::onGetData(SoundStream::Chunk& data)
|
||||
{
|
||||
Lock lock(m_mutex);
|
||||
|
||||
// Fill the chunk parameters
|
||||
data.Samples = &m_samples[0];
|
||||
data.SampleCount = m_file->Read(&m_samples[0], m_samples.size());
|
||||
data.samples = &m_samples[0];
|
||||
data.sampleCount = m_file->read(&m_samples[0], m_samples.size());
|
||||
|
||||
// Check if we have reached the end of the audio file
|
||||
return data.SampleCount == m_samples.size();
|
||||
return data.sampleCount == m_samples.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Music::OnSeek(Time timeOffset)
|
||||
void Music::onSeek(Time timeOffset)
|
||||
{
|
||||
Lock lock(m_mutex);
|
||||
|
||||
m_file->Seek(timeOffset);
|
||||
m_file->seek(timeOffset);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Music::Initialize()
|
||||
void Music::initialize()
|
||||
{
|
||||
// Compute the music duration
|
||||
m_duration = Seconds(static_cast<float>(m_file->GetSampleCount()) / m_file->GetSampleRate() / m_file->GetChannelCount());
|
||||
m_duration = seconds(static_cast<float>(m_file->getSampleCount()) / m_file->getSampleRate() / m_file->getChannelCount());
|
||||
|
||||
// Resize the internal buffer so that it can contain 1 second of audio samples
|
||||
m_samples.resize(m_file->GetSampleRate() * m_file->GetChannelCount());
|
||||
m_samples.resize(m_file->getSampleRate() * m_file->getChannelCount());
|
||||
|
||||
// Initialize the stream
|
||||
SoundStream::Initialize(m_file->GetChannelCount(), m_file->GetSampleRate());
|
||||
SoundStream::initialize(m_file->getChannelCount(), m_file->getSampleRate());
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -43,7 +43,7 @@ m_buffer(NULL)
|
|||
Sound::Sound(const SoundBuffer& buffer) :
|
||||
m_buffer(NULL)
|
||||
{
|
||||
SetBuffer(buffer);
|
||||
setBuffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,103 +53,103 @@ SoundSource(copy),
|
|||
m_buffer (NULL)
|
||||
{
|
||||
if (copy.m_buffer)
|
||||
SetBuffer(*copy.m_buffer);
|
||||
SetLoop(copy.GetLoop());
|
||||
setBuffer(*copy.m_buffer);
|
||||
setLoop(copy.getLoop());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::~Sound()
|
||||
{
|
||||
Stop();
|
||||
stop();
|
||||
if (m_buffer)
|
||||
m_buffer->DetachSound(this);
|
||||
m_buffer->detachSound(this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::Play()
|
||||
void Sound::play()
|
||||
{
|
||||
ALCheck(alSourcePlay(m_source));
|
||||
alCheck(alSourcePlay(m_source));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::Pause()
|
||||
void Sound::pause()
|
||||
{
|
||||
ALCheck(alSourcePause(m_source));
|
||||
alCheck(alSourcePause(m_source));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::Stop()
|
||||
void Sound::stop()
|
||||
{
|
||||
ALCheck(alSourceStop(m_source));
|
||||
alCheck(alSourceStop(m_source));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::SetBuffer(const SoundBuffer& buffer)
|
||||
void Sound::setBuffer(const SoundBuffer& buffer)
|
||||
{
|
||||
// First detach from the previous buffer
|
||||
if (m_buffer)
|
||||
{
|
||||
Stop();
|
||||
m_buffer->DetachSound(this);
|
||||
stop();
|
||||
m_buffer->detachSound(this);
|
||||
}
|
||||
|
||||
// Assign and use the new buffer
|
||||
m_buffer = &buffer;
|
||||
m_buffer->AttachSound(this);
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, m_buffer->m_buffer));
|
||||
m_buffer->attachSound(this);
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, m_buffer->m_buffer));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::SetLoop(bool Loop)
|
||||
void Sound::setLoop(bool Loop)
|
||||
{
|
||||
ALCheck(alSourcei(m_source, AL_LOOPING, Loop));
|
||||
alCheck(alSourcei(m_source, AL_LOOPING, Loop));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::SetPlayingOffset(Time timeOffset)
|
||||
void Sound::setPlayingOffset(Time timeOffset)
|
||||
{
|
||||
ALCheck(alSourcef(m_source, AL_SEC_OFFSET, timeOffset.AsSeconds()));
|
||||
alCheck(alSourcef(m_source, AL_SEC_OFFSET, timeOffset.asSeconds()));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const SoundBuffer* Sound::GetBuffer() const
|
||||
const SoundBuffer* Sound::getBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Sound::GetLoop() const
|
||||
bool Sound::getLoop() const
|
||||
{
|
||||
ALint loop;
|
||||
ALCheck(alGetSourcei(m_source, AL_LOOPING, &loop));
|
||||
alCheck(alGetSourcei(m_source, AL_LOOPING, &loop));
|
||||
|
||||
return loop != 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Sound::GetPlayingOffset() const
|
||||
Time Sound::getPlayingOffset() const
|
||||
{
|
||||
ALfloat seconds = 0.f;
|
||||
ALCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &seconds));
|
||||
ALfloat secs = 0.f;
|
||||
alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs));
|
||||
|
||||
return Seconds(seconds);
|
||||
return seconds(secs);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Status Sound::GetStatus() const
|
||||
Sound::Status Sound::getStatus() const
|
||||
{
|
||||
return SoundSource::GetStatus();
|
||||
return SoundSource::getStatus();
|
||||
}
|
||||
|
||||
|
||||
|
@ -162,34 +162,34 @@ Sound& Sound::operator =(const Sound& right)
|
|||
// Detach the sound instance from the previous buffer (if any)
|
||||
if (m_buffer)
|
||||
{
|
||||
Stop();
|
||||
m_buffer->DetachSound(this);
|
||||
stop();
|
||||
m_buffer->detachSound(this);
|
||||
m_buffer = NULL;
|
||||
}
|
||||
|
||||
// Copy the sound attributes
|
||||
if (right.m_buffer)
|
||||
SetBuffer(*right.m_buffer);
|
||||
SetLoop(right.GetLoop());
|
||||
SetPitch(right.GetPitch());
|
||||
SetVolume(right.GetVolume());
|
||||
SetPosition(right.GetPosition());
|
||||
SetRelativeToListener(right.IsRelativeToListener());
|
||||
SetMinDistance(right.GetMinDistance());
|
||||
SetAttenuation(right.GetAttenuation());
|
||||
setBuffer(*right.m_buffer);
|
||||
setLoop(right.getLoop());
|
||||
setPitch(right.getPitch());
|
||||
setVolume(right.getVolume());
|
||||
setPosition(right.getPosition());
|
||||
setRelativeToListener(right.isRelativeToListener());
|
||||
setMinDistance(right.getMinDistance());
|
||||
setAttenuation(right.getAttenuation());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::ResetBuffer()
|
||||
void Sound::resetBuffer()
|
||||
{
|
||||
// First stop the sound in case it is playing
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
// Detach the buffer
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
m_buffer = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
@ -41,10 +41,10 @@ SoundBuffer::SoundBuffer() :
|
|||
m_buffer (0),
|
||||
m_duration()
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
// Create the buffer
|
||||
ALCheck(alGenBuffers(1, &m_buffer));
|
||||
alCheck(alGenBuffers(1, &m_buffer));
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,10 +56,10 @@ m_duration(copy.m_duration),
|
|||
m_sounds () // don't copy the attached sounds
|
||||
{
|
||||
// Create the buffer
|
||||
ALCheck(alGenBuffers(1, &m_buffer));
|
||||
alCheck(alGenBuffers(1, &m_buffer));
|
||||
|
||||
// Update the internal buffer with the new samples
|
||||
Update(copy.GetChannelCount(), copy.GetSampleRate());
|
||||
update(copy.getChannelCount(), copy.getSampleRate());
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,49 +68,49 @@ SoundBuffer::~SoundBuffer()
|
|||
{
|
||||
// First detach the buffer from the sounds that use it (to avoid OpenAL errors)
|
||||
for (SoundList::const_iterator it = m_sounds.begin(); it != m_sounds.end(); ++it)
|
||||
(*it)->ResetBuffer();
|
||||
(*it)->resetBuffer();
|
||||
|
||||
// Destroy the buffer
|
||||
if (m_buffer)
|
||||
ALCheck(alDeleteBuffers(1, &m_buffer));
|
||||
alCheck(alDeleteBuffers(1, &m_buffer));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::LoadFromFile(const std::string& filename)
|
||||
bool SoundBuffer::loadFromFile(const std::string& filename)
|
||||
{
|
||||
priv::SoundFile file;
|
||||
if (file.OpenRead(filename))
|
||||
return Initialize(file);
|
||||
if (file.openRead(filename))
|
||||
return initialize(file);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
bool SoundBuffer::loadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
{
|
||||
priv::SoundFile file;
|
||||
if (file.OpenRead(data, sizeInBytes))
|
||||
return Initialize(file);
|
||||
if (file.openRead(data, sizeInBytes))
|
||||
return initialize(file);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::LoadFromStream(InputStream& stream)
|
||||
bool SoundBuffer::loadFromStream(InputStream& stream)
|
||||
{
|
||||
priv::SoundFile file;
|
||||
if (file.OpenRead(stream))
|
||||
return Initialize(file);
|
||||
if (file.openRead(stream))
|
||||
return initialize(file);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate)
|
||||
bool SoundBuffer::loadFromSamples(const Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate)
|
||||
{
|
||||
if (samples && sampleCount && channelCount && sampleRate)
|
||||
{
|
||||
|
@ -118,12 +118,12 @@ bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t sampleCount,
|
|||
m_samples.assign(samples, samples + sampleCount);
|
||||
|
||||
// Update the internal buffer with the new samples
|
||||
return Update(channelCount, sampleRate);
|
||||
return update(channelCount, sampleRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
Err() << "Failed to load sound buffer from samples ("
|
||||
err() << "Failed to load sound buffer from samples ("
|
||||
<< "array: " << samples << ", "
|
||||
<< "count: " << sampleCount << ", "
|
||||
<< "channels: " << channelCount << ", "
|
||||
|
@ -136,14 +136,14 @@ bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t sampleCount,
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::SaveToFile(const std::string& filename) const
|
||||
bool SoundBuffer::saveToFile(const std::string& filename) const
|
||||
{
|
||||
// Create the sound file in write mode
|
||||
priv::SoundFile file;
|
||||
if (file.OpenWrite(filename, GetChannelCount(), GetSampleRate()))
|
||||
if (file.openWrite(filename, getChannelCount(), getSampleRate()))
|
||||
{
|
||||
// Write the samples to the opened file
|
||||
file.Write(&m_samples[0], m_samples.size());
|
||||
file.write(&m_samples[0], m_samples.size());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -155,41 +155,41 @@ bool SoundBuffer::SaveToFile(const std::string& filename) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Int16* SoundBuffer::GetSamples() const
|
||||
const Int16* SoundBuffer::getSamples() const
|
||||
{
|
||||
return m_samples.empty() ? NULL : &m_samples[0];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t SoundBuffer::GetSampleCount() const
|
||||
std::size_t SoundBuffer::getSampleCount() const
|
||||
{
|
||||
return m_samples.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundBuffer::GetSampleRate() const
|
||||
unsigned int SoundBuffer::getSampleRate() const
|
||||
{
|
||||
ALint sampleRate;
|
||||
ALCheck(alGetBufferi(m_buffer, AL_FREQUENCY, &sampleRate));
|
||||
alCheck(alGetBufferi(m_buffer, AL_FREQUENCY, &sampleRate));
|
||||
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundBuffer::GetChannelCount() const
|
||||
unsigned int SoundBuffer::getChannelCount() const
|
||||
{
|
||||
ALint channelCount;
|
||||
ALCheck(alGetBufferi(m_buffer, AL_CHANNELS, &channelCount));
|
||||
alCheck(alGetBufferi(m_buffer, AL_CHANNELS, &channelCount));
|
||||
|
||||
return channelCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time SoundBuffer::GetDuration() const
|
||||
Time SoundBuffer::getDuration() const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
@ -210,19 +210,19 @@ SoundBuffer& SoundBuffer::operator =(const SoundBuffer& right)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::Initialize(priv::SoundFile& file)
|
||||
bool SoundBuffer::initialize(priv::SoundFile& file)
|
||||
{
|
||||
// Retrieve the sound parameters
|
||||
std::size_t sampleCount = file.GetSampleCount();
|
||||
unsigned int channelCount = file.GetChannelCount();
|
||||
unsigned int sampleRate = file.GetSampleRate();
|
||||
std::size_t sampleCount = file.getSampleCount();
|
||||
unsigned int channelCount = file.getChannelCount();
|
||||
unsigned int sampleRate = file.getSampleRate();
|
||||
|
||||
// Read the samples from the provided file
|
||||
m_samples.resize(sampleCount);
|
||||
if (file.Read(&m_samples[0], sampleCount) == sampleCount)
|
||||
if (file.read(&m_samples[0], sampleCount) == sampleCount)
|
||||
{
|
||||
// Update the internal buffer with the new samples
|
||||
return Update(channelCount, sampleRate);
|
||||
return update(channelCount, sampleRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -232,42 +232,42 @@ bool SoundBuffer::Initialize(priv::SoundFile& file)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBuffer::Update(unsigned int channelCount, unsigned int sampleRate)
|
||||
bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
|
||||
{
|
||||
// Check parameters
|
||||
if (!channelCount || !sampleRate || m_samples.empty())
|
||||
return false;
|
||||
|
||||
// Find the good format according to the number of channels
|
||||
ALenum format = priv::AudioDevice::GetFormatFromChannelCount(channelCount);
|
||||
ALenum format = priv::AudioDevice::getFormatFromChannelCount(channelCount);
|
||||
|
||||
// Check if the format is valid
|
||||
if (format == 0)
|
||||
{
|
||||
Err() << "Failed to load sound buffer (unsupported number of channels: " << channelCount << ")" << std::endl;
|
||||
err() << "Failed to load sound buffer (unsupported number of channels: " << channelCount << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fill the buffer
|
||||
ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
|
||||
ALCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
|
||||
alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
|
||||
|
||||
// Compute the duration
|
||||
m_duration = Milliseconds(1000 * m_samples.size() / sampleRate / channelCount);
|
||||
m_duration = milliseconds(1000 * m_samples.size() / sampleRate / channelCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundBuffer::AttachSound(Sound* sound) const
|
||||
void SoundBuffer::attachSound(Sound* sound) const
|
||||
{
|
||||
m_sounds.insert(sound);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundBuffer::DetachSound(Sound* sound) const
|
||||
void SoundBuffer::detachSound(Sound* sound) const
|
||||
{
|
||||
m_sounds.erase(sound);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBufferRecorder::OnStart()
|
||||
bool SoundBufferRecorder::onStart()
|
||||
{
|
||||
m_samples.clear();
|
||||
m_buffer = SoundBuffer();
|
||||
|
@ -43,7 +43,7 @@ bool SoundBufferRecorder::OnStart()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBufferRecorder::OnProcessSamples(const Int16* samples, std::size_t sampleCount)
|
||||
bool SoundBufferRecorder::onProcessSamples(const Int16* samples, std::size_t sampleCount)
|
||||
{
|
||||
std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));
|
||||
|
||||
|
@ -52,15 +52,15 @@ bool SoundBufferRecorder::OnProcessSamples(const Int16* samples, std::size_t sam
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundBufferRecorder::OnStop()
|
||||
void SoundBufferRecorder::onStop()
|
||||
{
|
||||
if (!m_samples.empty())
|
||||
m_buffer.LoadFromSamples(&m_samples[0], m_samples.size(), 1, GetSampleRate());
|
||||
m_buffer.loadFromSamples(&m_samples[0], m_samples.size(), 1, getSampleRate());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const SoundBuffer& SoundBufferRecorder::GetBuffer() const
|
||||
const SoundBuffer& SoundBufferRecorder::getBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
namespace
|
||||
{
|
||||
// Convert a string to lower case
|
||||
std::string ToLower(std::string str)
|
||||
std::string toLower(std::string str)
|
||||
{
|
||||
for (std::string::iterator i = str.begin(); i != str.end(); ++i)
|
||||
*i = static_cast<char>(std::tolower(*i));
|
||||
|
@ -68,28 +68,28 @@ SoundFile::~SoundFile()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t SoundFile::GetSampleCount() const
|
||||
std::size_t SoundFile::getSampleCount() const
|
||||
{
|
||||
return m_sampleCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundFile::GetChannelCount() const
|
||||
unsigned int SoundFile::getChannelCount() const
|
||||
{
|
||||
return m_channelCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundFile::GetSampleRate() const
|
||||
unsigned int SoundFile::getSampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenRead(const std::string& filename)
|
||||
bool SoundFile::openRead(const std::string& filename)
|
||||
{
|
||||
// If the file is already opened, first close it
|
||||
if (m_file)
|
||||
|
@ -100,7 +100,7 @@ bool SoundFile::OpenRead(const std::string& filename)
|
|||
m_file = sf_open(filename.c_str(), SFM_READ, &fileInfos);
|
||||
if (!m_file)
|
||||
{
|
||||
Err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ bool SoundFile::OpenRead(const std::string& filename)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
|
||||
bool SoundFile::openRead(const void* data, std::size_t sizeInBytes)
|
||||
{
|
||||
// If the file is already opened, first close it
|
||||
if (m_file)
|
||||
|
@ -122,10 +122,10 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
|
|||
|
||||
// Prepare the memory I/O structure
|
||||
SF_VIRTUAL_IO io;
|
||||
io.get_filelen = &Memory::GetLength;
|
||||
io.read = &Memory::Read;
|
||||
io.seek = &Memory::Seek;
|
||||
io.tell = &Memory::Tell;
|
||||
io.get_filelen = &Memory::getLength;
|
||||
io.read = &Memory::read;
|
||||
io.seek = &Memory::seek;
|
||||
io.tell = &Memory::tell;
|
||||
|
||||
// Initialize the memory data
|
||||
m_memory.DataStart = static_cast<const char*>(data);
|
||||
|
@ -137,7 +137,7 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
|
|||
m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &m_memory);
|
||||
if (!m_file)
|
||||
{
|
||||
Err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenRead(InputStream& stream)
|
||||
bool SoundFile::openRead(InputStream& stream)
|
||||
{
|
||||
// If the file is already opened, first close it
|
||||
if (m_file)
|
||||
|
@ -159,17 +159,17 @@ bool SoundFile::OpenRead(InputStream& stream)
|
|||
|
||||
// Prepare the memory I/O structure
|
||||
SF_VIRTUAL_IO io;
|
||||
io.get_filelen = &Stream::GetLength;
|
||||
io.read = &Stream::Read;
|
||||
io.seek = &Stream::Seek;
|
||||
io.tell = &Stream::Tell;
|
||||
io.get_filelen = &Stream::getLength;
|
||||
io.read = &Stream::read;
|
||||
io.seek = &Stream::seek;
|
||||
io.tell = &Stream::tell;
|
||||
|
||||
// Open the sound file
|
||||
SF_INFO fileInfos;
|
||||
m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &stream);
|
||||
if (!m_file)
|
||||
{
|
||||
Err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -183,18 +183,18 @@ bool SoundFile::OpenRead(InputStream& stream)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelCount, unsigned int sampleRate)
|
||||
bool SoundFile::openWrite(const std::string& filename, unsigned int channelCount, unsigned int sampleRate)
|
||||
{
|
||||
// If the file is already opened, first close it
|
||||
if (m_file)
|
||||
sf_close(m_file);
|
||||
|
||||
// Find the right format according to the file extension
|
||||
int format = GetFormatFromFilename(filename);
|
||||
int format = getFormatFromFilename(filename);
|
||||
if (format == -1)
|
||||
{
|
||||
// Error : unrecognized extension
|
||||
Err() << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl;
|
||||
err() << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelCount
|
|||
m_file = sf_open(filename.c_str(), SFM_WRITE, &fileInfos);
|
||||
if (!m_file)
|
||||
{
|
||||
Err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelCount
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t SoundFile::Read(Int16* data, std::size_t sampleCount)
|
||||
std::size_t SoundFile::read(Int16* data, std::size_t sampleCount)
|
||||
{
|
||||
if (m_file && data && sampleCount)
|
||||
return static_cast<std::size_t>(sf_read_short(m_file, data, sampleCount));
|
||||
|
@ -232,7 +232,7 @@ std::size_t SoundFile::Read(Int16* data, std::size_t sampleCount)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundFile::Write(const Int16* data, std::size_t sampleCount)
|
||||
void SoundFile::write(const Int16* data, std::size_t sampleCount)
|
||||
{
|
||||
if (m_file && data && sampleCount)
|
||||
{
|
||||
|
@ -250,18 +250,18 @@ void SoundFile::Write(const Int16* data, std::size_t sampleCount)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundFile::Seek(Time timeOffset)
|
||||
void SoundFile::seek(Time timeOffset)
|
||||
{
|
||||
if (m_file)
|
||||
{
|
||||
sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset.AsSeconds() * m_sampleRate);
|
||||
sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset.asSeconds() * m_sampleRate);
|
||||
sf_seek(m_file, frameOffset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int SoundFile::GetFormatFromFilename(const std::string& filename)
|
||||
int SoundFile::getFormatFromFilename(const std::string& filename)
|
||||
{
|
||||
// Extract the extension
|
||||
std::string ext = "wav";
|
||||
|
@ -270,38 +270,38 @@ int SoundFile::GetFormatFromFilename(const std::string& filename)
|
|||
ext = filename.substr(pos + 1);
|
||||
|
||||
// Match every supported extension with its format constant
|
||||
if (ToLower(ext) == "wav" ) return SF_FORMAT_WAV;
|
||||
if (ToLower(ext) == "aif" ) return SF_FORMAT_AIFF;
|
||||
if (ToLower(ext) == "aiff" ) return SF_FORMAT_AIFF;
|
||||
if (ToLower(ext) == "au" ) return SF_FORMAT_AU;
|
||||
if (ToLower(ext) == "raw" ) return SF_FORMAT_RAW;
|
||||
if (ToLower(ext) == "paf" ) return SF_FORMAT_PAF;
|
||||
if (ToLower(ext) == "svx" ) return SF_FORMAT_SVX;
|
||||
if (ToLower(ext) == "nist" ) return SF_FORMAT_NIST;
|
||||
if (ToLower(ext) == "voc" ) return SF_FORMAT_VOC;
|
||||
if (ToLower(ext) == "sf" ) return SF_FORMAT_IRCAM;
|
||||
if (ToLower(ext) == "w64" ) return SF_FORMAT_W64;
|
||||
if (ToLower(ext) == "mat4" ) return SF_FORMAT_MAT4;
|
||||
if (ToLower(ext) == "mat5" ) return SF_FORMAT_MAT5;
|
||||
if (ToLower(ext) == "pvf" ) return SF_FORMAT_PVF;
|
||||
if (ToLower(ext) == "xi" ) return SF_FORMAT_XI;
|
||||
if (ToLower(ext) == "htk" ) return SF_FORMAT_HTK;
|
||||
if (ToLower(ext) == "sds" ) return SF_FORMAT_SDS;
|
||||
if (ToLower(ext) == "avr" ) return SF_FORMAT_AVR;
|
||||
if (ToLower(ext) == "sd2" ) return SF_FORMAT_SD2;
|
||||
if (ToLower(ext) == "flac" ) return SF_FORMAT_FLAC;
|
||||
if (ToLower(ext) == "caf" ) return SF_FORMAT_CAF;
|
||||
if (ToLower(ext) == "wve" ) return SF_FORMAT_WVE;
|
||||
if (ToLower(ext) == "ogg" ) return SF_FORMAT_OGG;
|
||||
if (ToLower(ext) == "mpc2k") return SF_FORMAT_MPC2K;
|
||||
if (ToLower(ext) == "rf64" ) return SF_FORMAT_RF64;
|
||||
if (toLower(ext) == "wav" ) return SF_FORMAT_WAV;
|
||||
if (toLower(ext) == "aif" ) return SF_FORMAT_AIFF;
|
||||
if (toLower(ext) == "aiff" ) return SF_FORMAT_AIFF;
|
||||
if (toLower(ext) == "au" ) return SF_FORMAT_AU;
|
||||
if (toLower(ext) == "raw" ) return SF_FORMAT_RAW;
|
||||
if (toLower(ext) == "paf" ) return SF_FORMAT_PAF;
|
||||
if (toLower(ext) == "svx" ) return SF_FORMAT_SVX;
|
||||
if (toLower(ext) == "nist" ) return SF_FORMAT_NIST;
|
||||
if (toLower(ext) == "voc" ) return SF_FORMAT_VOC;
|
||||
if (toLower(ext) == "sf" ) return SF_FORMAT_IRCAM;
|
||||
if (toLower(ext) == "w64" ) return SF_FORMAT_W64;
|
||||
if (toLower(ext) == "mat4" ) return SF_FORMAT_MAT4;
|
||||
if (toLower(ext) == "mat5" ) return SF_FORMAT_MAT5;
|
||||
if (toLower(ext) == "pvf" ) return SF_FORMAT_PVF;
|
||||
if (toLower(ext) == "xi" ) return SF_FORMAT_XI;
|
||||
if (toLower(ext) == "htk" ) return SF_FORMAT_HTK;
|
||||
if (toLower(ext) == "sds" ) return SF_FORMAT_SDS;
|
||||
if (toLower(ext) == "avr" ) return SF_FORMAT_AVR;
|
||||
if (toLower(ext) == "sd2" ) return SF_FORMAT_SD2;
|
||||
if (toLower(ext) == "flac" ) return SF_FORMAT_FLAC;
|
||||
if (toLower(ext) == "caf" ) return SF_FORMAT_CAF;
|
||||
if (toLower(ext) == "wve" ) return SF_FORMAT_WVE;
|
||||
if (toLower(ext) == "ogg" ) return SF_FORMAT_OGG;
|
||||
if (toLower(ext) == "mpc2k") return SF_FORMAT_MPC2K;
|
||||
if (toLower(ext) == "rf64" ) return SF_FORMAT_RF64;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Memory::GetLength(void* user)
|
||||
sf_count_t SoundFile::Memory::getLength(void* user)
|
||||
{
|
||||
Memory* memory = static_cast<Memory*>(user);
|
||||
return memory->TotalSize;
|
||||
|
@ -309,7 +309,7 @@ sf_count_t SoundFile::Memory::GetLength(void* user)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Memory::Read(void* ptr, sf_count_t count, void* user)
|
||||
sf_count_t SoundFile::Memory::read(void* ptr, sf_count_t count, void* user)
|
||||
{
|
||||
Memory* memory = static_cast<Memory*>(user);
|
||||
|
||||
|
@ -324,7 +324,7 @@ sf_count_t SoundFile::Memory::Read(void* ptr, sf_count_t count, void* user)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Memory::Seek(sf_count_t offset, int whence, void* user)
|
||||
sf_count_t SoundFile::Memory::seek(sf_count_t offset, int whence, void* user)
|
||||
{
|
||||
Memory* memory = static_cast<Memory*>(user);
|
||||
sf_count_t position = 0;
|
||||
|
@ -347,7 +347,7 @@ sf_count_t SoundFile::Memory::Seek(sf_count_t offset, int whence, void* user)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Memory::Tell(void* user)
|
||||
sf_count_t SoundFile::Memory::tell(void* user)
|
||||
{
|
||||
Memory* memory = static_cast<Memory*>(user);
|
||||
return memory->DataPtr - memory->DataStart;
|
||||
|
@ -355,40 +355,40 @@ sf_count_t SoundFile::Memory::Tell(void* user)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Stream::GetLength(void* userData)
|
||||
sf_count_t SoundFile::Stream::getLength(void* userData)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(userData);
|
||||
return stream->GetSize();
|
||||
return stream->getSize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Stream::Read(void* ptr, sf_count_t count, void* userData)
|
||||
sf_count_t SoundFile::Stream::read(void* ptr, sf_count_t count, void* userData)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(userData);
|
||||
return stream->Read(reinterpret_cast<char*>(ptr), count);
|
||||
return stream->read(reinterpret_cast<char*>(ptr), count);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Stream::Seek(sf_count_t offset, int whence, void* userData)
|
||||
sf_count_t SoundFile::Stream::seek(sf_count_t offset, int whence, void* userData)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(userData);
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET : return stream->Seek(offset);
|
||||
case SEEK_CUR : return stream->Seek(stream->Tell() + offset);
|
||||
case SEEK_END : return stream->Seek(stream->GetSize() - offset);
|
||||
default : return stream->Seek(0);
|
||||
case SEEK_SET : return stream->seek(offset);
|
||||
case SEEK_CUR : return stream->seek(stream->tell() + offset);
|
||||
case SEEK_END : return stream->seek(stream->getSize() - offset);
|
||||
default : return stream->seek(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::Stream::Tell(void* userData)
|
||||
sf_count_t SoundFile::Stream::tell(void* userData)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(userData);
|
||||
return stream->Tell();
|
||||
return stream->tell();
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -66,7 +66,7 @@ public :
|
|||
/// \return Number of samples
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t GetSampleCount() const;
|
||||
std::size_t getSampleCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of channels used by the sound
|
||||
|
@ -74,7 +74,7 @@ public :
|
|||
/// \return Number of channels (1 = mono, 2 = stereo)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int GetChannelCount() const;
|
||||
unsigned int getChannelCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the sample rate of the sound
|
||||
|
@ -82,7 +82,7 @@ public :
|
|||
/// \return Sample rate, in samples per second
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int GetSampleRate() const;
|
||||
unsigned int getSampleRate() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file for reading
|
||||
|
@ -92,7 +92,7 @@ public :
|
|||
/// \return True if the file was successfully opened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool OpenRead(const std::string& filename);
|
||||
bool openRead(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file in memory for reading
|
||||
|
@ -103,7 +103,7 @@ public :
|
|||
/// \return True if the file was successfully opened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool OpenRead(const void* data, std::size_t sizeInBytes);
|
||||
bool openRead(const void* data, std::size_t sizeInBytes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file from a custom stream for reading
|
||||
|
@ -113,7 +113,7 @@ public :
|
|||
/// \return True if the file was successfully opened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool OpenRead(InputStream& stream);
|
||||
bool openRead(InputStream& stream);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief a the sound file for writing
|
||||
|
@ -125,7 +125,7 @@ public :
|
|||
/// \return True if the file was successfully opened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool OpenWrite(const std::string& filename, unsigned int channelCount, unsigned int sampleRate);
|
||||
bool openWrite(const std::string& filename, unsigned int channelCount, unsigned int sampleRate);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read audio samples from the loaded sound
|
||||
|
@ -136,7 +136,7 @@ public :
|
|||
/// \return Number of samples actually read (may be less than \a sampleCount)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t Read(Int16* data, std::size_t sampleCount);
|
||||
std::size_t read(Int16* data, std::size_t sampleCount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Write audio samples to the file
|
||||
|
@ -145,7 +145,7 @@ public :
|
|||
/// \param sampleCount Number of samples to write
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Write(const Int16* data, std::size_t sampleCount);
|
||||
void write(const Int16* data, std::size_t sampleCount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current read position in the file
|
||||
|
@ -153,7 +153,7 @@ public :
|
|||
/// \param timeOffset New playing position, from the beginning of the file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Seek(Time timeOffset);
|
||||
void seek(Time timeOffset);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -166,7 +166,7 @@ private :
|
|||
/// \return Internal format matching the filename (-1 if no match)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static int GetFormatFromFilename(const std::string& filename);
|
||||
static int getFormatFromFilename(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Data and callbacks for opening from memory
|
||||
|
@ -178,10 +178,10 @@ private :
|
|||
const char* DataPtr;
|
||||
sf_count_t TotalSize;
|
||||
|
||||
static sf_count_t GetLength(void* user);
|
||||
static sf_count_t Read(void* ptr, sf_count_t count, void* user);
|
||||
static sf_count_t Seek(sf_count_t offset, int whence, void* user);
|
||||
static sf_count_t Tell(void* user);
|
||||
static sf_count_t getLength(void* user);
|
||||
static sf_count_t read(void* ptr, sf_count_t count, void* user);
|
||||
static sf_count_t seek(sf_count_t offset, int whence, void* user);
|
||||
static sf_count_t tell(void* user);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -190,10 +190,10 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
struct Stream
|
||||
{
|
||||
static sf_count_t GetLength(void* user);
|
||||
static sf_count_t Read(void* ptr, sf_count_t count, void* user);
|
||||
static sf_count_t Seek(sf_count_t offset, int whence, void* user);
|
||||
static sf_count_t Tell(void* user);
|
||||
static sf_count_t getLength(void* user);
|
||||
static sf_count_t read(void* ptr, sf_count_t count, void* user);
|
||||
static sf_count_t seek(sf_count_t offset, int whence, void* user);
|
||||
static sf_count_t tell(void* user);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundRecorder.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
@ -45,11 +45,11 @@ namespace sf
|
|||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundRecorder::SoundRecorder() :
|
||||
m_thread (&SoundRecorder::Record, this),
|
||||
m_thread (&SoundRecorder::record, this),
|
||||
m_sampleRate (0),
|
||||
m_isCapturing(false)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,19 +61,19 @@ SoundRecorder::~SoundRecorder()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Start(unsigned int sampleRate)
|
||||
void SoundRecorder::start(unsigned int sampleRate)
|
||||
{
|
||||
// Check if the device can do audio capture
|
||||
if (!IsAvailable())
|
||||
if (!isAvailable())
|
||||
{
|
||||
Err() << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::IsAvailable to check it)" << std::endl;
|
||||
err() << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::IsAvailable to check it)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that another capture is not already running
|
||||
if (captureDevice)
|
||||
{
|
||||
Err() << "Trying to start audio capture, but another capture is already running" << std::endl;
|
||||
err() << "Trying to start audio capture, but another capture is already running" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ void SoundRecorder::Start(unsigned int sampleRate)
|
|||
captureDevice = alcCaptureOpenDevice(NULL, sampleRate, AL_FORMAT_MONO16, sampleRate);
|
||||
if (!captureDevice)
|
||||
{
|
||||
Err() << "Failed to open the audio capture device" << std::endl;
|
||||
err() << "Failed to open the audio capture device" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,44 +92,44 @@ void SoundRecorder::Start(unsigned int sampleRate)
|
|||
m_sampleRate = sampleRate;
|
||||
|
||||
// Notify derived class
|
||||
if (OnStart())
|
||||
if (onStart())
|
||||
{
|
||||
// Start the capture
|
||||
alcCaptureStart(captureDevice);
|
||||
|
||||
// Start the capture in a new thread, to avoid blocking the main thread
|
||||
m_isCapturing = true;
|
||||
m_thread.Launch();
|
||||
m_thread.launch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Stop()
|
||||
void SoundRecorder::stop()
|
||||
{
|
||||
// Stop the capturing thread
|
||||
m_isCapturing = false;
|
||||
m_thread.Wait();
|
||||
m_thread.wait();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundRecorder::GetSampleRate() const
|
||||
unsigned int SoundRecorder::getSampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundRecorder::IsAvailable()
|
||||
bool SoundRecorder::isAvailable()
|
||||
{
|
||||
return (priv::AudioDevice::IsExtensionSupported("ALC_EXT_CAPTURE") != AL_FALSE) ||
|
||||
(priv::AudioDevice::IsExtensionSupported("ALC_EXT_capture") != AL_FALSE); // "bug" in Mac OS X 10.5 and 10.6
|
||||
return (priv::AudioDevice::isExtensionSupported("ALC_EXT_CAPTURE") != AL_FALSE) ||
|
||||
(priv::AudioDevice::isExtensionSupported("ALC_EXT_capture") != AL_FALSE); // "bug" in Mac OS X 10.5 and 10.6
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundRecorder::OnStart()
|
||||
bool SoundRecorder::onStart()
|
||||
{
|
||||
// Nothing to do
|
||||
return true;
|
||||
|
@ -137,34 +137,34 @@ bool SoundRecorder::OnStart()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::OnStop()
|
||||
void SoundRecorder::onStop()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Record()
|
||||
void SoundRecorder::record()
|
||||
{
|
||||
while (m_isCapturing)
|
||||
{
|
||||
// Process available samples
|
||||
ProcessCapturedSamples();
|
||||
processCapturedSamples();
|
||||
|
||||
// Don't bother the CPU while waiting for more captured data
|
||||
Sleep(Milliseconds(100));
|
||||
sleep(milliseconds(100));
|
||||
}
|
||||
|
||||
// Capture is finished : clean up everything
|
||||
CleanUp();
|
||||
cleanup();
|
||||
|
||||
// Notify derived class
|
||||
OnStop();
|
||||
onStop();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::ProcessCapturedSamples()
|
||||
void SoundRecorder::processCapturedSamples()
|
||||
{
|
||||
// Get the number of samples available
|
||||
ALCint samplesAvailable;
|
||||
|
@ -177,7 +177,7 @@ void SoundRecorder::ProcessCapturedSamples()
|
|||
alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);
|
||||
|
||||
// Forward them to the derived class
|
||||
if (!OnProcessSamples(&m_samples[0], m_samples.size()))
|
||||
if (!onProcessSamples(&m_samples[0], m_samples.size()))
|
||||
{
|
||||
// The user wants to stop the capture
|
||||
m_isCapturing = false;
|
||||
|
@ -187,13 +187,13 @@ void SoundRecorder::ProcessCapturedSamples()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::CleanUp()
|
||||
void SoundRecorder::cleanup()
|
||||
{
|
||||
// Stop the capture
|
||||
alcCaptureStop(captureDevice);
|
||||
|
||||
// Get the samples left in the buffer
|
||||
ProcessCapturedSamples();
|
||||
processCapturedSamples();
|
||||
|
||||
// Close the device
|
||||
alcCaptureCloseDevice(captureDevice);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundSource.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -34,151 +34,151 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
SoundSource::SoundSource()
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
ALCheck(alGenSources(1, &m_source));
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alGenSources(1, &m_source));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::SoundSource(const SoundSource& copy)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
priv::ensureALInit();
|
||||
|
||||
ALCheck(alGenSources(1, &m_source));
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alGenSources(1, &m_source));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
|
||||
SetPitch(copy.GetPitch());
|
||||
SetVolume(copy.GetVolume());
|
||||
SetPosition(copy.GetPosition());
|
||||
SetRelativeToListener(copy.IsRelativeToListener());
|
||||
SetMinDistance(copy.GetMinDistance());
|
||||
SetAttenuation(copy.GetAttenuation());
|
||||
setPitch(copy.getPitch());
|
||||
setVolume(copy.getVolume());
|
||||
setPosition(copy.getPosition());
|
||||
setRelativeToListener(copy.isRelativeToListener());
|
||||
setMinDistance(copy.getMinDistance());
|
||||
setAttenuation(copy.getAttenuation());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::~SoundSource()
|
||||
{
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
ALCheck(alDeleteSources(1, &m_source));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alDeleteSources(1, &m_source));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetPitch(float pitch)
|
||||
void SoundSource::setPitch(float pitch)
|
||||
{
|
||||
ALCheck(alSourcef(m_source, AL_PITCH, pitch));
|
||||
alCheck(alSourcef(m_source, AL_PITCH, pitch));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetVolume(float volume)
|
||||
void SoundSource::setVolume(float volume)
|
||||
{
|
||||
ALCheck(alSourcef(m_source, AL_GAIN, volume * 0.01f));
|
||||
alCheck(alSourcef(m_source, AL_GAIN, volume * 0.01f));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetPosition(float x, float y, float z)
|
||||
void SoundSource::setPosition(float x, float y, float z)
|
||||
{
|
||||
ALCheck(alSource3f(m_source, AL_POSITION, x, y, z));
|
||||
alCheck(alSource3f(m_source, AL_POSITION, x, y, z));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetPosition(const Vector3f& position)
|
||||
void SoundSource::setPosition(const Vector3f& position)
|
||||
{
|
||||
SetPosition(position.x, position.y, position.z);
|
||||
setPosition(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetRelativeToListener(bool relative)
|
||||
void SoundSource::setRelativeToListener(bool relative)
|
||||
{
|
||||
ALCheck(alSourcei(m_source, AL_SOURCE_RELATIVE, relative));
|
||||
alCheck(alSourcei(m_source, AL_SOURCE_RELATIVE, relative));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetMinDistance(float distance)
|
||||
void SoundSource::setMinDistance(float distance)
|
||||
{
|
||||
ALCheck(alSourcef(m_source, AL_REFERENCE_DISTANCE, distance));
|
||||
alCheck(alSourcef(m_source, AL_REFERENCE_DISTANCE, distance));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundSource::SetAttenuation(float attenuation)
|
||||
void SoundSource::setAttenuation(float attenuation)
|
||||
{
|
||||
ALCheck(alSourcef(m_source, AL_ROLLOFF_FACTOR, attenuation));
|
||||
alCheck(alSourcef(m_source, AL_ROLLOFF_FACTOR, attenuation));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundSource::GetPitch() const
|
||||
float SoundSource::getPitch() const
|
||||
{
|
||||
ALfloat pitch;
|
||||
ALCheck(alGetSourcef(m_source, AL_PITCH, &pitch));
|
||||
alCheck(alGetSourcef(m_source, AL_PITCH, &pitch));
|
||||
|
||||
return pitch;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundSource::GetVolume() const
|
||||
float SoundSource::getVolume() const
|
||||
{
|
||||
ALfloat gain;
|
||||
ALCheck(alGetSourcef(m_source, AL_GAIN, &gain));
|
||||
alCheck(alGetSourcef(m_source, AL_GAIN, &gain));
|
||||
|
||||
return gain * 100.f;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3f SoundSource::GetPosition() const
|
||||
Vector3f SoundSource::getPosition() const
|
||||
{
|
||||
Vector3f position;
|
||||
ALCheck(alGetSource3f(m_source, AL_POSITION, &position.x, &position.y, &position.z));
|
||||
alCheck(alGetSource3f(m_source, AL_POSITION, &position.x, &position.y, &position.z));
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundSource::IsRelativeToListener() const
|
||||
bool SoundSource::isRelativeToListener() const
|
||||
{
|
||||
ALint relative;
|
||||
ALCheck(alGetSourcei(m_source, AL_SOURCE_RELATIVE, &relative));
|
||||
alCheck(alGetSourcei(m_source, AL_SOURCE_RELATIVE, &relative));
|
||||
|
||||
return relative != 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundSource::GetMinDistance() const
|
||||
float SoundSource::getMinDistance() const
|
||||
{
|
||||
ALfloat distance;
|
||||
ALCheck(alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &distance));
|
||||
alCheck(alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &distance));
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundSource::GetAttenuation() const
|
||||
float SoundSource::getAttenuation() const
|
||||
{
|
||||
ALfloat attenuation;
|
||||
ALCheck(alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &attenuation));
|
||||
alCheck(alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &attenuation));
|
||||
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::Status SoundSource::GetStatus() const
|
||||
SoundSource::Status SoundSource::getStatus() const
|
||||
{
|
||||
ALint status;
|
||||
ALCheck(alGetSourcei(m_source, AL_SOURCE_STATE, &status));
|
||||
alCheck(alGetSourcei(m_source, AL_SOURCE_STATE, &status));
|
||||
|
||||
switch (status)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/alCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace sf
|
|||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundStream::SoundStream() :
|
||||
m_thread (&SoundStream::Stream, this),
|
||||
m_thread (&SoundStream::stream, this),
|
||||
m_isStreaming (false),
|
||||
m_channelCount (0),
|
||||
m_sampleRate (0),
|
||||
|
@ -56,92 +56,92 @@ m_samplesProcessed(0)
|
|||
SoundStream::~SoundStream()
|
||||
{
|
||||
// Stop the sound if it was playing
|
||||
Stop();
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Initialize(unsigned int channelCount, unsigned int sampleRate)
|
||||
void SoundStream::initialize(unsigned int channelCount, unsigned int sampleRate)
|
||||
{
|
||||
m_channelCount = channelCount;
|
||||
m_sampleRate = sampleRate;
|
||||
|
||||
// Deduce the format from the number of channels
|
||||
m_format = priv::AudioDevice::GetFormatFromChannelCount(channelCount);
|
||||
m_format = priv::AudioDevice::getFormatFromChannelCount(channelCount);
|
||||
|
||||
// Check if the format is valid
|
||||
if (m_format == 0)
|
||||
{
|
||||
m_channelCount = 0;
|
||||
m_sampleRate = 0;
|
||||
Err() << "Unsupported number of channels (" << m_channelCount << ")" << std::endl;
|
||||
err() << "Unsupported number of channels (" << m_channelCount << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Play()
|
||||
void SoundStream::play()
|
||||
{
|
||||
// Check if the sound parameters have been set
|
||||
if (m_format == 0)
|
||||
{
|
||||
Err() << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl;
|
||||
err() << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// If the sound is already playing (probably paused), just resume it
|
||||
if (m_isStreaming)
|
||||
{
|
||||
ALCheck(alSourcePlay(m_source));
|
||||
alCheck(alSourcePlay(m_source));
|
||||
return;
|
||||
}
|
||||
|
||||
// Move to the beginning
|
||||
OnSeek(Time::Zero);
|
||||
onSeek(Time::Zero);
|
||||
|
||||
// Start updating the stream in a separate thread to avoid blocking the application
|
||||
m_samplesProcessed = 0;
|
||||
m_isStreaming = true;
|
||||
m_thread.Launch();
|
||||
m_thread.launch();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Pause()
|
||||
void SoundStream::pause()
|
||||
{
|
||||
ALCheck(alSourcePause(m_source));
|
||||
alCheck(alSourcePause(m_source));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Stop()
|
||||
void SoundStream::stop()
|
||||
{
|
||||
// Wait for the thread to terminate
|
||||
m_isStreaming = false;
|
||||
m_thread.Wait();
|
||||
m_thread.wait();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundStream::GetChannelCount() const
|
||||
unsigned int SoundStream::getChannelCount() const
|
||||
{
|
||||
return m_channelCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundStream::GetSampleRate() const
|
||||
unsigned int SoundStream::getSampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundStream::Status SoundStream::GetStatus() const
|
||||
SoundStream::Status SoundStream::getStatus() const
|
||||
{
|
||||
Status status = SoundSource::GetStatus();
|
||||
Status status = SoundSource::getStatus();
|
||||
|
||||
// To compensate for the lag between Play() and alSourcePlay()
|
||||
// To compensate for the lag between play() and alSourceplay()
|
||||
if ((status == Stopped) && m_isStreaming)
|
||||
status = Playing;
|
||||
|
||||
|
@ -150,68 +150,68 @@ SoundStream::Status SoundStream::GetStatus() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::SetPlayingOffset(Time timeOffset)
|
||||
void SoundStream::setPlayingOffset(Time timeOffset)
|
||||
{
|
||||
// Stop the stream
|
||||
Stop();
|
||||
stop();
|
||||
|
||||
// Let the derived class update the current position
|
||||
OnSeek(timeOffset);
|
||||
onSeek(timeOffset);
|
||||
|
||||
// Restart streaming
|
||||
m_samplesProcessed = static_cast<Uint64>(timeOffset.AsSeconds() * m_sampleRate * m_channelCount);
|
||||
m_samplesProcessed = static_cast<Uint64>(timeOffset.asSeconds() * m_sampleRate * m_channelCount);
|
||||
m_isStreaming = true;
|
||||
m_thread.Launch();
|
||||
m_thread.launch();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time SoundStream::GetPlayingOffset() const
|
||||
Time SoundStream::getPlayingOffset() const
|
||||
{
|
||||
ALfloat seconds = 0.f;
|
||||
ALCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &seconds));
|
||||
ALfloat secs = 0.f;
|
||||
alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs));
|
||||
|
||||
return Seconds(seconds + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);
|
||||
return seconds(secs + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::SetLoop(bool loop)
|
||||
void SoundStream::setLoop(bool loop)
|
||||
{
|
||||
m_loop = loop;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::GetLoop() const
|
||||
bool SoundStream::getLoop() const
|
||||
{
|
||||
return m_loop;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Stream()
|
||||
void SoundStream::stream()
|
||||
{
|
||||
// Create the buffers
|
||||
ALCheck(alGenBuffers(BufferCount, m_buffers));
|
||||
alCheck(alGenBuffers(BufferCount, m_buffers));
|
||||
for (int i = 0; i < BufferCount; ++i)
|
||||
m_endBuffers[i] = false;
|
||||
|
||||
// Fill the queue
|
||||
bool requestStop = FillQueue();
|
||||
bool requestStop = fillQueue();
|
||||
|
||||
// Play the sound
|
||||
ALCheck(alSourcePlay(m_source));
|
||||
alCheck(alSourcePlay(m_source));
|
||||
|
||||
while (m_isStreaming)
|
||||
{
|
||||
// The stream has been interrupted!
|
||||
if (SoundSource::GetStatus() == Stopped)
|
||||
if (SoundSource::getStatus() == Stopped)
|
||||
{
|
||||
if (!requestStop)
|
||||
{
|
||||
// Just continue
|
||||
ALCheck(alSourcePlay(m_source));
|
||||
alCheck(alSourcePlay(m_source));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -222,13 +222,13 @@ void SoundStream::Stream()
|
|||
|
||||
// Get the number of buffers that have been processed (ie. ready for reuse)
|
||||
ALint nbProcessed = 0;
|
||||
ALCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed));
|
||||
alCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed));
|
||||
|
||||
while (nbProcessed--)
|
||||
{
|
||||
// Pop the first unused buffer from the queue
|
||||
ALuint buffer;
|
||||
ALCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
|
||||
alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
|
||||
|
||||
// Find its number
|
||||
unsigned int bufferNum = 0;
|
||||
|
@ -249,44 +249,44 @@ void SoundStream::Stream()
|
|||
else
|
||||
{
|
||||
ALint size, bits;
|
||||
ALCheck(alGetBufferi(buffer, AL_SIZE, &size));
|
||||
ALCheck(alGetBufferi(buffer, AL_BITS, &bits));
|
||||
alCheck(alGetBufferi(buffer, AL_SIZE, &size));
|
||||
alCheck(alGetBufferi(buffer, AL_BITS, &bits));
|
||||
m_samplesProcessed += size / (bits / 8);
|
||||
}
|
||||
|
||||
// Fill it and push it back into the playing queue
|
||||
if (!requestStop)
|
||||
{
|
||||
if (FillAndPushBuffer(bufferNum))
|
||||
if (fillAndPushBuffer(bufferNum))
|
||||
requestStop = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Leave some time for the other threads if the stream is still playing
|
||||
if (SoundSource::GetStatus() != Stopped)
|
||||
Sleep(Milliseconds(10));
|
||||
if (SoundSource::getStatus() != Stopped)
|
||||
sleep(milliseconds(10));
|
||||
}
|
||||
|
||||
// Stop the playback
|
||||
ALCheck(alSourceStop(m_source));
|
||||
alCheck(alSourceStop(m_source));
|
||||
|
||||
// Unqueue any buffer left in the queue
|
||||
ClearQueue();
|
||||
clearQueue();
|
||||
|
||||
// Delete the buffers
|
||||
ALCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
ALCheck(alDeleteBuffers(BufferCount, m_buffers));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alDeleteBuffers(BufferCount, m_buffers));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
|
||||
bool SoundStream::fillAndPushBuffer(unsigned int bufferNum)
|
||||
{
|
||||
bool requestStop = false;
|
||||
|
||||
// Acquire audio data
|
||||
Chunk data = {NULL, 0};
|
||||
if (!OnGetData(data))
|
||||
if (!onGetData(data))
|
||||
{
|
||||
// Mark the buffer as the last one (so that we know when to reset the playing position)
|
||||
m_endBuffers[bufferNum] = true;
|
||||
|
@ -295,12 +295,12 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
|
|||
if (m_loop)
|
||||
{
|
||||
// Return to the beginning of the stream source
|
||||
OnSeek(Time::Zero);
|
||||
onSeek(Time::Zero);
|
||||
|
||||
// If we previously had no data, try to fill the buffer once again
|
||||
if (!data.Samples || (data.SampleCount == 0))
|
||||
if (!data.samples || (data.sampleCount == 0))
|
||||
{
|
||||
return FillAndPushBuffer(bufferNum);
|
||||
return fillAndPushBuffer(bufferNum);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -311,16 +311,16 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
|
|||
}
|
||||
|
||||
// Fill the buffer if some data was returned
|
||||
if (data.Samples && data.SampleCount)
|
||||
if (data.samples && data.sampleCount)
|
||||
{
|
||||
unsigned int buffer = m_buffers[bufferNum];
|
||||
|
||||
// Fill the buffer
|
||||
ALsizei size = static_cast<ALsizei>(data.SampleCount) * sizeof(Int16);
|
||||
ALCheck(alBufferData(buffer, m_format, data.Samples, size, m_sampleRate));
|
||||
ALsizei size = static_cast<ALsizei>(data.sampleCount) * sizeof(Int16);
|
||||
alCheck(alBufferData(buffer, m_format, data.samples, size, m_sampleRate));
|
||||
|
||||
// Push it into the sound queue
|
||||
ALCheck(alSourceQueueBuffers(m_source, 1, &buffer));
|
||||
alCheck(alSourceQueueBuffers(m_source, 1, &buffer));
|
||||
}
|
||||
|
||||
return requestStop;
|
||||
|
@ -328,13 +328,13 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::FillQueue()
|
||||
bool SoundStream::fillQueue()
|
||||
{
|
||||
// Fill and enqueue all the available buffers
|
||||
bool requestStop = false;
|
||||
for (int i = 0; (i < BufferCount) && !requestStop; ++i)
|
||||
{
|
||||
if (FillAndPushBuffer(i))
|
||||
if (fillAndPushBuffer(i))
|
||||
requestStop = true;
|
||||
}
|
||||
|
||||
|
@ -343,16 +343,16 @@ bool SoundStream::FillQueue()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::ClearQueue()
|
||||
void SoundStream::clearQueue()
|
||||
{
|
||||
// Get the number of buffers still in the queue
|
||||
ALint nbQueued;
|
||||
ALCheck(alGetSourcei(m_source, AL_BUFFERS_QUEUED, &nbQueued));
|
||||
alCheck(alGetSourcei(m_source, AL_BUFFERS_QUEUED, &nbQueued));
|
||||
|
||||
// Unqueue them all
|
||||
ALuint buffer;
|
||||
for (ALint i = 0; i < nbQueued; ++i)
|
||||
ALCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
|
||||
alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -36,41 +36,41 @@ CircleShape::CircleShape(float radius, unsigned int pointCount) :
|
|||
m_radius (radius),
|
||||
m_pointCount(pointCount)
|
||||
{
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CircleShape::SetRadius(float radius)
|
||||
void CircleShape::setRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float CircleShape::GetRadius() const
|
||||
float CircleShape::getRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CircleShape::SetPointCount(unsigned int count)
|
||||
void CircleShape::setPointCount(unsigned int count)
|
||||
{
|
||||
m_pointCount = count;
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int CircleShape::GetPointCount() const
|
||||
unsigned int CircleShape::getPointCount() const
|
||||
{
|
||||
return m_pointCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f CircleShape::GetPoint(unsigned int index) const
|
||||
Vector2f CircleShape::getPoint(unsigned int index) const
|
||||
{
|
||||
static const float pi = 3.141592654f;
|
||||
|
||||
|
|
|
@ -33,35 +33,35 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
ConvexShape::ConvexShape(unsigned int pointCount)
|
||||
{
|
||||
SetPointCount(pointCount);
|
||||
setPointCount(pointCount);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ConvexShape::SetPointCount(unsigned int count)
|
||||
void ConvexShape::setPointCount(unsigned int count)
|
||||
{
|
||||
m_points.resize(count);
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int ConvexShape::GetPointCount() const
|
||||
unsigned int ConvexShape::getPointCount() const
|
||||
{
|
||||
return static_cast<unsigned int>(m_points.size());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ConvexShape::SetPoint(unsigned int index, const Vector2f& point)
|
||||
void ConvexShape::setPoint(unsigned int index, const Vector2f& point)
|
||||
{
|
||||
m_points[index] = point;
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f ConvexShape::GetPoint(unsigned int index) const
|
||||
Vector2f ConvexShape::getPoint(unsigned int index) const
|
||||
{
|
||||
return m_points[index];
|
||||
}
|
||||
|
|
|
@ -40,20 +40,20 @@
|
|||
namespace
|
||||
{
|
||||
// FreeType callbacks that operate on a sf::InputStream
|
||||
unsigned long Read(FT_Stream rec, unsigned long offset, unsigned char* buffer, unsigned long count)
|
||||
unsigned long read(FT_Stream rec, unsigned long offset, unsigned char* buffer, unsigned long count)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(rec->descriptor.pointer);
|
||||
if (static_cast<unsigned long>(stream->Seek(offset)) == offset)
|
||||
if (static_cast<unsigned long>(stream->seek(offset)) == offset)
|
||||
{
|
||||
if (count > 0)
|
||||
return static_cast<unsigned long>(stream->Read(reinterpret_cast<char*>(buffer), count));
|
||||
return static_cast<unsigned long>(stream->read(reinterpret_cast<char*>(buffer), count));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return count > 0 ? 0 : 1; // error code is 0 if we're reading, or nonzero if we're seeking
|
||||
}
|
||||
void Close(FT_Stream)
|
||||
void close(FT_Stream)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -92,15 +92,15 @@ m_pixelBuffer(copy.m_pixelBuffer)
|
|||
////////////////////////////////////////////////////////////
|
||||
Font::~Font()
|
||||
{
|
||||
Cleanup();
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::LoadFromFile(const std::string& filename)
|
||||
bool Font::loadFromFile(const std::string& filename)
|
||||
{
|
||||
// Cleanup the previous resources
|
||||
Cleanup();
|
||||
cleanup();
|
||||
m_refCount = new int(1);
|
||||
|
||||
// Initialize FreeType
|
||||
|
@ -109,7 +109,7 @@ bool Font::LoadFromFile(const std::string& filename)
|
|||
FT_Library library;
|
||||
if (FT_Init_FreeType(&library) != 0)
|
||||
{
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
|
||||
err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_library = library;
|
||||
|
@ -118,14 +118,14 @@ bool Font::LoadFromFile(const std::string& filename)
|
|||
FT_Face face;
|
||||
if (FT_New_Face(static_cast<FT_Library>(m_library), filename.c_str(), 0, &face) != 0)
|
||||
{
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
|
||||
err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the unicode character map
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
|
||||
{
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
|
||||
err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,10 +137,10 @@ bool Font::LoadFromFile(const std::string& filename)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
{
|
||||
// Cleanup the previous resources
|
||||
Cleanup();
|
||||
cleanup();
|
||||
m_refCount = new int(1);
|
||||
|
||||
// Initialize FreeType
|
||||
|
@ -149,7 +149,7 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
|||
FT_Library library;
|
||||
if (FT_Init_FreeType(&library) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from memory (failed to initialize FreeType)" << std::endl;
|
||||
err() << "Failed to load font from memory (failed to initialize FreeType)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_library = library;
|
||||
|
@ -158,14 +158,14 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
|||
FT_Face face;
|
||||
if (FT_New_Memory_Face(static_cast<FT_Library>(m_library), reinterpret_cast<const FT_Byte*>(data), static_cast<FT_Long>(sizeInBytes), 0, &face) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from memory (failed to create the font face)" << std::endl;
|
||||
err() << "Failed to load font from memory (failed to create the font face)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the unicode character map
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl;
|
||||
err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -177,10 +177,10 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::LoadFromStream(InputStream& stream)
|
||||
bool Font::loadFromStream(InputStream& stream)
|
||||
{
|
||||
// Cleanup the previous resources
|
||||
Cleanup();
|
||||
cleanup();
|
||||
m_refCount = new int(1);
|
||||
|
||||
// Initialize FreeType
|
||||
|
@ -189,7 +189,7 @@ bool Font::LoadFromStream(InputStream& stream)
|
|||
FT_Library library;
|
||||
if (FT_Init_FreeType(&library) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from stream (failed to initialize FreeType)" << std::endl;
|
||||
err() << "Failed to load font from stream (failed to initialize FreeType)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_library = library;
|
||||
|
@ -198,11 +198,11 @@ bool Font::LoadFromStream(InputStream& stream)
|
|||
FT_StreamRec* rec = new FT_StreamRec;
|
||||
std::memset(rec, 0, sizeof(*rec));
|
||||
rec->base = NULL;
|
||||
rec->size = static_cast<unsigned long>(stream.GetSize());
|
||||
rec->size = static_cast<unsigned long>(stream.getSize());
|
||||
rec->pos = 0;
|
||||
rec->descriptor.pointer = &stream;
|
||||
rec->read = &Read;
|
||||
rec->close = &Close;
|
||||
rec->read = &read;
|
||||
rec->close = &close;
|
||||
|
||||
// Setup the FreeType callbacks that will read our stream
|
||||
FT_Open_Args args;
|
||||
|
@ -214,14 +214,14 @@ bool Font::LoadFromStream(InputStream& stream)
|
|||
FT_Face face;
|
||||
if (FT_Open_Face(static_cast<FT_Library>(m_library), &args, 0, &face) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
|
||||
err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the unicode character map
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
|
||||
{
|
||||
Err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl;
|
||||
err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -234,10 +234,10 @@ bool Font::LoadFromStream(InputStream& stream)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Glyph& Font::GetGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
|
||||
const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
|
||||
{
|
||||
// Get the page corresponding to the character size
|
||||
GlyphTable& glyphs = m_pages[characterSize].Glyphs;
|
||||
GlyphTable& glyphs = m_pages[characterSize].glyphs;
|
||||
|
||||
// Build the key by combining the code point and the bold flag
|
||||
Uint32 key = ((bold ? 1 : 0) << 31) | codePoint;
|
||||
|
@ -252,14 +252,14 @@ const Glyph& Font::GetGlyph(Uint32 codePoint, unsigned int characterSize, bool b
|
|||
else
|
||||
{
|
||||
// Not found: we have to load it
|
||||
Glyph glyph = LoadGlyph(codePoint, characterSize, bold);
|
||||
Glyph glyph = loadGlyph(codePoint, characterSize, bold);
|
||||
return glyphs.insert(std::make_pair(key, glyph)).first->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int Font::GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) const
|
||||
int Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const
|
||||
{
|
||||
// Special case where first or second is 0 (null character)
|
||||
if (first == 0 || second == 0)
|
||||
|
@ -267,7 +267,7 @@ int Font::GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) co
|
|||
|
||||
FT_Face face = static_cast<FT_Face>(m_face);
|
||||
|
||||
if (face && FT_HAS_KERNING(face) && SetCurrentSize(characterSize))
|
||||
if (face && FT_HAS_KERNING(face) && setCurrentSize(characterSize))
|
||||
{
|
||||
// Convert the characters to indices
|
||||
FT_UInt index1 = FT_Get_Char_Index(face, first);
|
||||
|
@ -289,11 +289,11 @@ int Font::GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) co
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int Font::GetLineSpacing(unsigned int characterSize) const
|
||||
int Font::getLineSpacing(unsigned int characterSize) const
|
||||
{
|
||||
FT_Face face = static_cast<FT_Face>(m_face);
|
||||
|
||||
if (face && SetCurrentSize(characterSize))
|
||||
if (face && setCurrentSize(characterSize))
|
||||
{
|
||||
return (face->size->metrics.height >> 6);
|
||||
}
|
||||
|
@ -305,9 +305,9 @@ int Font::GetLineSpacing(unsigned int characterSize) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture& Font::GetTexture(unsigned int characterSize) const
|
||||
const Texture& Font::getTexture(unsigned int characterSize) const
|
||||
{
|
||||
return m_pages[characterSize].Texture;
|
||||
return m_pages[characterSize].texture;
|
||||
}
|
||||
|
||||
|
||||
|
@ -327,7 +327,7 @@ Font& Font::operator =(const Font& right)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Font& Font::GetDefaultFont()
|
||||
const Font& Font::getDefaultFont()
|
||||
{
|
||||
static Font font;
|
||||
static bool loaded = false;
|
||||
|
@ -340,7 +340,7 @@ const Font& Font::GetDefaultFont()
|
|||
#include <SFML/Graphics/Arial.hpp>
|
||||
};
|
||||
|
||||
font.LoadFromMemory(data, sizeof(data));
|
||||
font.loadFromMemory(data, sizeof(data));
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ const Font& Font::GetDefaultFont()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Font::Cleanup()
|
||||
void Font::cleanup()
|
||||
{
|
||||
// Check if we must destroy the FreeType pointers
|
||||
if (m_refCount)
|
||||
|
@ -388,7 +388,7 @@ void Font::Cleanup()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
|
||||
Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
|
||||
{
|
||||
// The glyph to return
|
||||
Glyph glyph;
|
||||
|
@ -399,7 +399,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
return glyph;
|
||||
|
||||
// Set the character size
|
||||
if (!SetCurrentSize(characterSize))
|
||||
if (!setCurrentSize(characterSize))
|
||||
return glyph;
|
||||
|
||||
// Load the glyph corresponding to the code point
|
||||
|
@ -432,9 +432,9 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
}
|
||||
|
||||
// Compute the glyph's advance offset
|
||||
glyph.Advance = glyphDesc->advance.x >> 16;
|
||||
glyph.advance = glyphDesc->advance.x >> 16;
|
||||
if (bold)
|
||||
glyph.Advance += weight >> 6;
|
||||
glyph.advance += weight >> 6;
|
||||
|
||||
int width = bitmap.width;
|
||||
int height = bitmap.rows;
|
||||
|
@ -448,13 +448,13 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
Page& page = m_pages[characterSize];
|
||||
|
||||
// Find a good position for the new glyph into the texture
|
||||
glyph.TextureRect = FindGlyphRect(page, width + 2 * padding, height + 2 * padding);
|
||||
glyph.textureRect = findGlyphRect(page, width + 2 * padding, height + 2 * padding);
|
||||
|
||||
// Compute the glyph's bounding box
|
||||
glyph.Bounds.Left = bitmapGlyph->left - padding;
|
||||
glyph.Bounds.Top = -bitmapGlyph->top - padding;
|
||||
glyph.Bounds.Width = width + 2 * padding;
|
||||
glyph.Bounds.Height = height + 2 * padding;
|
||||
glyph.bounds.left = bitmapGlyph->left - padding;
|
||||
glyph.bounds.top = -bitmapGlyph->top - padding;
|
||||
glyph.bounds.width = width + 2 * padding;
|
||||
glyph.bounds.height = height + 2 * padding;
|
||||
|
||||
// Extract the glyph's pixels from the bitmap
|
||||
m_pixelBuffer.resize(width * height * 4, 255);
|
||||
|
@ -489,11 +489,11 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
}
|
||||
|
||||
// Write the pixels to the texture
|
||||
unsigned int x = glyph.TextureRect.Left + padding;
|
||||
unsigned int y = glyph.TextureRect.Top + padding;
|
||||
unsigned int width = glyph.TextureRect.Width - 2 * padding;
|
||||
unsigned int height = glyph.TextureRect.Height - 2 * padding;
|
||||
page.Texture.Update(&m_pixelBuffer[0], width, height, x, y);
|
||||
unsigned int x = glyph.textureRect.left + padding;
|
||||
unsigned int y = glyph.textureRect.top + padding;
|
||||
unsigned int width = glyph.textureRect.width - 2 * padding;
|
||||
unsigned int height = glyph.textureRect.height - 2 * padding;
|
||||
page.texture.update(&m_pixelBuffer[0], width, height, x, y);
|
||||
}
|
||||
|
||||
// Delete the FT glyph
|
||||
|
@ -505,21 +505,21 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IntRect Font::FindGlyphRect(Page& page, unsigned int width, unsigned int height) const
|
||||
IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) const
|
||||
{
|
||||
// Find the line that fits well the glyph
|
||||
Row* row = NULL;
|
||||
float bestRatio = 0;
|
||||
for (std::vector<Row>::iterator it = page.Rows.begin(); it != page.Rows.end() && !row; ++it)
|
||||
for (std::vector<Row>::iterator it = page.rows.begin(); it != page.rows.end() && !row; ++it)
|
||||
{
|
||||
float ratio = static_cast<float>(height) / it->Height;
|
||||
float ratio = static_cast<float>(height) / it->height;
|
||||
|
||||
// Ignore rows that are either too small or too high
|
||||
if ((ratio < 0.7f) || (ratio > 1.f))
|
||||
continue;
|
||||
|
||||
// Check if there's enough horizontal space left in the row
|
||||
if (width > page.Texture.GetWidth() - it->Width)
|
||||
if (width > page.texture.getWidth() - it->width)
|
||||
continue;
|
||||
|
||||
// Make sure that this new row is the best found so far
|
||||
|
@ -535,44 +535,44 @@ IntRect Font::FindGlyphRect(Page& page, unsigned int width, unsigned int height)
|
|||
if (!row)
|
||||
{
|
||||
int rowHeight = height + height / 10;
|
||||
if (page.NextRow + rowHeight >= page.Texture.GetHeight())
|
||||
if (page.nextRow + rowHeight >= page.texture.getHeight())
|
||||
{
|
||||
// Not enough space: resize the texture if possible
|
||||
unsigned int textureWidth = page.Texture.GetWidth();
|
||||
unsigned int textureHeight = page.Texture.GetHeight();
|
||||
if ((textureWidth * 2 <= Texture::GetMaximumSize()) && (textureHeight * 2 <= Texture::GetMaximumSize()))
|
||||
unsigned int textureWidth = page.texture.getWidth();
|
||||
unsigned int textureHeight = page.texture.getHeight();
|
||||
if ((textureWidth * 2 <= Texture::getMaximumSize()) && (textureHeight * 2 <= Texture::getMaximumSize()))
|
||||
{
|
||||
// Make the texture 2 times bigger
|
||||
sf::Image pixels = page.Texture.CopyToImage();
|
||||
page.Texture.Create(textureWidth * 2, textureHeight * 2);
|
||||
page.Texture.Update(pixels);
|
||||
sf::Image pixels = page.texture.copyToImage();
|
||||
page.texture.create(textureWidth * 2, textureHeight * 2);
|
||||
page.texture.update(pixels);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Oops, we've reached the maximum texture size...
|
||||
Err() << "Failed to add a new character to the font: the maximum texture size has been reached" << std::endl;
|
||||
err() << "Failed to add a new character to the font: the maximum texture size has been reached" << std::endl;
|
||||
return IntRect(0, 0, 2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// We can now create the new row
|
||||
page.Rows.push_back(Row(page.NextRow, rowHeight));
|
||||
page.NextRow += rowHeight;
|
||||
row = &page.Rows.back();
|
||||
page.rows.push_back(Row(page.nextRow, rowHeight));
|
||||
page.nextRow += rowHeight;
|
||||
row = &page.rows.back();
|
||||
}
|
||||
|
||||
// Find the glyph's rectangle on the selected row
|
||||
IntRect rect(row->Width, row->Top, width, height);
|
||||
IntRect rect(row->width, row->top, width, height);
|
||||
|
||||
// Update the row informations
|
||||
row->Width += width;
|
||||
row->width += width;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::SetCurrentSize(unsigned int characterSize) const
|
||||
bool Font::setCurrentSize(unsigned int characterSize) const
|
||||
{
|
||||
// FT_Set_Pixel_Sizes is an expensive function, so we must call it
|
||||
// only when necessary to avoid killing performances
|
||||
|
@ -593,20 +593,20 @@ bool Font::SetCurrentSize(unsigned int characterSize) const
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
Font::Page::Page() :
|
||||
NextRow(2)
|
||||
nextRow(2)
|
||||
{
|
||||
// Make sure that the texture is initialized by default
|
||||
sf::Image image;
|
||||
image.Create(128, 128, Color(255, 255, 255, 0));
|
||||
image.create(128, 128, Color(255, 255, 255, 0));
|
||||
|
||||
// Reserve a 2x2 white square for texturing underlines
|
||||
for (int x = 0; x < 2; ++x)
|
||||
for (int y = 0; y < 2; ++y)
|
||||
image.SetPixel(x, y, Color(255, 255, 255, 255));
|
||||
image.setPixel(x, y, Color(255, 255, 255, 255));
|
||||
|
||||
// Create the texture
|
||||
Texture.LoadFromImage(image);
|
||||
Texture.SetSmooth(true);
|
||||
texture.loadFromImage(image);
|
||||
texture.setSmooth(true);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void GLCheckError(const std::string& file, unsigned int line)
|
||||
void glCheckError(const std::string& file, unsigned int line)
|
||||
{
|
||||
// Get the last error
|
||||
GLenum errorCode = glGetError();
|
||||
|
@ -98,7 +98,7 @@ void GLCheckError(const std::string& file, unsigned int line)
|
|||
}
|
||||
|
||||
// Log the error
|
||||
Err() << "An internal OpenGL call failed in "
|
||||
err() << "An internal OpenGL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
|
@ -107,7 +107,7 @@ void GLCheckError(const std::string& file, unsigned int line)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void EnsureGlewInit()
|
||||
void ensureGlewInit()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (!initialized)
|
||||
|
@ -119,7 +119,7 @@ void EnsureGlewInit()
|
|||
}
|
||||
else
|
||||
{
|
||||
Err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
|
||||
err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,18 +38,17 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenGL
|
||||
/// API calls
|
||||
/// Let's define a macro to quickly check every OpenGL API calls
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
// In debug mode, perform a test on every OpenGL call
|
||||
#define GLCheck(call) ((call), sf::priv::GLCheckError(__FILE__, __LINE__))
|
||||
#define glCheck(call) ((call), sf::priv::glCheckError(__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define GLCheck(call) (call)
|
||||
#define glCheck(call) (call)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -60,13 +59,13 @@ namespace priv
|
|||
/// \param line Line number of the source file where the call is located
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void GLCheckError(const std::string& file, unsigned int line);
|
||||
void glCheckError(const std::string& file, unsigned int line);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sure that GLEW is initialized
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void EnsureGlewInit();
|
||||
void ensureGlewInit();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ m_height(0)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::Create(unsigned int width, unsigned int height, const Color& color)
|
||||
void Image::create(unsigned int width, unsigned int height, const Color& color)
|
||||
{
|
||||
// Assign the new size
|
||||
m_width = width;
|
||||
|
@ -67,7 +67,7 @@ void Image::Create(unsigned int width, unsigned int height, const Color& color)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::Create(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
void Image::create(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
{
|
||||
if (pixels)
|
||||
{
|
||||
|
@ -91,49 +91,49 @@ void Image::Create(unsigned int width, unsigned int height, const Uint8* pixels)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Image::LoadFromFile(const std::string& filename)
|
||||
bool Image::loadFromFile(const std::string& filename)
|
||||
{
|
||||
return priv::ImageLoader::GetInstance().LoadImageFromFile(filename, m_pixels, m_width, m_height);
|
||||
return priv::ImageLoader::getInstance().loadImageFromFile(filename, m_pixels, m_width, m_height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Image::LoadFromMemory(const void* data, std::size_t size)
|
||||
bool Image::loadFromMemory(const void* data, std::size_t size)
|
||||
{
|
||||
return priv::ImageLoader::GetInstance().LoadImageFromMemory(data, size, m_pixels, m_width, m_height);
|
||||
return priv::ImageLoader::getInstance().loadImageFromMemory(data, size, m_pixels, m_width, m_height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Image::LoadFromStream(InputStream& stream)
|
||||
bool Image::loadFromStream(InputStream& stream)
|
||||
{
|
||||
return priv::ImageLoader::GetInstance().LoadImageFromStream(stream, m_pixels, m_width, m_height);
|
||||
return priv::ImageLoader::getInstance().loadImageFromStream(stream, m_pixels, m_width, m_height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Image::SaveToFile(const std::string& filename) const
|
||||
bool Image::saveToFile(const std::string& filename) const
|
||||
{
|
||||
return priv::ImageLoader::GetInstance().SaveImageToFile(filename, m_pixels, m_width, m_height);
|
||||
return priv::ImageLoader::getInstance().saveImageToFile(filename, m_pixels, m_width, m_height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Image::GetWidth() const
|
||||
unsigned int Image::getWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Image::GetHeight() const
|
||||
unsigned int Image::getHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::CreateMaskFromColor(const Color& color, Uint8 alpha)
|
||||
void Image::createMaskFromColor(const Color& color, Uint8 alpha)
|
||||
{
|
||||
// Make sure that the image is not empty
|
||||
if (!m_pixels.empty())
|
||||
|
@ -152,7 +152,7 @@ void Image::CreateMaskFromColor(const Color& color, Uint8 alpha)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect, bool applyAlpha)
|
||||
void Image::copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect, bool applyAlpha)
|
||||
{
|
||||
// Make sure that both images are valid
|
||||
if ((source.m_width == 0) || (source.m_height == 0) || (m_width == 0) || (m_height == 0))
|
||||
|
@ -160,24 +160,24 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
|
|||
|
||||
// Adjust the source rectangle
|
||||
IntRect srcRect = sourceRect;
|
||||
if (srcRect.Width == 0 || (srcRect.Height == 0))
|
||||
if (srcRect.width == 0 || (srcRect.height == 0))
|
||||
{
|
||||
srcRect.Left = 0;
|
||||
srcRect.Top = 0;
|
||||
srcRect.Width = source.m_width;
|
||||
srcRect.Height = source.m_height;
|
||||
srcRect.left = 0;
|
||||
srcRect.top = 0;
|
||||
srcRect.width = source.m_width;
|
||||
srcRect.height = source.m_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (srcRect.Left < 0) srcRect.Left = 0;
|
||||
if (srcRect.Top < 0) srcRect.Top = 0;
|
||||
if (srcRect.Width > static_cast<int>(source.m_width)) srcRect.Width = source.m_width;
|
||||
if (srcRect.Height > static_cast<int>(source.m_height)) srcRect.Height = source.m_height;
|
||||
if (srcRect.left < 0) srcRect.left = 0;
|
||||
if (srcRect.top < 0) srcRect.top = 0;
|
||||
if (srcRect.width > static_cast<int>(source.m_width)) srcRect.width = source.m_width;
|
||||
if (srcRect.height > static_cast<int>(source.m_height)) srcRect.height = source.m_height;
|
||||
}
|
||||
|
||||
// Then find the valid bounds of the destination rectangle
|
||||
int width = srcRect.Width;
|
||||
int height = srcRect.Height;
|
||||
int width = srcRect.width;
|
||||
int height = srcRect.height;
|
||||
if (destX + width > m_width) width = m_width - destX;
|
||||
if (destY + height > m_height) height = m_height - destY;
|
||||
|
||||
|
@ -190,7 +190,7 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
|
|||
int rows = height;
|
||||
int srcStride = source.m_width * 4;
|
||||
int dstStride = m_width * 4;
|
||||
const Uint8* srcPixels = &source.m_pixels[0] + (srcRect.Left + srcRect.Top * source.m_width) * 4;
|
||||
const Uint8* srcPixels = &source.m_pixels[0] + (srcRect.left + srcRect.top * source.m_width) * 4;
|
||||
Uint8* dstPixels = &m_pixels[0] + (destX + destY * m_width) * 4;
|
||||
|
||||
// Copy the pixels
|
||||
|
@ -231,7 +231,7 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::SetPixel(unsigned int x, unsigned int y, const Color& color)
|
||||
void Image::setPixel(unsigned int x, unsigned int y, const Color& color)
|
||||
{
|
||||
Uint8* pixel = &m_pixels[(x + y * m_width) * 4];
|
||||
*pixel++ = color.r;
|
||||
|
@ -242,7 +242,7 @@ void Image::SetPixel(unsigned int x, unsigned int y, const Color& color)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Color Image::GetPixel(unsigned int x, unsigned int y) const
|
||||
Color Image::getPixel(unsigned int x, unsigned int y) const
|
||||
{
|
||||
const Uint8* pixel = &m_pixels[(x + y * m_width) * 4];
|
||||
return Color(pixel[0], pixel[1], pixel[2], pixel[3]);
|
||||
|
@ -250,7 +250,7 @@ Color Image::GetPixel(unsigned int x, unsigned int y) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint8* Image::GetPixelsPtr() const
|
||||
const Uint8* Image::getPixelsPtr() const
|
||||
{
|
||||
if (!m_pixels.empty())
|
||||
{
|
||||
|
@ -258,14 +258,14 @@ const Uint8* Image::GetPixelsPtr() const
|
|||
}
|
||||
else
|
||||
{
|
||||
Err() << "Trying to access the pixels of an empty image" << std::endl;
|
||||
err() << "Trying to access the pixels of an empty image" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::FlipHorizontally()
|
||||
void Image::flipHorizontally()
|
||||
{
|
||||
if (!m_pixels.empty())
|
||||
{
|
||||
|
@ -290,7 +290,7 @@ void Image::FlipHorizontally()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::FlipVertically()
|
||||
void Image::flipVertically()
|
||||
{
|
||||
if (!m_pixels.empty())
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ extern "C"
|
|||
namespace
|
||||
{
|
||||
// Convert a string to lower case
|
||||
std::string ToLower(std::string str)
|
||||
std::string toLower(std::string str)
|
||||
{
|
||||
for (std::string::iterator i = str.begin(); i != str.end(); ++i)
|
||||
*i = static_cast<char>(std::tolower(*i));
|
||||
|
@ -50,20 +50,20 @@ namespace
|
|||
}
|
||||
|
||||
// stb_image callbacks that operate on a sf::InputStream
|
||||
int Read(void* user, char* data, int size)
|
||||
int read(void* user, char* data, int size)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(user);
|
||||
return static_cast<int>(stream->Read(data, size));
|
||||
return static_cast<int>(stream->read(data, size));
|
||||
}
|
||||
void Skip(void* user, unsigned int size)
|
||||
void skip(void* user, unsigned int size)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(user);
|
||||
stream->Seek(stream->Tell() + size);
|
||||
stream->seek(stream->tell() + size);
|
||||
}
|
||||
int Eof(void* user)
|
||||
int eof(void* user)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(user);
|
||||
return stream->Tell() >= stream->GetSize();
|
||||
return stream->tell() >= stream->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
ImageLoader& ImageLoader::GetInstance()
|
||||
ImageLoader& ImageLoader::getInstance()
|
||||
{
|
||||
static ImageLoader Instance;
|
||||
|
||||
|
@ -96,7 +96,7 @@ ImageLoader::~ImageLoader()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool ImageLoader::LoadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
{
|
||||
// Clear the array (just in case)
|
||||
pixels.clear();
|
||||
|
@ -123,7 +123,7 @@ bool ImageLoader::LoadImageFromFile(const std::string& filename, std::vector<Uin
|
|||
else
|
||||
{
|
||||
// Error, failed to load the image
|
||||
Err() << "Failed to load image \"" << filename << "\". Reason : " << stbi_failure_reason() << std::endl;
|
||||
err() << "Failed to load image \"" << filename << "\". Reason : " << stbi_failure_reason() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ bool ImageLoader::LoadImageFromFile(const std::string& filename, std::vector<Uin
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool ImageLoader::LoadImageFromMemory(const void* data, std::size_t size, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
bool ImageLoader::loadImageFromMemory(const void* data, std::size_t size, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
{
|
||||
// Check input parameters
|
||||
if (data && size)
|
||||
|
@ -162,30 +162,30 @@ bool ImageLoader::LoadImageFromMemory(const void* data, std::size_t size, std::v
|
|||
else
|
||||
{
|
||||
// Error, failed to load the image
|
||||
Err() << "Failed to load image from memory. Reason : " << stbi_failure_reason() << std::endl;
|
||||
err() << "Failed to load image from memory. Reason : " << stbi_failure_reason() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Err() << "Failed to load image from memory, no data provided" << std::endl;
|
||||
err() << "Failed to load image from memory, no data provided" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool ImageLoader::LoadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height)
|
||||
{
|
||||
// Clear the array (just in case)
|
||||
pixels.clear();
|
||||
|
||||
// Setup the stb_image callbacks
|
||||
stbi_io_callbacks callbacks;
|
||||
callbacks.read = &Read;
|
||||
callbacks.skip = &Skip;
|
||||
callbacks.eof = &Eof;
|
||||
callbacks.read = &read;
|
||||
callbacks.skip = &skip;
|
||||
callbacks.eof = &eof;
|
||||
|
||||
// Load the image and get a pointer to the pixels in memory
|
||||
int imgWidth, imgHeight, imgChannels;
|
||||
|
@ -209,7 +209,7 @@ bool ImageLoader::LoadImageFromStream(InputStream& stream, std::vector<Uint8>& p
|
|||
else
|
||||
{
|
||||
// Error, failed to load the image
|
||||
Err() << "Failed to load image from stream. Reason : " << stbi_failure_reason() << std::endl;
|
||||
err() << "Failed to load image from stream. Reason : " << stbi_failure_reason() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ bool ImageLoader::LoadImageFromStream(InputStream& stream, std::vector<Uint8>& p
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool ImageLoader::SaveImageToFile(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height)
|
||||
bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height)
|
||||
{
|
||||
// Make sure the image is not empty
|
||||
if (!pixels.empty() && width && height)
|
||||
|
@ -228,40 +228,40 @@ bool ImageLoader::SaveImageToFile(const std::string& filename, const std::vector
|
|||
// Extract the extension
|
||||
std::string extension = filename.substr(filename.size() - 3);
|
||||
|
||||
if (ToLower(extension) == "bmp")
|
||||
if (toLower(extension) == "bmp")
|
||||
{
|
||||
// BMP format
|
||||
if (stbi_write_bmp(filename.c_str(), width, height, 4, &pixels[0]))
|
||||
return true;
|
||||
}
|
||||
else if (ToLower(extension) == "tga")
|
||||
else if (toLower(extension) == "tga")
|
||||
{
|
||||
// TGA format
|
||||
if (stbi_write_tga(filename.c_str(), width, height, 4, &pixels[0]))
|
||||
return true;
|
||||
}
|
||||
else if(ToLower(extension) == "png")
|
||||
else if(toLower(extension) == "png")
|
||||
{
|
||||
// PNG format
|
||||
if (stbi_write_png(filename.c_str(), width, height, 4, &pixels[0], 0))
|
||||
return true;
|
||||
}
|
||||
else if (ToLower(extension) == "jpg")
|
||||
else if (toLower(extension) == "jpg")
|
||||
{
|
||||
// JPG format
|
||||
if (WriteJpg(filename, pixels, width, height))
|
||||
if (writeJpg(filename, pixels, width, height))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err() << "Failed to save image \"" << filename << "\"" << std::endl;
|
||||
err() << "Failed to save image \"" << filename << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool ImageLoader::WriteJpg(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height)
|
||||
bool ImageLoader::writeJpg(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height)
|
||||
{
|
||||
// Open the file to write in
|
||||
FILE* file = fopen(filename.c_str(), "wb");
|
||||
|
|
|
@ -53,7 +53,7 @@ public :
|
|||
/// \return Reference to the ImageLoader instance
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static ImageLoader& GetInstance();
|
||||
static ImageLoader& getInstance();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load an image from a file on disk
|
||||
|
@ -66,7 +66,7 @@ public :
|
|||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
bool loadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load an image from a file in memory
|
||||
|
@ -80,7 +80,7 @@ public :
|
|||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadImageFromMemory(const void* data, std::size_t size, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
bool loadImageFromMemory(const void* data, std::size_t size, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load an image from a custom stream
|
||||
|
@ -93,7 +93,7 @@ public :
|
|||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
bool loadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \bref Save an array of pixels as an image file
|
||||
|
@ -106,7 +106,7 @@ public :
|
|||
/// \return True if saving was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SaveImageToFile(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height);
|
||||
bool saveImageToFile(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -133,7 +133,7 @@ private :
|
|||
/// \return True if saving was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WriteJpg(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height);
|
||||
bool writeJpg(const std::string& filename, const std::vector<Uint8>& pixels, unsigned int width, unsigned int height);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -34,34 +34,34 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
RectangleShape::RectangleShape(const Vector2f& size)
|
||||
{
|
||||
SetSize(size);
|
||||
setSize(size);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RectangleShape::SetSize(const Vector2f& size)
|
||||
void RectangleShape::setSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
Update();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& RectangleShape::GetSize() const
|
||||
const Vector2f& RectangleShape::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int RectangleShape::GetPointCount() const
|
||||
unsigned int RectangleShape::getPointCount() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f RectangleShape::GetPoint(unsigned int index) const
|
||||
Vector2f RectangleShape::getPoint(unsigned int index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
|
|
|
@ -37,61 +37,61 @@ const RenderStates RenderStates::Default;
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates() :
|
||||
BlendMode(BlendAlpha),
|
||||
Transform(),
|
||||
Texture (NULL),
|
||||
Shader (NULL)
|
||||
blendMode(BlendAlpha),
|
||||
transform(),
|
||||
texture (NULL),
|
||||
shader (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates(const sf::Transform& transform) :
|
||||
BlendMode(BlendAlpha),
|
||||
Transform(transform),
|
||||
Texture (NULL),
|
||||
Shader (NULL)
|
||||
RenderStates::RenderStates(const Transform& transform) :
|
||||
blendMode(BlendAlpha),
|
||||
transform(transform),
|
||||
texture (NULL),
|
||||
shader (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates(sf::BlendMode blendMode) :
|
||||
BlendMode(blendMode),
|
||||
Transform(),
|
||||
Texture (NULL),
|
||||
Shader (NULL)
|
||||
RenderStates::RenderStates(BlendMode blendMode) :
|
||||
blendMode(blendMode),
|
||||
transform(),
|
||||
texture (NULL),
|
||||
shader (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates(const sf::Texture* texture) :
|
||||
BlendMode(BlendAlpha),
|
||||
Transform(),
|
||||
Texture (texture),
|
||||
Shader (NULL)
|
||||
RenderStates::RenderStates(const Texture* texture) :
|
||||
blendMode(BlendAlpha),
|
||||
transform(),
|
||||
texture (texture),
|
||||
shader (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates(const sf::Shader* shader) :
|
||||
BlendMode(BlendAlpha),
|
||||
Transform(),
|
||||
Texture (NULL),
|
||||
Shader (shader)
|
||||
RenderStates::RenderStates(const Shader* shader) :
|
||||
blendMode(BlendAlpha),
|
||||
transform(),
|
||||
texture (NULL),
|
||||
shader (shader)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates::RenderStates(sf::BlendMode blendMode, const sf::Transform& transform,
|
||||
const sf::Texture* texture, const sf::Shader* shader) :
|
||||
BlendMode(blendMode),
|
||||
Transform(transform),
|
||||
Texture (texture),
|
||||
Shader (shader)
|
||||
RenderStates::RenderStates(BlendMode blendMode, const Transform& transform,
|
||||
const Texture* texture, const Shader* shader) :
|
||||
blendMode(blendMode),
|
||||
transform(transform),
|
||||
texture (texture),
|
||||
shader (shader)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
@ -52,89 +52,89 @@ RenderTarget::~RenderTarget()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::Clear(const Color& color)
|
||||
void RenderTarget::clear(const Color& color)
|
||||
{
|
||||
if (Activate(true))
|
||||
if (activate(true))
|
||||
{
|
||||
GLCheck(glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f));
|
||||
GLCheck(glClear(GL_COLOR_BUFFER_BIT));
|
||||
glCheck(glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f));
|
||||
glCheck(glClear(GL_COLOR_BUFFER_BIT));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::SetView(const View& view)
|
||||
void RenderTarget::setView(const View& view)
|
||||
{
|
||||
m_view = view;
|
||||
m_cache.ViewChanged = true;
|
||||
m_cache.viewChanged = true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const View& RenderTarget::GetView() const
|
||||
const View& RenderTarget::getView() const
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const View& RenderTarget::GetDefaultView() const
|
||||
const View& RenderTarget::getDefaultView() const
|
||||
{
|
||||
return m_defaultView;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IntRect RenderTarget::GetViewport(const View& view) const
|
||||
IntRect RenderTarget::getViewport(const View& view) const
|
||||
{
|
||||
float width = static_cast<float>(GetSize().x);
|
||||
float height = static_cast<float>(GetSize().y);
|
||||
const FloatRect& viewport = view.GetViewport();
|
||||
float width = static_cast<float>(getSize().x);
|
||||
float height = static_cast<float>(getSize().y);
|
||||
const FloatRect& viewport = view.getViewport();
|
||||
|
||||
return IntRect(static_cast<int>(0.5f + width * viewport.Left),
|
||||
static_cast<int>(0.5f + height * viewport.Top),
|
||||
static_cast<int>(width * viewport.Width),
|
||||
static_cast<int>(height * viewport.Height));
|
||||
return IntRect(static_cast<int>(0.5f + width * viewport.left),
|
||||
static_cast<int>(0.5f + height * viewport.top),
|
||||
static_cast<int>(width * viewport.width),
|
||||
static_cast<int>(height * viewport.height));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f RenderTarget::ConvertCoords(unsigned int x, unsigned int y) const
|
||||
Vector2f RenderTarget::convertCoords(unsigned int x, unsigned int y) const
|
||||
{
|
||||
return ConvertCoords(x, y, GetView());
|
||||
return convertCoords(x, y, getView());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f RenderTarget::ConvertCoords(unsigned int x, unsigned int y, const View& view) const
|
||||
Vector2f RenderTarget::convertCoords(unsigned int x, unsigned int y, const View& view) const
|
||||
{
|
||||
// First, convert from viewport coordinates to homogeneous coordinates
|
||||
Vector2f coords;
|
||||
IntRect viewport = GetViewport(view);
|
||||
coords.x = -1.f + 2.f * (static_cast<int>(x) - viewport.Left) / viewport.Width;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.Top) / viewport.Height;
|
||||
IntRect viewport = getViewport(view);
|
||||
coords.x = -1.f + 2.f * (static_cast<int>(x) - viewport.left) / viewport.width;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.top) / viewport.height;
|
||||
|
||||
// Then transform by the inverse of the view matrix
|
||||
return view.GetInverseTransform().TransformPoint(coords);
|
||||
return view.getInverseTransform().transformPoint(coords);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::Draw(const Drawable& drawable, const RenderStates& states)
|
||||
void RenderTarget::draw(const Drawable& drawable, const RenderStates& states)
|
||||
{
|
||||
drawable.Draw(*this, states);
|
||||
drawable.draw(*this, states);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
|
||||
void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount,
|
||||
PrimitiveType type, const RenderStates& states)
|
||||
{
|
||||
// Nothing to draw?
|
||||
if (!vertices || (vertexCount == 0))
|
||||
return;
|
||||
|
||||
if (Activate(true))
|
||||
if (activate(true))
|
||||
{
|
||||
// Check if the vertex count is low enough so that we can pre-transform them
|
||||
bool useVertexCache = (vertexCount <= StatesCache::VertexCacheSize);
|
||||
|
@ -143,44 +143,44 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
|
|||
// Pre-transform the vertices and store them into the vertex cache
|
||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
Vertex& vertex = m_cache.VertexCache[i];
|
||||
vertex.Position = states.Transform * vertices[i].Position;
|
||||
vertex.Color = vertices[i].Color;
|
||||
vertex.TexCoords = vertices[i].TexCoords;
|
||||
Vertex& vertex = m_cache.vertexCache[i];
|
||||
vertex.position = states.transform * vertices[i].position;
|
||||
vertex.color = vertices[i].color;
|
||||
vertex.texCoords = vertices[i].texCoords;
|
||||
}
|
||||
|
||||
// Since vertices are transformed, we must use an identity transform to render them
|
||||
if (!m_cache.UseVertexCache)
|
||||
ApplyTransform(Transform::Identity);
|
||||
if (!m_cache.useVertexCache)
|
||||
applyTransform(Transform::Identity);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyTransform(states.Transform);
|
||||
applyTransform(states.transform);
|
||||
}
|
||||
|
||||
// Apply the view
|
||||
if (m_cache.ViewChanged)
|
||||
ApplyCurrentView();
|
||||
if (m_cache.viewChanged)
|
||||
applyCurrentView();
|
||||
|
||||
// Apply the blend mode
|
||||
if (states.BlendMode != m_cache.LastBlendMode)
|
||||
ApplyBlendMode(states.BlendMode);
|
||||
if (states.blendMode != m_cache.lastBlendMode)
|
||||
applyBlendMode(states.blendMode);
|
||||
|
||||
// Apply the texture
|
||||
Uint64 textureId = states.Texture ? states.Texture->m_cacheId : 0;
|
||||
if (textureId != m_cache.LastTextureId)
|
||||
ApplyTexture(states.Texture);
|
||||
Uint64 textureId = states.texture ? states.texture->m_cacheId : 0;
|
||||
if (textureId != m_cache.lastTextureId)
|
||||
applyTexture(states.texture);
|
||||
|
||||
// Apply the shader
|
||||
if (states.Shader)
|
||||
ApplyShader(states.Shader);
|
||||
if (states.shader)
|
||||
applyShader(states.shader);
|
||||
|
||||
// If we pre-transform the vertices, we must use our internal vertex cache
|
||||
if (useVertexCache)
|
||||
{
|
||||
// ... and if we already used it previously, we don't need to set the pointers again
|
||||
if (!m_cache.UseVertexCache)
|
||||
vertices = m_cache.VertexCache;
|
||||
if (!m_cache.useVertexCache)
|
||||
vertices = m_cache.vertexCache;
|
||||
else
|
||||
vertices = NULL;
|
||||
}
|
||||
|
@ -189,9 +189,9 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
|
|||
if (vertices)
|
||||
{
|
||||
const char* data = reinterpret_cast<const char*>(vertices);
|
||||
GLCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0));
|
||||
GLCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8));
|
||||
GLCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
|
||||
glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0));
|
||||
glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8));
|
||||
glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12));
|
||||
}
|
||||
|
||||
// Find the OpenGL primitive type
|
||||
|
@ -200,119 +200,119 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
|
|||
GLenum mode = modes[type];
|
||||
|
||||
// Draw the primitives
|
||||
GLCheck(glDrawArrays(mode, 0, vertexCount));
|
||||
glCheck(glDrawArrays(mode, 0, vertexCount));
|
||||
|
||||
// Unbind the shader, if any
|
||||
if (states.Shader)
|
||||
ApplyShader(NULL);
|
||||
if (states.shader)
|
||||
applyShader(NULL);
|
||||
|
||||
// Update the cache
|
||||
m_cache.UseVertexCache = useVertexCache;
|
||||
m_cache.useVertexCache = useVertexCache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::PushGLStates()
|
||||
void RenderTarget::pushGLStates()
|
||||
{
|
||||
if (Activate(true))
|
||||
if (activate(true))
|
||||
{
|
||||
GLCheck(glPushAttrib(GL_ALL_ATTRIB_BITS));
|
||||
GLCheck(glMatrixMode(GL_MODELVIEW));
|
||||
GLCheck(glPushMatrix());
|
||||
GLCheck(glMatrixMode(GL_PROJECTION));
|
||||
GLCheck(glPushMatrix());
|
||||
GLCheck(glMatrixMode(GL_TEXTURE));
|
||||
GLCheck(glPushMatrix());
|
||||
glCheck(glPushAttrib(GL_ALL_ATTRIB_BITS));
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glPushMatrix());
|
||||
glCheck(glMatrixMode(GL_PROJECTION));
|
||||
glCheck(glPushMatrix());
|
||||
glCheck(glMatrixMode(GL_TEXTURE));
|
||||
glCheck(glPushMatrix());
|
||||
}
|
||||
|
||||
ResetGLStates();
|
||||
resetGLStates();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::PopGLStates()
|
||||
void RenderTarget::popGLStates()
|
||||
{
|
||||
if (Activate(true))
|
||||
if (activate(true))
|
||||
{
|
||||
GLCheck(glPopAttrib());
|
||||
GLCheck(glMatrixMode(GL_PROJECTION));
|
||||
GLCheck(glPopMatrix());
|
||||
GLCheck(glMatrixMode(GL_MODELVIEW));
|
||||
GLCheck(glPopMatrix());
|
||||
GLCheck(glMatrixMode(GL_TEXTURE));
|
||||
GLCheck(glPopMatrix());
|
||||
glCheck(glPopAttrib());
|
||||
glCheck(glMatrixMode(GL_PROJECTION));
|
||||
glCheck(glPopMatrix());
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glPopMatrix());
|
||||
glCheck(glMatrixMode(GL_TEXTURE));
|
||||
glCheck(glPopMatrix());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ResetGLStates()
|
||||
void RenderTarget::resetGLStates()
|
||||
{
|
||||
if (Activate(true))
|
||||
if (activate(true))
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
priv::EnsureGlewInit();
|
||||
priv::ensureGlewInit();
|
||||
|
||||
// Define the default OpenGL states
|
||||
GLCheck(glDisable(GL_LIGHTING));
|
||||
GLCheck(glDisable(GL_DEPTH_TEST));
|
||||
GLCheck(glEnable(GL_TEXTURE_2D));
|
||||
GLCheck(glEnable(GL_ALPHA_TEST));
|
||||
GLCheck(glEnable(GL_BLEND));
|
||||
GLCheck(glAlphaFunc(GL_GREATER, 0));
|
||||
GLCheck(glMatrixMode(GL_MODELVIEW));
|
||||
GLCheck(glEnableClientState(GL_VERTEX_ARRAY));
|
||||
GLCheck(glEnableClientState(GL_COLOR_ARRAY));
|
||||
GLCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
|
||||
glCheck(glDisable(GL_LIGHTING));
|
||||
glCheck(glDisable(GL_DEPTH_TEST));
|
||||
glCheck(glEnable(GL_TEXTURE_2D));
|
||||
glCheck(glEnable(GL_ALPHA_TEST));
|
||||
glCheck(glEnable(GL_BLEND));
|
||||
glCheck(glAlphaFunc(GL_GREATER, 0));
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glEnableClientState(GL_VERTEX_ARRAY));
|
||||
glCheck(glEnableClientState(GL_COLOR_ARRAY));
|
||||
glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
|
||||
|
||||
// Apply the default SFML states
|
||||
ApplyBlendMode(BlendAlpha);
|
||||
ApplyTransform(Transform::Identity);
|
||||
ApplyTexture(NULL);
|
||||
if (Shader::IsAvailable())
|
||||
ApplyShader(NULL);
|
||||
m_cache.UseVertexCache = false;
|
||||
applyBlendMode(BlendAlpha);
|
||||
applyTransform(Transform::Identity);
|
||||
applyTexture(NULL);
|
||||
if (Shader::isAvailable())
|
||||
applyShader(NULL);
|
||||
m_cache.useVertexCache = false;
|
||||
|
||||
// Set the default view
|
||||
SetView(GetView());
|
||||
setView(getView());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::Initialize()
|
||||
void RenderTarget::initialize()
|
||||
{
|
||||
// Setup the default and current views
|
||||
m_defaultView.Reset(FloatRect(0, 0, static_cast<float>(GetSize().x), static_cast<float>(GetSize().y)));
|
||||
m_defaultView.reset(FloatRect(0, 0, static_cast<float>(getSize().x), static_cast<float>(getSize().y)));
|
||||
m_view = m_defaultView;
|
||||
|
||||
// Initialize the default OpenGL render-states
|
||||
ResetGLStates();
|
||||
resetGLStates();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ApplyCurrentView()
|
||||
void RenderTarget::applyCurrentView()
|
||||
{
|
||||
// Set the viewport
|
||||
IntRect viewport = GetViewport(m_view);
|
||||
int top = GetSize().y - (viewport.Top + viewport.Height);
|
||||
GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height));
|
||||
IntRect viewport = getViewport(m_view);
|
||||
int top = getSize().y - (viewport.top + viewport.height);
|
||||
glCheck(glViewport(viewport.left, top, viewport.width, viewport.height));
|
||||
|
||||
// Set the projection matrix
|
||||
GLCheck(glMatrixMode(GL_PROJECTION));
|
||||
GLCheck(glLoadMatrixf(m_view.GetTransform().GetMatrix()));
|
||||
glCheck(glMatrixMode(GL_PROJECTION));
|
||||
glCheck(glLoadMatrixf(m_view.getTransform().getMatrix()));
|
||||
|
||||
// Go back to model-view mode
|
||||
GLCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
|
||||
m_cache.ViewChanged = false;
|
||||
m_cache.viewChanged = false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ApplyBlendMode(BlendMode mode)
|
||||
void RenderTarget::applyBlendMode(BlendMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
|
@ -322,59 +322,59 @@ void RenderTarget::ApplyBlendMode(BlendMode mode)
|
|||
default :
|
||||
case BlendAlpha :
|
||||
if (GLEW_EXT_blend_func_separate)
|
||||
GLCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
else
|
||||
GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
break;
|
||||
|
||||
// Additive blending
|
||||
case BlendAdd :
|
||||
GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
|
||||
break;
|
||||
|
||||
// Multiplicative blending
|
||||
case BlendMultiply :
|
||||
GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO));
|
||||
glCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO));
|
||||
break;
|
||||
|
||||
// No blending
|
||||
case BlendNone :
|
||||
GLCheck(glBlendFunc(GL_ONE, GL_ZERO));
|
||||
glCheck(glBlendFunc(GL_ONE, GL_ZERO));
|
||||
break;
|
||||
}
|
||||
|
||||
m_cache.LastBlendMode = mode;
|
||||
m_cache.lastBlendMode = mode;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ApplyTransform(const Transform& transform)
|
||||
void RenderTarget::applyTransform(const Transform& transform)
|
||||
{
|
||||
// No need to call glMatrixMode(GL_MODELVIEW), it is always the
|
||||
// current mode (for optimization purpose, since it's the most used)
|
||||
GLCheck(glLoadMatrixf(transform.GetMatrix()));
|
||||
glCheck(glLoadMatrixf(transform.getMatrix()));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ApplyTexture(const Texture* texture)
|
||||
void RenderTarget::applyTexture(const Texture* texture)
|
||||
{
|
||||
if (texture)
|
||||
texture->Bind(Texture::Pixels);
|
||||
texture->bind(Texture::Pixels);
|
||||
else
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
|
||||
m_cache.LastTextureId = texture ? texture->m_cacheId : 0;
|
||||
m_cache.lastTextureId = texture ? texture->m_cacheId : 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::ApplyShader(const Shader* shader)
|
||||
void RenderTarget::applyShader(const Shader* shader)
|
||||
{
|
||||
if (shader)
|
||||
shader->Bind();
|
||||
shader->bind();
|
||||
else
|
||||
GLCheck(glUseProgramObjectARB(0));
|
||||
glCheck(glUseProgramObjectARB(0));
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -49,21 +49,21 @@ RenderTexture::~RenderTexture()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTexture::Create(unsigned int width, unsigned int height, bool depthBuffer)
|
||||
bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBuffer)
|
||||
{
|
||||
// Create the texture
|
||||
if (!m_texture.Create(width, height))
|
||||
if (!m_texture.create(width, height))
|
||||
{
|
||||
Err() << "Impossible to create render texture (failed to create the target texture)" << std::endl;
|
||||
err() << "Impossible to create render texture (failed to create the target texture)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// We disable smoothing by default for render textures
|
||||
SetSmooth(false);
|
||||
setSmooth(false);
|
||||
|
||||
// Create the implementation
|
||||
delete m_impl;
|
||||
if (priv::RenderTextureImplFBO::IsAvailable())
|
||||
if (priv::RenderTextureImplFBO::isAvailable())
|
||||
{
|
||||
// Use frame-buffer object (FBO)
|
||||
m_impl = new priv::RenderTextureImplFBO;
|
||||
|
@ -75,67 +75,67 @@ bool RenderTexture::Create(unsigned int width, unsigned int height, bool depthBu
|
|||
}
|
||||
|
||||
// Initialize the render texture
|
||||
if (!m_impl->Create(width, height, m_texture.m_texture, depthBuffer))
|
||||
if (!m_impl->create(width, height, m_texture.m_texture, depthBuffer))
|
||||
return false;
|
||||
|
||||
// We can now initialize the render target part
|
||||
RenderTarget::Initialize();
|
||||
RenderTarget::initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTexture::SetSmooth(bool smooth)
|
||||
void RenderTexture::setSmooth(bool smooth)
|
||||
{
|
||||
m_texture.SetSmooth(smooth);
|
||||
m_texture.setSmooth(smooth);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTexture::IsSmooth() const
|
||||
bool RenderTexture::isSmooth() const
|
||||
{
|
||||
return m_texture.IsSmooth();
|
||||
return m_texture.isSmooth();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTexture::SetActive(bool active)
|
||||
bool RenderTexture::setActive(bool active)
|
||||
{
|
||||
return m_impl && m_impl->Activate(active);
|
||||
return m_impl && m_impl->activate(active);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTexture::Display()
|
||||
void RenderTexture::display()
|
||||
{
|
||||
// Update the target texture
|
||||
if (SetActive(true))
|
||||
if (setActive(true))
|
||||
{
|
||||
m_impl->UpdateTexture(m_texture.m_texture);
|
||||
m_impl->updateTexture(m_texture.m_texture);
|
||||
m_texture.m_pixelsFlipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u RenderTexture::GetSize() const
|
||||
Vector2u RenderTexture::getSize() const
|
||||
{
|
||||
return Vector2u(m_texture.GetWidth(), m_texture.GetHeight());
|
||||
return Vector2u(m_texture.getWidth(), m_texture.getHeight());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture& RenderTexture::GetTexture() const
|
||||
const Texture& RenderTexture::getTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTexture::Activate(bool active)
|
||||
bool RenderTexture::activate(bool active)
|
||||
{
|
||||
return SetActive(active);
|
||||
return setActive(active);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -60,7 +60,7 @@ public :
|
|||
/// \return True if creation has been successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer) = 0;
|
||||
virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the render texture for rendering
|
||||
|
@ -70,7 +70,7 @@ public :
|
|||
/// \return True on success, false on failure
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Activate(bool active) = 0;
|
||||
virtual bool activate(bool active) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the pixels of the target texture
|
||||
|
@ -78,7 +78,7 @@ public :
|
|||
/// \param textureId OpenGL identifier of the target texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void UpdateTexture(unsigned int textureId) = 0;
|
||||
virtual void updateTexture(unsigned int textureId) = 0;
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/RenderTextureImplDefault.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <SFML/Graphics/TextureSaver.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
@ -55,7 +55,7 @@ RenderTextureImplDefault::~RenderTextureImplDefault()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTextureImplDefault::Create(unsigned int width, unsigned int height, unsigned int, bool depthBuffer)
|
||||
bool RenderTextureImplDefault::create(unsigned int width, unsigned int height, unsigned int, bool depthBuffer)
|
||||
{
|
||||
// Store the dimensions
|
||||
m_width = width;
|
||||
|
@ -69,21 +69,21 @@ bool RenderTextureImplDefault::Create(unsigned int width, unsigned int height, u
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTextureImplDefault::Activate(bool active)
|
||||
bool RenderTextureImplDefault::activate(bool active)
|
||||
{
|
||||
return m_context->SetActive(active);
|
||||
return m_context->setActive(active);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTextureImplDefault::UpdateTexture(unsigned int textureId)
|
||||
void RenderTextureImplDefault::updateTexture(unsigned int textureId)
|
||||
{
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
// Copy the rendered pixels to the texture
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, textureId));
|
||||
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, textureId));
|
||||
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height));
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -71,7 +71,7 @@ private :
|
|||
/// \return True if creation has been successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer);
|
||||
virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the render texture for rendering
|
||||
|
@ -81,7 +81,7 @@ private :
|
|||
/// \return True on success, false on failure
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Activate(bool active);
|
||||
virtual bool activate(bool active);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the pixels of the target texture
|
||||
|
@ -89,7 +89,7 @@ private :
|
|||
/// \param textureId OpenGL identifier of the target texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void UpdateTexture(unsigned textureId);
|
||||
virtual void updateTexture(unsigned textureId);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/RenderTextureImplFBO.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
|
@ -47,20 +47,20 @@ m_depthBuffer(0)
|
|||
////////////////////////////////////////////////////////////
|
||||
RenderTextureImplFBO::~RenderTextureImplFBO()
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Destroy the depth buffer
|
||||
if (m_depthBuffer)
|
||||
{
|
||||
GLuint depthBuffer = static_cast<GLuint>(m_depthBuffer);
|
||||
GLCheck(glDeleteFramebuffersEXT(1, &depthBuffer));
|
||||
glCheck(glDeleteFramebuffersEXT(1, &depthBuffer));
|
||||
}
|
||||
|
||||
// Destroy the frame buffer
|
||||
if (m_frameBuffer)
|
||||
{
|
||||
GLuint frameBuffer = static_cast<GLuint>(m_frameBuffer);
|
||||
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
||||
glCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
||||
}
|
||||
|
||||
// Delete the context
|
||||
|
@ -69,58 +69,58 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTextureImplFBO::IsAvailable()
|
||||
bool RenderTextureImplFBO::isAvailable()
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::EnsureGlewInit();
|
||||
priv::ensureGlewInit();
|
||||
|
||||
return GLEW_EXT_framebuffer_object != 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTextureImplFBO::Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
|
||||
bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
|
||||
{
|
||||
// Create the context
|
||||
m_context = new Context;
|
||||
|
||||
// Create the framebuffer object
|
||||
GLuint frameBuffer = 0;
|
||||
GLCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
||||
glCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
||||
m_frameBuffer = static_cast<unsigned int>(frameBuffer);
|
||||
if (!m_frameBuffer)
|
||||
{
|
||||
Err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
|
||||
err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
|
||||
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
|
||||
|
||||
// Create the depth buffer if requested
|
||||
if (depthBuffer)
|
||||
{
|
||||
GLuint depth = 0;
|
||||
GLCheck(glGenRenderbuffersEXT(1, &depth));
|
||||
glCheck(glGenRenderbuffersEXT(1, &depth));
|
||||
m_depthBuffer = static_cast<unsigned int>(depth);
|
||||
if (!m_depthBuffer)
|
||||
{
|
||||
Err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
|
||||
err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
GLCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
|
||||
GLCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
|
||||
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
}
|
||||
|
||||
// Link the texture to the frame buffer
|
||||
GLCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
|
||||
glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
|
||||
|
||||
// A final check, just to be sure...
|
||||
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||
{
|
||||
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
|
||||
Err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
|
||||
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
|
||||
err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -129,13 +129,14 @@ bool RenderTextureImplFBO::Create(unsigned int width, unsigned int height, unsig
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderTextureImplFBO::Activate(bool active)
|
||||
bool RenderTextureImplFBO::activate(bool active)
|
||||
{
|
||||
return m_context->SetActive(active);
|
||||
return m_context->setActive(active);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTextureImplFBO::UpdateTexture(unsigned int)
|
||||
void RenderTextureImplFBO::updateTexture(unsigned int)
|
||||
{
|
||||
glFlush();
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public :
|
|||
/// \return True if FBO render textures are supported
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool IsAvailable();
|
||||
static bool isAvailable();
|
||||
|
||||
private :
|
||||
|
||||
|
@ -79,7 +79,7 @@ private :
|
|||
/// \return True if creation has been successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer);
|
||||
virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the render texture for rendering
|
||||
|
@ -89,7 +89,7 @@ private :
|
|||
/// \return True on success, false on failure
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool Activate(bool active);
|
||||
virtual bool activate(bool active);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the pixels of the target texture
|
||||
|
@ -97,7 +97,7 @@ private :
|
|||
/// \param textureId OpenGL identifier of the target texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void UpdateTexture(unsigned textureId);
|
||||
virtual void updateTexture(unsigned textureId);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -42,7 +42,7 @@ RenderWindow::RenderWindow()
|
|||
RenderWindow::RenderWindow(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings)
|
||||
{
|
||||
// Don't call the base class constructor because it contains virtual function calls
|
||||
Create(mode, title, style, settings);
|
||||
create(mode, title, style, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ RenderWindow::RenderWindow(VideoMode mode, const std::string& title, Uint32 styl
|
|||
RenderWindow::RenderWindow(WindowHandle handle, const ContextSettings& settings)
|
||||
{
|
||||
// Don't call the base class constructor because it contains virtual function calls
|
||||
Create(handle, settings);
|
||||
create(handle, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,37 +62,37 @@ RenderWindow::~RenderWindow()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderWindow::Activate(bool active)
|
||||
bool RenderWindow::activate(bool active)
|
||||
{
|
||||
return SetActive(active);
|
||||
return setActive(active);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u RenderWindow::GetSize() const
|
||||
Vector2u RenderWindow::getSize() const
|
||||
{
|
||||
return Window::GetSize();
|
||||
return Window::getSize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Image RenderWindow::Capture() const
|
||||
Image RenderWindow::capture() const
|
||||
{
|
||||
Image image;
|
||||
if (SetActive())
|
||||
if (setActive())
|
||||
{
|
||||
int width = static_cast<int>(GetSize().x);
|
||||
int height = static_cast<int>(GetSize().y);
|
||||
int width = static_cast<int>(getSize().x);
|
||||
int height = static_cast<int>(getSize().y);
|
||||
|
||||
// copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top)
|
||||
std::vector<Uint8> pixels(width * height * 4);
|
||||
for (int i = 0; i < height; ++i)
|
||||
{
|
||||
Uint8* ptr = &pixels[i * width * 4];
|
||||
GLCheck(glReadPixels(0, height - i - 1, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, ptr));
|
||||
glCheck(glReadPixels(0, height - i - 1, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, ptr));
|
||||
}
|
||||
|
||||
image.Create(width, height, &pixels[0]);
|
||||
image.create(width, height, &pixels[0]);
|
||||
}
|
||||
|
||||
return image;
|
||||
|
@ -100,18 +100,18 @@ Image RenderWindow::Capture() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderWindow::OnCreate()
|
||||
void RenderWindow::onCreate()
|
||||
{
|
||||
// Just initialize the render target part
|
||||
RenderTarget::Initialize();
|
||||
RenderTarget::initialize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderWindow::OnResize()
|
||||
void RenderWindow::onResize()
|
||||
{
|
||||
// Update the current view (recompute the viewport, which is stored in relative coordinates)
|
||||
SetView(GetView());
|
||||
setView(getView());
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <SFML/System/InputStream.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <fstream>
|
||||
|
@ -38,15 +38,15 @@
|
|||
namespace
|
||||
{
|
||||
// Retrieve the maximum number of texture units available
|
||||
GLint GetMaxTextureUnits()
|
||||
GLint getMaxTextureUnits()
|
||||
{
|
||||
GLint maxUnits;
|
||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &maxUnits));
|
||||
glCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &maxUnits));
|
||||
return maxUnits;
|
||||
}
|
||||
|
||||
// Read the contents of a file into an array of char
|
||||
bool GetFileContents(const std::string& filename, std::vector<char>& buffer)
|
||||
bool getFileContents(const std::string& filename, std::vector<char>& buffer)
|
||||
{
|
||||
std::ifstream file(filename.c_str(), std::ios_base::binary);
|
||||
if (file)
|
||||
|
@ -66,11 +66,11 @@ namespace
|
|||
}
|
||||
|
||||
// Read the contents of a stream into an array of char
|
||||
bool GetStreamContents(sf::InputStream& stream, std::vector<char>& buffer)
|
||||
bool getStreamContents(sf::InputStream& stream, std::vector<char>& buffer)
|
||||
{
|
||||
sf::Int64 size = stream.GetSize();
|
||||
sf::Int64 size = stream.getSize();
|
||||
buffer.resize(static_cast<std::size_t>(size));
|
||||
sf::Int64 read = stream.Read(&buffer[0], size);
|
||||
sf::Int64 read = stream.read(&buffer[0], size);
|
||||
buffer.push_back('\0');
|
||||
return read == size;
|
||||
}
|
||||
|
@ -94,272 +94,272 @@ m_currentTexture(-1)
|
|||
////////////////////////////////////////////////////////////
|
||||
Shader::~Shader()
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Destroy effect program
|
||||
if (m_shaderProgram)
|
||||
GLCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
glCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromFile(const std::string& filename, Type type)
|
||||
bool Shader::loadFromFile(const std::string& filename, Type type)
|
||||
{
|
||||
// Read the file
|
||||
std::vector<char> shader;
|
||||
if (!GetFileContents(filename, shader))
|
||||
if (!getFileContents(filename, shader))
|
||||
{
|
||||
Err() << "Failed to open shader file \"" << filename << "\"" << std::endl;
|
||||
err() << "Failed to open shader file \"" << filename << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile the shader program
|
||||
if (type == Vertex)
|
||||
return Compile(&shader[0], NULL);
|
||||
return compile(&shader[0], NULL);
|
||||
else
|
||||
return Compile(NULL, &shader[0]);
|
||||
return compile(NULL, &shader[0]);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename)
|
||||
bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename)
|
||||
{
|
||||
// Read the vertex shader file
|
||||
std::vector<char> vertexShader;
|
||||
if (!GetFileContents(vertexShaderFilename, vertexShader))
|
||||
if (!getFileContents(vertexShaderFilename, vertexShader))
|
||||
{
|
||||
Err() << "Failed to open vertex shader file \"" << vertexShaderFilename << "\"" << std::endl;
|
||||
err() << "Failed to open vertex shader file \"" << vertexShaderFilename << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the fragment shader file
|
||||
std::vector<char> fragmentShader;
|
||||
if (!GetFileContents(fragmentShaderFilename, fragmentShader))
|
||||
if (!getFileContents(fragmentShaderFilename, fragmentShader))
|
||||
{
|
||||
Err() << "Failed to open fragment shader file \"" << fragmentShaderFilename << "\"" << std::endl;
|
||||
err() << "Failed to open fragment shader file \"" << fragmentShaderFilename << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile the shader program
|
||||
return Compile(&vertexShader[0], &fragmentShader[0]);
|
||||
return compile(&vertexShader[0], &fragmentShader[0]);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromMemory(const std::string& shader, Type type)
|
||||
bool Shader::loadFromMemory(const std::string& shader, Type type)
|
||||
{
|
||||
// Compile the shader program
|
||||
if (type == Vertex)
|
||||
return Compile(shader.c_str(), NULL);
|
||||
return compile(shader.c_str(), NULL);
|
||||
else
|
||||
return Compile(NULL, shader.c_str());
|
||||
return compile(NULL, shader.c_str());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromMemory(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
bool Shader::loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
{
|
||||
// Compile the shader program
|
||||
return Compile(vertexShader.c_str(), fragmentShader.c_str());
|
||||
return compile(vertexShader.c_str(), fragmentShader.c_str());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromStream(InputStream& stream, Type type)
|
||||
bool Shader::loadFromStream(InputStream& stream, Type type)
|
||||
{
|
||||
// Read the shader code from the stream
|
||||
std::vector<char> shader;
|
||||
if (!GetStreamContents(stream, shader))
|
||||
if (!getStreamContents(stream, shader))
|
||||
{
|
||||
Err() << "Failed to read shader from stream" << std::endl;
|
||||
err() << "Failed to read shader from stream" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile the shader program
|
||||
if (type == Vertex)
|
||||
return Compile(&shader[0], NULL);
|
||||
return compile(&shader[0], NULL);
|
||||
else
|
||||
return Compile(NULL, &shader[0]);
|
||||
return compile(NULL, &shader[0]);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::LoadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream)
|
||||
bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream)
|
||||
{
|
||||
// Read the vertex shader code from the stream
|
||||
std::vector<char> vertexShader;
|
||||
if (!GetStreamContents(vertexShaderStream, vertexShader))
|
||||
if (!getStreamContents(vertexShaderStream, vertexShader))
|
||||
{
|
||||
Err() << "Failed to read vertex shader from stream" << std::endl;
|
||||
err() << "Failed to read vertex shader from stream" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the fragment shader code from the stream
|
||||
std::vector<char> fragmentShader;
|
||||
if (!GetStreamContents(fragmentShaderStream, fragmentShader))
|
||||
if (!getStreamContents(fragmentShaderStream, fragmentShader))
|
||||
{
|
||||
Err() << "Failed to read fragment shader from stream" << std::endl;
|
||||
err() << "Failed to read fragment shader from stream" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile the shader program
|
||||
return Compile(&vertexShader[0], &fragmentShader[0]);
|
||||
return compile(&vertexShader[0], &fragmentShader[0]);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, float x)
|
||||
void Shader::setParameter(const std::string& name, float x)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location != -1)
|
||||
GLCheck(glUniform1fARB(location, x));
|
||||
glCheck(glUniform1fARB(location, x));
|
||||
else
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, float x, float y)
|
||||
void Shader::setParameter(const std::string& name, float x, float y)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location != -1)
|
||||
GLCheck(glUniform2fARB(location, x, y));
|
||||
glCheck(glUniform2fARB(location, x, y));
|
||||
else
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, float x, float y, float z)
|
||||
void Shader::setParameter(const std::string& name, float x, float y, float z)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location != -1)
|
||||
GLCheck(glUniform3fARB(location, x, y, z));
|
||||
glCheck(glUniform3fARB(location, x, y, z));
|
||||
else
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, float x, float y, float z, float w)
|
||||
void Shader::setParameter(const std::string& name, float x, float y, float z, float w)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location != -1)
|
||||
GLCheck(glUniform4fARB(location, x, y, z, w));
|
||||
glCheck(glUniform4fARB(location, x, y, z, w));
|
||||
else
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, const Vector2f& v)
|
||||
void Shader::setParameter(const std::string& name, const Vector2f& v)
|
||||
{
|
||||
SetParameter(name, v.x, v.y);
|
||||
setParameter(name, v.x, v.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, const Vector3f& v)
|
||||
void Shader::setParameter(const std::string& name, const Vector3f& v)
|
||||
{
|
||||
SetParameter(name, v.x, v.y, v.z);
|
||||
setParameter(name, v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, const Color& color)
|
||||
void Shader::setParameter(const std::string& name, const Color& color)
|
||||
{
|
||||
SetParameter(name, color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f);
|
||||
setParameter(name, color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, const sf::Transform& transform)
|
||||
void Shader::setParameter(const std::string& name, const sf::Transform& transform)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location != -1)
|
||||
GLCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.GetMatrix()));
|
||||
glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));
|
||||
else
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, const Texture& texture)
|
||||
void Shader::setParameter(const std::string& name, const Texture& texture)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Find the location of the variable in the shader
|
||||
int location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (location == -1)
|
||||
{
|
||||
Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -368,10 +368,10 @@ void Shader::SetParameter(const std::string& name, const Texture& texture)
|
|||
if (it == m_textures.end())
|
||||
{
|
||||
// New entry, make sure there are enough texture units
|
||||
static const GLint maxUnits = GetMaxTextureUnits();
|
||||
static const GLint maxUnits = getMaxTextureUnits();
|
||||
if (m_textures.size() + 1 >= static_cast<std::size_t>(maxUnits))
|
||||
{
|
||||
Err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
||||
err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -387,56 +387,56 @@ void Shader::SetParameter(const std::string& name, const Texture& texture)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::SetParameter(const std::string& name, CurrentTextureType)
|
||||
void Shader::setParameter(const std::string& name, CurrentTextureType)
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Find the location of the variable in the shader
|
||||
m_currentTexture = glGetUniformLocationARB(m_shaderProgram, name.c_str());
|
||||
if (m_currentTexture == -1)
|
||||
Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
err() << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::Bind() const
|
||||
void Shader::bind() const
|
||||
{
|
||||
if (m_shaderProgram)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Enable the program
|
||||
GLCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Bind the textures
|
||||
BindTextures();
|
||||
bindTextures();
|
||||
|
||||
// Bind the current texture
|
||||
if (m_currentTexture != -1)
|
||||
GLCheck(glUniform1iARB(m_currentTexture, 0));
|
||||
glCheck(glUniform1iARB(m_currentTexture, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::Unbind() const
|
||||
void Shader::unbind() const
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
GLCheck(glUseProgramObjectARB(0));
|
||||
glCheck(glUseProgramObjectARB(0));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::IsAvailable()
|
||||
bool Shader::isAvailable()
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::EnsureGlewInit();
|
||||
priv::ensureGlewInit();
|
||||
|
||||
return GLEW_ARB_shading_language_100 &&
|
||||
GLEW_ARB_shader_objects &&
|
||||
|
@ -446,21 +446,21 @@ bool Shader::IsAvailable()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCode)
|
||||
bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCode)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// First make sure that we can use shaders
|
||||
if (!IsAvailable())
|
||||
if (!isAvailable())
|
||||
{
|
||||
Err() << "Failed to create a shader: your system doesn't support shaders "
|
||||
err() << "Failed to create a shader: your system doesn't support shaders "
|
||||
<< "(you should test Shader::IsAvailable() before trying to use the Shader class)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Destroy the shader if it was already created
|
||||
if (m_shaderProgram)
|
||||
GLCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
glCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
|
||||
// Create the program
|
||||
m_shaderProgram = glCreateProgramObjectARB();
|
||||
|
@ -470,27 +470,27 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
|||
{
|
||||
// Create and compile the shader
|
||||
GLhandleARB vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
|
||||
GLCheck(glShaderSourceARB(vertexShader, 1, &vertexShaderCode, NULL));
|
||||
GLCheck(glCompileShaderARB(vertexShader));
|
||||
glCheck(glShaderSourceARB(vertexShader, 1, &vertexShaderCode, NULL));
|
||||
glCheck(glCompileShaderARB(vertexShader));
|
||||
|
||||
// Check the compile log
|
||||
GLint success;
|
||||
GLCheck(glGetObjectParameterivARB(vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &success));
|
||||
glCheck(glGetObjectParameterivARB(vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &success));
|
||||
if (success == GL_FALSE)
|
||||
{
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(vertexShader, sizeof(log), 0, log));
|
||||
Err() << "Failed to compile vertex shader:" << std::endl
|
||||
glCheck(glGetInfoLogARB(vertexShader, sizeof(log), 0, log));
|
||||
err() << "Failed to compile vertex shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(vertexShader));
|
||||
GLCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
glCheck(glDeleteObjectARB(vertexShader));
|
||||
glCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
m_shaderProgram = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attach the shader to the program, and delete it (not needed anymore)
|
||||
GLCheck(glAttachObjectARB(m_shaderProgram, vertexShader));
|
||||
GLCheck(glDeleteObjectARB(vertexShader));
|
||||
glCheck(glAttachObjectARB(m_shaderProgram, vertexShader));
|
||||
glCheck(glDeleteObjectARB(vertexShader));
|
||||
}
|
||||
|
||||
// Create the fragment shader if needed
|
||||
|
@ -498,42 +498,42 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
|||
{
|
||||
// Create and compile the shader
|
||||
GLhandleARB fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
||||
GLCheck(glShaderSourceARB(fragmentShader, 1, &fragmentShaderCode, NULL));
|
||||
GLCheck(glCompileShaderARB(fragmentShader));
|
||||
glCheck(glShaderSourceARB(fragmentShader, 1, &fragmentShaderCode, NULL));
|
||||
glCheck(glCompileShaderARB(fragmentShader));
|
||||
|
||||
// Check the compile log
|
||||
GLint success;
|
||||
GLCheck(glGetObjectParameterivARB(fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &success));
|
||||
glCheck(glGetObjectParameterivARB(fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &success));
|
||||
if (success == GL_FALSE)
|
||||
{
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(fragmentShader, sizeof(log), 0, log));
|
||||
Err() << "Failed to compile fragment shader:" << std::endl
|
||||
glCheck(glGetInfoLogARB(fragmentShader, sizeof(log), 0, log));
|
||||
err() << "Failed to compile fragment shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(fragmentShader));
|
||||
GLCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
glCheck(glDeleteObjectARB(fragmentShader));
|
||||
glCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
m_shaderProgram = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attach the shader to the program, and delete it (not needed anymore)
|
||||
GLCheck(glAttachObjectARB(m_shaderProgram, fragmentShader));
|
||||
GLCheck(glDeleteObjectARB(fragmentShader));
|
||||
glCheck(glAttachObjectARB(m_shaderProgram, fragmentShader));
|
||||
glCheck(glDeleteObjectARB(fragmentShader));
|
||||
}
|
||||
|
||||
// Link the program
|
||||
GLCheck(glLinkProgramARB(m_shaderProgram));
|
||||
glCheck(glLinkProgramARB(m_shaderProgram));
|
||||
|
||||
// Check the link log
|
||||
GLint success;
|
||||
GLCheck(glGetObjectParameterivARB(m_shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &success));
|
||||
glCheck(glGetObjectParameterivARB(m_shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &success));
|
||||
if (success == GL_FALSE)
|
||||
{
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(m_shaderProgram, sizeof(log), 0, log));
|
||||
Err() << "Failed to link shader:" << std::endl
|
||||
glCheck(glGetInfoLogARB(m_shaderProgram, sizeof(log), 0, log));
|
||||
err() << "Failed to link shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
glCheck(glDeleteObjectARB(m_shaderProgram));
|
||||
m_shaderProgram = 0;
|
||||
return false;
|
||||
}
|
||||
|
@ -543,20 +543,20 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::BindTextures() const
|
||||
void Shader::bindTextures() const
|
||||
{
|
||||
TextureTable::const_iterator it = m_textures.begin();
|
||||
for (std::size_t i = 0; i < m_textures.size(); ++i)
|
||||
{
|
||||
GLint index = static_cast<GLsizei>(i + 1);
|
||||
GLCheck(glUniform1iARB(it->first, index));
|
||||
GLCheck(glActiveTextureARB(GL_TEXTURE0_ARB + index));
|
||||
it->second->Bind();
|
||||
glCheck(glUniform1iARB(it->first, index));
|
||||
glCheck(glActiveTextureARB(GL_TEXTURE0_ARB + index));
|
||||
it->second->bind();
|
||||
++it;
|
||||
}
|
||||
|
||||
// Make sure that the texture unit which is left active is the number 0
|
||||
GLCheck(glActiveTextureARB(GL_TEXTURE0_ARB));
|
||||
glCheck(glActiveTextureARB(GL_TEXTURE0_ARB));
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
namespace
|
||||
{
|
||||
// Compute the normal of a segment
|
||||
sf::Vector2f ComputeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2)
|
||||
sf::Vector2f computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2)
|
||||
{
|
||||
sf::Vector2f normal(p1.y - p2.y, p2.x - p1.x);
|
||||
float length = std::sqrt(normal.x * normal.x + normal.y * normal.y);
|
||||
|
@ -55,11 +55,11 @@ Shape::~Shape()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::SetTexture(const Texture* texture, bool resetRect)
|
||||
void Shape::setTexture(const Texture* texture, bool resetRect)
|
||||
{
|
||||
// Recompute the texture area if requested, or if there was no texture before
|
||||
if (texture && (resetRect || !m_texture))
|
||||
SetTextureRect(IntRect(0, 0, texture->GetWidth(), texture->GetHeight()));
|
||||
setTextureRect(IntRect(0, 0, texture->getWidth(), texture->getHeight()));
|
||||
|
||||
// Assign the new texture
|
||||
m_texture = texture;
|
||||
|
@ -67,83 +67,83 @@ void Shape::SetTexture(const Texture* texture, bool resetRect)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* Shape::GetTexture() const
|
||||
const Texture* Shape::getTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::SetTextureRect(const IntRect& rect)
|
||||
void Shape::setTextureRect(const IntRect& rect)
|
||||
{
|
||||
m_textureRect = rect;
|
||||
UpdateTexCoords();
|
||||
updateTexCoords();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const IntRect& Shape::GetTextureRect() const
|
||||
const IntRect& Shape::getTextureRect() const
|
||||
{
|
||||
return m_textureRect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::SetFillColor(const Color& color)
|
||||
void Shape::setFillColor(const Color& color)
|
||||
{
|
||||
m_fillColor = color;
|
||||
UpdateFillColors();
|
||||
updateFillColors();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& Shape::GetFillColor() const
|
||||
const Color& Shape::getFillColor() const
|
||||
{
|
||||
return m_fillColor;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::SetOutlineColor(const Color& color)
|
||||
void Shape::setOutlineColor(const Color& color)
|
||||
{
|
||||
m_outlineColor = color;
|
||||
UpdateOutlineColors();
|
||||
updateOutlineColors();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& Shape::GetOutlineColor() const
|
||||
const Color& Shape::getOutlineColor() const
|
||||
{
|
||||
return m_outlineColor;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::SetOutlineThickness(float thickness)
|
||||
void Shape::setOutlineThickness(float thickness)
|
||||
{
|
||||
m_outlineThickness = thickness;
|
||||
Update(); // recompute everything because the whole shape must be offset
|
||||
update(); // recompute everything because the whole shape must be offset
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Shape::GetOutlineThickness() const
|
||||
float Shape::getOutlineThickness() const
|
||||
{
|
||||
return m_outlineThickness;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Shape::GetLocalBounds() const
|
||||
FloatRect Shape::getLocalBounds() const
|
||||
{
|
||||
return m_bounds;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Shape::GetGlobalBounds() const
|
||||
FloatRect Shape::getGlobalBounds() const
|
||||
{
|
||||
return GetTransform().TransformRect(GetLocalBounds());
|
||||
return getTransform().transformRect(getLocalBounds());
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,130 +163,130 @@ m_bounds ()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::Update()
|
||||
void Shape::update()
|
||||
{
|
||||
// Get the total number of points of the shape
|
||||
unsigned int count = GetPointCount();
|
||||
unsigned int count = getPointCount();
|
||||
if (count < 3)
|
||||
{
|
||||
m_vertices.Resize(0);
|
||||
m_outlineVertices.Resize(0);
|
||||
m_vertices.resize(0);
|
||||
m_outlineVertices.resize(0);
|
||||
return;
|
||||
}
|
||||
|
||||
m_vertices.Resize(count + 2); // + 2 for center and repeated first point
|
||||
m_vertices.resize(count + 2); // + 2 for center and repeated first point
|
||||
|
||||
// Position
|
||||
for (unsigned int i = 0; i < count; ++i)
|
||||
m_vertices[i + 1].Position = GetPoint(i);
|
||||
m_vertices[count + 1].Position = m_vertices[1].Position;
|
||||
m_vertices[i + 1].position = getPoint(i);
|
||||
m_vertices[count + 1].position = m_vertices[1].position;
|
||||
|
||||
// Update the bounding rectangle
|
||||
m_vertices[0] = m_vertices[1]; // so that the result of GetBounds() is correct
|
||||
m_insideBounds = m_vertices.GetBounds();
|
||||
m_vertices[0] = m_vertices[1]; // so that the result of getBounds() is correct
|
||||
m_insideBounds = m_vertices.getBounds();
|
||||
|
||||
// Compute the center and make it the first vertex
|
||||
m_vertices[0].Position.x = m_insideBounds.Left + m_insideBounds.Width / 2;
|
||||
m_vertices[0].Position.y = m_insideBounds.Top + m_insideBounds.Height / 2;
|
||||
m_vertices[0].position.x = m_insideBounds.left + m_insideBounds.width / 2;
|
||||
m_vertices[0].position.y = m_insideBounds.top + m_insideBounds.height / 2;
|
||||
|
||||
// Color
|
||||
UpdateFillColors();
|
||||
updateFillColors();
|
||||
|
||||
// Texture coordinates
|
||||
UpdateTexCoords();
|
||||
updateTexCoords();
|
||||
|
||||
// Outline
|
||||
UpdateOutline();
|
||||
updateOutline();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::Draw(RenderTarget& target, RenderStates states) const
|
||||
void Shape::draw(RenderTarget& target, RenderStates states) const
|
||||
{
|
||||
states.Transform *= GetTransform();
|
||||
states.transform *= getTransform();
|
||||
|
||||
// Render the inside
|
||||
if (m_fillColor.a > 0)
|
||||
{
|
||||
states.Texture = m_texture;
|
||||
target.Draw(m_vertices, states);
|
||||
states.texture = m_texture;
|
||||
target.draw(m_vertices, states);
|
||||
}
|
||||
|
||||
// Render the outline
|
||||
if ((m_outlineColor.a > 0) && (m_outlineThickness > 0))
|
||||
{
|
||||
states.Texture = NULL;
|
||||
target.Draw(m_outlineVertices, states);
|
||||
states.texture = NULL;
|
||||
target.draw(m_outlineVertices, states);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::UpdateFillColors()
|
||||
void Shape::updateFillColors()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
|
||||
m_vertices[i].Color = m_fillColor;
|
||||
for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i)
|
||||
m_vertices[i].color = m_fillColor;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::UpdateTexCoords()
|
||||
void Shape::updateTexCoords()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
|
||||
for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i)
|
||||
{
|
||||
float xratio = (m_vertices[i].Position.x - m_insideBounds.Left) / m_insideBounds.Width;
|
||||
float yratio = (m_vertices[i].Position.y - m_insideBounds.Top) / m_insideBounds.Height;
|
||||
m_vertices[i].TexCoords.x = m_textureRect.Left + m_textureRect.Width * xratio;
|
||||
m_vertices[i].TexCoords.y = m_textureRect.Top + m_textureRect.Height * yratio;
|
||||
float xratio = (m_vertices[i].position.x - m_insideBounds.left) / m_insideBounds.width;
|
||||
float yratio = (m_vertices[i].position.y - m_insideBounds.top) / m_insideBounds.height;
|
||||
m_vertices[i].texCoords.x = m_textureRect.left + m_textureRect.width * xratio;
|
||||
m_vertices[i].texCoords.y = m_textureRect.top + m_textureRect.height * yratio;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::UpdateOutline()
|
||||
void Shape::updateOutline()
|
||||
{
|
||||
unsigned int count = m_vertices.GetVertexCount() - 2;
|
||||
m_outlineVertices.Resize((count + 1) * 2);
|
||||
unsigned int count = m_vertices.getVertexCount() - 2;
|
||||
m_outlineVertices.resize((count + 1) * 2);
|
||||
|
||||
for (unsigned int i = 0; i < count; ++i)
|
||||
{
|
||||
unsigned int index = i + 1;
|
||||
|
||||
// Get the two segments shared by the current point
|
||||
Vector2f p0 = (i == 0) ? m_vertices[count].Position : m_vertices[index - 1].Position;
|
||||
Vector2f p1 = m_vertices[index].Position;
|
||||
Vector2f p2 = m_vertices[index + 1].Position;
|
||||
Vector2f p0 = (i == 0) ? m_vertices[count].position : m_vertices[index - 1].position;
|
||||
Vector2f p1 = m_vertices[index].position;
|
||||
Vector2f p2 = m_vertices[index + 1].position;
|
||||
|
||||
// Compute their normal
|
||||
Vector2f n1 = ComputeNormal(p0, p1);
|
||||
Vector2f n2 = ComputeNormal(p1, p2);
|
||||
Vector2f n1 = computeNormal(p0, p1);
|
||||
Vector2f n2 = computeNormal(p1, p2);
|
||||
|
||||
// Combine them to get the extrusion direction
|
||||
float factor = 1.f + (n1.x * n2.x + n1.y * n2.y);
|
||||
Vector2f normal = -(n1 + n2) / factor;
|
||||
|
||||
// Update the outline points
|
||||
m_outlineVertices[i * 2 + 0].Position = p1;
|
||||
m_outlineVertices[i * 2 + 1].Position = p1 + normal * m_outlineThickness;
|
||||
m_outlineVertices[i * 2 + 0].position = p1;
|
||||
m_outlineVertices[i * 2 + 1].position = p1 + normal * m_outlineThickness;
|
||||
}
|
||||
|
||||
// Duplicate the first point at the end, to close the outline
|
||||
m_outlineVertices[count * 2 + 0].Position = m_outlineVertices[0].Position;
|
||||
m_outlineVertices[count * 2 + 1].Position = m_outlineVertices[1].Position;
|
||||
m_outlineVertices[count * 2 + 0].position = m_outlineVertices[0].position;
|
||||
m_outlineVertices[count * 2 + 1].position = m_outlineVertices[1].position;
|
||||
|
||||
// Update outline colors
|
||||
UpdateOutlineColors();
|
||||
updateOutlineColors();
|
||||
|
||||
// Update the shape's bounds
|
||||
m_bounds = m_outlineVertices.GetBounds();
|
||||
m_bounds = m_outlineVertices.getBounds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shape::UpdateOutlineColors()
|
||||
void Shape::updateOutlineColors()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_outlineVertices.GetVertexCount(); ++i)
|
||||
m_outlineVertices[i].Color = m_outlineColor;
|
||||
for (unsigned int i = 0; i < m_outlineVertices.getVertexCount(); ++i)
|
||||
m_outlineVertices[i].color = m_outlineColor;
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -45,7 +45,7 @@ Sprite::Sprite(const Texture& texture) :
|
|||
m_texture (NULL),
|
||||
m_textureRect(0, 0, 0, 0)
|
||||
{
|
||||
SetTexture(texture);
|
||||
setTexture(texture);
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,17 +54,17 @@ Sprite::Sprite(const Texture& texture, const IntRect& rectangle) :
|
|||
m_texture (NULL),
|
||||
m_textureRect(0, 0, 0, 0)
|
||||
{
|
||||
SetTexture(texture);
|
||||
SetTextureRect(rectangle);
|
||||
setTexture(texture);
|
||||
setTextureRect(rectangle);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::SetTexture(const Texture& texture, bool resetRect)
|
||||
void Sprite::setTexture(const Texture& texture, bool resetRect)
|
||||
{
|
||||
// Recompute the texture area if requested, or if there was no valid texture before
|
||||
if (resetRect || !m_texture)
|
||||
SetTextureRect(IntRect(0, 0, texture.GetWidth(), texture.GetHeight()));
|
||||
setTextureRect(IntRect(0, 0, texture.getWidth(), texture.getHeight()));
|
||||
|
||||
// Assign the new texture
|
||||
m_texture = &texture;
|
||||
|
@ -72,103 +72,103 @@ void Sprite::SetTexture(const Texture& texture, bool resetRect)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::SetTextureRect(const IntRect& rectangle)
|
||||
void Sprite::setTextureRect(const IntRect& rectangle)
|
||||
{
|
||||
if (rectangle != m_textureRect)
|
||||
{
|
||||
m_textureRect = rectangle;
|
||||
UpdatePositions();
|
||||
UpdateTexCoords();
|
||||
updatePositions();
|
||||
updateTexCoords();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::SetColor(const Color& color)
|
||||
void Sprite::setColor(const Color& color)
|
||||
{
|
||||
// Update the vertices' color
|
||||
m_vertices[0].Color = color;
|
||||
m_vertices[1].Color = color;
|
||||
m_vertices[2].Color = color;
|
||||
m_vertices[3].Color = color;
|
||||
m_vertices[0].color = color;
|
||||
m_vertices[1].color = color;
|
||||
m_vertices[2].color = color;
|
||||
m_vertices[3].color = color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* Sprite::GetTexture() const
|
||||
const Texture* Sprite::getTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const IntRect& Sprite::GetTextureRect() const
|
||||
const IntRect& Sprite::getTextureRect() const
|
||||
{
|
||||
return m_textureRect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& Sprite::GetColor() const
|
||||
const Color& Sprite::getColor() const
|
||||
{
|
||||
return m_vertices[0].Color;
|
||||
return m_vertices[0].color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Sprite::GetLocalBounds() const
|
||||
FloatRect Sprite::getLocalBounds() const
|
||||
{
|
||||
float width = static_cast<float>(m_textureRect.Width);
|
||||
float height = static_cast<float>(m_textureRect.Height);
|
||||
float width = static_cast<float>(m_textureRect.width);
|
||||
float height = static_cast<float>(m_textureRect.height);
|
||||
|
||||
return FloatRect(0.f, 0.f, width, height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Sprite::GetGlobalBounds() const
|
||||
FloatRect Sprite::getGlobalBounds() const
|
||||
{
|
||||
return GetTransform().TransformRect(GetLocalBounds());
|
||||
return getTransform().transformRect(getLocalBounds());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::Draw(RenderTarget& target, RenderStates states) const
|
||||
void Sprite::draw(RenderTarget& target, RenderStates states) const
|
||||
{
|
||||
if (m_texture)
|
||||
{
|
||||
states.Transform *= GetTransform();
|
||||
states.Texture = m_texture;
|
||||
target.Draw(m_vertices, 4, Quads, states);
|
||||
states.transform *= getTransform();
|
||||
states.texture = m_texture;
|
||||
target.draw(m_vertices, 4, Quads, states);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::UpdatePositions()
|
||||
void Sprite::updatePositions()
|
||||
{
|
||||
float width = static_cast<float>(m_textureRect.Width);
|
||||
float height = static_cast<float>(m_textureRect.Height);
|
||||
float width = static_cast<float>(m_textureRect.width);
|
||||
float height = static_cast<float>(m_textureRect.height);
|
||||
|
||||
m_vertices[0].Position = Vector2f(0, 0);
|
||||
m_vertices[1].Position = Vector2f(0, height);
|
||||
m_vertices[2].Position = Vector2f(width, height);
|
||||
m_vertices[3].Position = Vector2f(width, 0);
|
||||
m_vertices[0].position = Vector2f(0, 0);
|
||||
m_vertices[1].position = Vector2f(0, height);
|
||||
m_vertices[2].position = Vector2f(width, height);
|
||||
m_vertices[3].position = Vector2f(width, 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::UpdateTexCoords()
|
||||
void Sprite::updateTexCoords()
|
||||
{
|
||||
float left = static_cast<float>(m_textureRect.Left);
|
||||
float right = left + m_textureRect.Width;
|
||||
float top = static_cast<float>(m_textureRect.Top);
|
||||
float bottom = top + m_textureRect.Height;
|
||||
float left = static_cast<float>(m_textureRect.left);
|
||||
float right = left + m_textureRect.width;
|
||||
float top = static_cast<float>(m_textureRect.top);
|
||||
float bottom = top + m_textureRect.height;
|
||||
|
||||
m_vertices[0].TexCoords = Vector2f(left, top);
|
||||
m_vertices[1].TexCoords = Vector2f(left, bottom);
|
||||
m_vertices[2].TexCoords = Vector2f(right, bottom);
|
||||
m_vertices[3].TexCoords = Vector2f(right, top);
|
||||
m_vertices[0].texCoords = Vector2f(left, top);
|
||||
m_vertices[1].texCoords = Vector2f(left, bottom);
|
||||
m_vertices[2].texCoords = Vector2f(right, bottom);
|
||||
m_vertices[3].texCoords = Vector2f(right, top);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Text::Text() :
|
||||
m_string (),
|
||||
m_font (&Font::GetDefaultFont()),
|
||||
m_font (&Font::getDefaultFont()),
|
||||
m_characterSize(30),
|
||||
m_style (Regular),
|
||||
m_color (255, 255, 255),
|
||||
|
@ -57,112 +57,112 @@ m_color (255, 255, 255),
|
|||
m_vertices (Quads),
|
||||
m_bounds ()
|
||||
{
|
||||
UpdateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetString(const String& string)
|
||||
void Text::setString(const String& string)
|
||||
{
|
||||
m_string = string;
|
||||
UpdateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetFont(const Font& font)
|
||||
void Text::setFont(const Font& font)
|
||||
{
|
||||
if (m_font != &font)
|
||||
{
|
||||
m_font = &font;
|
||||
UpdateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetCharacterSize(unsigned int size)
|
||||
void Text::setCharacterSize(unsigned int size)
|
||||
{
|
||||
if (m_characterSize != size)
|
||||
{
|
||||
m_characterSize = size;
|
||||
UpdateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetStyle(Uint32 style)
|
||||
void Text::setStyle(Uint32 style)
|
||||
{
|
||||
if (m_style != style)
|
||||
{
|
||||
m_style = style;
|
||||
UpdateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetColor(const Color& color)
|
||||
void Text::setColor(const Color& color)
|
||||
{
|
||||
if (color != m_color)
|
||||
{
|
||||
m_color = color;
|
||||
for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
|
||||
m_vertices[i].Color = m_color;
|
||||
for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i)
|
||||
m_vertices[i].color = m_color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const String& Text::GetString() const
|
||||
const String& Text::getString() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Font& Text::GetFont() const
|
||||
const Font& Text::getFont() const
|
||||
{
|
||||
assert(m_font != NULL); // can never be NULL, always &Font::GetDefaultFont() by default
|
||||
assert(m_font != NULL); // can never be NULL, always &Font::getDefaultFont() by default
|
||||
return *m_font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Text::GetCharacterSize() const
|
||||
unsigned int Text::getCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 Text::GetStyle() const
|
||||
Uint32 Text::getStyle() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& Text::GetColor() const
|
||||
const Color& Text::getColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f Text::FindCharacterPos(std::size_t index) const
|
||||
Vector2f Text::findCharacterPos(std::size_t index) const
|
||||
{
|
||||
assert(m_font != NULL);
|
||||
|
||||
// Adjust the index if it's out of range
|
||||
if (index > m_string.GetSize())
|
||||
index = m_string.GetSize();
|
||||
if (index > m_string.getSize())
|
||||
index = m_string.getSize();
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
bool bold = (m_style & Bold) != 0;
|
||||
float hspace = static_cast<float>(m_font->GetGlyph(L' ', m_characterSize, bold).Advance);
|
||||
float vspace = static_cast<float>(m_font->GetLineSpacing(m_characterSize));
|
||||
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
|
||||
float vspace = static_cast<float>(m_font->getLineSpacing(m_characterSize));
|
||||
|
||||
// Compute the position
|
||||
Vector2f position;
|
||||
|
@ -172,7 +172,7 @@ Vector2f Text::FindCharacterPos(std::size_t index) const
|
|||
Uint32 curChar = m_string[i];
|
||||
|
||||
// Apply the kerning offset
|
||||
position.x += static_cast<float>(m_font->GetKerning(prevChar, curChar, m_characterSize));
|
||||
position.x += static_cast<float>(m_font->getKerning(prevChar, curChar, m_characterSize));
|
||||
prevChar = curChar;
|
||||
|
||||
// Handle special characters
|
||||
|
@ -185,52 +185,52 @@ Vector2f Text::FindCharacterPos(std::size_t index) const
|
|||
}
|
||||
|
||||
// For regular characters, add the advance offset of the glyph
|
||||
position.x += static_cast<float>(m_font->GetGlyph(curChar, m_characterSize, bold).Advance);
|
||||
position.x += static_cast<float>(m_font->getGlyph(curChar, m_characterSize, bold).advance);
|
||||
}
|
||||
|
||||
// Transform the position to global coordinates
|
||||
position = GetTransform().TransformPoint(position);
|
||||
position = getTransform().transformPoint(position);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Text::GetLocalBounds() const
|
||||
FloatRect Text::getLocalBounds() const
|
||||
{
|
||||
return m_bounds;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Text::GetGlobalBounds() const
|
||||
FloatRect Text::getGlobalBounds() const
|
||||
{
|
||||
return GetTransform().TransformRect(GetLocalBounds());
|
||||
return getTransform().transformRect(getLocalBounds());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::Draw(RenderTarget& target, RenderStates states) const
|
||||
void Text::draw(RenderTarget& target, RenderStates states) const
|
||||
{
|
||||
assert(m_font != NULL);
|
||||
|
||||
states.Transform *= GetTransform();
|
||||
states.BlendMode = BlendAlpha; // alpha blending is mandatory for proper text rendering
|
||||
states.Texture = &m_font->GetTexture(m_characterSize);
|
||||
target.Draw(m_vertices, states);
|
||||
states.transform *= getTransform();
|
||||
states.blendMode = BlendAlpha; // alpha blending is mandatory for proper text rendering
|
||||
states.texture = &m_font->getTexture(m_characterSize);
|
||||
target.draw(m_vertices, states);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::UpdateGeometry()
|
||||
void Text::updateGeometry()
|
||||
{
|
||||
assert(m_font != NULL);
|
||||
|
||||
// Clear the previous geometry
|
||||
m_vertices.Clear();
|
||||
m_vertices.clear();
|
||||
|
||||
// No text: nothing to draw
|
||||
if (m_string.IsEmpty())
|
||||
if (m_string.isEmpty())
|
||||
return;
|
||||
|
||||
// Compute values related to the text style
|
||||
|
@ -241,19 +241,19 @@ void Text::UpdateGeometry()
|
|||
float underlineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
float hspace = static_cast<float>(m_font->GetGlyph(L' ', m_characterSize, bold).Advance);
|
||||
float vspace = static_cast<float>(m_font->GetLineSpacing(m_characterSize));
|
||||
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
|
||||
float vspace = static_cast<float>(m_font->getLineSpacing(m_characterSize));
|
||||
float x = 0.f;
|
||||
float y = static_cast<float>(m_characterSize);
|
||||
|
||||
// Create one quad for each character
|
||||
Uint32 prevChar = 0;
|
||||
for (std::size_t i = 0; i < m_string.GetSize(); ++i)
|
||||
for (std::size_t i = 0; i < m_string.getSize(); ++i)
|
||||
{
|
||||
Uint32 curChar = m_string[i];
|
||||
|
||||
// Apply the kerning offset
|
||||
x += static_cast<float>(m_font->GetKerning(prevChar, curChar, m_characterSize));
|
||||
x += static_cast<float>(m_font->getKerning(prevChar, curChar, m_characterSize));
|
||||
prevChar = curChar;
|
||||
|
||||
// If we're using the underlined style and there's a new line, draw a line
|
||||
|
@ -262,10 +262,10 @@ void Text::UpdateGeometry()
|
|||
float top = y + underlineOffset;
|
||||
float bottom = top + underlineThickness;
|
||||
|
||||
m_vertices.Append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Handle special characters
|
||||
|
@ -278,26 +278,26 @@ void Text::UpdateGeometry()
|
|||
}
|
||||
|
||||
// Extract the current glyph's description
|
||||
const Glyph& glyph = m_font->GetGlyph(curChar, m_characterSize, bold);
|
||||
const Glyph& glyph = m_font->getGlyph(curChar, m_characterSize, bold);
|
||||
|
||||
int left = glyph.Bounds.Left;
|
||||
int top = glyph.Bounds.Top;
|
||||
int right = glyph.Bounds.Left + glyph.Bounds.Width;
|
||||
int bottom = glyph.Bounds.Top + glyph.Bounds.Height;
|
||||
int left = glyph.bounds.left;
|
||||
int top = glyph.bounds.top;
|
||||
int right = glyph.bounds.left + glyph.bounds.width;
|
||||
int bottom = glyph.bounds.top + glyph.bounds.height;
|
||||
|
||||
float u1 = static_cast<float>(glyph.TextureRect.Left);
|
||||
float v1 = static_cast<float>(glyph.TextureRect.Top);
|
||||
float u2 = static_cast<float>(glyph.TextureRect.Left + glyph.TextureRect.Width);
|
||||
float v2 = static_cast<float>(glyph.TextureRect.Top + glyph.TextureRect.Height);
|
||||
float u1 = static_cast<float>(glyph.textureRect.left);
|
||||
float v1 = static_cast<float>(glyph.textureRect.top);
|
||||
float u2 = static_cast<float>(glyph.textureRect.left + glyph.textureRect.width);
|
||||
float v2 = static_cast<float>(glyph.textureRect.top + glyph.textureRect.height);
|
||||
|
||||
// Add a quad for the current character
|
||||
m_vertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), m_color, Vector2f(u1, v1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), m_color, Vector2f(u2, v2)));
|
||||
m_vertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), m_color, Vector2f(u1, v2)));
|
||||
m_vertices.append(Vertex(Vector2f(x + left - italic * top, y + top), m_color, Vector2f(u1, v1)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), m_color, Vector2f(u2, v2)));
|
||||
m_vertices.append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), m_color, Vector2f(u1, v2)));
|
||||
|
||||
// Advance to the next character
|
||||
x += glyph.Advance;
|
||||
x += glyph.advance;
|
||||
}
|
||||
|
||||
// If we're using the underlined style, add the last line
|
||||
|
@ -306,14 +306,14 @@ void Text::UpdateGeometry()
|
|||
float top = y + underlineOffset;
|
||||
float bottom = top + underlineThickness;
|
||||
|
||||
m_vertices.Append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.Append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Recompute the bounding rectangle
|
||||
m_bounds = m_vertices.GetBounds();
|
||||
m_bounds = m_vertices.getBounds();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
#include <SFML/Graphics/TextureSaver.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
|
@ -41,7 +41,7 @@ namespace
|
|||
{
|
||||
// Thread-safe unique identifier generator,
|
||||
// is used for states cache (see RenderTarget)
|
||||
sf::Uint64 GetUniqueId()
|
||||
sf::Uint64 getUniqueId()
|
||||
{
|
||||
static sf::Uint64 id = 1; // start at 1, zero is "no texture"
|
||||
static sf::Mutex mutex;
|
||||
|
@ -64,7 +64,7 @@ m_texture (0),
|
|||
m_isSmooth (false),
|
||||
m_isRepeated (false),
|
||||
m_pixelsFlipped(false),
|
||||
m_cacheId (GetUniqueId())
|
||||
m_cacheId (getUniqueId())
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ m_texture (0),
|
|||
m_isSmooth (copy.m_isSmooth),
|
||||
m_isRepeated (copy.m_isRepeated),
|
||||
m_pixelsFlipped(false),
|
||||
m_cacheId (GetUniqueId())
|
||||
m_cacheId (getUniqueId())
|
||||
{
|
||||
if (copy.m_texture)
|
||||
LoadFromImage(copy.CopyToImage());
|
||||
loadFromImage(copy.copyToImage());
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,33 +93,33 @@ Texture::~Texture()
|
|||
// Destroy the OpenGL texture
|
||||
if (m_texture)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
GLuint Texture = static_cast<GLuint>(m_texture);
|
||||
GLCheck(glDeleteTextures(1, &Texture));
|
||||
glCheck(glDeleteTextures(1, &Texture));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::Create(unsigned int width, unsigned int height)
|
||||
bool Texture::create(unsigned int width, unsigned int height)
|
||||
{
|
||||
// Check if texture parameters are valid before creating it
|
||||
if (!width || !height)
|
||||
{
|
||||
Err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl;
|
||||
err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute the internal texture dimensions depending on NPOT textures support
|
||||
unsigned int textureWidth = GetValidSize(width);
|
||||
unsigned int textureHeight = GetValidSize(height);
|
||||
unsigned int textureWidth = getValidSize(width);
|
||||
unsigned int textureHeight = getValidSize(height);
|
||||
|
||||
// Check the maximum texture size
|
||||
unsigned int maxSize = GetMaximumSize();
|
||||
unsigned int maxSize = getMaximumSize();
|
||||
if ((textureWidth > maxSize) || (textureHeight > maxSize))
|
||||
{
|
||||
Err() << "Failed to create texture, its internal size is too high "
|
||||
err() << "Failed to create texture, its internal size is too high "
|
||||
<< "(" << textureWidth << "x" << textureHeight << ", "
|
||||
<< "maximum is " << maxSize << "x" << maxSize << ")"
|
||||
<< std::endl;
|
||||
|
@ -133,13 +133,13 @@ bool Texture::Create(unsigned int width, unsigned int height)
|
|||
m_textureHeight = textureHeight;
|
||||
m_pixelsFlipped = false;
|
||||
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Create the OpenGL texture if it doesn't exist yet
|
||||
if (!m_texture)
|
||||
{
|
||||
GLuint texture;
|
||||
GLCheck(glGenTextures(1, &texture));
|
||||
glCheck(glGenTextures(1, &texture));
|
||||
m_texture = static_cast<unsigned int>(texture);
|
||||
}
|
||||
|
||||
|
@ -147,57 +147,57 @@ bool Texture::Create(unsigned int width, unsigned int height)
|
|||
priv::TextureSaver save;
|
||||
|
||||
// Initialize the texture
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_textureWidth, m_textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
m_cacheId = GetUniqueId();
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_textureWidth, m_textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
m_cacheId = getUniqueId();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::LoadFromFile(const std::string& filename, const IntRect& area)
|
||||
bool Texture::loadFromFile(const std::string& filename, const IntRect& area)
|
||||
{
|
||||
Image image;
|
||||
return image.LoadFromFile(filename) && LoadFromImage(image, area);
|
||||
return image.loadFromFile(filename) && loadFromImage(image, area);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::LoadFromMemory(const void* data, std::size_t size, const IntRect& area)
|
||||
bool Texture::loadFromMemory(const void* data, std::size_t size, const IntRect& area)
|
||||
{
|
||||
Image image;
|
||||
return image.LoadFromMemory(data, size) && LoadFromImage(image, area);
|
||||
return image.loadFromMemory(data, size) && loadFromImage(image, area);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::LoadFromStream(InputStream& stream, const IntRect& area)
|
||||
bool Texture::loadFromStream(InputStream& stream, const IntRect& area)
|
||||
{
|
||||
Image image;
|
||||
return image.LoadFromStream(stream) && LoadFromImage(image, area);
|
||||
return image.loadFromStream(stream) && loadFromImage(image, area);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::LoadFromImage(const Image& image, const IntRect& area)
|
||||
bool Texture::loadFromImage(const Image& image, const IntRect& area)
|
||||
{
|
||||
// Retrieve the image size
|
||||
int width = static_cast<int>(image.GetWidth());
|
||||
int height = static_cast<int>(image.GetHeight());
|
||||
int width = static_cast<int>(image.getWidth());
|
||||
int height = static_cast<int>(image.getHeight());
|
||||
|
||||
// Load the entire image if the source area is either empty or contains the whole image
|
||||
if (area.Width == 0 || (area.Height == 0) ||
|
||||
((area.Left <= 0) && (area.Top <= 0) && (area.Width >= width) && (area.Height >= height)))
|
||||
if (area.width == 0 || (area.height == 0) ||
|
||||
((area.left <= 0) && (area.top <= 0) && (area.width >= width) && (area.height >= height)))
|
||||
{
|
||||
// Load the entire image
|
||||
if (Create(image.GetWidth(), image.GetHeight()))
|
||||
if (create(image.getWidth(), image.getHeight()))
|
||||
{
|
||||
Update(image);
|
||||
update(image);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -211,23 +211,23 @@ bool Texture::LoadFromImage(const Image& image, const IntRect& area)
|
|||
|
||||
// Adjust the rectangle to the size of the image
|
||||
IntRect rectangle = area;
|
||||
if (rectangle.Left < 0) rectangle.Left = 0;
|
||||
if (rectangle.Top < 0) rectangle.Top = 0;
|
||||
if (rectangle.Left + rectangle.Width > width) rectangle.Width = width - rectangle.Left;
|
||||
if (rectangle.Top + rectangle.Height > height) rectangle.Height = height - rectangle.Top;
|
||||
if (rectangle.left < 0) rectangle.left = 0;
|
||||
if (rectangle.top < 0) rectangle.top = 0;
|
||||
if (rectangle.left + rectangle.width > width) rectangle.width = width - rectangle.left;
|
||||
if (rectangle.top + rectangle.height > height) rectangle.height = height - rectangle.top;
|
||||
|
||||
// Create the texture and upload the pixels
|
||||
if (Create(rectangle.Width, rectangle.Height))
|
||||
if (create(rectangle.width, rectangle.height))
|
||||
{
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
// Copy the pixels to the texture, row by row
|
||||
const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top));
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
for (int i = 0; i < rectangle.Height; ++i)
|
||||
const Uint8* pixels = image.getPixelsPtr() + 4 * (rectangle.left + (width * rectangle.top));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
for (int i = 0; i < rectangle.height; ++i)
|
||||
{
|
||||
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, m_width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, m_width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
pixels += 4 * width;
|
||||
}
|
||||
|
||||
|
@ -242,27 +242,27 @@ bool Texture::LoadFromImage(const Image& image, const IntRect& area)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Texture::GetWidth() const
|
||||
unsigned int Texture::getWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Texture::GetHeight() const
|
||||
unsigned int Texture::getHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Image Texture::CopyToImage() const
|
||||
Image Texture::copyToImage() const
|
||||
{
|
||||
// Easy case: empty texture
|
||||
if (!m_texture)
|
||||
return Image();
|
||||
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
@ -273,8 +273,8 @@ Image Texture::CopyToImage() const
|
|||
if ((m_width == m_textureWidth) && (m_height == m_textureHeight) && !m_pixelsFlipped)
|
||||
{
|
||||
// Texture is not padded nor flipped, we can use a direct copy
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -282,8 +282,8 @@ Image Texture::CopyToImage() const
|
|||
|
||||
// All the pixels will first be copied to a temporary array
|
||||
std::vector<Uint8> allPixels(m_textureWidth * m_textureHeight * 4);
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0]));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0]));
|
||||
|
||||
// Then we copy the useful pixels from the temporary array to the final one
|
||||
const Uint8* src = &allPixels[0];
|
||||
|
@ -308,89 +308,89 @@ Image Texture::CopyToImage() const
|
|||
|
||||
// Create the image
|
||||
Image image;
|
||||
image.Create(m_width, m_height, &pixels[0]);
|
||||
image.create(m_width, m_height, &pixels[0]);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Uint8* pixels)
|
||||
void Texture::update(const Uint8* pixels)
|
||||
{
|
||||
// Update the whole texture
|
||||
Update(pixels, m_width, m_height, 0, 0);
|
||||
update(pixels, m_width, m_height, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
|
||||
void Texture::update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
|
||||
{
|
||||
assert(x + width <= m_width);
|
||||
assert(y + height <= m_height);
|
||||
|
||||
if (pixels && m_texture)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
// Copy pixels from the given array to the texture
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
m_pixelsFlipped = false;
|
||||
m_cacheId = GetUniqueId();
|
||||
m_cacheId = getUniqueId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Image& image)
|
||||
void Texture::update(const Image& image)
|
||||
{
|
||||
// Update the whole texture
|
||||
Update(image.GetPixelsPtr(), image.GetWidth(), image.GetHeight(), 0, 0);
|
||||
update(image.getPixelsPtr(), image.getWidth(), image.getHeight(), 0, 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Image& image, unsigned int x, unsigned int y)
|
||||
void Texture::update(const Image& image, unsigned int x, unsigned int y)
|
||||
{
|
||||
Update(image.GetPixelsPtr(), image.GetWidth(), image.GetHeight(), x, y);
|
||||
update(image.getPixelsPtr(), image.getWidth(), image.getHeight(), x, y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Window& window)
|
||||
void Texture::update(const Window& window)
|
||||
{
|
||||
Update(window, 0, 0);
|
||||
update(window, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Window& window, unsigned int x, unsigned int y)
|
||||
void Texture::update(const Window& window, unsigned int x, unsigned int y)
|
||||
{
|
||||
assert(x + window.GetSize().x <= m_width);
|
||||
assert(y + window.GetSize().y <= m_height);
|
||||
assert(x + window.getSize().x <= m_width);
|
||||
assert(y + window.getSize().y <= m_height);
|
||||
|
||||
if (m_texture && window.SetActive(true))
|
||||
if (m_texture && window.setActive(true))
|
||||
{
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
// Copy pixels from the back-buffer to the texture
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetSize().x, window.GetSize().y));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.getSize().x, window.getSize().y));
|
||||
m_pixelsFlipped = true;
|
||||
m_cacheId = GetUniqueId();
|
||||
m_cacheId = getUniqueId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Bind(CoordinateType coordinateType) const
|
||||
void Texture::bind(CoordinateType coordinateType) const
|
||||
{
|
||||
// Bind the texture
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
|
||||
// Check if we need to define a special texture matrix
|
||||
if ((coordinateType == Pixels) || m_pixelsFlipped)
|
||||
|
@ -416,17 +416,17 @@ void Texture::Bind(CoordinateType coordinateType) const
|
|||
}
|
||||
|
||||
// Load the matrix
|
||||
GLCheck(glMatrixMode(GL_TEXTURE));
|
||||
GLCheck(glLoadMatrixf(matrix));
|
||||
glCheck(glMatrixMode(GL_TEXTURE));
|
||||
glCheck(glLoadMatrixf(matrix));
|
||||
|
||||
// Go back to model-view mode (sf::RenderTarget relies on it)
|
||||
GLCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::SetSmooth(bool smooth)
|
||||
void Texture::setSmooth(bool smooth)
|
||||
{
|
||||
if (smooth != m_isSmooth)
|
||||
{
|
||||
|
@ -434,28 +434,28 @@ void Texture::SetSmooth(bool smooth)
|
|||
|
||||
if (m_texture)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::IsSmooth() const
|
||||
bool Texture::isSmooth() const
|
||||
{
|
||||
return m_isSmooth;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::SetRepeated(bool repeated)
|
||||
void Texture::setRepeated(bool repeated)
|
||||
{
|
||||
if (repeated != m_isRepeated)
|
||||
{
|
||||
|
@ -463,33 +463,33 @@ void Texture::SetRepeated(bool repeated)
|
|||
|
||||
if (m_texture)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that the current texture binding will be preserved
|
||||
priv::TextureSaver save;
|
||||
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::IsRepeated() const
|
||||
bool Texture::isRepeated() const
|
||||
{
|
||||
return m_isRepeated;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Texture::GetMaximumSize()
|
||||
unsigned int Texture::getMaximumSize()
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
GLint size;
|
||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
|
||||
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
|
||||
|
||||
return static_cast<unsigned int>(size);
|
||||
}
|
||||
|
@ -508,19 +508,19 @@ Texture& Texture::operator =(const Texture& right)
|
|||
std::swap(m_isSmooth, temp.m_isSmooth);
|
||||
std::swap(m_isRepeated, temp.m_isRepeated);
|
||||
std::swap(m_pixelsFlipped, temp.m_pixelsFlipped);
|
||||
m_cacheId = GetUniqueId();
|
||||
m_cacheId = getUniqueId();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Texture::GetValidSize(unsigned int size)
|
||||
unsigned int Texture::getValidSize(unsigned int size)
|
||||
{
|
||||
EnsureGlContext();
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::EnsureGlewInit();
|
||||
priv::ensureGlewInit();
|
||||
|
||||
if (GLEW_ARB_texture_non_power_of_two)
|
||||
{
|
||||
|
|
|
@ -35,14 +35,14 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
TextureSaver::TextureSaver()
|
||||
{
|
||||
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &m_textureBinding));
|
||||
glCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &m_textureBinding));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
TextureSaver::~TextureSaver()
|
||||
{
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, m_textureBinding));
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_textureBinding));
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Graphics/glCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
|
|
@ -59,14 +59,14 @@ Transform::Transform(float a00, float a01, float a02,
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const float* Transform::GetMatrix() const
|
||||
const float* Transform::getMatrix() const
|
||||
{
|
||||
return m_matrix;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform Transform::GetInverse() const
|
||||
Transform Transform::getInverse() const
|
||||
{
|
||||
// Compute the determinant
|
||||
float det = m_matrix[0] * (m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) -
|
||||
|
@ -95,7 +95,7 @@ Transform Transform::GetInverse() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f Transform::TransformPoint(float x, float y) const
|
||||
Vector2f Transform::transformPoint(float x, float y) const
|
||||
{
|
||||
return Vector2f(m_matrix[0] * x + m_matrix[4] * y + m_matrix[12],
|
||||
m_matrix[1] * x + m_matrix[5] * y + m_matrix[13]);
|
||||
|
@ -103,22 +103,22 @@ Vector2f Transform::TransformPoint(float x, float y) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f Transform::TransformPoint(const Vector2f& point) const
|
||||
Vector2f Transform::transformPoint(const Vector2f& point) const
|
||||
{
|
||||
return TransformPoint(point.x, point.y);
|
||||
return transformPoint(point.x, point.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Transform::TransformRect(const FloatRect& rectangle) const
|
||||
FloatRect Transform::transformRect(const FloatRect& rectangle) const
|
||||
{
|
||||
// Transform the 4 corners of the rectangle
|
||||
const Vector2f points[] =
|
||||
{
|
||||
TransformPoint(rectangle.Left, rectangle.Top),
|
||||
TransformPoint(rectangle.Left, rectangle.Top + rectangle.Height),
|
||||
TransformPoint(rectangle.Left + rectangle.Width, rectangle.Top),
|
||||
TransformPoint(rectangle.Left + rectangle.Width, rectangle.Top + rectangle.Height)
|
||||
transformPoint(rectangle.left, rectangle.top),
|
||||
transformPoint(rectangle.left, rectangle.top + rectangle.height),
|
||||
transformPoint(rectangle.left + rectangle.width, rectangle.top),
|
||||
transformPoint(rectangle.left + rectangle.width, rectangle.top + rectangle.height)
|
||||
};
|
||||
|
||||
// Compute the bounding rectangle of the transformed points
|
||||
|
@ -139,7 +139,7 @@ FloatRect Transform::TransformRect(const FloatRect& rectangle) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Combine(const Transform& transform)
|
||||
Transform& Transform::combine(const Transform& transform)
|
||||
{
|
||||
const float* a = m_matrix;
|
||||
const float* b = transform.m_matrix;
|
||||
|
@ -159,25 +159,25 @@ Transform& Transform::Combine(const Transform& transform)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Translate(float x, float y)
|
||||
Transform& Transform::translate(float x, float y)
|
||||
{
|
||||
Transform translation(1, 0, x,
|
||||
0, 1, y,
|
||||
0, 0, 1);
|
||||
|
||||
return Combine(translation);
|
||||
return combine(translation);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Translate(const Vector2f& offset)
|
||||
Transform& Transform::translate(const Vector2f& offset)
|
||||
{
|
||||
return Translate(offset.x, offset.y);
|
||||
return translate(offset.x, offset.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Rotate(float angle)
|
||||
Transform& Transform::rotate(float angle)
|
||||
{
|
||||
float rad = angle * 3.141592654f / 180.f;
|
||||
float cos = std::cos(rad);
|
||||
|
@ -187,12 +187,12 @@ Transform& Transform::Rotate(float angle)
|
|||
sin, cos, 0,
|
||||
0, 0, 1);
|
||||
|
||||
return Combine(rotation);
|
||||
return combine(rotation);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Rotate(float angle, float centerX, float centerY)
|
||||
Transform& Transform::rotate(float angle, float centerX, float centerY)
|
||||
{
|
||||
float rad = angle * 3.141592654f / 180.f;
|
||||
float cos = std::cos(rad);
|
||||
|
@ -202,71 +202,71 @@ Transform& Transform::Rotate(float angle, float centerX, float centerY)
|
|||
sin, cos, centerY * (1 - cos) - centerX * sin,
|
||||
0, 0, 1);
|
||||
|
||||
return Combine(rotation);
|
||||
return combine(rotation);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Rotate(float angle, const Vector2f& center)
|
||||
Transform& Transform::rotate(float angle, const Vector2f& center)
|
||||
{
|
||||
return Rotate(angle, center.x, center.y);
|
||||
return rotate(angle, center.x, center.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Scale(float scaleX, float scaleY)
|
||||
Transform& Transform::scale(float scaleX, float scaleY)
|
||||
{
|
||||
Transform scaling(scaleX, 0, 0,
|
||||
0, scaleY, 0,
|
||||
0, 0, 1);
|
||||
|
||||
return Combine(scaling);
|
||||
return combine(scaling);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Scale(float scaleX, float scaleY, float centerX, float centerY)
|
||||
Transform& Transform::scale(float scaleX, float scaleY, float centerX, float centerY)
|
||||
{
|
||||
Transform scaling(scaleX, 0, centerX * (1 - scaleX),
|
||||
0, scaleY, centerY * (1 - scaleY),
|
||||
0, 0, 1);
|
||||
|
||||
return Combine(scaling);
|
||||
return combine(scaling);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Scale(const Vector2f& factors)
|
||||
Transform& Transform::scale(const Vector2f& factors)
|
||||
{
|
||||
return Scale(factors.x, factors.y);
|
||||
return scale(factors.x, factors.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& Transform::Scale(const Vector2f& factors, const Vector2f& center)
|
||||
Transform& Transform::scale(const Vector2f& factors, const Vector2f& center)
|
||||
{
|
||||
return Scale(factors.x, factors.y, center.x, center.y);
|
||||
return scale(factors.x, factors.y, center.x, center.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform operator *(const Transform& left, const Transform& right)
|
||||
{
|
||||
return Transform(left).Combine(right);
|
||||
return Transform(left).combine(right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& operator *=(Transform& left, const Transform& right)
|
||||
{
|
||||
return left.Combine(right);
|
||||
return left.combine(right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f operator *(const Transform& left, const Vector2f& right)
|
||||
{
|
||||
return left.TransformPoint(right);
|
||||
return left.transformPoint(right);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -52,7 +52,7 @@ Transformable::~Transformable()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetPosition(float x, float y)
|
||||
void Transformable::setPosition(float x, float y)
|
||||
{
|
||||
m_position.x = x;
|
||||
m_position.y = y;
|
||||
|
@ -62,14 +62,14 @@ void Transformable::SetPosition(float x, float y)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetPosition(const Vector2f& position)
|
||||
void Transformable::setPosition(const Vector2f& position)
|
||||
{
|
||||
SetPosition(position.x, position.y);
|
||||
setPosition(position.x, position.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetRotation(float angle)
|
||||
void Transformable::setRotation(float angle)
|
||||
{
|
||||
m_rotation = angle;
|
||||
m_transformNeedUpdate = true;
|
||||
|
@ -78,7 +78,7 @@ void Transformable::SetRotation(float angle)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetScale(float factorX, float factorY)
|
||||
void Transformable::setScale(float factorX, float factorY)
|
||||
{
|
||||
m_scale.x = factorX;
|
||||
m_scale.y = factorY;
|
||||
|
@ -88,14 +88,14 @@ void Transformable::SetScale(float factorX, float factorY)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetScale(const Vector2f& factors)
|
||||
void Transformable::setScale(const Vector2f& factors)
|
||||
{
|
||||
SetScale(factors.x, factors.y);
|
||||
setScale(factors.x, factors.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetOrigin(float x, float y)
|
||||
void Transformable::setOrigin(float x, float y)
|
||||
{
|
||||
m_origin.x = x;
|
||||
m_origin.y = y;
|
||||
|
@ -105,77 +105,77 @@ void Transformable::SetOrigin(float x, float y)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::SetOrigin(const Vector2f& origin)
|
||||
void Transformable::setOrigin(const Vector2f& origin)
|
||||
{
|
||||
SetOrigin(origin.x, origin.y);
|
||||
setOrigin(origin.x, origin.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& Transformable::GetPosition() const
|
||||
const Vector2f& Transformable::getPosition() const
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Transformable::GetRotation() const
|
||||
float Transformable::getRotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& Transformable::GetScale() const
|
||||
const Vector2f& Transformable::getScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& Transformable::GetOrigin() const
|
||||
const Vector2f& Transformable::getOrigin() const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::Move(float offsetX, float offsetY)
|
||||
void Transformable::move(float offsetX, float offsetY)
|
||||
{
|
||||
SetPosition(m_position.x + offsetX, m_position.y + offsetY);
|
||||
setPosition(m_position.x + offsetX, m_position.y + offsetY);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::Move(const Vector2f& offset)
|
||||
void Transformable::move(const Vector2f& offset)
|
||||
{
|
||||
SetPosition(m_position.x + offset.x, m_position.y + offset.y);
|
||||
setPosition(m_position.x + offset.x, m_position.y + offset.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::Rotate(float angle)
|
||||
void Transformable::rotate(float angle)
|
||||
{
|
||||
SetRotation(m_rotation + angle);
|
||||
setRotation(m_rotation + angle);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::Scale(float factorX, float factorY)
|
||||
void Transformable::scale(float factorX, float factorY)
|
||||
{
|
||||
SetScale(m_scale.x * factorX, m_scale.y * factorY);
|
||||
setScale(m_scale.x * factorX, m_scale.y * factorY);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Transformable::Scale(const Vector2f& factor)
|
||||
void Transformable::scale(const Vector2f& factor)
|
||||
{
|
||||
SetScale(m_scale.x * factor.x, m_scale.y * factor.y);
|
||||
setScale(m_scale.x * factor.x, m_scale.y * factor.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& Transformable::GetTransform() const
|
||||
const Transform& Transformable::getTransform() const
|
||||
{
|
||||
// Recompute the combined transform if needed
|
||||
if (m_transformNeedUpdate)
|
||||
|
@ -201,12 +201,12 @@ const Transform& Transformable::GetTransform() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& Transformable::GetInverseTransform() const
|
||||
const Transform& Transformable::getInverseTransform() const
|
||||
{
|
||||
// Recompute the inverse transform if needed
|
||||
if (m_inverseTransformNeedUpdate)
|
||||
{
|
||||
m_inverseTransform = GetTransform().GetInverse();
|
||||
m_inverseTransform = getTransform().getInverse();
|
||||
m_inverseTransformNeedUpdate = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,45 +32,45 @@ namespace sf
|
|||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex::Vertex() :
|
||||
Position (0, 0),
|
||||
Color (255, 255, 255),
|
||||
TexCoords(0, 0)
|
||||
position (0, 0),
|
||||
color (255, 255, 255),
|
||||
texCoords(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex::Vertex(const Vector2f& position) :
|
||||
Position (position),
|
||||
Color (255, 255, 255),
|
||||
TexCoords(0, 0)
|
||||
position (position),
|
||||
color (255, 255, 255),
|
||||
texCoords(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex::Vertex(const Vector2f& position, const sf::Color& color) :
|
||||
Position (position),
|
||||
Color (color),
|
||||
TexCoords(0, 0)
|
||||
Vertex::Vertex(const Vector2f& position, const Color& color) :
|
||||
position (position),
|
||||
color (color),
|
||||
texCoords(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex::Vertex(const Vector2f& position, const Vector2f& texCoords) :
|
||||
Position (position),
|
||||
Color (255, 255, 255),
|
||||
TexCoords(texCoords)
|
||||
position (position),
|
||||
color (255, 255, 255),
|
||||
texCoords(texCoords)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex::Vertex(const Vector2f& position, const sf::Color& color, const Vector2f& texCoords) :
|
||||
Position (position),
|
||||
Color (color),
|
||||
TexCoords(texCoords)
|
||||
Vertex::Vertex(const Vector2f& position, const Color& color, const Vector2f& texCoords) :
|
||||
position (position),
|
||||
color (color),
|
||||
texCoords(texCoords)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ m_primitiveType(type)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int VertexArray::GetVertexCount() const
|
||||
unsigned int VertexArray::getVertexCount() const
|
||||
{
|
||||
return static_cast<unsigned int>(m_vertices.size());
|
||||
}
|
||||
|
@ -69,53 +69,53 @@ const Vertex& VertexArray::operator [](unsigned int index) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void VertexArray::Clear()
|
||||
void VertexArray::clear()
|
||||
{
|
||||
m_vertices.clear();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void VertexArray::Resize(unsigned int vertexCount)
|
||||
void VertexArray::resize(unsigned int vertexCount)
|
||||
{
|
||||
m_vertices.resize(vertexCount);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void VertexArray::Append(const Vertex& vertex)
|
||||
void VertexArray::append(const Vertex& vertex)
|
||||
{
|
||||
m_vertices.push_back(vertex);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void VertexArray::SetPrimitiveType(PrimitiveType type)
|
||||
void VertexArray::setPrimitiveType(PrimitiveType type)
|
||||
{
|
||||
m_primitiveType = type;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
PrimitiveType VertexArray::GetPrimitiveType() const
|
||||
PrimitiveType VertexArray::getPrimitiveType() const
|
||||
{
|
||||
return m_primitiveType;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect VertexArray::GetBounds() const
|
||||
FloatRect VertexArray::getBounds() const
|
||||
{
|
||||
if (!m_vertices.empty())
|
||||
{
|
||||
float left = m_vertices[0].Position.x;
|
||||
float top = m_vertices[0].Position.y;
|
||||
float right = m_vertices[0].Position.x;
|
||||
float bottom = m_vertices[0].Position.y;
|
||||
float left = m_vertices[0].position.x;
|
||||
float top = m_vertices[0].position.y;
|
||||
float right = m_vertices[0].position.x;
|
||||
float bottom = m_vertices[0].position.y;
|
||||
|
||||
for (std::size_t i = 0; i < m_vertices.size(); ++i)
|
||||
{
|
||||
Vector2f position = m_vertices[i].Position;
|
||||
Vector2f position = m_vertices[i].position;
|
||||
|
||||
// Update left and right
|
||||
if (position.x < left)
|
||||
|
@ -141,10 +141,10 @@ FloatRect VertexArray::GetBounds() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void VertexArray::Draw(RenderTarget& target, RenderStates states) const
|
||||
void VertexArray::draw(RenderTarget& target, RenderStates states) const
|
||||
{
|
||||
if (!m_vertices.empty())
|
||||
target.Draw(&m_vertices[0], static_cast<unsigned int>(m_vertices.size()), m_primitiveType, states);
|
||||
target.draw(&m_vertices[0], static_cast<unsigned int>(m_vertices.size()), m_primitiveType, states);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -40,7 +40,7 @@ m_viewport (0, 0, 1, 1),
|
|||
m_transformUpdated (false),
|
||||
m_invTransformUpdated(false)
|
||||
{
|
||||
Reset(FloatRect(0, 0, 1000, 1000));
|
||||
reset(FloatRect(0, 0, 1000, 1000));
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ m_viewport (0, 0, 1, 1),
|
|||
m_transformUpdated (false),
|
||||
m_invTransformUpdated(false)
|
||||
{
|
||||
Reset(rectangle);
|
||||
reset(rectangle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ m_invTransformUpdated(false)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetCenter(float x, float y)
|
||||
void View::setCenter(float x, float y)
|
||||
{
|
||||
m_center.x = x;
|
||||
m_center.y = y;
|
||||
|
@ -81,14 +81,14 @@ void View::SetCenter(float x, float y)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetCenter(const Vector2f& center)
|
||||
void View::setCenter(const Vector2f& center)
|
||||
{
|
||||
SetCenter(center.x, center.y);
|
||||
setCenter(center.x, center.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetSize(float width, float height)
|
||||
void View::setSize(float width, float height)
|
||||
{
|
||||
m_size.x = width;
|
||||
m_size.y = height;
|
||||
|
@ -99,14 +99,14 @@ void View::SetSize(float width, float height)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetSize(const Vector2f& size)
|
||||
void View::setSize(const Vector2f& size)
|
||||
{
|
||||
SetSize(size.x, size.y);
|
||||
setSize(size.x, size.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetRotation(float angle)
|
||||
void View::setRotation(float angle)
|
||||
{
|
||||
m_rotation = static_cast<float>(fmod(angle, 360));
|
||||
if (m_rotation < 0)
|
||||
|
@ -118,19 +118,19 @@ void View::SetRotation(float angle)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::SetViewport(const FloatRect& viewport)
|
||||
void View::setViewport(const FloatRect& viewport)
|
||||
{
|
||||
m_viewport = viewport;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::Reset(const FloatRect& rectangle)
|
||||
void View::reset(const FloatRect& rectangle)
|
||||
{
|
||||
m_center.x = rectangle.Left + rectangle.Width / 2.f;
|
||||
m_center.y = rectangle.Top + rectangle.Height / 2.f;
|
||||
m_size.x = rectangle.Width;
|
||||
m_size.y = rectangle.Height;
|
||||
m_center.x = rectangle.left + rectangle.width / 2.f;
|
||||
m_center.y = rectangle.top + rectangle.height / 2.f;
|
||||
m_size.x = rectangle.width;
|
||||
m_size.y = rectangle.height;
|
||||
m_rotation = 0;
|
||||
|
||||
m_transformUpdated = false;
|
||||
|
@ -139,63 +139,63 @@ void View::Reset(const FloatRect& rectangle)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& View::GetCenter() const
|
||||
const Vector2f& View::getCenter() const
|
||||
{
|
||||
return m_center;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& View::GetSize() const
|
||||
const Vector2f& View::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float View::GetRotation() const
|
||||
float View::getRotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const FloatRect& View::GetViewport() const
|
||||
const FloatRect& View::getViewport() const
|
||||
{
|
||||
return m_viewport;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::Move(float offsetX, float offsetY)
|
||||
void View::move(float offsetX, float offsetY)
|
||||
{
|
||||
SetCenter(m_center.x + offsetX, m_center.y + offsetY);
|
||||
setCenter(m_center.x + offsetX, m_center.y + offsetY);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::Move(const Vector2f& offset)
|
||||
void View::move(const Vector2f& offset)
|
||||
{
|
||||
SetCenter(m_center + offset);
|
||||
setCenter(m_center + offset);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::Rotate(float angle)
|
||||
void View::rotate(float angle)
|
||||
{
|
||||
SetRotation(m_rotation + angle);
|
||||
setRotation(m_rotation + angle);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::Zoom(float factor)
|
||||
void View::zoom(float factor)
|
||||
{
|
||||
SetSize(m_size.x * factor, m_size.y * factor);
|
||||
setSize(m_size.x * factor, m_size.y * factor);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& View::GetTransform() const
|
||||
const Transform& View::getTransform() const
|
||||
{
|
||||
// Recompute the matrix if needed
|
||||
if (!m_transformUpdated)
|
||||
|
@ -225,12 +225,12 @@ const Transform& View::GetTransform() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& View::GetInverseTransform() const
|
||||
const Transform& View::getInverseTransform() const
|
||||
{
|
||||
// Recompute the matrix if needed
|
||||
if (!m_invTransformUpdated)
|
||||
{
|
||||
m_inverseTransform = GetTransform().GetInverse();
|
||||
m_inverseTransform = getTransform().getInverse();
|
||||
m_invTransformUpdated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@ public :
|
|||
DataChannel(Ftp& owner);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Open(Ftp::TransferMode mode);
|
||||
Ftp::Response open(Ftp::TransferMode mode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Send(const std::vector<char>& data);
|
||||
void send(const std::vector<char>& data);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Receive(std::vector<char>& data);
|
||||
void receive(std::vector<char>& data);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -72,21 +72,21 @@ m_message(message)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Ftp::Response::IsOk() const
|
||||
bool Ftp::Response::isOk() const
|
||||
{
|
||||
return m_status < 400;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response::Status Ftp::Response::GetStatus() const
|
||||
Ftp::Response::Status Ftp::Response::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& Ftp::Response::GetMessage() const
|
||||
const std::string& Ftp::Response::getMessage() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
@ -96,18 +96,18 @@ const std::string& Ftp::Response::GetMessage() const
|
|||
Ftp::DirectoryResponse::DirectoryResponse(const Ftp::Response& response) :
|
||||
Ftp::Response(response)
|
||||
{
|
||||
if (IsOk())
|
||||
if (isOk())
|
||||
{
|
||||
// Extract the directory from the server response
|
||||
std::string::size_type begin = GetMessage().find('"', 0);
|
||||
std::string::size_type end = GetMessage().find('"', begin + 1);
|
||||
m_directory = GetMessage().substr(begin + 1, end - begin - 1);
|
||||
std::string::size_type begin = getMessage().find('"', 0);
|
||||
std::string::size_type end = getMessage().find('"', begin + 1);
|
||||
m_directory = getMessage().substr(begin + 1, end - begin - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& Ftp::DirectoryResponse::GetDirectory() const
|
||||
const std::string& Ftp::DirectoryResponse::getDirectory() const
|
||||
{
|
||||
return m_directory;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ const std::string& Ftp::DirectoryResponse::GetDirectory() const
|
|||
Ftp::ListingResponse::ListingResponse(const Ftp::Response& response, const std::vector<char>& data) :
|
||||
Ftp::Response(response)
|
||||
{
|
||||
if (IsOk())
|
||||
if (isOk())
|
||||
{
|
||||
// Fill the array of strings
|
||||
std::string paths(data.begin(), data.end());
|
||||
|
@ -132,7 +132,7 @@ Ftp::Response(response)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::vector<std::string>& Ftp::ListingResponse::GetFilenames() const
|
||||
const std::vector<std::string>& Ftp::ListingResponse::getFilenames() const
|
||||
{
|
||||
return m_filenames;
|
||||
}
|
||||
|
@ -141,84 +141,84 @@ const std::vector<std::string>& Ftp::ListingResponse::GetFilenames() const
|
|||
////////////////////////////////////////////////////////////
|
||||
Ftp::~Ftp()
|
||||
{
|
||||
Disconnect();
|
||||
disconnect();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, Time timeout)
|
||||
Ftp::Response Ftp::connect(const IpAddress& server, unsigned short port, Time timeout)
|
||||
{
|
||||
// Connect to the server
|
||||
if (m_commandSocket.Connect(server, port, timeout) != Socket::Done)
|
||||
if (m_commandSocket.connect(server, port, timeout) != Socket::Done)
|
||||
return Response(Response::ConnectionFailed);
|
||||
|
||||
// Get the response to the connection
|
||||
return GetResponse();
|
||||
return getResponse();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Login()
|
||||
Ftp::Response Ftp::login()
|
||||
{
|
||||
return Login("anonymous", "user@sfml-dev.org");
|
||||
return login("anonymous", "user@sfml-dev.org");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Login(const std::string& name, const std::string& password)
|
||||
Ftp::Response Ftp::login(const std::string& name, const std::string& password)
|
||||
{
|
||||
Response response = SendCommand("USER", name);
|
||||
if (response.IsOk())
|
||||
response = SendCommand("PASS", password);
|
||||
Response response = sendCommand("USER", name);
|
||||
if (response.isOk())
|
||||
response = sendCommand("PASS", password);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Disconnect()
|
||||
Ftp::Response Ftp::disconnect()
|
||||
{
|
||||
// Send the exit command
|
||||
Response response = SendCommand("QUIT");
|
||||
if (response.IsOk())
|
||||
m_commandSocket.Disconnect();
|
||||
Response response = sendCommand("QUIT");
|
||||
if (response.isOk())
|
||||
m_commandSocket.disconnect();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::KeepAlive()
|
||||
Ftp::Response Ftp::keepAlive()
|
||||
{
|
||||
return SendCommand("NOOP");
|
||||
return sendCommand("NOOP");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::DirectoryResponse Ftp::GetWorkingDirectory()
|
||||
Ftp::DirectoryResponse Ftp::getWorkingDirectory()
|
||||
{
|
||||
return DirectoryResponse(SendCommand("PWD"));
|
||||
return DirectoryResponse(sendCommand("PWD"));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::ListingResponse Ftp::GetDirectoryListing(const std::string& directory)
|
||||
Ftp::ListingResponse Ftp::getDirectoryListing(const std::string& directory)
|
||||
{
|
||||
// Open a data channel on default port (20) using ASCII transfer mode
|
||||
std::vector<char> directoryData;
|
||||
DataChannel data(*this);
|
||||
Response response = data.Open(Ascii);
|
||||
if (response.IsOk())
|
||||
Response response = data.open(Ascii);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Tell the server to send us the listing
|
||||
response = SendCommand("NLST", directory);
|
||||
if (response.IsOk())
|
||||
response = sendCommand("NLST", directory);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Receive the listing
|
||||
data.Receive(directoryData);
|
||||
data.receive(directoryData);
|
||||
|
||||
// Get the response from the server
|
||||
response = GetResponse();
|
||||
response = getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,70 +227,70 @@ Ftp::ListingResponse Ftp::GetDirectoryListing(const std::string& directory)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::ChangeDirectory(const std::string& directory)
|
||||
Ftp::Response Ftp::changeDirectory(const std::string& directory)
|
||||
{
|
||||
return SendCommand("CWD", directory);
|
||||
return sendCommand("CWD", directory);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::ParentDirectory()
|
||||
Ftp::Response Ftp::parentDirectory()
|
||||
{
|
||||
return SendCommand("CDUP");
|
||||
return sendCommand("CDUP");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::CreateDirectory(const std::string& name)
|
||||
Ftp::Response Ftp::createDirectory(const std::string& name)
|
||||
{
|
||||
return SendCommand("MKD", name);
|
||||
return sendCommand("MKD", name);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::DeleteDirectory(const std::string& name)
|
||||
Ftp::Response Ftp::deleteDirectory(const std::string& name)
|
||||
{
|
||||
return SendCommand("RMD", name);
|
||||
return sendCommand("RMD", name);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::RenameFile(const std::string& file, const std::string& newName)
|
||||
Ftp::Response Ftp::renameFile(const std::string& file, const std::string& newName)
|
||||
{
|
||||
Response response = SendCommand("RNFR", file);
|
||||
if (response.IsOk())
|
||||
response = SendCommand("RNTO", newName);
|
||||
Response response = sendCommand("RNFR", file);
|
||||
if (response.isOk())
|
||||
response = sendCommand("RNTO", newName);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::DeleteFile(const std::string& name)
|
||||
Ftp::Response Ftp::deleteFile(const std::string& name)
|
||||
{
|
||||
return SendCommand("DELE", name);
|
||||
return sendCommand("DELE", name);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Download(const std::string& remoteFile, const std::string& localPath, TransferMode mode)
|
||||
Ftp::Response Ftp::download(const std::string& remoteFile, const std::string& localPath, TransferMode mode)
|
||||
{
|
||||
// Open a data channel using the given transfer mode
|
||||
DataChannel data(*this);
|
||||
Response response = data.Open(mode);
|
||||
if (response.IsOk())
|
||||
Response response = data.open(mode);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Tell the server to start the transfer
|
||||
response = SendCommand("RETR", remoteFile);
|
||||
if (response.IsOk())
|
||||
response = sendCommand("RETR", remoteFile);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Receive the file data
|
||||
std::vector<char> fileData;
|
||||
data.Receive(fileData);
|
||||
data.receive(fileData);
|
||||
|
||||
// Get the response from the server
|
||||
response = GetResponse();
|
||||
if (response.IsOk())
|
||||
response = getResponse();
|
||||
if (response.isOk())
|
||||
{
|
||||
// Extract the filename from the file path
|
||||
std::string filename = remoteFile;
|
||||
|
@ -319,7 +319,7 @@ Ftp::Response Ftp::Download(const std::string& remoteFile, const std::string& lo
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::Upload(const std::string& localFile, const std::string& remotePath, TransferMode mode)
|
||||
Ftp::Response Ftp::upload(const std::string& localFile, const std::string& remotePath, TransferMode mode)
|
||||
{
|
||||
// Get the contents of the file to send
|
||||
std::ifstream file(localFile.c_str(), std::ios_base::binary);
|
||||
|
@ -346,18 +346,18 @@ Ftp::Response Ftp::Upload(const std::string& localFile, const std::string& remot
|
|||
|
||||
// Open a data channel using the given transfer mode
|
||||
DataChannel data(*this);
|
||||
Response response = data.Open(mode);
|
||||
if (response.IsOk())
|
||||
Response response = data.open(mode);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Tell the server to start the transfer
|
||||
response = SendCommand("STOR", path + filename);
|
||||
if (response.IsOk())
|
||||
response = sendCommand("STOR", path + filename);
|
||||
if (response.isOk())
|
||||
{
|
||||
// Send the file data
|
||||
data.Send(fileData);
|
||||
data.send(fileData);
|
||||
|
||||
// Get the response from the server
|
||||
response = GetResponse();
|
||||
response = getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ Ftp::Response Ftp::Upload(const std::string& localFile, const std::string& remot
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::SendCommand(const std::string& command, const std::string& parameter)
|
||||
Ftp::Response Ftp::sendCommand(const std::string& command, const std::string& parameter)
|
||||
{
|
||||
// Build the command string
|
||||
std::string commandStr;
|
||||
|
@ -376,16 +376,16 @@ Ftp::Response Ftp::SendCommand(const std::string& command, const std::string& pa
|
|||
commandStr = command + "\r\n";
|
||||
|
||||
// Send it to the server
|
||||
if (m_commandSocket.Send(commandStr.c_str(), commandStr.length()) != Socket::Done)
|
||||
if (m_commandSocket.send(commandStr.c_str(), commandStr.length()) != Socket::Done)
|
||||
return Response(Response::ConnectionClosed);
|
||||
|
||||
// Get the response
|
||||
return GetResponse();
|
||||
return getResponse();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::GetResponse()
|
||||
Ftp::Response Ftp::getResponse()
|
||||
{
|
||||
// We'll use a variable to keep track of the last valid code.
|
||||
// It is useful in case of multi-lines responses, because the end of such a response
|
||||
|
@ -399,7 +399,7 @@ Ftp::Response Ftp::GetResponse()
|
|||
// Receive the response from the server
|
||||
char buffer[1024];
|
||||
std::size_t length;
|
||||
if (m_commandSocket.Receive(buffer, sizeof(buffer), length) != Socket::Done)
|
||||
if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done)
|
||||
return Response(Response::ConnectionClosed);
|
||||
|
||||
// There can be several lines inside the received buffer, extract them all
|
||||
|
@ -525,18 +525,18 @@ m_ftp(owner)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
|
||||
Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
|
||||
{
|
||||
// Open a data connection in active mode (we connect to the server)
|
||||
Ftp::Response response = m_ftp.SendCommand("PASV");
|
||||
if (response.IsOk())
|
||||
Ftp::Response response = m_ftp.sendCommand("PASV");
|
||||
if (response.isOk())
|
||||
{
|
||||
// Extract the connection address and port from the response
|
||||
std::string::size_type begin = response.GetMessage().find_first_of("0123456789");
|
||||
std::string::size_type begin = response.getMessage().find_first_of("0123456789");
|
||||
if (begin != std::string::npos)
|
||||
{
|
||||
Uint8 data[6] = {0, 0, 0, 0, 0, 0};
|
||||
std::string str = response.GetMessage().substr(begin);
|
||||
std::string str = response.getMessage().substr(begin);
|
||||
std::size_t index = 0;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
|
@ -559,7 +559,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
|
|||
static_cast<Uint8>(data[3]));
|
||||
|
||||
// Connect the data channel to the server
|
||||
if (m_dataSocket.Connect(address, port) == Socket::Done)
|
||||
if (m_dataSocket.connect(address, port) == Socket::Done)
|
||||
{
|
||||
// Translate the transfer mode to the corresponding FTP parameter
|
||||
std::string modeStr;
|
||||
|
@ -571,7 +571,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
|
|||
}
|
||||
|
||||
// Set the transfer mode
|
||||
response = m_ftp.SendCommand("TYPE", modeStr);
|
||||
response = m_ftp.sendCommand("TYPE", modeStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -586,31 +586,31 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Ftp::DataChannel::Receive(std::vector<char>& data)
|
||||
void Ftp::DataChannel::receive(std::vector<char>& data)
|
||||
{
|
||||
// Receive data
|
||||
data.clear();
|
||||
char buffer[1024];
|
||||
std::size_t received;
|
||||
while (m_dataSocket.Receive(buffer, sizeof(buffer), received) == Socket::Done)
|
||||
while (m_dataSocket.receive(buffer, sizeof(buffer), received) == Socket::Done)
|
||||
{
|
||||
std::copy(buffer, buffer + received, std::back_inserter(data));
|
||||
}
|
||||
|
||||
// Close the data socket
|
||||
m_dataSocket.Disconnect();
|
||||
m_dataSocket.disconnect();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Ftp::DataChannel::Send(const std::vector<char>& data)
|
||||
void Ftp::DataChannel::send(const std::vector<char>& data)
|
||||
{
|
||||
// Send data
|
||||
if (!data.empty())
|
||||
m_dataSocket.Send(&data[0], data.size());
|
||||
m_dataSocket.send(&data[0], data.size());
|
||||
|
||||
// Close the data socket
|
||||
m_dataSocket.Disconnect();
|
||||
m_dataSocket.disconnect();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
namespace
|
||||
{
|
||||
// Convert a string to lower case
|
||||
std::string ToLower(std::string str)
|
||||
std::string toLower(std::string str)
|
||||
{
|
||||
for (std::string::iterator i = str.begin(); i != str.end(); ++i)
|
||||
*i = static_cast<char>(std::tolower(*i));
|
||||
|
@ -49,40 +49,40 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Http::Request::Request(const std::string& uri, Method method, const std::string& body)
|
||||
{
|
||||
SetMethod(method);
|
||||
SetUri(uri);
|
||||
SetHttpVersion(1, 0);
|
||||
SetBody(body);
|
||||
setMethod(method);
|
||||
setUri(uri);
|
||||
setHttpVersion(1, 0);
|
||||
setBody(body);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Request::SetField(const std::string& field, const std::string& value)
|
||||
void Http::Request::setField(const std::string& field, const std::string& value)
|
||||
{
|
||||
m_fields[ToLower(field)] = value;
|
||||
m_fields[toLower(field)] = value;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Request::SetMethod(Http::Request::Method method)
|
||||
void Http::Request::setMethod(Http::Request::Method method)
|
||||
{
|
||||
m_method = method;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Request::SetUri(const std::string& uri)
|
||||
void Http::Request::setUri(const std::string& uri)
|
||||
{
|
||||
m_uRI = uri;
|
||||
m_uri = uri;
|
||||
|
||||
// Make sure it starts with a '/'
|
||||
if (m_uRI.empty() || (m_uRI[0] != '/'))
|
||||
m_uRI.insert(0, "/");
|
||||
if (m_uri.empty() || (m_uri[0] != '/'))
|
||||
m_uri.insert(0, "/");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Request::SetHttpVersion(unsigned int major, unsigned int minor)
|
||||
void Http::Request::setHttpVersion(unsigned int major, unsigned int minor)
|
||||
{
|
||||
m_majorVersion = major;
|
||||
m_minorVersion = minor;
|
||||
|
@ -90,14 +90,14 @@ void Http::Request::SetHttpVersion(unsigned int major, unsigned int minor)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Request::SetBody(const std::string& body)
|
||||
void Http::Request::setBody(const std::string& body)
|
||||
{
|
||||
m_body = body;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string Http::Request::Prepare() const
|
||||
std::string Http::Request::prepare() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
|
@ -112,7 +112,7 @@ std::string Http::Request::Prepare() const
|
|||
}
|
||||
|
||||
// Write the first line containing the request type
|
||||
out << method << " " << m_uRI << " ";
|
||||
out << method << " " << m_uri << " ";
|
||||
out << "HTTP/" << m_majorVersion << "." << m_minorVersion << "\r\n";
|
||||
|
||||
// Write fields
|
||||
|
@ -132,9 +132,9 @@ std::string Http::Request::Prepare() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Http::Request::HasField(const std::string& field) const
|
||||
bool Http::Request::hasField(const std::string& field) const
|
||||
{
|
||||
return m_fields.find(ToLower(field)) != m_fields.end();
|
||||
return m_fields.find(toLower(field)) != m_fields.end();
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,9 +149,9 @@ m_minorVersion(0)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& Http::Response::GetField(const std::string& field) const
|
||||
const std::string& Http::Response::getField(const std::string& field) const
|
||||
{
|
||||
FieldTable::const_iterator it = m_fields.find(ToLower(field));
|
||||
FieldTable::const_iterator it = m_fields.find(toLower(field));
|
||||
if (it != m_fields.end())
|
||||
{
|
||||
return it->second;
|
||||
|
@ -165,35 +165,35 @@ const std::string& Http::Response::GetField(const std::string& field) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Http::Response::Status Http::Response::GetStatus() const
|
||||
Http::Response::Status Http::Response::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Http::Response::GetMajorHttpVersion() const
|
||||
unsigned int Http::Response::getMajorHttpVersion() const
|
||||
{
|
||||
return m_majorVersion;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Http::Response::GetMinorHttpVersion() const
|
||||
unsigned int Http::Response::getMinorHttpVersion() const
|
||||
{
|
||||
return m_minorVersion;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& Http::Response::GetBody() const
|
||||
const std::string& Http::Response::getBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::Response::Parse(const std::string& data)
|
||||
void Http::Response::parse(const std::string& data)
|
||||
{
|
||||
std::istringstream in(data);
|
||||
|
||||
|
@ -202,7 +202,7 @@ void Http::Response::Parse(const std::string& data)
|
|||
if (in >> version)
|
||||
{
|
||||
if ((version.size() >= 8) && (version[6] == '.') &&
|
||||
(ToLower(version.substr(0, 5)) == "http/") &&
|
||||
(toLower(version.substr(0, 5)) == "http/") &&
|
||||
isdigit(version[5]) && isdigit(version[7]))
|
||||
{
|
||||
m_majorVersion = version[5] - '0';
|
||||
|
@ -248,7 +248,7 @@ void Http::Response::Parse(const std::string& data)
|
|||
value.erase(value.size() - 1);
|
||||
|
||||
// Add the field
|
||||
m_fields[ToLower(field)] = value;
|
||||
m_fields[toLower(field)] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,15 +270,15 @@ m_port(0)
|
|||
////////////////////////////////////////////////////////////
|
||||
Http::Http(const std::string& host, unsigned short port)
|
||||
{
|
||||
SetHost(host, port);
|
||||
setHost(host, port);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::SetHost(const std::string& host, unsigned short port)
|
||||
void Http::setHost(const std::string& host, unsigned short port)
|
||||
{
|
||||
// Detect the protocol used
|
||||
std::string protocol = ToLower(host.substr(0, 8));
|
||||
std::string protocol = toLower(host.substr(0, 8));
|
||||
if (protocol.substr(0, 7) == "http://")
|
||||
{
|
||||
// HTTP protocol
|
||||
|
@ -307,67 +307,67 @@ void Http::SetHost(const std::string& host, unsigned short port)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Http::Response Http::SendRequest(const Http::Request& request, Time timeout)
|
||||
Http::Response Http::sendRequest(const Http::Request& request, Time timeout)
|
||||
{
|
||||
// First make sure that the request is valid -- add missing mandatory fields
|
||||
Request toSend(request);
|
||||
if (!toSend.HasField("From"))
|
||||
if (!toSend.hasField("From"))
|
||||
{
|
||||
toSend.SetField("From", "user@sfml-dev.org");
|
||||
toSend.setField("From", "user@sfml-dev.org");
|
||||
}
|
||||
if (!toSend.HasField("User-Agent"))
|
||||
if (!toSend.hasField("User-Agent"))
|
||||
{
|
||||
toSend.SetField("User-Agent", "libsfml-network/2.x");
|
||||
toSend.setField("User-Agent", "libsfml-network/2.x");
|
||||
}
|
||||
if (!toSend.HasField("Host"))
|
||||
if (!toSend.hasField("Host"))
|
||||
{
|
||||
toSend.SetField("Host", m_hostName);
|
||||
toSend.setField("Host", m_hostName);
|
||||
}
|
||||
if (!toSend.HasField("Content-Length"))
|
||||
if (!toSend.hasField("Content-Length"))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << toSend.m_body.size();
|
||||
toSend.SetField("Content-Length", out.str());
|
||||
toSend.setField("Content-Length", out.str());
|
||||
}
|
||||
if ((toSend.m_method == Request::Post) && !toSend.HasField("Content-Type"))
|
||||
if ((toSend.m_method == Request::Post) && !toSend.hasField("Content-Type"))
|
||||
{
|
||||
toSend.SetField("Content-Type", "application/x-www-form-urlencoded");
|
||||
toSend.setField("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
if ((toSend.m_majorVersion * 10 + toSend.m_minorVersion >= 11) && !toSend.HasField("Connection"))
|
||||
if ((toSend.m_majorVersion * 10 + toSend.m_minorVersion >= 11) && !toSend.hasField("Connection"))
|
||||
{
|
||||
toSend.SetField("Connection", "close");
|
||||
toSend.setField("Connection", "close");
|
||||
}
|
||||
|
||||
// Prepare the response
|
||||
Response received;
|
||||
|
||||
// Connect the socket to the host
|
||||
if (m_connection.Connect(m_host, m_port, timeout) == Socket::Done)
|
||||
if (m_connection.connect(m_host, m_port, timeout) == Socket::Done)
|
||||
{
|
||||
// Convert the request to string and send it through the connected socket
|
||||
std::string requestStr = toSend.Prepare();
|
||||
std::string requestStr = toSend.prepare();
|
||||
|
||||
if (!requestStr.empty())
|
||||
{
|
||||
// Send it through the socket
|
||||
if (m_connection.Send(requestStr.c_str(), requestStr.size()) == Socket::Done)
|
||||
if (m_connection.send(requestStr.c_str(), requestStr.size()) == Socket::Done)
|
||||
{
|
||||
// Wait for the server's response
|
||||
std::string receivedStr;
|
||||
std::size_t size = 0;
|
||||
char buffer[1024];
|
||||
while (m_connection.Receive(buffer, sizeof(buffer), size) == Socket::Done)
|
||||
while (m_connection.receive(buffer, sizeof(buffer), size) == Socket::Done)
|
||||
{
|
||||
receivedStr.append(buffer, buffer + size);
|
||||
}
|
||||
|
||||
// Build the Response object from the received data
|
||||
received.Parse(receivedStr);
|
||||
received.parse(receivedStr);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the connection
|
||||
m_connection.Disconnect();
|
||||
m_connection.disconnect();
|
||||
}
|
||||
|
||||
return received;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
sf::Uint32 Resolve(const std::string& address)
|
||||
sf::Uint32 resolve(const std::string& address)
|
||||
{
|
||||
if (address == "255.255.255.255")
|
||||
{
|
||||
|
@ -79,14 +79,14 @@ m_address(0)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress::IpAddress(const std::string& address) :
|
||||
m_address(Resolve(address))
|
||||
m_address(resolve(address))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress::IpAddress(const char* address) :
|
||||
m_address(Resolve(address))
|
||||
m_address(resolve(address))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ m_address(htonl(address))
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string IpAddress::ToString() const
|
||||
std::string IpAddress::toString() const
|
||||
{
|
||||
in_addr address;
|
||||
address.s_addr = m_address;
|
||||
|
@ -116,14 +116,14 @@ std::string IpAddress::ToString() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 IpAddress::ToInteger() const
|
||||
Uint32 IpAddress::toInteger() const
|
||||
{
|
||||
return ntohl(m_address);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress IpAddress::GetLocalAddress()
|
||||
IpAddress IpAddress::getLocalAddress()
|
||||
{
|
||||
// The method here is to connect a UDP socket to anyone (here to localhost),
|
||||
// and get the local socket address with the getsockname function.
|
||||
|
@ -133,14 +133,14 @@ IpAddress IpAddress::GetLocalAddress()
|
|||
|
||||
// Create the socket
|
||||
SocketHandle sock = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (sock == priv::SocketImpl::InvalidSocket())
|
||||
if (sock == priv::SocketImpl::invalidSocket())
|
||||
return localAddress;
|
||||
|
||||
// Connect the socket to localhost on any port
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(ntohl(INADDR_LOOPBACK), 0);
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(ntohl(INADDR_LOOPBACK), 0);
|
||||
if (connect(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
{
|
||||
priv::SocketImpl::Close(sock);
|
||||
priv::SocketImpl::close(sock);
|
||||
return localAddress;
|
||||
}
|
||||
|
||||
|
@ -148,12 +148,12 @@ IpAddress IpAddress::GetLocalAddress()
|
|||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getsockname(sock, reinterpret_cast<sockaddr*>(&address), &size) == -1)
|
||||
{
|
||||
priv::SocketImpl::Close(sock);
|
||||
priv::SocketImpl::close(sock);
|
||||
return localAddress;
|
||||
}
|
||||
|
||||
// Close the socket
|
||||
priv::SocketImpl::Close(sock);
|
||||
priv::SocketImpl::close(sock);
|
||||
|
||||
// Finally build the IP address
|
||||
localAddress = IpAddress(ntohl(address.sin_addr.s_addr));
|
||||
|
@ -163,7 +163,7 @@ IpAddress IpAddress::GetLocalAddress()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress IpAddress::GetPublicAddress(Time timeout)
|
||||
IpAddress IpAddress::getPublicAddress(Time timeout)
|
||||
{
|
||||
// The trick here is more complicated, because the only way
|
||||
// to get our public IP address is to get it from a distant computer.
|
||||
|
@ -173,9 +173,9 @@ IpAddress IpAddress::GetPublicAddress(Time timeout)
|
|||
|
||||
Http server("www.sfml-dev.org");
|
||||
Http::Request request("/ip-provider.php", Http::Request::Get);
|
||||
Http::Response page = server.SendRequest(request, timeout);
|
||||
if (page.GetStatus() == Http::Response::Ok)
|
||||
return IpAddress(page.GetBody());
|
||||
Http::Response page = server.sendRequest(request, timeout);
|
||||
if (page.getStatus() == Http::Response::Ok)
|
||||
return IpAddress(page.getBody());
|
||||
|
||||
// Something failed: return an invalid address
|
||||
return IpAddress();
|
||||
|
@ -185,7 +185,7 @@ IpAddress IpAddress::GetPublicAddress(Time timeout)
|
|||
////////////////////////////////////////////////////////////
|
||||
bool operator ==(const IpAddress& left, const IpAddress& right)
|
||||
{
|
||||
return left.ToInteger() == right.ToInteger();
|
||||
return left.toInteger() == right.toInteger();
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,7 +199,7 @@ bool operator !=(const IpAddress& left, const IpAddress& right)
|
|||
////////////////////////////////////////////////////////////
|
||||
bool operator <(const IpAddress& left, const IpAddress& right)
|
||||
{
|
||||
return left.ToInteger() < right.ToInteger();
|
||||
return left.toInteger() < right.toInteger();
|
||||
}
|
||||
|
||||
|
||||
|
@ -238,7 +238,7 @@ std::istream& operator >>(std::istream& stream, IpAddress& address)
|
|||
////////////////////////////////////////////////////////////
|
||||
std::ostream& operator <<(std::ostream& stream, const IpAddress& address)
|
||||
{
|
||||
return stream << address.ToString();
|
||||
return stream << address.toString();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -50,7 +50,7 @@ Packet::~Packet()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Packet::Append(const void* data, std::size_t sizeInBytes)
|
||||
void Packet::append(const void* data, std::size_t sizeInBytes)
|
||||
{
|
||||
if (data && (sizeInBytes > 0))
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ void Packet::Append(const void* data, std::size_t sizeInBytes)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Packet::Clear()
|
||||
void Packet::clear()
|
||||
{
|
||||
m_data.clear();
|
||||
m_readPos = 0;
|
||||
|
@ -71,21 +71,21 @@ void Packet::Clear()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* Packet::GetData() const
|
||||
const char* Packet::getData() const
|
||||
{
|
||||
return !m_data.empty() ? &m_data[0] : NULL;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t Packet::GetDataSize() const
|
||||
std::size_t Packet::getDataSize() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Packet::EndOfPacket() const
|
||||
bool Packet::endOfPacket() const
|
||||
{
|
||||
return m_readPos >= m_data.size();
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ bool Packet::EndOfPacket() const
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet::operator BoolType() const
|
||||
{
|
||||
return m_isValid ? &Packet::CheckSize : NULL;
|
||||
return m_isValid ? &Packet::checkSize : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,9 +112,9 @@ Packet& Packet::operator >>(bool& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Int8& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const Int8*>(GetData() + m_readPos);
|
||||
data = *reinterpret_cast<const Int8*>(getData() + m_readPos);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -125,9 +125,9 @@ Packet& Packet::operator >>(Int8& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Uint8& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const Uint8*>(GetData() + m_readPos);
|
||||
data = *reinterpret_cast<const Uint8*>(getData() + m_readPos);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -138,9 +138,9 @@ Packet& Packet::operator >>(Uint8& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Int16& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohs(*reinterpret_cast<const Int16*>(GetData() + m_readPos));
|
||||
data = ntohs(*reinterpret_cast<const Int16*>(getData() + m_readPos));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,9 @@ Packet& Packet::operator >>(Int16& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Uint16& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohs(*reinterpret_cast<const Uint16*>(GetData() + m_readPos));
|
||||
data = ntohs(*reinterpret_cast<const Uint16*>(getData() + m_readPos));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -164,9 +164,9 @@ Packet& Packet::operator >>(Uint16& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Int32& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohl(*reinterpret_cast<const Int32*>(GetData() + m_readPos));
|
||||
data = ntohl(*reinterpret_cast<const Int32*>(getData() + m_readPos));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -177,9 +177,9 @@ Packet& Packet::operator >>(Int32& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(Uint32& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohl(*reinterpret_cast<const Uint32*>(GetData() + m_readPos));
|
||||
data = ntohl(*reinterpret_cast<const Uint32*>(getData() + m_readPos));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -190,9 +190,9 @@ Packet& Packet::operator >>(Uint32& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(float& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const float*>(GetData() + m_readPos);
|
||||
data = *reinterpret_cast<const float*>(getData() + m_readPos);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -203,9 +203,9 @@ Packet& Packet::operator >>(float& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator >>(double& data)
|
||||
{
|
||||
if (CheckSize(sizeof(data)))
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const double*>(GetData() + m_readPos);
|
||||
data = *reinterpret_cast<const double*>(getData() + m_readPos);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -220,10 +220,10 @@ Packet& Packet::operator >>(char* data)
|
|||
Uint32 length = 0;
|
||||
*this >> length;
|
||||
|
||||
if ((length > 0) && CheckSize(length))
|
||||
if ((length > 0) && checkSize(length))
|
||||
{
|
||||
// Then extract characters
|
||||
std::memcpy(data, GetData() + m_readPos, length);
|
||||
std::memcpy(data, getData() + m_readPos, length);
|
||||
data[length] = '\0';
|
||||
|
||||
// Update reading position
|
||||
|
@ -242,10 +242,10 @@ Packet& Packet::operator >>(std::string& data)
|
|||
*this >> length;
|
||||
|
||||
data.clear();
|
||||
if ((length > 0) && CheckSize(length))
|
||||
if ((length > 0) && checkSize(length))
|
||||
{
|
||||
// Then extract characters
|
||||
data.assign(GetData() + m_readPos, length);
|
||||
data.assign(getData() + m_readPos, length);
|
||||
|
||||
// Update reading position
|
||||
m_readPos += length;
|
||||
|
@ -262,7 +262,7 @@ Packet& Packet::operator >>(wchar_t* data)
|
|||
Uint32 length = 0;
|
||||
*this >> length;
|
||||
|
||||
if ((length > 0) && CheckSize(length * sizeof(Uint32)))
|
||||
if ((length > 0) && checkSize(length * sizeof(Uint32)))
|
||||
{
|
||||
// Then extract characters
|
||||
for (Uint32 i = 0; i < length; ++i)
|
||||
|
@ -286,7 +286,7 @@ Packet& Packet::operator >>(std::wstring& data)
|
|||
*this >> length;
|
||||
|
||||
data.clear();
|
||||
if ((length > 0) && CheckSize(length * sizeof(Uint32)))
|
||||
if ((length > 0) && checkSize(length * sizeof(Uint32)))
|
||||
{
|
||||
// Then extract characters
|
||||
for (Uint32 i = 0; i < length; ++i)
|
||||
|
@ -308,8 +308,8 @@ Packet& Packet::operator >>(String& data)
|
|||
Uint32 length = 0;
|
||||
*this >> length;
|
||||
|
||||
data.Clear();
|
||||
if ((length > 0) && CheckSize(length * sizeof(Uint32)))
|
||||
data.clear();
|
||||
if ((length > 0) && checkSize(length * sizeof(Uint32)))
|
||||
{
|
||||
// Then extract characters
|
||||
for (Uint32 i = 0; i < length; ++i)
|
||||
|
@ -335,7 +335,7 @@ Packet& Packet::operator <<(bool data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator <<(Int8 data)
|
||||
{
|
||||
Append(&data, sizeof(data));
|
||||
append(&data, sizeof(data));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,7 @@ Packet& Packet::operator <<(Int8 data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator <<(Uint8 data)
|
||||
{
|
||||
Append(&data, sizeof(data));
|
||||
append(&data, sizeof(data));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ Packet& Packet::operator <<(Uint8 data)
|
|||
Packet& Packet::operator <<(Int16 data)
|
||||
{
|
||||
Int16 toWrite = htons(data);
|
||||
Append(&toWrite, sizeof(toWrite));
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ Packet& Packet::operator <<(Int16 data)
|
|||
Packet& Packet::operator <<(Uint16 data)
|
||||
{
|
||||
Uint16 toWrite = htons(data);
|
||||
Append(&toWrite, sizeof(toWrite));
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -370,7 +370,7 @@ Packet& Packet::operator <<(Uint16 data)
|
|||
Packet& Packet::operator <<(Int32 data)
|
||||
{
|
||||
Int32 toWrite = htonl(data);
|
||||
Append(&toWrite, sizeof(toWrite));
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ Packet& Packet::operator <<(Int32 data)
|
|||
Packet& Packet::operator <<(Uint32 data)
|
||||
{
|
||||
Uint32 toWrite = htonl(data);
|
||||
Append(&toWrite, sizeof(toWrite));
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ Packet& Packet::operator <<(Uint32 data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator <<(float data)
|
||||
{
|
||||
Append(&data, sizeof(data));
|
||||
append(&data, sizeof(data));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ Packet& Packet::operator <<(float data)
|
|||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator <<(double data)
|
||||
{
|
||||
Append(&data, sizeof(data));
|
||||
append(&data, sizeof(data));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ Packet& Packet::operator <<(const char* data)
|
|||
*this << length;
|
||||
|
||||
// Then insert characters
|
||||
Append(data, length * sizeof(char));
|
||||
append(data, length * sizeof(char));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ Packet& Packet::operator <<(const std::string& data)
|
|||
// Then insert characters
|
||||
if (length > 0)
|
||||
{
|
||||
Append(data.c_str(), length * sizeof(std::string::value_type));
|
||||
append(data.c_str(), length * sizeof(std::string::value_type));
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
@ -472,13 +472,13 @@ Packet& Packet::operator <<(const std::wstring& data)
|
|||
Packet& Packet::operator <<(const String& data)
|
||||
{
|
||||
// First insert the string length
|
||||
Uint32 length = static_cast<Uint32>(data.GetSize());
|
||||
Uint32 length = static_cast<Uint32>(data.getSize());
|
||||
*this << length;
|
||||
|
||||
// Then insert characters
|
||||
if (length > 0)
|
||||
{
|
||||
for (String::ConstIterator c = data.Begin(); c != data.End(); ++c)
|
||||
for (String::ConstIterator c = data.begin(); c != data.end(); ++c)
|
||||
*this << *c;
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ Packet& Packet::operator <<(const String& data)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Packet::CheckSize(std::size_t size)
|
||||
bool Packet::checkSize(std::size_t size)
|
||||
{
|
||||
m_isValid = m_isValid && (m_readPos + size <= m_data.size());
|
||||
|
||||
|
@ -496,17 +496,17 @@ bool Packet::CheckSize(std::size_t size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* Packet::OnSend(std::size_t& size)
|
||||
const char* Packet::onSend(std::size_t& size)
|
||||
{
|
||||
size = GetDataSize();
|
||||
return GetData();
|
||||
size = getDataSize();
|
||||
return getData();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Packet::OnReceive(const char* data, std::size_t size)
|
||||
void Packet::onReceive(const char* data, std::size_t size)
|
||||
{
|
||||
Append(data, size);
|
||||
append(data, size);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Socket::Socket(Type type) :
|
||||
m_type (type),
|
||||
m_socket (priv::SocketImpl::InvalidSocket()),
|
||||
m_socket (priv::SocketImpl::invalidSocket()),
|
||||
m_isBlocking(true)
|
||||
{
|
||||
|
||||
|
@ -46,58 +46,58 @@ m_isBlocking(true)
|
|||
Socket::~Socket()
|
||||
{
|
||||
// Close the socket before it gets destructed
|
||||
Close();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Socket::SetBlocking(bool blocking)
|
||||
void Socket::setBlocking(bool blocking)
|
||||
{
|
||||
// Apply if the socket is already created
|
||||
if (m_socket != priv::SocketImpl::InvalidSocket())
|
||||
priv::SocketImpl::SetBlocking(m_socket, blocking);
|
||||
if (m_socket != priv::SocketImpl::invalidSocket())
|
||||
priv::SocketImpl::setBlocking(m_socket, blocking);
|
||||
|
||||
m_isBlocking = blocking;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Socket::IsBlocking() const
|
||||
bool Socket::isBlocking() const
|
||||
{
|
||||
return m_isBlocking;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketHandle Socket::GetHandle() const
|
||||
SocketHandle Socket::getHandle() const
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Socket::Create()
|
||||
void Socket::create()
|
||||
{
|
||||
// Don't create the socket if it already exists
|
||||
if (m_socket == priv::SocketImpl::InvalidSocket())
|
||||
if (m_socket == priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
SocketHandle handle = socket(PF_INET, m_type == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
|
||||
Create(handle);
|
||||
create(handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Socket::Create(SocketHandle handle)
|
||||
void Socket::create(SocketHandle handle)
|
||||
{
|
||||
// Don't create the socket if it already exists
|
||||
if (m_socket == priv::SocketImpl::InvalidSocket())
|
||||
if (m_socket == priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Assign the new handle
|
||||
m_socket = handle;
|
||||
|
||||
// Set the current blocking state
|
||||
SetBlocking(m_isBlocking);
|
||||
setBlocking(m_isBlocking);
|
||||
|
||||
if (m_type == Tcp)
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ void Socket::Create(SocketHandle handle)
|
|||
int yes = 1;
|
||||
if (setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
Err() << "Failed to set socket option \"TCP_NODELAY\" ; "
|
||||
err() << "Failed to set socket option \"TCP_NODELAY\" ; "
|
||||
<< "all your TCP packets will be buffered" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ void Socket::Create(SocketHandle handle)
|
|||
int yes = 1;
|
||||
if (setsockopt(m_socket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
Err() << "Failed to enable broadcast on UDP socket" << std::endl;
|
||||
err() << "Failed to enable broadcast on UDP socket" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,13 +123,13 @@ void Socket::Create(SocketHandle handle)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Socket::Close()
|
||||
void Socket::close()
|
||||
{
|
||||
// Close the socket
|
||||
if (m_socket != priv::SocketImpl::InvalidSocket())
|
||||
if (m_socket != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
priv::SocketImpl::Close(m_socket);
|
||||
m_socket = priv::SocketImpl::InvalidSocket();
|
||||
priv::SocketImpl::close(m_socket);
|
||||
m_socket = priv::SocketImpl::invalidSocket();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ struct SocketSelector::SocketSelectorImpl
|
|||
SocketSelector::SocketSelector() :
|
||||
m_impl(new SocketSelectorImpl)
|
||||
{
|
||||
Clear();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,26 +71,26 @@ SocketSelector::~SocketSelector()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketSelector::Add(Socket& socket)
|
||||
void SocketSelector::add(Socket& socket)
|
||||
{
|
||||
FD_SET(socket.GetHandle(), &m_impl->AllSockets);
|
||||
FD_SET(socket.getHandle(), &m_impl->AllSockets);
|
||||
|
||||
int size = static_cast<int>(socket.GetHandle());
|
||||
int size = static_cast<int>(socket.getHandle());
|
||||
if (size > m_impl->MaxSocket)
|
||||
m_impl->MaxSocket = size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketSelector::Remove(Socket& socket)
|
||||
void SocketSelector::remove(Socket& socket)
|
||||
{
|
||||
FD_CLR(socket.GetHandle(), &m_impl->AllSockets);
|
||||
FD_CLR(socket.GetHandle(), &m_impl->SocketsReady);
|
||||
FD_CLR(socket.getHandle(), &m_impl->AllSockets);
|
||||
FD_CLR(socket.getHandle(), &m_impl->SocketsReady);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketSelector::Clear()
|
||||
void SocketSelector::clear()
|
||||
{
|
||||
FD_ZERO(&m_impl->AllSockets);
|
||||
FD_ZERO(&m_impl->SocketsReady);
|
||||
|
@ -100,12 +100,12 @@ void SocketSelector::Clear()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SocketSelector::Wait(Time timeout)
|
||||
bool SocketSelector::wait(Time timeout)
|
||||
{
|
||||
// Setup the timeout
|
||||
timeval time;
|
||||
time.tv_sec = static_cast<long>(timeout.AsMicroseconds() / 1000000);
|
||||
time.tv_usec = static_cast<long>(timeout.AsMicroseconds() % 1000000);
|
||||
time.tv_sec = static_cast<long>(timeout.asMicroseconds() / 1000000);
|
||||
time.tv_usec = static_cast<long>(timeout.asMicroseconds() % 1000000);
|
||||
|
||||
// Initialize the set that will contain the sockets that are ready
|
||||
m_impl->SocketsReady = m_impl->AllSockets;
|
||||
|
@ -118,9 +118,9 @@ bool SocketSelector::Wait(Time timeout)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SocketSelector::IsReady(Socket& socket) const
|
||||
bool SocketSelector::isReady(Socket& socket) const
|
||||
{
|
||||
return FD_ISSET(socket.GetHandle(), &m_impl->SocketsReady) != 0;
|
||||
return FD_ISSET(socket.getHandle(), &m_impl->SocketsReady) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,14 +42,14 @@ Socket(Tcp)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short TcpListener::GetLocalPort() const
|
||||
unsigned short TcpListener::getLocalPort() const
|
||||
{
|
||||
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Retrieve informations about the local end of the socket
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getsockname(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
if (getsockname(getHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
{
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
|
@ -61,25 +61,25 @@ unsigned short TcpListener::GetLocalPort() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpListener::Listen(unsigned short port)
|
||||
Socket::Status TcpListener::listen(unsigned short port)
|
||||
{
|
||||
// Create the internal socket if it doesn't exist
|
||||
Create();
|
||||
create();
|
||||
|
||||
// Bind the socket to the specified port
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(INADDR_ANY, port);
|
||||
if (bind(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(INADDR_ANY, port);
|
||||
if (bind(getHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
{
|
||||
// Not likely to happen, but...
|
||||
Err() << "Failed to bind listener socket to port " << port << std::endl;
|
||||
err() << "Failed to bind listener socket to port " << port << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Listen to the bound port
|
||||
if (listen(GetHandle(), 0) == -1)
|
||||
if (::listen(getHandle(), 0) == -1)
|
||||
{
|
||||
// Oops, socket is deaf
|
||||
Err() << "Failed to listen to port " << port << std::endl;
|
||||
err() << "Failed to listen to port " << port << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
@ -88,35 +88,35 @@ Socket::Status TcpListener::Listen(unsigned short port)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void TcpListener::Close()
|
||||
void TcpListener::close()
|
||||
{
|
||||
// Simply close the socket
|
||||
Socket::Close();
|
||||
Socket::close();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpListener::Accept(TcpSocket& socket)
|
||||
Socket::Status TcpListener::accept(TcpSocket& socket)
|
||||
{
|
||||
// Make sure that we're listening
|
||||
if (GetHandle() == priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() == priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
Err() << "Failed to accept a new connection, the socket is not listening" << std::endl;
|
||||
err() << "Failed to accept a new connection, the socket is not listening" << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Accept a new connection
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength length = sizeof(address);
|
||||
SocketHandle remote = accept(GetHandle(), reinterpret_cast<sockaddr*>(&address), &length);
|
||||
SocketHandle remote = ::accept(getHandle(), reinterpret_cast<sockaddr*>(&address), &length);
|
||||
|
||||
// Check for errors
|
||||
if (remote == priv::SocketImpl::InvalidSocket())
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
if (remote == priv::SocketImpl::invalidSocket())
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
|
||||
// Initialize the new connected socket
|
||||
socket.Close();
|
||||
socket.Create(remote);
|
||||
socket.close();
|
||||
socket.create(remote);
|
||||
|
||||
return Done;
|
||||
}
|
||||
|
|
|
@ -49,14 +49,14 @@ Socket(Tcp)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short TcpSocket::GetLocalPort() const
|
||||
unsigned short TcpSocket::getLocalPort() const
|
||||
{
|
||||
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Retrieve informations about the local end of the socket
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getsockname(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
if (getsockname(getHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
{
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
|
@ -68,14 +68,14 @@ unsigned short TcpSocket::GetLocalPort() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress TcpSocket::GetRemoteAddress() const
|
||||
IpAddress TcpSocket::getRemoteAddress() const
|
||||
{
|
||||
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Retrieve informations about the remote end of the socket
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getpeername(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
if (getpeername(getHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
{
|
||||
return IpAddress(ntohl(address.sin_addr.s_addr));
|
||||
}
|
||||
|
@ -87,14 +87,14 @@ IpAddress TcpSocket::GetRemoteAddress() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short TcpSocket::GetRemotePort() const
|
||||
unsigned short TcpSocket::getRemotePort() const
|
||||
{
|
||||
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Retrieve informations about the remote end of the socket
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getpeername(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
if (getpeername(getHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
{
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
|
@ -106,21 +106,21 @@ unsigned short TcpSocket::GetRemotePort() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout)
|
||||
Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout)
|
||||
{
|
||||
// Create the internal socket if it doesn't exist
|
||||
Create();
|
||||
create();
|
||||
|
||||
// Create the remote address
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort);
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
||||
|
||||
if (timeout <= Time::Zero)
|
||||
{
|
||||
// ----- We're not using a timeout: just try to connect -----
|
||||
|
||||
// Connect the socket
|
||||
if (connect(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
if (::connect(getHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
|
||||
// Connection succeeded
|
||||
return Done;
|
||||
|
@ -130,21 +130,21 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
// ----- We're using a timeout: we'll need a few tricks to make it work -----
|
||||
|
||||
// Save the previous blocking state
|
||||
bool blocking = IsBlocking();
|
||||
bool blocking = isBlocking();
|
||||
|
||||
// Switch to non-blocking to enable our connection timeout
|
||||
if (blocking)
|
||||
SetBlocking(false);
|
||||
setBlocking(false);
|
||||
|
||||
// Try to connect to the remote address
|
||||
if (connect(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) >= 0)
|
||||
if (::connect(getHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) >= 0)
|
||||
{
|
||||
// We got instantly connected! (it may no happen a lot...)
|
||||
return Done;
|
||||
}
|
||||
|
||||
// Get the error status
|
||||
Status status = priv::SocketImpl::GetErrorStatus();
|
||||
Status status = priv::SocketImpl::getErrorStatus();
|
||||
|
||||
// If we were in non-blocking mode, return immediatly
|
||||
if (!blocking)
|
||||
|
@ -156,19 +156,19 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
// Setup the selector
|
||||
fd_set selector;
|
||||
FD_ZERO(&selector);
|
||||
FD_SET(GetHandle(), &selector);
|
||||
FD_SET(getHandle(), &selector);
|
||||
|
||||
// Setup the timeout
|
||||
timeval time;
|
||||
time.tv_sec = static_cast<long>(timeout.AsMicroseconds() / 1000000);
|
||||
time.tv_usec = static_cast<long>(timeout.AsMicroseconds() % 1000000);
|
||||
time.tv_sec = static_cast<long>(timeout.asMicroseconds() / 1000000);
|
||||
time.tv_usec = static_cast<long>(timeout.asMicroseconds() % 1000000);
|
||||
|
||||
// Wait for something to write on our socket (which means that the connection request has returned)
|
||||
if (select(static_cast<int>(GetHandle() + 1), NULL, &selector, NULL, &time) > 0)
|
||||
if (select(static_cast<int>(getHandle() + 1), NULL, &selector, NULL, &time) > 0)
|
||||
{
|
||||
// At this point the connection may have been either accepted or refused.
|
||||
// To know whether it's a success or a failure, we must check the address of the connected peer
|
||||
if (GetRemoteAddress() != sf::IpAddress::None)
|
||||
if (getRemoteAddress() != sf::IpAddress::None)
|
||||
{
|
||||
// Connection accepted
|
||||
status = Done;
|
||||
|
@ -176,18 +176,18 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
else
|
||||
{
|
||||
// Connection refused
|
||||
status = priv::SocketImpl::GetErrorStatus();
|
||||
status = priv::SocketImpl::getErrorStatus();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed to connect before timeout is over
|
||||
status = priv::SocketImpl::GetErrorStatus();
|
||||
status = priv::SocketImpl::getErrorStatus();
|
||||
}
|
||||
}
|
||||
|
||||
// Switch back to blocking mode
|
||||
SetBlocking(true);
|
||||
setBlocking(true);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -195,10 +195,10 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void TcpSocket::Disconnect()
|
||||
void TcpSocket::disconnect()
|
||||
{
|
||||
// Close the socket
|
||||
Close();
|
||||
close();
|
||||
|
||||
// Reset the pending packet data
|
||||
m_pendingPacket = PendingPacket();
|
||||
|
@ -206,12 +206,12 @@ void TcpSocket::Disconnect()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::Send(const char* data, std::size_t size)
|
||||
Socket::Status TcpSocket::send(const char* data, std::size_t size)
|
||||
{
|
||||
// Check the parameters
|
||||
if (!data || (size == 0))
|
||||
{
|
||||
Err() << "Cannot send data over the network (no data to send)" << std::endl;
|
||||
err() << "Cannot send data over the network (no data to send)" << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
@ -221,11 +221,11 @@ Socket::Status TcpSocket::Send(const char* data, std::size_t size)
|
|||
for (int length = 0; length < sizeToSend; length += sent)
|
||||
{
|
||||
// Send a chunk of data
|
||||
sent = send(GetHandle(), data + length, sizeToSend - length, 0);
|
||||
sent = ::send(getHandle(), data + length, sizeToSend - length, 0);
|
||||
|
||||
// Check for errors
|
||||
if (sent < 0)
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
}
|
||||
|
||||
return Done;
|
||||
|
@ -233,7 +233,7 @@ Socket::Status TcpSocket::Send(const char* data, std::size_t size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::Receive(char* data, std::size_t size, std::size_t& received)
|
||||
Socket::Status TcpSocket::receive(char* data, std::size_t size, std::size_t& received)
|
||||
{
|
||||
// First clear the variables to fill
|
||||
received = 0;
|
||||
|
@ -241,12 +241,12 @@ Socket::Status TcpSocket::Receive(char* data, std::size_t size, std::size_t& rec
|
|||
// Check the destination buffer
|
||||
if (!data)
|
||||
{
|
||||
Err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
||||
err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Receive a chunk of bytes
|
||||
int sizeReceived = recv(GetHandle(), data, static_cast<int>(size), 0);
|
||||
int sizeReceived = recv(getHandle(), data, static_cast<int>(size), 0);
|
||||
|
||||
// Check the number of bytes received
|
||||
if (sizeReceived > 0)
|
||||
|
@ -260,13 +260,13 @@ Socket::Status TcpSocket::Receive(char* data, std::size_t size, std::size_t& rec
|
|||
}
|
||||
else
|
||||
{
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::Send(Packet& packet)
|
||||
Socket::Status TcpSocket::send(Packet& packet)
|
||||
{
|
||||
// TCP is a stream protocol, it doesn't preserve messages boundaries.
|
||||
// This means that we have to send the packet size first, so that the
|
||||
|
@ -274,11 +274,11 @@ Socket::Status TcpSocket::Send(Packet& packet)
|
|||
|
||||
// Get the data to send from the packet
|
||||
std::size_t size = 0;
|
||||
const char* data = packet.OnSend(size);
|
||||
const char* data = packet.onSend(size);
|
||||
|
||||
// First send the packet size
|
||||
Uint32 packetSize = htonl(static_cast<Uint32>(size));
|
||||
Status status = Send(reinterpret_cast<const char*>(&packetSize), sizeof(packetSize));
|
||||
Status status = send(reinterpret_cast<const char*>(&packetSize), sizeof(packetSize));
|
||||
|
||||
// Make sure that the size was properly sent
|
||||
if (status != Done)
|
||||
|
@ -287,7 +287,7 @@ Socket::Status TcpSocket::Send(Packet& packet)
|
|||
// Send the packet data
|
||||
if (packetSize > 0)
|
||||
{
|
||||
return Send(data, size);
|
||||
return send(data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -297,10 +297,10 @@ Socket::Status TcpSocket::Send(Packet& packet)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::Receive(Packet& packet)
|
||||
Socket::Status TcpSocket::receive(Packet& packet)
|
||||
{
|
||||
// First clear the variables to fill
|
||||
packet.Clear();
|
||||
packet.clear();
|
||||
|
||||
// We start by getting the size of the incoming packet
|
||||
Uint32 packetSize = 0;
|
||||
|
@ -312,7 +312,7 @@ Socket::Status TcpSocket::Receive(Packet& packet)
|
|||
while (m_pendingPacket.SizeReceived < sizeof(m_pendingPacket.Size))
|
||||
{
|
||||
char* data = reinterpret_cast<char*>(&m_pendingPacket.Size) + m_pendingPacket.SizeReceived;
|
||||
Status status = Receive(data, sizeof(m_pendingPacket.Size) - m_pendingPacket.SizeReceived, received);
|
||||
Status status = receive(data, sizeof(m_pendingPacket.Size) - m_pendingPacket.SizeReceived, received);
|
||||
m_pendingPacket.SizeReceived += received;
|
||||
|
||||
if (status != Done)
|
||||
|
@ -334,7 +334,7 @@ Socket::Status TcpSocket::Receive(Packet& packet)
|
|||
{
|
||||
// Receive a chunk of data
|
||||
std::size_t sizeToGet = std::min(static_cast<std::size_t>(packetSize - m_pendingPacket.Data.size()), sizeof(buffer));
|
||||
Status status = Receive(buffer, sizeToGet, received);
|
||||
Status status = receive(buffer, sizeToGet, received);
|
||||
if (status != Done)
|
||||
return status;
|
||||
|
||||
|
@ -349,7 +349,7 @@ Socket::Status TcpSocket::Receive(Packet& packet)
|
|||
|
||||
// We have received all the packet data: we can copy it to the user packet
|
||||
if (!m_pendingPacket.Data.empty())
|
||||
packet.OnReceive(&m_pendingPacket.Data[0], m_pendingPacket.Data.size());
|
||||
packet.onReceive(&m_pendingPacket.Data[0], m_pendingPacket.Data.size());
|
||||
|
||||
// Clear the pending packet data
|
||||
m_pendingPacket = PendingPacket();
|
||||
|
|
|
@ -45,14 +45,14 @@ m_buffer(MaxDatagramSize)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short UdpSocket::GetLocalPort() const
|
||||
unsigned short UdpSocket::getLocalPort() const
|
||||
{
|
||||
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||
if (getHandle() != priv::SocketImpl::invalidSocket())
|
||||
{
|
||||
// Retrieve informations about the local end of the socket
|
||||
sockaddr_in address;
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getsockname(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
if (getsockname(getHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||
{
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
|
@ -64,16 +64,16 @@ unsigned short UdpSocket::GetLocalPort() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::Bind(unsigned short port)
|
||||
Socket::Status UdpSocket::bind(unsigned short port)
|
||||
{
|
||||
// Create the internal socket if it doesn't exist
|
||||
Create();
|
||||
create();
|
||||
|
||||
// Bind the socket
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(INADDR_ANY, port);
|
||||
if (bind(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(INADDR_ANY, port);
|
||||
if (::bind(getHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
{
|
||||
Err() << "Failed to bind socket to port " << port << std::endl;
|
||||
err() << "Failed to bind socket to port " << port << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
@ -82,43 +82,43 @@ Socket::Status UdpSocket::Bind(unsigned short port)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void UdpSocket::Unbind()
|
||||
void UdpSocket::unbind()
|
||||
{
|
||||
// Simply close the socket
|
||||
Close();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::Send(const char* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
Socket::Status UdpSocket::send(const char* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
{
|
||||
// Create the internal socket if it doesn't exist
|
||||
Create();
|
||||
create();
|
||||
|
||||
// Make sure that all the data will fit in one datagram
|
||||
if (size > MaxDatagramSize)
|
||||
{
|
||||
Err() << "Cannot send data over the network "
|
||||
err() << "Cannot send data over the network "
|
||||
<< "(the number of bytes to send is greater than sf::UdpSocket::MaxDatagramSize)" << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Build the target address
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort);
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
||||
|
||||
// Send the data (unlike TCP, all the data is always sent in one call)
|
||||
int sent = sendto(GetHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
|
||||
int sent = sendto(getHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
|
||||
|
||||
// Check for errors
|
||||
if (sent < 0)
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
|
||||
return Done;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::Receive(char* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
Socket::Status UdpSocket::receive(char* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
{
|
||||
// First clear the variables to fill
|
||||
received = 0;
|
||||
|
@ -128,20 +128,20 @@ Socket::Status UdpSocket::Receive(char* data, std::size_t size, std::size_t& rec
|
|||
// Check the destination buffer
|
||||
if (!data)
|
||||
{
|
||||
Err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
||||
err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Data that will be filled with the other computer's address
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(INADDR_ANY, 0);
|
||||
sockaddr_in address = priv::SocketImpl::createAddress(INADDR_ANY, 0);
|
||||
|
||||
// Receive a chunk of bytes
|
||||
priv::SocketImpl::AddrLength addressSize = sizeof(address);
|
||||
int sizeReceived = recvfrom(GetHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
|
||||
int sizeReceived = recvfrom(getHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
|
||||
|
||||
// Check for errors
|
||||
if (sizeReceived < 0)
|
||||
return priv::SocketImpl::GetErrorStatus();
|
||||
return priv::SocketImpl::getErrorStatus();
|
||||
|
||||
// Fill the sender informations
|
||||
received = static_cast<std::size_t>(sizeReceived);
|
||||
|
@ -153,7 +153,7 @@ Socket::Status UdpSocket::Receive(char* data, std::size_t size, std::size_t& rec
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::Send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
Socket::Status UdpSocket::send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
{
|
||||
// UDP is a datagram-oriented protocol (as opposed to TCP which is a stream protocol).
|
||||
// Sending one datagram is almost safe: it may be lost but if it's received, then its data
|
||||
|
@ -165,26 +165,26 @@ Socket::Status UdpSocket::Send(Packet& packet, const IpAddress& remoteAddress, u
|
|||
|
||||
// Get the data to send from the packet
|
||||
std::size_t size = 0;
|
||||
const char* data = packet.OnSend(size);
|
||||
const char* data = packet.onSend(size);
|
||||
|
||||
// Send it
|
||||
return Send(data, size, remoteAddress, remotePort);
|
||||
return send(data, size, remoteAddress, remotePort);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::Receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
Socket::Status UdpSocket::receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
{
|
||||
// See the detailed comment in Send(Packet) above.
|
||||
// See the detailed comment in send(Packet) above.
|
||||
|
||||
// Receive the datagram
|
||||
std::size_t received = 0;
|
||||
Status status = Receive(&m_buffer[0], m_buffer.size(), received, remoteAddress, remotePort);
|
||||
Status status = receive(&m_buffer[0], m_buffer.size(), received, remoteAddress, remotePort);
|
||||
|
||||
// If we received valid data, we can copy it to the user packet
|
||||
packet.Clear();
|
||||
packet.clear();
|
||||
if ((status == Done) && (received > 0))
|
||||
packet.OnReceive(&m_buffer[0], received);
|
||||
packet.onReceive(&m_buffer[0], received);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
||||
sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
|
||||
|
@ -49,21 +49,21 @@ sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketHandle SocketImpl::InvalidSocket()
|
||||
SocketHandle SocketImpl::invalidSocket()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketImpl::Close(SocketHandle sock)
|
||||
void SocketImpl::close(SocketHandle sock)
|
||||
{
|
||||
close(sock);
|
||||
::close(sock);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketImpl::SetBlocking(SocketHandle sock, bool block)
|
||||
void SocketImpl::setBlocking(SocketHandle sock, bool block)
|
||||
{
|
||||
int status = fcntl(sock, F_GETFL);
|
||||
if (block)
|
||||
|
@ -74,7 +74,7 @@ void SocketImpl::SetBlocking(SocketHandle sock, bool block)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status SocketImpl::GetErrorStatus()
|
||||
Socket::Status SocketImpl::getErrorStatus()
|
||||
{
|
||||
// The followings are sometimes equal to EWOULDBLOCK,
|
||||
// so we have to make a special case for them in order
|
||||
|
|
|
@ -65,7 +65,7 @@ public :
|
|||
/// \return sockaddr_in ready to be used by socket functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static sockaddr_in CreateAddress(Uint32 address, unsigned short port);
|
||||
static sockaddr_in createAddress(Uint32 address, unsigned short port);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the value of the invalid socket
|
||||
|
@ -73,7 +73,7 @@ public :
|
|||
/// \return Special value of the invalid socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static SocketHandle InvalidSocket();
|
||||
static SocketHandle invalidSocket();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close and destroy a socket
|
||||
|
@ -81,7 +81,7 @@ public :
|
|||
/// \param sock Handle of the socket to close
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void Close(SocketHandle sock);
|
||||
static void close(SocketHandle sock);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set a socket as blocking or non-blocking
|
||||
|
@ -90,7 +90,7 @@ public :
|
|||
/// \param block New blocking state of the socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetBlocking(SocketHandle sock, bool block);
|
||||
static void setBlocking(SocketHandle sock, bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the last socket error status
|
||||
|
@ -98,7 +98,7 @@ public :
|
|||
/// \return Status corresponding to the last socket error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Socket::Status GetErrorStatus();
|
||||
static Socket::Status getErrorStatus();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
||||
sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
|
||||
|
@ -47,21 +47,21 @@ sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketHandle SocketImpl::InvalidSocket()
|
||||
SocketHandle SocketImpl::invalidSocket()
|
||||
{
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketImpl::Close(SocketHandle sock)
|
||||
void SocketImpl::close(SocketHandle sock)
|
||||
{
|
||||
closesocket(sock);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SocketImpl::SetBlocking(SocketHandle sock, bool block)
|
||||
void SocketImpl::setBlocking(SocketHandle sock, bool block)
|
||||
{
|
||||
u_long blocking = block ? 0 : 1;
|
||||
ioctlsocket(sock, FIONBIO, &blocking);
|
||||
|
@ -69,7 +69,7 @@ void SocketImpl::SetBlocking(SocketHandle sock, bool block)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status SocketImpl::GetErrorStatus()
|
||||
Socket::Status SocketImpl::getErrorStatus()
|
||||
{
|
||||
switch (WSAGetLastError())
|
||||
{
|
||||
|
|
|
@ -59,7 +59,7 @@ public :
|
|||
/// \return sockaddr_in ready to be used by socket functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static sockaddr_in CreateAddress(Uint32 address, unsigned short port);
|
||||
static sockaddr_in createAddress(Uint32 address, unsigned short port);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the value of the invalid socket
|
||||
|
@ -67,7 +67,7 @@ public :
|
|||
/// \return Special value of the invalid socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static SocketHandle InvalidSocket();
|
||||
static SocketHandle invalidSocket();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close and destroy a socket
|
||||
|
@ -75,7 +75,7 @@ public :
|
|||
/// \param sock Handle of the socket to close
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void Close(SocketHandle sock);
|
||||
static void close(SocketHandle sock);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set a socket as blocking or non-blocking
|
||||
|
@ -84,7 +84,7 @@ public :
|
|||
/// \param block New blocking state of the socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetBlocking(SocketHandle sock, bool block);
|
||||
static void setBlocking(SocketHandle sock, bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the last socket error status
|
||||
|
@ -92,7 +92,7 @@ public :
|
|||
/// \return Status corresponding to the last socket error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Socket::Status GetErrorStatus();
|
||||
static Socket::Status getErrorStatus();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -38,22 +38,22 @@ namespace sf
|
|||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Clock::Clock() :
|
||||
m_startTime(priv::ClockImpl::GetCurrentTime())
|
||||
m_startTime(priv::ClockImpl::getCurrentTime())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Clock::GetElapsedTime() const
|
||||
Time Clock::getElapsedTime() const
|
||||
{
|
||||
return priv::ClockImpl::GetCurrentTime() - m_startTime;
|
||||
return priv::ClockImpl::getCurrentTime() - m_startTime;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Clock::Restart()
|
||||
Time Clock::restart()
|
||||
{
|
||||
Time now = priv::ClockImpl::GetCurrentTime();
|
||||
Time now = priv::ClockImpl::getCurrentTime();
|
||||
Time elapsed = now - m_startTime;
|
||||
m_startTime = now;
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ private :
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& Err()
|
||||
std::ostream& err()
|
||||
{
|
||||
static DefaultErrStreamBuf buffer;
|
||||
static std::ostream stream(&buffer);
|
||||
|
|
|
@ -35,14 +35,14 @@ namespace sf
|
|||
Lock::Lock(Mutex& mutex) :
|
||||
m_mutex(mutex)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
m_mutex.lock();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Lock::~Lock()
|
||||
{
|
||||
m_mutex.Unlock();
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -27,15 +27,10 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <SFML/System/Win32/MutexImpl.hpp>
|
||||
|
||||
#else
|
||||
|
||||
#include <SFML/System/Unix/MutexImpl.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -56,16 +51,16 @@ Mutex::~Mutex()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Mutex::Lock()
|
||||
void Mutex::lock()
|
||||
{
|
||||
m_mutexImpl->Lock();
|
||||
m_mutexImpl->lock();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Mutex::Unlock()
|
||||
void Mutex::unlock()
|
||||
{
|
||||
m_mutexImpl->Unlock();
|
||||
m_mutexImpl->unlock();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -37,10 +37,10 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sleep(Time duration)
|
||||
void sleep(Time duration)
|
||||
{
|
||||
if (duration >= Time::Zero)
|
||||
priv::SleepImpl(duration);
|
||||
priv::sleepImpl(duration);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -46,14 +46,14 @@ String::String()
|
|||
////////////////////////////////////////////////////////////
|
||||
String::String(char ansiChar, const std::locale& locale)
|
||||
{
|
||||
m_string += Utf32::DecodeAnsi(ansiChar, locale);
|
||||
m_string += Utf32::decodeAnsi(ansiChar, locale);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(wchar_t wideChar)
|
||||
{
|
||||
m_string += Utf32::DecodeWide(wideChar);
|
||||
m_string += Utf32::decodeWide(wideChar);
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ String::String(const char* ansiString, const std::locale& locale)
|
|||
if (length > 0)
|
||||
{
|
||||
m_string.reserve(length + 1);
|
||||
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(m_string), locale);
|
||||
Utf32::fromAnsi(ansiString, ansiString + length, std::back_inserter(m_string), locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ String::String(const char* ansiString, const std::locale& locale)
|
|||
String::String(const std::string& ansiString, const std::locale& locale)
|
||||
{
|
||||
m_string.reserve(ansiString.length() + 1);
|
||||
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_string), locale);
|
||||
Utf32::fromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_string), locale);
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,7 +96,7 @@ String::String(const wchar_t* wideString)
|
|||
if (length > 0)
|
||||
{
|
||||
m_string.reserve(length + 1);
|
||||
Utf32::FromWide(wideString, wideString + length, std::back_inserter(m_string));
|
||||
Utf32::fromWide(wideString, wideString + length, std::back_inserter(m_string));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ String::String(const wchar_t* wideString)
|
|||
String::String(const std::wstring& wideString)
|
||||
{
|
||||
m_string.reserve(wideString.length() + 1);
|
||||
Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(m_string));
|
||||
Utf32::fromWide(wideString.begin(), wideString.end(), std::back_inserter(m_string));
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,40 +135,40 @@ m_string(copy.m_string)
|
|||
////////////////////////////////////////////////////////////
|
||||
String::operator std::string() const
|
||||
{
|
||||
return ToAnsiString();
|
||||
return toAnsiString();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::operator std::wstring() const
|
||||
{
|
||||
return ToWideString();
|
||||
return toWideString();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string String::ToAnsiString(const std::locale& locale) const
|
||||
std::string String::toAnsiString(const std::locale& locale) const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::string output;
|
||||
output.reserve(m_string.length() + 1);
|
||||
|
||||
// Convert
|
||||
Utf32::ToAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale);
|
||||
Utf32::toAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::wstring String::ToWideString() const
|
||||
std::wstring String::toWideString() const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::wstring output;
|
||||
output.reserve(m_string.length() + 1);
|
||||
|
||||
// Convert
|
||||
Utf32::ToWide(m_string.begin(), m_string.end(), std::back_inserter(output), 0);
|
||||
Utf32::toWide(m_string.begin(), m_string.end(), std::back_inserter(output), 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -205,77 +205,77 @@ Uint32& String::operator [](std::size_t index)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Clear()
|
||||
void String::clear()
|
||||
{
|
||||
m_string.clear();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t String::GetSize() const
|
||||
std::size_t String::getSize() const
|
||||
{
|
||||
return m_string.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool String::IsEmpty() const
|
||||
bool String::isEmpty() const
|
||||
{
|
||||
return m_string.empty();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Erase(std::size_t position, std::size_t count)
|
||||
void String::erase(std::size_t position, std::size_t count)
|
||||
{
|
||||
m_string.erase(position, count);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Insert(std::size_t position, const String& str)
|
||||
void String::insert(std::size_t position, const String& str)
|
||||
{
|
||||
m_string.insert(position, str.m_string);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t String::Find(const String& str, std::size_t start) const
|
||||
std::size_t String::find(const String& str, std::size_t start) const
|
||||
{
|
||||
return m_string.find(str.m_string, start);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint32* String::GetData() const
|
||||
const Uint32* String::getData() const
|
||||
{
|
||||
return m_string.c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::Iterator String::Begin()
|
||||
String::Iterator String::begin()
|
||||
{
|
||||
return m_string.begin();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::ConstIterator String::Begin() const
|
||||
String::ConstIterator String::begin() const
|
||||
{
|
||||
return m_string.begin();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::Iterator String::End()
|
||||
String::Iterator String::end()
|
||||
{
|
||||
return m_string.end();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::ConstIterator String::End() const
|
||||
String::ConstIterator String::end() const
|
||||
{
|
||||
return m_string.end();
|
||||
}
|
||||
|
|
|
@ -40,25 +40,25 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Thread::~Thread()
|
||||
{
|
||||
Wait();
|
||||
wait();
|
||||
delete m_entryPoint;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Thread::Launch()
|
||||
void Thread::launch()
|
||||
{
|
||||
Wait();
|
||||
wait();
|
||||
m_impl = new priv::ThreadImpl(this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Thread::Wait()
|
||||
void Thread::wait()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Wait();
|
||||
m_impl->wait();
|
||||
delete m_impl;
|
||||
m_impl = NULL;
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ void Thread::Wait()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Thread::Terminate()
|
||||
void Thread::terminate()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Terminate();
|
||||
m_impl->terminate();
|
||||
delete m_impl;
|
||||
m_impl = NULL;
|
||||
}
|
||||
|
@ -78,9 +78,9 @@ void Thread::Terminate()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Thread::Run()
|
||||
void Thread::run()
|
||||
{
|
||||
m_entryPoint->Run();
|
||||
m_entryPoint->run();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -27,15 +27,10 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/ThreadLocal.hpp>
|
||||
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <SFML/System/Win32/ThreadLocalImpl.hpp>
|
||||
|
||||
#else
|
||||
|
||||
#include <SFML/System/Unix/ThreadLocalImpl.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -45,7 +40,7 @@ namespace sf
|
|||
ThreadLocal::ThreadLocal(void* value)
|
||||
{
|
||||
m_impl = new priv::ThreadLocalImpl;
|
||||
SetValue(value);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,16 +52,16 @@ ThreadLocal::~ThreadLocal()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadLocal::SetValue(void* value)
|
||||
void ThreadLocal::setValue(void* value)
|
||||
{
|
||||
m_impl->SetValue(value);
|
||||
m_impl->setValue(value);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void* ThreadLocal::GetValue() const
|
||||
void* ThreadLocal::getValue() const
|
||||
{
|
||||
return m_impl->GetValue();
|
||||
return m_impl->getValue();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -42,21 +42,21 @@ m_microseconds(0)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Time::AsSeconds() const
|
||||
float Time::asSeconds() const
|
||||
{
|
||||
return m_microseconds / 1000000.f;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Int32 Time::AsMilliseconds() const
|
||||
Int32 Time::asMilliseconds() const
|
||||
{
|
||||
return static_cast<Uint32>(m_microseconds / 1000);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Int64 Time::AsMicroseconds() const
|
||||
Int64 Time::asMicroseconds() const
|
||||
{
|
||||
return m_microseconds;
|
||||
}
|
||||
|
@ -70,21 +70,21 @@ m_microseconds(microseconds)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Seconds(float amount)
|
||||
Time seconds(float amount)
|
||||
{
|
||||
return Time(static_cast<Uint64>(amount * 1000000));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Milliseconds(Int32 amount)
|
||||
Time milliseconds(Int32 amount)
|
||||
{
|
||||
return Time(static_cast<Uint64>(amount) * 1000);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time Microseconds(Int64 amount)
|
||||
Time microseconds(Int64 amount)
|
||||
{
|
||||
return Time(amount);
|
||||
}
|
||||
|
@ -93,56 +93,56 @@ Time Microseconds(Int64 amount)
|
|||
////////////////////////////////////////////////////////////
|
||||
bool operator ==(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() == right.AsMicroseconds();
|
||||
return left.asMicroseconds() == right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator !=(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() != right.AsMicroseconds();
|
||||
return left.asMicroseconds() != right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() < right.AsMicroseconds();
|
||||
return left.asMicroseconds() < right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() > right.AsMicroseconds();
|
||||
return left.asMicroseconds() > right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <=(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() <= right.AsMicroseconds();
|
||||
return left.asMicroseconds() <= right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >=(Time left, Time right)
|
||||
{
|
||||
return left.AsMicroseconds() >= right.AsMicroseconds();
|
||||
return left.asMicroseconds() >= right.asMicroseconds();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time operator -(Time right)
|
||||
{
|
||||
return Microseconds(-right.AsMicroseconds());
|
||||
return microseconds(-right.asMicroseconds());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time operator +(Time left, Time right)
|
||||
{
|
||||
return Microseconds(left.AsMicroseconds() + right.AsMicroseconds());
|
||||
return microseconds(left.asMicroseconds() + right.asMicroseconds());
|
||||
}
|
||||
|
||||
|
||||
|
@ -156,7 +156,7 @@ Time& operator +=(Time& left, Time right)
|
|||
////////////////////////////////////////////////////////////
|
||||
Time operator -(Time left, Time right)
|
||||
{
|
||||
return Microseconds(left.AsMicroseconds() - right.AsMicroseconds());
|
||||
return microseconds(left.asMicroseconds() - right.asMicroseconds());
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,14 +170,14 @@ Time& operator -=(Time& left, Time right)
|
|||
////////////////////////////////////////////////////////////
|
||||
Time operator *(Time left, float right)
|
||||
{
|
||||
return Seconds(left.AsSeconds() * right);
|
||||
return seconds(left.asSeconds() * right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time operator *(Time left, Int64 right)
|
||||
{
|
||||
return Microseconds(left.AsMicroseconds() * right);
|
||||
return microseconds(left.asMicroseconds() * right);
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,14 +212,14 @@ Time& operator *=(Time& left, Int64 right)
|
|||
////////////////////////////////////////////////////////////
|
||||
Time operator /(Time left, float right)
|
||||
{
|
||||
return Seconds(left.AsSeconds() / right);
|
||||
return seconds(left.asSeconds() / right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Time operator /(Time left, Int64 right)
|
||||
{
|
||||
return Microseconds(left.AsMicroseconds() / right);
|
||||
return microseconds(left.asMicroseconds() / right);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Time ClockImpl::GetCurrentTime()
|
||||
Time ClockImpl::getCurrentTime()
|
||||
{
|
||||
#ifdef SFML_SYSTEM_MACOS
|
||||
|
||||
|
@ -47,14 +47,14 @@ Time ClockImpl::GetCurrentTime()
|
|||
if (frequency.denom == 0)
|
||||
mach_timebase_info(&frequency);
|
||||
Uint64 nanoseconds = mach_absolute_time() * frequency.numer / frequency.denom;
|
||||
return sf::Microseconds(nanoseconds / 1000);
|
||||
return sf::microseconds(nanoseconds / 1000);
|
||||
|
||||
#else
|
||||
|
||||
// POSIX implementation
|
||||
timespec time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
return sf::Microseconds(static_cast<Uint64>(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
|
||||
return sf::microseconds(static_cast<Uint64>(time.tv_sec) * 1000000 + time.tv_nsec / 1000);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public :
|
|||
/// \return Current time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Time GetCurrentTime();
|
||||
static Time getCurrentTime();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -52,14 +52,14 @@ MutexImpl::~MutexImpl()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void MutexImpl::Lock()
|
||||
void MutexImpl::lock()
|
||||
{
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void MutexImpl::Unlock()
|
||||
void MutexImpl::unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ public :
|
|||
/// \brief Lock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Lock();
|
||||
void lock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Unlock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Unlock();
|
||||
void unlock();
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void SleepImpl(Time time)
|
||||
void sleepImpl(Time time)
|
||||
{
|
||||
// usleep is not reliable enough (it might block the
|
||||
// whole process instead of just the current thread)
|
||||
|
@ -44,7 +44,7 @@ void SleepImpl(Time time)
|
|||
|
||||
// this implementation is inspired from Qt
|
||||
|
||||
Uint64 usecs = time.AsMicroseconds();
|
||||
Uint64 usecs = time.asMicroseconds();
|
||||
|
||||
// get the current time
|
||||
timeval tv;
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace priv
|
|||
/// \param time Time to sleep
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SleepImpl(Time time);
|
||||
void sleepImpl(Time time);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace priv
|
|||
ThreadImpl::ThreadImpl(Thread* owner) :
|
||||
m_isActive(true)
|
||||
{
|
||||
m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::EntryPoint, owner) == 0;
|
||||
m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::entryPoint, owner) == 0;
|
||||
|
||||
if (!m_isActive)
|
||||
std::cerr << "Failed to create thread" << std::endl;
|
||||
|
@ -47,7 +47,7 @@ m_isActive(true)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadImpl::Wait()
|
||||
void ThreadImpl::wait()
|
||||
{
|
||||
if (m_isActive)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ void ThreadImpl::Wait()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadImpl::Terminate()
|
||||
void ThreadImpl::terminate()
|
||||
{
|
||||
if (m_isActive)
|
||||
pthread_cancel(m_thread);
|
||||
|
@ -66,7 +66,7 @@ void ThreadImpl::Terminate()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void* ThreadImpl::EntryPoint(void* userData)
|
||||
void* ThreadImpl::entryPoint(void* userData)
|
||||
{
|
||||
// The Thread instance is stored in the user data
|
||||
Thread* owner = static_cast<Thread*>(userData);
|
||||
|
@ -75,7 +75,7 @@ void* ThreadImpl::EntryPoint(void* userData)
|
|||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
// Forward to the owner
|
||||
owner->Run();
|
||||
owner->run();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -57,13 +57,13 @@ public :
|
|||
/// \brief Wait until the thread finishes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Wait();
|
||||
void wait();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Terminate the thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Terminate();
|
||||
void terminate();
|
||||
|
||||
private :
|
||||
|
||||
|
@ -75,7 +75,7 @@ private :
|
|||
/// \return Os specific error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void* EntryPoint(void* userData);
|
||||
static void* entryPoint(void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
|
|
@ -47,14 +47,14 @@ ThreadLocalImpl::~ThreadLocalImpl()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadLocalImpl::SetValue(void* value)
|
||||
void ThreadLocalImpl::setValue(void* value)
|
||||
{
|
||||
pthread_setspecific(m_key, value);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void* ThreadLocalImpl::GetValue() const
|
||||
void* ThreadLocalImpl::getValue() const
|
||||
{
|
||||
return pthread_getspecific(m_key);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public :
|
|||
/// \param value Value of the variable for this thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetValue(void* value);
|
||||
void setValue(void* value);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the thread-specific value of the variable
|
||||
|
@ -69,7 +69,7 @@ public :
|
|||
/// \return Value of the variable for this thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void* GetValue() const;
|
||||
void* getValue() const;
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
@ -27,12 +27,11 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Win32/ClockImpl.hpp>
|
||||
#include <windows.h>
|
||||
#undef GetCurrentTime // Windows macros are really evil...
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
LARGE_INTEGER GetFrequency()
|
||||
LARGE_INTEGER getFrequency()
|
||||
{
|
||||
LARGE_INTEGER frequency;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
|
@ -45,7 +44,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Time ClockImpl::GetCurrentTime()
|
||||
Time ClockImpl::getCurrentTime()
|
||||
{
|
||||
// Force the following code to run on first core
|
||||
// (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx)
|
||||
|
@ -54,7 +53,7 @@ Time ClockImpl::GetCurrentTime()
|
|||
|
||||
// Get the frequency of the performance counter
|
||||
// (it is constant across the program lifetime)
|
||||
static LARGE_INTEGER frequency = GetFrequency();
|
||||
static LARGE_INTEGER frequency = getFrequency();
|
||||
|
||||
// Get the current time
|
||||
LARGE_INTEGER time;
|
||||
|
@ -64,7 +63,7 @@ Time ClockImpl::GetCurrentTime()
|
|||
SetThreadAffinityMask(currentThread, previousMask);
|
||||
|
||||
// Return the current time as microseconds
|
||||
return sf::Microseconds(1000000 * time.QuadPart / frequency.QuadPart);
|
||||
return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -50,7 +50,7 @@ public :
|
|||
/// \return Current time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Time GetCurrentTime();
|
||||
static Time getCurrentTime();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -47,14 +47,14 @@ MutexImpl::~MutexImpl()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void MutexImpl::Lock()
|
||||
void MutexImpl::lock()
|
||||
{
|
||||
EnterCriticalSection(&m_mutex);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void MutexImpl::Unlock()
|
||||
void MutexImpl::unlock()
|
||||
{
|
||||
LeaveCriticalSection(&m_mutex);
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ public :
|
|||
/// \brief Lock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Lock();
|
||||
void lock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Unlock the mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Unlock();
|
||||
void unlock();
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void SleepImpl(Time time)
|
||||
void sleepImpl(Time time)
|
||||
{
|
||||
::Sleep(time.AsMilliseconds());
|
||||
::Sleep(time.asMilliseconds());
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace priv
|
|||
/// \param time Time to sleep
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SleepImpl(Time time);
|
||||
void sleepImpl(Time time);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
ThreadImpl::ThreadImpl(Thread* owner)
|
||||
{
|
||||
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, &m_threadId));
|
||||
m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::entryPoint, owner, 0, &m_threadId));
|
||||
|
||||
if (!m_thread)
|
||||
Err() << "Failed to create thread" << std::endl;
|
||||
err() << "Failed to create thread" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ ThreadImpl::~ThreadImpl()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadImpl::Wait()
|
||||
void ThreadImpl::wait()
|
||||
{
|
||||
if (m_thread)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ void ThreadImpl::Wait()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadImpl::Terminate()
|
||||
void ThreadImpl::terminate()
|
||||
{
|
||||
if (m_thread)
|
||||
TerminateThread(m_thread, 0);
|
||||
|
@ -74,13 +74,13 @@ void ThreadImpl::Terminate()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int __stdcall ThreadImpl::EntryPoint(void* userData)
|
||||
unsigned int __stdcall ThreadImpl::entryPoint(void* userData)
|
||||
{
|
||||
// The Thread instance is stored in the user data
|
||||
Thread* owner = static_cast<Thread*>(userData);
|
||||
|
||||
// Forward to the owner
|
||||
owner->Run();
|
||||
owner->run();
|
||||
|
||||
// Optional, but it is cleaner
|
||||
_endthreadex(0);
|
||||
|
|
|
@ -63,13 +63,13 @@ public :
|
|||
/// \brief Wait until the thread finishes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Wait();
|
||||
void wait();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Terminate the thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Terminate();
|
||||
void terminate();
|
||||
|
||||
private :
|
||||
|
||||
|
@ -81,7 +81,7 @@ private :
|
|||
/// \return OS specific error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int __stdcall EntryPoint(void* userData);
|
||||
static unsigned int __stdcall entryPoint(void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
|
|
@ -47,14 +47,14 @@ ThreadLocalImpl::~ThreadLocalImpl()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ThreadLocalImpl::SetValue(void* value)
|
||||
void ThreadLocalImpl::setValue(void* value)
|
||||
{
|
||||
TlsSetValue(m_index, value);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void* ThreadLocalImpl::GetValue() const
|
||||
void* ThreadLocalImpl::getValue() const
|
||||
{
|
||||
return TlsGetValue(m_index);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public :
|
|||
/// \param value Value of the variable for this thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetValue(void* value);
|
||||
void setValue(void* value);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the thread-specific value of the variable
|
||||
|
@ -69,7 +69,7 @@ public :
|
|||
/// \return Value of the variable for this thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void* GetValue() const;
|
||||
void* getValue() const;
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Context::Context()
|
||||
{
|
||||
m_context = priv::GlContext::Create();
|
||||
SetActive(true);
|
||||
m_context = priv::GlContext::create();
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,17 +47,17 @@ Context::~Context()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Context::SetActive(bool active)
|
||||
bool Context::setActive(bool active)
|
||||
{
|
||||
return m_context->SetActive(active);
|
||||
return m_context->setActive(active);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Context::Context(const ContextSettings& settings, unsigned int width, unsigned int height)
|
||||
{
|
||||
m_context = priv::GlContext::Create(settings, width, height);
|
||||
SetActive(true);
|
||||
m_context = priv::GlContext::create(settings, width, height);
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace
|
|||
sf::Mutex internalContextsMutex;
|
||||
|
||||
// Check if the internal context of the current thread is valid
|
||||
bool HasInternalContext()
|
||||
bool hasInternalContext()
|
||||
{
|
||||
// The internal context can be null...
|
||||
if (!internalContext)
|
||||
|
@ -80,11 +80,11 @@ namespace
|
|||
}
|
||||
|
||||
// Retrieve the internal context for the current thread
|
||||
sf::priv::GlContext* GetInternalContext()
|
||||
sf::priv::GlContext* getInternalContext()
|
||||
{
|
||||
if (!HasInternalContext())
|
||||
if (!hasInternalContext())
|
||||
{
|
||||
internalContext = sf::priv::GlContext::Create();
|
||||
internalContext = sf::priv::GlContext::create();
|
||||
sf::Lock lock(internalContextsMutex);
|
||||
internalContexts.insert(internalContext);
|
||||
}
|
||||
|
@ -99,21 +99,21 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlContext::GlobalInit()
|
||||
void GlContext::globalInit()
|
||||
{
|
||||
// Create the shared context
|
||||
sharedContext = new ContextType(NULL);
|
||||
sharedContext->Initialize();
|
||||
sharedContext->initialize();
|
||||
|
||||
// This call makes sure that:
|
||||
// - the shared context is inactive (it must never be)
|
||||
// - another valid context is activated in the current thread
|
||||
sharedContext->SetActive(false);
|
||||
sharedContext->setActive(false);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlContext::GlobalCleanup()
|
||||
void GlContext::globalCleanup()
|
||||
{
|
||||
// Destroy the shared context
|
||||
delete sharedContext;
|
||||
|
@ -128,47 +128,47 @@ void GlContext::GlobalCleanup()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlContext::EnsureContext()
|
||||
void GlContext::ensureContext()
|
||||
{
|
||||
// If there's no active context on the current thread, activate an internal one
|
||||
if (!currentContext)
|
||||
GetInternalContext()->SetActive(true);
|
||||
getInternalContext()->setActive(true);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
GlContext* GlContext::Create()
|
||||
GlContext* GlContext::create()
|
||||
{
|
||||
GlContext* context = new ContextType(sharedContext);
|
||||
context->Initialize();
|
||||
context->initialize();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
GlContext* GlContext::Create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel)
|
||||
GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel)
|
||||
{
|
||||
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
||||
EnsureContext();
|
||||
ensureContext();
|
||||
|
||||
// Create the context
|
||||
GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel);
|
||||
context->Initialize();
|
||||
context->initialize();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
GlContext* GlContext::Create(const ContextSettings& settings, unsigned int width, unsigned int height)
|
||||
GlContext* GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height)
|
||||
{
|
||||
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
||||
EnsureContext();
|
||||
ensureContext();
|
||||
|
||||
// Create the context
|
||||
GlContext* context = new ContextType(sharedContext, settings, width, height);
|
||||
context->Initialize();
|
||||
context->initialize();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -179,26 +179,26 @@ GlContext::~GlContext()
|
|||
{
|
||||
// Deactivate the context before killing it, unless we're inside Cleanup()
|
||||
if (sharedContext)
|
||||
SetActive(false);
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& GlContext::GetSettings() const
|
||||
const ContextSettings& GlContext::getSettings() const
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool GlContext::SetActive(bool active)
|
||||
bool GlContext::setActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (this != currentContext)
|
||||
{
|
||||
// Activate the context
|
||||
if (MakeCurrent())
|
||||
if (makeCurrent())
|
||||
{
|
||||
// Set it as the new current context for this thread
|
||||
currentContext = this;
|
||||
|
@ -221,7 +221,7 @@ bool GlContext::SetActive(bool active)
|
|||
{
|
||||
// To deactivate the context, we actually activate another one so that we make
|
||||
// sure that there is always an active context for subsequent graphics operations
|
||||
return GetInternalContext()->SetActive(true);
|
||||
return getInternalContext()->setActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -240,38 +240,38 @@ GlContext::GlContext()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int GlContext::EvaluateFormat(unsigned int bitsPerPixel, const ContextSettings& settings, int colorBits, int depthBits, int stencilBits, int antialiasing)
|
||||
int GlContext::evaluateFormat(unsigned int bitsPerPixel, const ContextSettings& settings, int colorBits, int depthBits, int stencilBits, int antialiasing)
|
||||
{
|
||||
return std::abs(static_cast<int>(bitsPerPixel - colorBits)) +
|
||||
std::abs(static_cast<int>(settings.DepthBits - depthBits)) +
|
||||
std::abs(static_cast<int>(settings.StencilBits - stencilBits)) +
|
||||
std::abs(static_cast<int>(settings.AntialiasingLevel - antialiasing));
|
||||
std::abs(static_cast<int>(settings.depthBits - depthBits)) +
|
||||
std::abs(static_cast<int>(settings.stencilBits - stencilBits)) +
|
||||
std::abs(static_cast<int>(settings.antialiasingLevel - antialiasing));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlContext::Initialize()
|
||||
void GlContext::initialize()
|
||||
{
|
||||
// Activate the context
|
||||
SetActive(true);
|
||||
setActive(true);
|
||||
|
||||
// Retrieve the context version number
|
||||
const GLubyte* version = glGetString(GL_VERSION);
|
||||
if (version)
|
||||
{
|
||||
// The beginning of the returned string is "major.minor" (this is standard)
|
||||
m_settings.MajorVersion = version[0] - '0';
|
||||
m_settings.MinorVersion = version[2] - '0';
|
||||
m_settings.majorVersion = version[0] - '0';
|
||||
m_settings.minorVersion = version[2] - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Can't get the version number, assume 2.0
|
||||
m_settings.MajorVersion = 2;
|
||||
m_settings.MinorVersion = 0;
|
||||
m_settings.majorVersion = 2;
|
||||
m_settings.minorVersion = 0;
|
||||
}
|
||||
|
||||
// Enable antialiasing if needed
|
||||
if (m_settings.AntialiasingLevel > 0)
|
||||
if (m_settings.antialiasingLevel > 0)
|
||||
glEnable(GL_MULTISAMPLE_ARB);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,25 +57,25 @@ public :
|
|||
/// can be called only once.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void GlobalInit();
|
||||
static void globalInit();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Perform the global cleanup
|
||||
///
|
||||
/// This function is called after the very last OpenGL resource
|
||||
/// is destroyed. It makes sure that everything that was
|
||||
/// created by Initialize() is properly released.
|
||||
/// created by initialize() is properly released.
|
||||
/// Note: this function doesn't need to be thread-safe, as it
|
||||
/// can be called only once.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void GlobalCleanup();
|
||||
static void globalCleanup();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Ensures that an OpenGL context is active in the current thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void EnsureContext();
|
||||
static void ensureContext();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context, not associated to a window
|
||||
|
@ -86,7 +86,7 @@ public :
|
|||
/// \return Pointer to the created context (don't forget to delete it)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static GlContext* Create();
|
||||
static GlContext* create();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context attached to a window
|
||||
|
@ -101,7 +101,7 @@ public :
|
|||
/// \return Pointer to the created context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static GlContext* Create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel);
|
||||
static GlContext* create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context that embeds its own rendering target
|
||||
|
@ -116,7 +116,7 @@ public :
|
|||
/// \return Pointer to the created context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static GlContext* Create(const ContextSettings& settings, unsigned int width, unsigned int height);
|
||||
static GlContext* create(const ContextSettings& settings, unsigned int width, unsigned int height);
|
||||
|
||||
public :
|
||||
|
||||
|
@ -136,11 +136,10 @@ public :
|
|||
/// \return Structure containing the settings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& GetSettings() const;
|
||||
const ContextSettings& getSettings() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the context as the current target
|
||||
/// for rendering
|
||||
/// \brief Activate or deactivate the context as the current target for rendering
|
||||
///
|
||||
/// A context is active only on the current thread, if you want to
|
||||
/// make it active on another thread you have to deactivate it
|
||||
|
@ -153,13 +152,13 @@ public :
|
|||
/// \return True if operation was successful, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SetActive(bool active);
|
||||
bool setActive(bool active);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Display what has been rendered to the context so far
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void Display() = 0;
|
||||
virtual void display() = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
|
@ -172,7 +171,7 @@ public :
|
|||
/// \param enabled True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetVerticalSyncEnabled(bool enabled) = 0;
|
||||
virtual void setVerticalSyncEnabled(bool enabled) = 0;
|
||||
|
||||
protected :
|
||||
|
||||
|
@ -191,7 +190,7 @@ protected :
|
|||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool MakeCurrent() = 0;
|
||||
virtual bool makeCurrent() = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Evaluate a pixel format configuration
|
||||
|
@ -211,7 +210,7 @@ protected :
|
|||
/// \return Score of the configuration
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static int EvaluateFormat(unsigned int bitsPerPixel, const ContextSettings& settings, int colorBits, int depthBits, int stencilBits, int antialiasing);
|
||||
static int evaluateFormat(unsigned int bitsPerPixel, const ContextSettings& settings, int colorBits, int depthBits, int stencilBits, int antialiasing);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
@ -224,7 +223,7 @@ private:
|
|||
/// \brief Perform various initializations after the context construction
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Initialize();
|
||||
void initialize();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -50,14 +50,14 @@ GlResource::GlResource()
|
|||
|
||||
// If this is the very first resource, trigger the global context initialization
|
||||
if (count == 0)
|
||||
priv::GlContext::GlobalInit();
|
||||
priv::GlContext::globalInit();
|
||||
|
||||
// Increment the resources counter
|
||||
count++;
|
||||
}
|
||||
|
||||
// Now make sure that there is an active OpenGL context in the current thread
|
||||
priv::GlContext::EnsureContext();
|
||||
priv::GlContext::ensureContext();
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,14 +72,14 @@ GlResource::~GlResource()
|
|||
|
||||
// If there's no more resource alive, we can trigger the global context cleanup
|
||||
if (count == 0)
|
||||
priv::GlContext::GlobalCleanup();
|
||||
priv::GlContext::globalCleanup();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlResource::EnsureGlContext()
|
||||
void GlResource::ensureGlContext()
|
||||
{
|
||||
priv::GlContext::EnsureContext();
|
||||
priv::GlContext::ensureContext();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -31,17 +31,11 @@
|
|||
#include <SFML/Config.hpp>
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <SFML/Window/Win32/InputImpl.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||
|
||||
#include <SFML/Window/Linux/InputImpl.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_MACOS)
|
||||
|
||||
#include <SFML/Window/OSX/InputImpl.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -32,44 +32,44 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Joystick::IsConnected(unsigned int joystick)
|
||||
bool Joystick::isConnected(unsigned int joystick)
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().GetState(joystick).Connected;
|
||||
return priv::JoystickManager::getInstance().getState(joystick).connected;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int Joystick::GetButtonCount(unsigned int joystick)
|
||||
unsigned int Joystick::getButtonCount(unsigned int joystick)
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().GetCapabilities(joystick).ButtonCount;
|
||||
return priv::JoystickManager::getInstance().getCapabilities(joystick).buttonCount;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Joystick::HasAxis(unsigned int joystick, Axis axis)
|
||||
bool Joystick::hasAxis(unsigned int joystick, Axis axis)
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().GetCapabilities(joystick).Axes[axis];
|
||||
return priv::JoystickManager::getInstance().getCapabilities(joystick).axes[axis];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Joystick::IsButtonPressed(unsigned int joystick, unsigned int button)
|
||||
bool Joystick::isButtonPressed(unsigned int joystick, unsigned int button)
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().GetState(joystick).Buttons[button];
|
||||
return priv::JoystickManager::getInstance().getState(joystick).buttons[button];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Joystick::GetAxisPosition(unsigned int joystick, Axis axis)
|
||||
float Joystick::getAxisPosition(unsigned int joystick, Axis axis)
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().GetState(joystick).Axes[axis];
|
||||
return priv::JoystickManager::getInstance().getState(joystick).axes[axis];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Joystick::Update()
|
||||
void Joystick::update()
|
||||
{
|
||||
return priv::JoystickManager::GetInstance().Update();
|
||||
return priv::JoystickManager::getInstance().update();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -45,12 +45,12 @@ struct JoystickCaps
|
|||
{
|
||||
JoystickCaps()
|
||||
{
|
||||
ButtonCount = 0;
|
||||
std::fill(Axes, Axes + Joystick::AxisCount, false);
|
||||
buttonCount = 0;
|
||||
std::fill(axes, axes + Joystick::AxisCount, false);
|
||||
}
|
||||
|
||||
unsigned int ButtonCount; ///< Number of buttons supported by the joystick
|
||||
bool Axes[Joystick::AxisCount]; ///< Support for each axis
|
||||
unsigned int buttonCount; ///< Number of buttons supported by the joystick
|
||||
bool axes[Joystick::AxisCount]; ///< Support for each axis
|
||||
};
|
||||
|
||||
|
||||
|
@ -62,14 +62,14 @@ struct JoystickState
|
|||
{
|
||||
JoystickState()
|
||||
{
|
||||
Connected = false;
|
||||
std::fill(Axes, Axes + Joystick::AxisCount, 0.f);
|
||||
std::fill(Buttons, Buttons + Joystick::ButtonCount, false);
|
||||
connected = false;
|
||||
std::fill(axes, axes + Joystick::AxisCount, 0.f);
|
||||
std::fill(buttons, buttons + Joystick::ButtonCount, false);
|
||||
}
|
||||
|
||||
bool Connected; ///< Is the joystick currently connected?
|
||||
float Axes[Joystick::AxisCount]; ///< Position of each axis, in range [-100, 100]
|
||||
bool Buttons[Joystick::ButtonCount]; ///< Status of each button (true = pressed)
|
||||
bool connected; ///< Is the joystick currently connected?
|
||||
float axes[Joystick::AxisCount]; ///< Position of each axis, in range [-100, 100]
|
||||
bool buttons[Joystick::ButtonCount]; ///< Status of each button (true = pressed)
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -78,17 +78,11 @@ struct JoystickState
|
|||
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <SFML/Window/Win32/JoystickImpl.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||
|
||||
#include <SFML/Window/Linux/JoystickImpl.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_MACOS)
|
||||
|
||||
#include <SFML/Window/OSX/JoystickImpl.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
JoystickManager& JoystickManager::GetInstance()
|
||||
JoystickManager& JoystickManager::getInstance()
|
||||
{
|
||||
static JoystickManager instance;
|
||||
return instance;
|
||||
|
@ -41,48 +41,48 @@ JoystickManager& JoystickManager::GetInstance()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const JoystickCaps& JoystickManager::GetCapabilities(unsigned int joystick) const
|
||||
const JoystickCaps& JoystickManager::getCapabilities(unsigned int joystick) const
|
||||
{
|
||||
return m_joysticks[joystick].Capabilities;
|
||||
return m_joysticks[joystick].capabilities;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const JoystickState& JoystickManager::GetState(unsigned int joystick) const
|
||||
const JoystickState& JoystickManager::getState(unsigned int joystick) const
|
||||
{
|
||||
return m_joysticks[joystick].State;
|
||||
return m_joysticks[joystick].state;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void JoystickManager::Update()
|
||||
void JoystickManager::update()
|
||||
{
|
||||
for (int i = 0; i < Joystick::Count; ++i)
|
||||
{
|
||||
Item& item = m_joysticks[i];
|
||||
|
||||
if (item.State.Connected)
|
||||
if (item.state.connected)
|
||||
{
|
||||
// Get the current state of the joystick
|
||||
item.State = item.Joystick.Update();
|
||||
item.state = item.joystick.update();
|
||||
|
||||
// Check if it's still connected
|
||||
if (!item.State.Connected)
|
||||
if (!item.state.connected)
|
||||
{
|
||||
item.Joystick.Close();
|
||||
item.Capabilities = JoystickCaps();
|
||||
item.State = JoystickState();
|
||||
item.joystick.close();
|
||||
item.capabilities = JoystickCaps();
|
||||
item.state = JoystickState();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if the joystick was connected since last update
|
||||
if (JoystickImpl::IsConnected(i))
|
||||
if (JoystickImpl::isConnected(i))
|
||||
{
|
||||
if (item.Joystick.Open(i))
|
||||
if (item.joystick.open(i))
|
||||
{
|
||||
item.Capabilities = item.Joystick.GetCapabilities();
|
||||
item.State = item.Joystick.Update();
|
||||
item.capabilities = item.joystick.getCapabilities();
|
||||
item.state = item.joystick.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ JoystickManager::~JoystickManager()
|
|||
{
|
||||
for (int i = 0; i < Joystick::Count; ++i)
|
||||
{
|
||||
if (m_joysticks[i].State.Connected)
|
||||
m_joysticks[i].Joystick.Close();
|
||||
if (m_joysticks[i].state.connected)
|
||||
m_joysticks[i].joystick.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public :
|
|||
/// \return Unique instance of the joystick manager
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static JoystickManager& GetInstance();
|
||||
static JoystickManager& getInstance();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the capabilities of an open joystick
|
||||
|
@ -61,7 +61,7 @@ public :
|
|||
/// \return Capabilities of the joystick
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const JoystickCaps& GetCapabilities(unsigned int joystick) const;
|
||||
const JoystickCaps& getCapabilities(unsigned int joystick) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current state of an open joystick
|
||||
|
@ -71,13 +71,13 @@ public :
|
|||
/// \return Current state of the joystick
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const JoystickState& GetState(unsigned int joystick) const;
|
||||
const JoystickState& getState(unsigned int joystick) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the state of all the joysticks
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Update();
|
||||
void update();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -99,9 +99,9 @@ private:
|
|||
////////////////////////////////////////////////////////////
|
||||
struct Item
|
||||
{
|
||||
JoystickImpl Joystick; ///< Joystick implementation
|
||||
JoystickState State; ///< The current joystick state
|
||||
JoystickCaps Capabilities; ///< The joystick capabilities
|
||||
JoystickImpl joystick; ///< Joystick implementation
|
||||
JoystickState state; ///< The current joystick state
|
||||
JoystickCaps capabilities; ///< The joystick capabilities
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Keyboard::IsKeyPressed(Key key)
|
||||
bool Keyboard::isKeyPressed(Key key)
|
||||
{
|
||||
return priv::InputImpl::IsKeyPressed(key);
|
||||
return priv::InputImpl::isKeyPressed(key);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -59,7 +59,7 @@ m_ownsWindow(true)
|
|||
0, NULL);
|
||||
|
||||
// Create the context
|
||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings());
|
||||
createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings());
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,14 +70,14 @@ m_context (NULL),
|
|||
m_ownsWindow(false)
|
||||
{
|
||||
// Use the same display as the owner window (important!)
|
||||
m_display = static_cast<const WindowImplX11*>(owner)->GetDisplay();
|
||||
m_display = static_cast<const WindowImplX11*>(owner)->getDisplay();
|
||||
|
||||
// Get the owner window and its device context
|
||||
m_window = static_cast< ::Window>(owner->GetSystemHandle());
|
||||
m_window = static_cast< ::Window>(owner->getSystemHandle());
|
||||
|
||||
// Create the context
|
||||
if (m_window)
|
||||
CreateContext(shared, bitsPerPixel, settings);
|
||||
createContext(shared, bitsPerPixel, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,7 +103,7 @@ m_ownsWindow(true)
|
|||
0, NULL);
|
||||
|
||||
// Create the context
|
||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
||||
createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,14 +132,14 @@ GlxContext::~GlxContext()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool GlxContext::MakeCurrent()
|
||||
bool GlxContext::makeCurrent()
|
||||
{
|
||||
return m_context && glXMakeCurrent(m_display, m_window, m_context);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlxContext::Display()
|
||||
void GlxContext::display()
|
||||
{
|
||||
if (m_window)
|
||||
glXSwapBuffers(m_display, m_window);
|
||||
|
@ -147,7 +147,7 @@ void GlxContext::Display()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlxContext::SetVerticalSyncEnabled(bool enabled)
|
||||
void GlxContext::setVerticalSyncEnabled(bool enabled)
|
||||
{
|
||||
const GLubyte* name = reinterpret_cast<const GLubyte*>("glXSwapIntervalSGI");
|
||||
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(name));
|
||||
|
@ -157,7 +157,7 @@ void GlxContext::SetVerticalSyncEnabled(bool enabled)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, const ContextSettings& settings)
|
||||
void GlxContext::createContext(GlxContext* shared, unsigned int bitsPerPixel, const ContextSettings& settings)
|
||||
{
|
||||
// Save the creation settings
|
||||
m_settings = settings;
|
||||
|
@ -166,7 +166,7 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
XWindowAttributes windowAttributes;
|
||||
if (XGetWindowAttributes(m_display, m_window, &windowAttributes) == 0)
|
||||
{
|
||||
Err() << "Failed to get the window attributes" << std::endl;
|
||||
err() << "Failed to get the window attributes" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
{
|
||||
if (visuals)
|
||||
XFree(visuals);
|
||||
Err() << "There is no valid visual for the selected screen" << std::endl;
|
||||
err() << "There is no valid visual for the selected screen" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
|
||||
// Evaluate the current configuration
|
||||
int color = red + green + blue + alpha;
|
||||
int score = EvaluateFormat(bitsPerPixel, m_settings, color, depth, stencil, multiSampling ? samples : 0);
|
||||
int score = evaluateFormat(bitsPerPixel, m_settings, color, depth, stencil, multiSampling ? samples : 0);
|
||||
|
||||
// Keep it if it's better than the current best
|
||||
if (score < bestScore)
|
||||
|
@ -224,7 +224,7 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
// Make sure that we have found a visual
|
||||
if (!bestVisual)
|
||||
{
|
||||
Err() << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl;
|
||||
err() << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
GLXContext toShare = shared ? shared->m_context : NULL;
|
||||
|
||||
// Create the OpenGL context -- first try context versions >= 3.0 if it is requested (they require special code)
|
||||
while (!m_context && (m_settings.MajorVersion >= 3))
|
||||
while (!m_context && (m_settings.majorVersion >= 3))
|
||||
{
|
||||
const GLubyte* name = reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB");
|
||||
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(name));
|
||||
|
@ -245,8 +245,8 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
// Create the context
|
||||
int attributes[] =
|
||||
{
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, m_settings.MajorVersion,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, m_settings.MinorVersion,
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, m_settings.majorVersion,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, m_settings.minorVersion,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
||||
0, 0
|
||||
};
|
||||
|
@ -261,16 +261,16 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
// Invalid version numbers will be generated by this algorithm (like 3.9), but we really don't care
|
||||
if (!m_context)
|
||||
{
|
||||
if (m_settings.MinorVersion > 0)
|
||||
if (m_settings.minorVersion > 0)
|
||||
{
|
||||
// If the minor version is not 0, we decrease it and try again
|
||||
m_settings.MinorVersion--;
|
||||
m_settings.minorVersion--;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the minor version is 0, we decrease the major version
|
||||
m_settings.MajorVersion--;
|
||||
m_settings.MinorVersion = 9;
|
||||
m_settings.majorVersion--;
|
||||
m_settings.minorVersion = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,13 +279,13 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
if (!m_context)
|
||||
{
|
||||
// set the context version to 2.0 (arbitrary)
|
||||
m_settings.MajorVersion = 2;
|
||||
m_settings.MinorVersion = 0;
|
||||
m_settings.majorVersion = 2;
|
||||
m_settings.minorVersion = 0;
|
||||
|
||||
m_context = glXCreateContext(m_display, bestVisual, toShare, true);
|
||||
if (!m_context)
|
||||
{
|
||||
Err() << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
err() << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -296,9 +296,9 @@ void GlxContext::CreateContext(GlxContext* shared, unsigned int bitsPerPixel, co
|
|||
glXGetConfig(m_display, bestVisual, GLX_STENCIL_SIZE, &stencil);
|
||||
glXGetConfig(m_display, bestVisual, GLX_SAMPLE_BUFFERS_ARB, &multiSampling);
|
||||
glXGetConfig(m_display, bestVisual, GLX_SAMPLES_ARB, &samples);
|
||||
m_settings.DepthBits = static_cast<unsigned int>(depth);
|
||||
m_settings.StencilBits = static_cast<unsigned int>(stencil);
|
||||
m_settings.AntialiasingLevel = multiSampling ? samples : 0;
|
||||
m_settings.depthBits = static_cast<unsigned int>(depth);
|
||||
m_settings.stencilBits = static_cast<unsigned int>(stencil);
|
||||
m_settings.antialiasingLevel = multiSampling ? samples : 0;
|
||||
|
||||
// Change the target window's colormap so that it matches the context's one
|
||||
::Window root = RootWindow(m_display, DefaultScreen(m_display));
|
||||
|
|
|
@ -82,19 +82,18 @@ public :
|
|||
~GlxContext();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate the context as the current target
|
||||
/// for rendering
|
||||
/// \brief Activate the context as the current target for rendering
|
||||
///
|
||||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool MakeCurrent();
|
||||
virtual bool makeCurrent();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Display what has been rendered to the context so far
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void Display();
|
||||
virtual void display();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
|
@ -104,10 +103,10 @@ public :
|
|||
/// This can avoid some visual artifacts, and limit the framerate
|
||||
/// to a good value (but not constant across different computers).
|
||||
///
|
||||
/// \param enabled : True to enable v-sync, false to deactivate
|
||||
/// \param enabled True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetVerticalSyncEnabled(bool enabled);
|
||||
virtual void setVerticalSyncEnabled(bool enabled);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -119,7 +118,7 @@ private :
|
|||
/// \param settings Creation parameters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void CreateContext(GlxContext* shared, unsigned int bitsPerPixel, const ContextSettings& settings);
|
||||
void createContext(GlxContext* shared, unsigned int bitsPerPixel, const ContextSettings& settings);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::IsKeyPressed(Keyboard::Key key)
|
||||
bool InputImpl::isKeyPressed(Keyboard::Key key)
|
||||
{
|
||||
// Get the corresponding X11 keysym
|
||||
KeySym keysym = 0;
|
||||
|
@ -187,7 +187,7 @@ bool InputImpl::IsKeyPressed(Keyboard::Key key)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
|
||||
bool InputImpl::isMouseButtonPressed(Mouse::Button button)
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
|
@ -212,7 +212,7 @@ bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition()
|
||||
Vector2i InputImpl::getMousePosition()
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
|
@ -228,9 +228,9 @@ Vector2i InputImpl::GetMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
|
@ -252,7 +252,7 @@ Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position)
|
||||
void InputImpl::setMousePosition(const Vector2i& position)
|
||||
{
|
||||
XWarpPointer(global.display, None, global.window, 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(global.display);
|
||||
|
@ -260,9 +260,9 @@ void InputImpl::SetMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
XWarpPointer(global.display, None, handle, 0, 0, 0, 0, position.x, position.y);
|
||||
|
|
|
@ -52,7 +52,7 @@ public :
|
|||
/// \return True if the key is pressed, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool IsKeyPressed(Keyboard::Key key);
|
||||
static bool isKeyPressed(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a mouse button is pressed
|
||||
|
@ -62,7 +62,7 @@ public :
|
|||
/// \return True if the button is pressed, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool IsMouseButtonPressed(Mouse::Button button);
|
||||
static bool isMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in desktop coordinates
|
||||
|
@ -73,7 +73,7 @@ public :
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition();
|
||||
static Vector2i getMousePosition();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in window coordinates
|
||||
|
@ -87,7 +87,7 @@ public :
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -99,7 +99,7 @@ public :
|
|||
/// \param position New position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position);
|
||||
static void setMousePosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in window coordinates
|
||||
|
@ -112,7 +112,7 @@ public :
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue