Changed the naming convention for member variables (prefix changed from "my" to "m_")

This commit is contained in:
Laurent Gomila 2012-03-09 01:22:47 +01:00
parent 15e9d999b3
commit ff5b69d312
124 changed files with 1889 additions and 1889 deletions

View File

@ -21,23 +21,23 @@ public :
const std::string& GetName() const const std::string& GetName() const
{ {
return myName; return m_name;
} }
void Load() void Load()
{ {
myIsLoaded = sf::Shader::IsAvailable() && OnLoad(); m_isLoaded = sf::Shader::IsAvailable() && OnLoad();
} }
void Update(float time, float x, float y) void Update(float time, float x, float y)
{ {
if (myIsLoaded) if (m_isLoaded)
OnUpdate(time, x, y); OnUpdate(time, x, y);
} }
void Draw(sf::RenderTarget& target, sf::RenderStates states) const void Draw(sf::RenderTarget& target, sf::RenderStates states) const
{ {
if (myIsLoaded) if (m_isLoaded)
{ {
OnDraw(target, states); OnDraw(target, states);
} }
@ -53,8 +53,8 @@ public :
protected : protected :
Effect(const std::string& name) : Effect(const std::string& name) :
myName(name), m_name(name),
myIsLoaded(false) m_isLoaded(false)
{ {
} }
@ -67,8 +67,8 @@ private :
private : private :
std::string myName; std::string m_name;
bool myIsLoaded; bool m_isLoaded;
}; };
#endif // EFFECT_HPP #endif // EFFECT_HPP

View File

@ -23,34 +23,34 @@ public :
bool OnLoad() bool OnLoad()
{ {
// Load the texture and initialize the sprite // Load the texture and initialize the sprite
if (!myTexture.LoadFromFile("resources/background.jpg")) if (!m_texture.LoadFromFile("resources/background.jpg"))
return false; return false;
mySprite.SetTexture(myTexture); m_sprite.SetTexture(m_texture);
// Load the shader // Load the shader
if (!myShader.LoadFromFile("resources/pixelate.frag", sf::Shader::Fragment)) if (!m_shader.LoadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
return false; return false;
myShader.SetParameter("texture", sf::Shader::CurrentTexture); m_shader.SetParameter("texture", sf::Shader::CurrentTexture);
return true; return true;
} }
void OnUpdate(float, float x, float y) void OnUpdate(float, float x, float y)
{ {
myShader.SetParameter("pixel_threshold", (x + y) / 30); m_shader.SetParameter("pixel_threshold", (x + y) / 30);
} }
void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const
{ {
states.Shader = &myShader; states.Shader = &m_shader;
target.Draw(mySprite, states); target.Draw(m_sprite, states);
} }
private: private:
sf::Texture myTexture; sf::Texture m_texture;
sf::Sprite mySprite; sf::Sprite m_sprite;
sf::Shader myShader; sf::Shader m_shader;
}; };
@ -69,7 +69,7 @@ public :
bool OnLoad() bool OnLoad()
{ {
// Create the text // Create the text
myText.SetString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" m_text.SetString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
"Donec fringilla scelerisque mauris et viverra.\n" "Donec fringilla scelerisque mauris et viverra.\n"
@ -87,11 +87,11 @@ public :
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
"Duis erat eros, porta in accumsan in, blandit quis sem.\n" "Duis erat eros, porta in accumsan in, blandit quis sem.\n"
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n"); "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
myText.SetCharacterSize(22); m_text.SetCharacterSize(22);
myText.SetPosition(30, 20); m_text.SetPosition(30, 20);
// Load the shader // Load the shader
if (!myShader.LoadFromFile("resources/wave.vert", "resources/blur.frag")) if (!m_shader.LoadFromFile("resources/wave.vert", "resources/blur.frag"))
return false; return false;
return true; return true;
@ -99,21 +99,21 @@ public :
void OnUpdate(float time, float x, float y) void OnUpdate(float time, float x, float y)
{ {
myShader.SetParameter("wave_phase", time); m_shader.SetParameter("wave_phase", time);
myShader.SetParameter("wave_amplitude", x * 40, y * 40); m_shader.SetParameter("wave_amplitude", x * 40, y * 40);
myShader.SetParameter("blur_radius", (x + y) * 0.008f); m_shader.SetParameter("blur_radius", (x + y) * 0.008f);
} }
void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const
{ {
states.Shader = &myShader; states.Shader = &m_shader;
target.Draw(myText, states); target.Draw(m_text, states);
} }
private: private:
sf::Text myText; sf::Text m_text;
sf::Shader myShader; sf::Shader m_shader;
}; };
@ -132,7 +132,7 @@ public :
bool OnLoad() bool OnLoad()
{ {
// Create the points // Create the points
myPoints.SetPrimitiveType(sf::Points); m_points.SetPrimitiveType(sf::Points);
for (int i = 0; i < 40000; ++i) for (int i = 0; i < 40000; ++i)
{ {
float x = static_cast<float>(std::rand() % 800); float x = static_cast<float>(std::rand() % 800);
@ -140,11 +140,11 @@ public :
sf::Uint8 r = std::rand() % 255; sf::Uint8 r = std::rand() % 255;
sf::Uint8 g = std::rand() % 255; sf::Uint8 g = std::rand() % 255;
sf::Uint8 b = std::rand() % 255; sf::Uint8 b = std::rand() % 255;
myPoints.Append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b))); m_points.Append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
} }
// Load the shader // Load the shader
if (!myShader.LoadFromFile("resources/storm.vert", "resources/blink.frag")) if (!m_shader.LoadFromFile("resources/storm.vert", "resources/blink.frag"))
return false; return false;
return true; return true;
@ -153,22 +153,22 @@ public :
void OnUpdate(float time, float x, float y) void OnUpdate(float time, float x, float y)
{ {
float radius = 200 + std::cos(time) * 150; float radius = 200 + std::cos(time) * 150;
myShader.SetParameter("storm_position", x * 800, y * 600); m_shader.SetParameter("storm_position", x * 800, y * 600);
myShader.SetParameter("storm_inner_radius", radius / 3); m_shader.SetParameter("storm_inner_radius", radius / 3);
myShader.SetParameter("storm_total_radius", radius); m_shader.SetParameter("storm_total_radius", radius);
myShader.SetParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f); m_shader.SetParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
} }
void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const
{ {
states.Shader = &myShader; states.Shader = &m_shader;
target.Draw(myPoints, states); target.Draw(m_points, states);
} }
private: private:
sf::VertexArray myPoints; sf::VertexArray m_points;
sf::Shader myShader; sf::Shader m_shader;
}; };
@ -187,71 +187,71 @@ public :
bool OnLoad() bool OnLoad()
{ {
// Create the off-screen surface // Create the off-screen surface
if (!mySurface.Create(800, 600)) if (!m_surface.Create(800, 600))
return false; return false;
mySurface.SetSmooth(true); m_surface.SetSmooth(true);
// Load the textures // Load the textures
if (!myBackgroundTexture.LoadFromFile("resources/sfml.png")) if (!m_backgroundTexture.LoadFromFile("resources/sfml.png"))
return false; return false;
myBackgroundTexture.SetSmooth(true); m_backgroundTexture.SetSmooth(true);
if (!myEntityTexture.LoadFromFile("resources/devices.png")) if (!m_entityTexture.LoadFromFile("resources/devices.png"))
return false; return false;
myEntityTexture.SetSmooth(true); m_entityTexture.SetSmooth(true);
// Initialize the background sprite // Initialize the background sprite
myBackgroundSprite.SetTexture(myBackgroundTexture); m_backgroundSprite.SetTexture(m_backgroundTexture);
myBackgroundSprite.SetPosition(135, 100); m_backgroundSprite.SetPosition(135, 100);
// Load the moving entities // Load the moving entities
for (int i = 0; i < 6; ++i) for (int i = 0; i < 6; ++i)
{ {
sf::Sprite entity(myEntityTexture, sf::IntRect(96 * i, 0, 96, 96)); sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96));
myEntities.push_back(entity); m_entities.push_back(entity);
} }
// Load the shader // Load the shader
if (!myShader.LoadFromFile("resources/edge.frag", sf::Shader::Fragment)) if (!m_shader.LoadFromFile("resources/edge.frag", sf::Shader::Fragment))
return false; return false;
myShader.SetParameter("texture", sf::Shader::CurrentTexture); m_shader.SetParameter("texture", sf::Shader::CurrentTexture);
return true; return true;
} }
void OnUpdate(float time, float x, float y) void OnUpdate(float time, float x, float y)
{ {
myShader.SetParameter("edge_threshold", 1 - (x + y) / 2); m_shader.SetParameter("edge_threshold", 1 - (x + y) / 2);
// Update the position of the moving entities // Update the position of the moving entities
for (std::size_t i = 0; i < myEntities.size(); ++i) for (std::size_t i = 0; i < m_entities.size(); ++i)
{ {
float x = std::cos(0.25f * (time * i + (myEntities.size() - i))) * 300 + 350; float x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
float y = std::sin(0.25f * (time * (myEntities.size() - i) + i)) * 200 + 250; float y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
myEntities[i].SetPosition(x, y); m_entities[i].SetPosition(x, y);
} }
// Render the updated scene to the off-screen surface // Render the updated scene to the off-screen surface
mySurface.Clear(sf::Color::White); m_surface.Clear(sf::Color::White);
mySurface.Draw(myBackgroundSprite); m_surface.Draw(m_backgroundSprite);
for (std::size_t i = 0; i < myEntities.size(); ++i) for (std::size_t i = 0; i < m_entities.size(); ++i)
mySurface.Draw(myEntities[i]); m_surface.Draw(m_entities[i]);
mySurface.Display(); m_surface.Display();
} }
void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const
{ {
states.Shader = &myShader; states.Shader = &m_shader;
target.Draw(sf::Sprite(mySurface.GetTexture()), states); target.Draw(sf::Sprite(m_surface.GetTexture()), states);
} }
private: private:
sf::RenderTexture mySurface; sf::RenderTexture m_surface;
sf::Texture myBackgroundTexture; sf::Texture m_backgroundTexture;
sf::Texture myEntityTexture; sf::Texture m_entityTexture;
sf::Sprite myBackgroundSprite; sf::Sprite m_backgroundSprite;
std::vector<sf::Sprite> myEntities; std::vector<sf::Sprite> m_entities;
sf::Shader myShader; sf::Shader m_shader;
}; };

View File

@ -27,8 +27,8 @@ public :
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
NetworkRecorder(const sf::IpAddress& host, unsigned short port) : NetworkRecorder(const sf::IpAddress& host, unsigned short port) :
myHost(host), m_host(host),
myPort(port) m_port(port)
{ {
} }
@ -40,9 +40,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual bool OnStart() virtual bool OnStart()
{ {
if (mySocket.Connect(myHost, myPort) == sf::Socket::Done) if (m_socket.Connect(m_host, m_port) == sf::Socket::Done)
{ {
std::cout << "Connected to server " << myHost << std::endl; std::cout << "Connected to server " << m_host << std::endl;
return true; return true;
} }
else else
@ -63,7 +63,7 @@ private :
packet.Append(samples, sampleCount * sizeof(sf::Int16)); packet.Append(samples, sampleCount * sizeof(sf::Int16));
// Send the audio packet to the server // Send the audio packet to the server
return mySocket.Send(packet) == sf::Socket::Done; return m_socket.Send(packet) == sf::Socket::Done;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -75,18 +75,18 @@ private :
// Send a "end-of-stream" packet // Send a "end-of-stream" packet
sf::Packet packet; sf::Packet packet;
packet << endOfStream; packet << endOfStream;
mySocket.Send(packet); m_socket.Send(packet);
// Close the socket // Close the socket
mySocket.Disconnect(); m_socket.Disconnect();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::IpAddress myHost; ///< Address of the remote host sf::IpAddress m_host; ///< Address of the remote host
unsigned short myPort; ///< Remote port unsigned short m_port; ///< Remote port
sf::TcpSocket mySocket; ///< Socket used to communicate with the server sf::TcpSocket m_socket; ///< Socket used to communicate with the server
}; };

View File

@ -26,8 +26,8 @@ public :
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
NetworkAudioStream() : NetworkAudioStream() :
myOffset (0), m_offset (0),
myHasFinished(false) m_hasFinished(false)
{ {
// Set the sound parameters // Set the sound parameters
Initialize(1, 44100); Initialize(1, 44100);
@ -39,17 +39,17 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Start(unsigned short port) void Start(unsigned short port)
{ {
if (!myHasFinished) if (!m_hasFinished)
{ {
// Listen to the given port for incoming connections // Listen to the given port for incoming connections
if (myListener.Listen(port) != sf::Socket::Done) if (m_listener.Listen(port) != sf::Socket::Done)
return; return;
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl; std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
// Wait for a connection // Wait for a connection
if (myListener.Accept(myClient) != sf::Socket::Done) if (m_listener.Accept(m_client) != sf::Socket::Done)
return; return;
std::cout << "Client connected: " << myClient.GetRemoteAddress() << std::endl; std::cout << "Client connected: " << m_client.GetRemoteAddress() << std::endl;
// Start playback // Start playback
Play(); Play();
@ -73,26 +73,26 @@ private :
virtual bool OnGetData(sf::SoundStream::Chunk& data) virtual bool OnGetData(sf::SoundStream::Chunk& data)
{ {
// We have reached the end of the buffer and all audio data have been played : we can stop playback // We have reached the end of the buffer and all audio data have been played : we can stop playback
if ((myOffset >= mySamples.size()) && myHasFinished) if ((m_offset >= m_samples.size()) && m_hasFinished)
return false; return false;
// No new data has arrived since last update : wait until we get some // No new data has arrived since last update : wait until we get some
while ((myOffset >= mySamples.size()) && !myHasFinished) while ((m_offset >= m_samples.size()) && !m_hasFinished)
sf::Sleep(sf::Milliseconds(10)); sf::Sleep(sf::Milliseconds(10));
// Copy samples into a local buffer to avoid synchronization problems // Copy samples into a local buffer to avoid synchronization problems
// (don't forget that we run in two separate threads) // (don't forget that we run in two separate threads)
{ {
sf::Lock lock(myMutex); sf::Lock lock(m_mutex);
myTempBuffer.assign(mySamples.begin() + myOffset, mySamples.end()); m_tempBuffer.assign(m_samples.begin() + m_offset, m_samples.end());
} }
// Fill audio data to pass to the stream // Fill audio data to pass to the stream
data.Samples = &myTempBuffer[0]; data.Samples = &m_tempBuffer[0];
data.SampleCount = myTempBuffer.size(); data.SampleCount = m_tempBuffer.size();
// Update the playing offset // Update the playing offset
myOffset += myTempBuffer.size(); m_offset += m_tempBuffer.size();
return true; return true;
} }
@ -103,7 +103,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void OnSeek(sf::Time timeOffset) virtual void OnSeek(sf::Time timeOffset)
{ {
myOffset = timeOffset.AsMilliseconds() * GetSampleRate() * GetChannelCount() / 1000; m_offset = timeOffset.AsMilliseconds() * GetSampleRate() * GetChannelCount() / 1000;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -112,11 +112,11 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ReceiveLoop() void ReceiveLoop()
{ {
while (!myHasFinished) while (!m_hasFinished)
{ {
// Get waiting audio data from the network // Get waiting audio data from the network
sf::Packet packet; sf::Packet packet;
if (myClient.Receive(packet) != sf::Socket::Done) if (m_client.Receive(packet) != sf::Socket::Done)
break; break;
// Extract the message ID // Extract the message ID
@ -132,21 +132,21 @@ private :
// Don't forget that the other thread can access the sample array at any time // Don't forget that the other thread can access the sample array at any time
// (so we protect any operation on it with the mutex) // (so we protect any operation on it with the mutex)
{ {
sf::Lock lock(myMutex); sf::Lock lock(m_mutex);
std::copy(samples, samples + sampleCount, std::back_inserter(mySamples)); std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));
} }
} }
else if (id == endOfStream) else if (id == endOfStream)
{ {
// End of stream reached : we stop receiving audio data // End of stream reached : we stop receiving audio data
std::cout << "Audio data has been 100% received!" << std::endl; std::cout << "Audio data has been 100% received!" << std::endl;
myHasFinished = true; m_hasFinished = true;
} }
else else
{ {
// Something's wrong... // Something's wrong...
std::cout << "Invalid packet received..." << std::endl; std::cout << "Invalid packet received..." << std::endl;
myHasFinished = true; m_hasFinished = true;
} }
} }
} }
@ -154,13 +154,13 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::TcpListener myListener; sf::TcpListener m_listener;
sf::TcpSocket myClient; sf::TcpSocket m_client;
sf::Mutex myMutex; sf::Mutex m_mutex;
std::vector<sf::Int16> mySamples; std::vector<sf::Int16> m_samples;
std::vector<sf::Int16> myTempBuffer; std::vector<sf::Int16> m_tempBuffer;
std::size_t myOffset; std::size_t m_offset;
bool myHasFinished; bool m_hasFinished;
}; };

View File

@ -162,10 +162,10 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::SoundFile* myFile; ///< Sound file priv::SoundFile* m_file; ///< Sound file
Time myDuration; ///< Music duration Time m_duration; ///< Music duration
std::vector<Int16> mySamples; ///< Temporary buffer of samples std::vector<Int16> m_samples; ///< Temporary buffer of samples
Mutex myMutex; ///< Mutex protecting the data Mutex m_mutex; ///< Mutex protecting the data
}; };
} // namespace sf } // namespace sf

View File

@ -215,7 +215,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const SoundBuffer* myBuffer; ///< Sound buffer bound to the source const SoundBuffer* m_buffer; ///< Sound buffer bound to the source
}; };
} // namespace sf } // namespace sf

View File

@ -279,10 +279,10 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int myBuffer; ///< OpenAL buffer identifier unsigned int m_buffer; ///< OpenAL buffer identifier
std::vector<Int16> mySamples; ///< Samples buffer std::vector<Int16> m_samples; ///< Samples buffer
Time myDuration; ///< Sound duration Time m_duration; ///< Sound duration
mutable SoundList mySounds; ///< List of sounds that are using this buffer mutable SoundList m_sounds; ///< List of sounds that are using this buffer
}; };
} // namespace sf } // namespace sf

View File

@ -88,8 +88,8 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<Int16> mySamples; ///< Temporary sample buffer to hold the recorded data std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
SoundBuffer myBuffer; ///< Sound buffer that will contain the recorded data SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
}; };
} // namespace sf } // namespace sf

View File

@ -181,10 +181,10 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Thread myThread; ///< Thread running the background recording task Thread m_thread; ///< Thread running the background recording task
std::vector<Int16> mySamples; ///< Buffer to store captured samples std::vector<Int16> m_samples; ///< Buffer to store captured samples
unsigned int mySampleRate; ///< Sample rate unsigned int m_sampleRate; ///< Sample rate
bool myIsCapturing; ///< Capturing state bool m_isCapturing; ///< Capturing state
}; };
} // namespace sf } // namespace sf

View File

@ -260,7 +260,7 @@ protected :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int mySource; ///< OpenAL source identifier unsigned int m_source; ///< OpenAL source identifier
}; };
} // namespace sf } // namespace sf

View File

@ -281,15 +281,15 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Thread myThread; ///< Thread running the background tasks Thread m_thread; ///< Thread running the background tasks
bool myIsStreaming; ///< Streaming state (true = playing, false = stopped) bool m_isStreaming; ///< Streaming state (true = playing, false = stopped)
unsigned int myBuffers[BufferCount]; ///< Sound buffers used to store temporary audio data unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data
unsigned int myChannelCount; ///< Number of channels (1 = mono, 2 = stereo, ...) unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int mySampleRate; ///< Frequency (samples / second) unsigned int m_sampleRate; ///< Frequency (samples / second)
Uint32 myFormat; ///< Format of the internal sound buffers Uint32 m_format; ///< Format of the internal sound buffers
bool myLoop; ///< Loop flag (true to loop, false to play once) bool m_loop; ///< Loop flag (true to loop, false to play once)
Uint64 mySamplesProcessed; ///< Number of buffers processed since beginning of the stream Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream
bool myEndBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
}; };
} // namespace sf } // namespace sf

View File

@ -108,8 +108,8 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float myRadius; ///< Radius of the circle float m_radius; ///< Radius of the circle
unsigned int myPointCount; ///< Number of points composing the circle unsigned int m_pointCount; ///< Number of points composing the circle
}; };
} // namespace sf } // namespace sf

View File

@ -109,7 +109,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<Vector2f> myPoints; ///< Points composing the convex polygon std::vector<Vector2f> m_points; ///< Points composing the convex polygon
}; };
} // namespace sf } // namespace sf

View File

@ -103,11 +103,11 @@ private :
/// virtual void Draw(sf::RenderTarget& target, RenderStates states) const /// virtual void Draw(sf::RenderTarget& target, RenderStates states) const
/// { /// {
/// // You can draw other high-level objects /// // You can draw other high-level objects
/// target.Draw(mySprite, states); /// target.Draw(m_sprite, states);
/// ///
/// // ... or use the low-level API /// // ... or use the low-level API
/// states.Texture = &myTexture; /// states.Texture = &m_texture;
/// target.Draw(myVertices, states); /// target.Draw(m_vertices, states);
/// ///
/// // ... or draw with OpenGL directly /// // ... or draw with OpenGL directly
/// glBegin(GL_QUADS); /// glBegin(GL_QUADS);
@ -115,9 +115,9 @@ private :
/// glEnd(); /// glEnd();
/// } /// }
/// ///
/// sf::Sprite mySprite; /// sf::Sprite m_sprite;
/// sf::Texture myTexture; /// sf::Texture m_texture;
/// sf::VertexArray myVertices; /// sf::VertexArray m_vertices;
/// }; /// };
/// \endcode /// \endcode
/// ///

View File

@ -293,12 +293,12 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void* myLibrary; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details) void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
void* myFace; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details) void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
void* myStreamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details) void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
int* myRefCount; ///< Reference counter used by implicit sharing int* m_refCount; ///< Reference counter used by implicit sharing
mutable PageTable myPages; ///< Table containing the glyphs pages by character size mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
mutable std::vector<Uint8> myPixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
}; };
} // namespace sf } // namespace sf

View File

@ -267,9 +267,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int myWidth; ///< Image width unsigned int m_width; ///< Image width
unsigned int myHeight; ///< Image Height unsigned int m_height; ///< Image Height
std::vector<Uint8> myPixels; ///< Pixels of the image std::vector<Uint8> m_pixels; ///< Pixels of the image
}; };
} // namespace sf } // namespace sf

View File

@ -95,7 +95,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f mySize; ///< Size of the rectangle Vector2f m_size; ///< Size of the rectangle
}; };
} // namespace sf } // namespace sf

View File

@ -366,9 +366,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
View myDefaultView; ///< Default view View m_defaultView; ///< Default view
View myView; ///< Current view View m_view; ///< Current view
StatesCache myCache; ///< Render states cache StatesCache m_cache; ///< Render states cache
}; };
} // namespace sf } // namespace sf

View File

@ -181,8 +181,8 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::RenderTextureImpl* myImpl; ///< Platform/hardware specific implementation priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
Texture myTexture; ///< Target texture to draw on Texture m_texture; ///< Target texture to draw on
}; };
} // namespace sf } // namespace sf

View File

@ -522,9 +522,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int myShaderProgram; ///< OpenGL identifier for the program unsigned int m_shaderProgram; ///< OpenGL identifier for the program
int myCurrentTexture; ///< Location of the current texture in the shader int m_currentTexture; ///< Location of the current texture in the shader
TextureTable myTextures; ///< Texture variables in the shader, mapped to their location TextureTable m_textures; ///< Texture variables in the shader, mapped to their location
}; };
} // namespace sf } // namespace sf

View File

@ -291,15 +291,15 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Texture* myTexture; ///< Texture of the shape const Texture* m_texture; ///< Texture of the shape
IntRect myTextureRect; ///< Rectangle defining the area of the source texture to display IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
Color myFillColor; ///< Fill color Color m_fillColor; ///< Fill color
Color myOutlineColor; ///< Outline color Color m_outlineColor; ///< Outline color
float myOutlineThickness; ///< Thickness of the shape's outline float m_outlineThickness; ///< Thickness of the shape's outline
VertexArray myVertices; ///< Vertex array containing the fill geometry VertexArray m_vertices; ///< Vertex array containing the fill geometry
VertexArray myOutlineVertices; ///< Vertex array containing the outline geometry VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
FloatRect myInsideBounds; ///< Bounding rectangle of the inside (fill) FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
FloatRect myBounds; ///< Bounding rectangle of the whole shape (outline + fill) FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
}; };
} // namespace sf } // namespace sf

View File

@ -215,9 +215,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex myVertices[4]; ///< Vertices defining the sprite's geometry Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
const Texture* myTexture; ///< Texture of the sprite const Texture* m_texture; ///< Texture of the sprite
IntRect myTextureRect; ///< Rectangle defining the area of the source texture to display IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
}; };
} // namespace sf } // namespace sf

View File

@ -284,13 +284,13 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String myString; ///< String to display String m_string; ///< String to display
const Font* myFont; ///< Font used to display the string const Font* m_font; ///< Font used to display the string
unsigned int myCharacterSize; ///< Base size of characters, in pixels unsigned int m_characterSize; ///< Base size of characters, in pixels
Uint32 myStyle; ///< Text style (see Style enum) Uint32 m_style; ///< Text style (see Style enum)
Color myColor; ///< Text color Color m_color; ///< Text color
VertexArray myVertices; ///< Vertex array containing the text's geometry VertexArray m_vertices; ///< Vertex array containing the text's geometry
FloatRect myBounds; ///< Bounding rectangle of the text (in local coordinates) FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
}; };
} // namespace sf } // namespace sf

View File

@ -489,15 +489,15 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int myWidth; ///< Image width unsigned int m_width; ///< Image width
unsigned int myHeight; ///< Image Height unsigned int m_height; ///< Image Height
unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding) unsigned int m_textureWidth; ///< Actual texture width (can be greater than image width because of padding)
unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding) unsigned int m_textureHeight; ///< Actual texture height (can be greater than image height because of padding)
unsigned int myTexture; ///< Internal texture identifier unsigned int m_texture; ///< Internal texture identifier
bool myIsSmooth; ///< Status of the smooth filter bool m_isSmooth; ///< Status of the smooth filter
bool myIsRepeated; ///< Is the texture in repeat mode? bool m_isRepeated; ///< Is the texture in repeat mode?
mutable bool myPixelsFlipped; ///< To work around the inconsistency in Y orientation mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
Uint64 myCacheId; ///< Unique number that identifies the texture to the render target's cache Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
}; };
} // namespace sf } // namespace sf

View File

@ -358,7 +358,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float myMatrix[16]; ///< 4x4 matrix defining the transformation float m_matrix[16]; ///< 4x4 matrix defining the transformation
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -316,14 +316,14 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f myOrigin; ///< Origin of translation/rotation/scaling of the object Vector2f m_origin; ///< Origin of translation/rotation/scaling of the object
Vector2f myPosition; ///< Position of the object in the 2D world Vector2f m_position; ///< Position of the object in the 2D world
float myRotation; ///< Orientation of the object, in degrees float m_rotation; ///< Orientation of the object, in degrees
Vector2f myScale; ///< Scale of the object Vector2f m_scale; ///< Scale of the object
mutable Transform myTransform; ///< Combined transformation of the object mutable Transform m_transform; ///< Combined transformation of the object
mutable bool myTransformNeedUpdate; ///< Does the transform need to be recomputed? mutable bool m_transformNeedUpdate; ///< Does the transform need to be recomputed?
mutable Transform myInverseTransform; ///< Combined transformation of the object mutable Transform m_inverseTransform; ///< Combined transformation of the object
mutable bool myInverseTransformNeedUpdate; ///< Does the transform need to be recomputed? mutable bool m_inverseTransformNeedUpdate; ///< Does the transform need to be recomputed?
}; };
} // namespace sf } // namespace sf

View File

@ -187,8 +187,8 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<Vertex> myVertices; ///< Vertices contained in the array std::vector<Vertex> m_vertices; ///< Vertices contained in the array
PrimitiveType myPrimitiveType; ///< Type of primitives to draw PrimitiveType m_primitiveType; ///< Type of primitives to draw
}; };
} // namespace sf } // namespace sf

View File

@ -269,14 +269,14 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f myCenter; ///< Center of the view, in scene coordinates Vector2f m_center; ///< Center of the view, in scene coordinates
Vector2f mySize; ///< Size of the view, in scene coordinates Vector2f m_size; ///< Size of the view, in scene coordinates
float myRotation; ///< Angle of rotation of the view rectangle, in degrees float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
FloatRect myViewport; ///< Viewport rectangle, expressed as a factor of the render-target's size FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
mutable Transform myTransform; ///< Precomputed projection transform corresponding to the view mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
mutable Transform myInverseTransform; ///< Precomputed inverse projection transform corresponding to the view mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
mutable bool myTransformUpdated; ///< Internal state telling if the transform needs to be updated mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
mutable bool myInvTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated mutable bool m_invTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated
}; };
} // namespace sf } // namespace sf

View File

@ -177,8 +177,8 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Status myStatus; ///< Status code returned from the server Status m_status; ///< Status code returned from the server
std::string myMessage; ///< Last message received from the server std::string m_message; ///< Last message received from the server
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -210,7 +210,7 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::string myDirectory; ///< Directory extracted from the response message std::string m_directory; ///< Directory extracted from the response message
}; };
@ -244,7 +244,7 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<std::string> myFilenames; ///< Filenames extracted from the data std::vector<std::string> m_filenames; ///< Filenames extracted from the data
}; };
@ -517,7 +517,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TcpSocket myCommandSocket; ///< Socket holding the control connection with the server TcpSocket m_commandSocket; ///< Socket holding the control connection with the server
}; };
} // namespace sf } // namespace sf

View File

@ -176,12 +176,12 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FieldTable myFields; ///< Fields of the header associated to their value FieldTable m_fields; ///< Fields of the header associated to their value
Method myMethod; ///< Method to use for the request Method m_method; ///< Method to use for the request
std::string myURI; ///< Target URI of the request std::string m_uRI; ///< Target URI of the request
unsigned int myMajorVersion; ///< Major HTTP version unsigned int m_majorVersion; ///< Major HTTP version
unsigned int myMinorVersion; ///< Minor HTTP version unsigned int m_minorVersion; ///< Minor HTTP version
std::string myBody; ///< Body of the request std::string m_body; ///< Body of the request
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -324,11 +324,11 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FieldTable myFields; ///< Fields of the header FieldTable m_fields; ///< Fields of the header
Status myStatus; ///< Status code Status m_status; ///< Status code
unsigned int myMajorVersion; ///< Major HTTP version unsigned int m_majorVersion; ///< Major HTTP version
unsigned int myMinorVersion; ///< Minor HTTP version unsigned int m_minorVersion; ///< Minor HTTP version
std::string myBody; ///< Body of the response std::string m_body; ///< Body of the response
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -395,10 +395,10 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TcpSocket myConnection; ///< Connection to the host TcpSocket m_connection; ///< Connection to the host
IpAddress myHost; ///< Web host address IpAddress m_host; ///< Web host address
std::string myHostName; ///< Web host name std::string m_hostName; ///< Web host name
unsigned short myPort; ///< Port used for connection with host unsigned short m_port; ///< Port used for connection with host
}; };
} // namespace sf } // namespace sf

View File

@ -190,7 +190,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32 myAddress; ///< Address stored as an unsigned 32 bits integer Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -272,9 +272,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<char> myData; ///< Data stored in the packet std::vector<char> m_data; ///< Data stored in the packet
std::size_t myReadPos; ///< Current reading position in the packet std::size_t m_readPos; ///< Current reading position in the packet
bool myIsValid; ///< Reading state of the packet bool m_isValid; ///< Reading state of the packet
}; };
} // namespace sf } // namespace sf

View File

@ -172,9 +172,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Type myType; ///< Type of the socket (TCP or UDP) Type m_type; ///< Type of the socket (TCP or UDP)
SocketHandle mySocket; ///< Socket descriptor SocketHandle m_socket; ///< Socket descriptor
bool myIsBlocking; ///< Current blocking mode of the socket bool m_isBlocking; ///< Current blocking mode of the socket
}; };
} // namespace sf } // namespace sf

View File

@ -157,7 +157,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketSelectorImpl* myImpl; ///< Opaque pointer to the implementation (which requires OS-specific types) SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types)
}; };
} // namespace sf } // namespace sf

View File

@ -204,7 +204,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
PendingPacket myPendingPacket; ///< Temporary data of the packet currently being received PendingPacket m_pendingPacket; ///< Temporary data of the packet currently being received
}; };
} // namespace sf } // namespace sf

View File

@ -187,7 +187,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<char> myBuffer; ///< Temporary buffer holding the received data in Receive(Packet) std::vector<char> m_buffer; ///< Temporary buffer holding the received data in Receive(Packet)
}; };
} // namespace sf } // namespace sf

View File

@ -78,7 +78,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time myStartTime; ///< Time of last reset, in microseconds Time m_startTime; ///< Time of last reset, in microseconds
}; };
} // namespace sf } // namespace sf

View File

@ -67,7 +67,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Mutex& myMutex; ///< Mutex to lock / unlock Mutex& m_mutex; ///< Mutex to lock / unlock
}; };
} // namespace sf } // namespace sf

View File

@ -85,7 +85,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::MutexImpl* myMutexImpl; ///< OS-specific implementation priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation
}; };
} // namespace sf } // namespace sf

View File

@ -400,7 +400,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::basic_string<Uint32> myString; ///< Internal string of UTF-32 characters std::basic_string<Uint32> m_string; ///< Internal string of UTF-32 characters
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -186,8 +186,8 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::ThreadImpl* myImpl; ///< OS-specific implementation of the thread priv::ThreadImpl* m_impl; ///< OS-specific implementation of the thread
priv::ThreadFunc* myEntryPoint; ///< Abstraction of the function to run priv::ThreadFunc* m_entryPoint; ///< Abstraction of the function to run
}; };
#include <SFML/System/Thread.inl> #include <SFML/System/Thread.inl>

View File

@ -35,29 +35,29 @@ struct ThreadFunc
template <typename T> template <typename T>
struct ThreadFunctor : ThreadFunc struct ThreadFunctor : ThreadFunc
{ {
ThreadFunctor(T functor) : myFunctor(functor) {} ThreadFunctor(T functor) : m_functor(functor) {}
virtual void Run() {myFunctor();} virtual void Run() {m_functor();}
T myFunctor; T m_functor;
}; };
// Specialization using a functor (including free functions) with one argument // Specialization using a functor (including free functions) with one argument
template <typename F, typename A> template <typename F, typename A>
struct ThreadFunctorWithArg : ThreadFunc struct ThreadFunctorWithArg : ThreadFunc
{ {
ThreadFunctorWithArg(F function, A arg) : myFunction(function), myArg(arg) {} ThreadFunctorWithArg(F function, A arg) : m_function(function), m_arg(arg) {}
virtual void Run() {myFunction(myArg);} virtual void Run() {m_function(m_arg);}
F myFunction; F m_function;
A myArg; A m_arg;
}; };
// Specialization using a member function // Specialization using a member function
template <typename C> template <typename C>
struct ThreadMemberFunc : ThreadFunc struct ThreadMemberFunc : ThreadFunc
{ {
ThreadMemberFunc(void(C::*function)(), C* object) : myFunction(function), myObject(object) {} ThreadMemberFunc(void(C::*function)(), C* object) : m_function(function), m_object(object) {}
virtual void Run() {(myObject->*myFunction)();} virtual void Run() {(m_object->*m_function)();}
void(C::*myFunction)(); void(C::*m_function)();
C* myObject; C* m_object;
}; };
} // namespace priv } // namespace priv
@ -66,8 +66,8 @@ struct ThreadMemberFunc : ThreadFunc
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename F> template <typename F>
Thread::Thread(F functor) : Thread::Thread(F functor) :
myImpl (NULL), m_impl (NULL),
myEntryPoint(new priv::ThreadFunctor<F>(functor)) m_entryPoint(new priv::ThreadFunctor<F>(functor))
{ {
} }
@ -75,8 +75,8 @@ myEntryPoint(new priv::ThreadFunctor<F>(functor))
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename F, typename A> template <typename F, typename A>
Thread::Thread(F function, A argument) : Thread::Thread(F function, A argument) :
myImpl (NULL), m_impl (NULL),
myEntryPoint(new priv::ThreadFunctorWithArg<F, A>(function, argument)) m_entryPoint(new priv::ThreadFunctorWithArg<F, A>(function, argument))
{ {
} }
@ -84,7 +84,7 @@ myEntryPoint(new priv::ThreadFunctorWithArg<F, A>(function, argument))
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename C> template <typename C>
Thread::Thread(void(C::*function)(), C* object) : Thread::Thread(void(C::*function)(), C* object) :
myImpl (NULL), m_impl (NULL),
myEntryPoint(new priv::ThreadMemberFunc<C>(function, object)) m_entryPoint(new priv::ThreadMemberFunc<C>(function, object))
{ {
} }

View File

@ -83,7 +83,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::ThreadLocalImpl* myImpl; ///< Pointer to the OS specific implementation priv::ThreadLocalImpl* m_impl; ///< Pointer to the OS specific implementation
}; };
} // namespace sf } // namespace sf

View File

@ -106,7 +106,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 myMicroseconds; ///< Time value stored as microseconds Int64 m_microseconds; ///< Time value stored as microseconds
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -95,7 +95,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::GlContext* myContext; ///< Internal OpenGL context priv::GlContext* m_context; ///< Internal OpenGL context
}; };
} // namespace sf } // namespace sf

View File

@ -467,10 +467,10 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::WindowImpl* myImpl; ///< Platform-specific implementation of the window priv::WindowImpl* m_impl; ///< Platform-specific implementation of the window
priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context priv::GlContext* m_context; ///< Platform-specific implementation of the OpenGL context
Clock myClock; ///< Clock for measuring the elapsed time between frames Clock m_clock; ///< Clock for measuring the elapsed time between frames
Time myFrameTimeLimit; ///< Current framerate limit Time m_frameTimeLimit; ///< Current framerate limit
}; };
} // namespace sf } // namespace sf

View File

@ -37,8 +37,8 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music::Music() : Music::Music() :
myFile (new priv::SoundFile), m_file (new priv::SoundFile),
myDuration() m_duration()
{ {
} }
@ -50,7 +50,7 @@ Music::~Music()
// We must stop before destroying the file :) // We must stop before destroying the file :)
Stop(); Stop();
delete myFile; delete m_file;
} }
@ -61,7 +61,7 @@ bool Music::OpenFromFile(const std::string& filename)
Stop(); Stop();
// Open the underlying sound file // Open the underlying sound file
if (!myFile->OpenRead(filename)) if (!m_file->OpenRead(filename))
return false; return false;
// Perform common initializations // Perform common initializations
@ -78,7 +78,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
Stop(); Stop();
// Open the underlying sound file // Open the underlying sound file
if (!myFile->OpenRead(data, sizeInBytes)) if (!m_file->OpenRead(data, sizeInBytes))
return false; return false;
// Perform common initializations // Perform common initializations
@ -95,7 +95,7 @@ bool Music::OpenFromStream(InputStream& stream)
Stop(); Stop();
// Open the underlying sound file // Open the underlying sound file
if (!myFile->OpenRead(stream)) if (!m_file->OpenRead(stream))
return false; return false;
// Perform common initializations // Perform common initializations
@ -108,30 +108,30 @@ bool Music::OpenFromStream(InputStream& stream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time Music::GetDuration() const Time Music::GetDuration() const
{ {
return myDuration; return m_duration;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::OnGetData(SoundStream::Chunk& data) bool Music::OnGetData(SoundStream::Chunk& data)
{ {
Lock lock(myMutex); Lock lock(m_mutex);
// Fill the chunk parameters // Fill the chunk parameters
data.Samples = &mySamples[0]; data.Samples = &m_samples[0];
data.SampleCount = myFile->Read(&mySamples[0], mySamples.size()); data.SampleCount = m_file->Read(&m_samples[0], m_samples.size());
// Check if we have reached the end of the audio file // Check if we have reached the end of the audio file
return data.SampleCount == mySamples.size(); return data.SampleCount == m_samples.size();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Music::OnSeek(Time timeOffset) void Music::OnSeek(Time timeOffset)
{ {
Lock lock(myMutex); Lock lock(m_mutex);
myFile->Seek(timeOffset); m_file->Seek(timeOffset);
} }
@ -139,13 +139,13 @@ void Music::OnSeek(Time timeOffset)
void Music::Initialize() void Music::Initialize()
{ {
// Compute the music duration // Compute the music duration
myDuration = Seconds(static_cast<float>(myFile->GetSampleCount()) / myFile->GetSampleRate() / myFile->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 // Resize the internal buffer so that it can contain 1 second of audio samples
mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelCount()); m_samples.resize(m_file->GetSampleRate() * m_file->GetChannelCount());
// Initialize the stream // Initialize the stream
SoundStream::Initialize(myFile->GetChannelCount(), myFile->GetSampleRate()); SoundStream::Initialize(m_file->GetChannelCount(), m_file->GetSampleRate());
} }
} // namespace sf } // namespace sf

View File

@ -34,14 +34,14 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sound::Sound() : Sound::Sound() :
myBuffer(NULL) m_buffer(NULL)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sound::Sound(const SoundBuffer& buffer) : Sound::Sound(const SoundBuffer& buffer) :
myBuffer(NULL) m_buffer(NULL)
{ {
SetBuffer(buffer); SetBuffer(buffer);
} }
@ -50,10 +50,10 @@ myBuffer(NULL)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sound::Sound(const Sound& copy) : Sound::Sound(const Sound& copy) :
SoundSource(copy), SoundSource(copy),
myBuffer (NULL) m_buffer (NULL)
{ {
if (copy.myBuffer) if (copy.m_buffer)
SetBuffer(*copy.myBuffer); SetBuffer(*copy.m_buffer);
SetLoop(copy.GetLoop()); SetLoop(copy.GetLoop());
} }
@ -62,29 +62,29 @@ myBuffer (NULL)
Sound::~Sound() Sound::~Sound()
{ {
Stop(); Stop();
if (myBuffer) if (m_buffer)
myBuffer->DetachSound(this); m_buffer->DetachSound(this);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::Play() void Sound::Play()
{ {
ALCheck(alSourcePlay(mySource)); ALCheck(alSourcePlay(m_source));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::Pause() void Sound::Pause()
{ {
ALCheck(alSourcePause(mySource)); ALCheck(alSourcePause(m_source));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::Stop() void Sound::Stop()
{ {
ALCheck(alSourceStop(mySource)); ALCheck(alSourceStop(m_source));
} }
@ -92,37 +92,37 @@ void Sound::Stop()
void Sound::SetBuffer(const SoundBuffer& buffer) void Sound::SetBuffer(const SoundBuffer& buffer)
{ {
// First detach from the previous buffer // First detach from the previous buffer
if (myBuffer) if (m_buffer)
{ {
Stop(); Stop();
myBuffer->DetachSound(this); m_buffer->DetachSound(this);
} }
// Assign and use the new buffer // Assign and use the new buffer
myBuffer = &buffer; m_buffer = &buffer;
myBuffer->AttachSound(this); m_buffer->AttachSound(this);
ALCheck(alSourcei(mySource, AL_BUFFER, myBuffer->myBuffer)); ALCheck(alSourcei(m_source, AL_BUFFER, m_buffer->m_buffer));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::SetLoop(bool Loop) void Sound::SetLoop(bool Loop)
{ {
ALCheck(alSourcei(mySource, AL_LOOPING, Loop)); ALCheck(alSourcei(m_source, AL_LOOPING, Loop));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::SetPlayingOffset(Time timeOffset) void Sound::SetPlayingOffset(Time timeOffset)
{ {
ALCheck(alSourcef(mySource, 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 myBuffer; return m_buffer;
} }
@ -130,7 +130,7 @@ const SoundBuffer* Sound::GetBuffer() const
bool Sound::GetLoop() const bool Sound::GetLoop() const
{ {
ALint loop; ALint loop;
ALCheck(alGetSourcei(mySource, AL_LOOPING, &loop)); ALCheck(alGetSourcei(m_source, AL_LOOPING, &loop));
return loop != 0; return loop != 0;
} }
@ -140,7 +140,7 @@ bool Sound::GetLoop() const
Time Sound::GetPlayingOffset() const Time Sound::GetPlayingOffset() const
{ {
ALfloat seconds = 0.f; ALfloat seconds = 0.f;
ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds)); ALCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &seconds));
return Seconds(seconds); return Seconds(seconds);
} }
@ -160,16 +160,16 @@ Sound& Sound::operator =(const Sound& right)
// the list of sound instances contained in the buffers // the list of sound instances contained in the buffers
// Detach the sound instance from the previous buffer (if any) // Detach the sound instance from the previous buffer (if any)
if (myBuffer) if (m_buffer)
{ {
Stop(); Stop();
myBuffer->DetachSound(this); m_buffer->DetachSound(this);
myBuffer = NULL; m_buffer = NULL;
} }
// Copy the sound attributes // Copy the sound attributes
if (right.myBuffer) if (right.m_buffer)
SetBuffer(*right.myBuffer); SetBuffer(*right.m_buffer);
SetLoop(right.GetLoop()); SetLoop(right.GetLoop());
SetPitch(right.GetPitch()); SetPitch(right.GetPitch());
SetVolume(right.GetVolume()); SetVolume(right.GetVolume());
@ -189,8 +189,8 @@ void Sound::ResetBuffer()
Stop(); Stop();
// Detach the buffer // Detach the buffer
ALCheck(alSourcei(mySource, AL_BUFFER, 0)); ALCheck(alSourcei(m_source, AL_BUFFER, 0));
myBuffer = NULL; m_buffer = NULL;
} }
} // namespace sf } // namespace sf

View File

@ -38,25 +38,25 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer::SoundBuffer() : SoundBuffer::SoundBuffer() :
myBuffer (0), m_buffer (0),
myDuration() m_duration()
{ {
priv::EnsureALInit(); priv::EnsureALInit();
// Create the buffer // Create the buffer
ALCheck(alGenBuffers(1, &myBuffer)); ALCheck(alGenBuffers(1, &m_buffer));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer::SoundBuffer(const SoundBuffer& copy) : SoundBuffer::SoundBuffer(const SoundBuffer& copy) :
myBuffer (0), m_buffer (0),
mySamples (copy.mySamples), m_samples (copy.m_samples),
myDuration(copy.myDuration), m_duration(copy.m_duration),
mySounds () // don't copy the attached sounds m_sounds () // don't copy the attached sounds
{ {
// Create the buffer // Create the buffer
ALCheck(alGenBuffers(1, &myBuffer)); ALCheck(alGenBuffers(1, &m_buffer));
// Update the internal buffer with the new samples // Update the internal buffer with the new samples
Update(copy.GetChannelCount(), copy.GetSampleRate()); Update(copy.GetChannelCount(), copy.GetSampleRate());
@ -67,12 +67,12 @@ mySounds () // don't copy the attached sounds
SoundBuffer::~SoundBuffer() SoundBuffer::~SoundBuffer()
{ {
// First detach the buffer from the sounds that use it (to avoid OpenAL errors) // First detach the buffer from the sounds that use it (to avoid OpenAL errors)
for (SoundList::const_iterator it = mySounds.begin(); it != mySounds.end(); ++it) for (SoundList::const_iterator it = m_sounds.begin(); it != m_sounds.end(); ++it)
(*it)->ResetBuffer(); (*it)->ResetBuffer();
// Destroy the buffer // Destroy the buffer
if (myBuffer) if (m_buffer)
ALCheck(alDeleteBuffers(1, &myBuffer)); ALCheck(alDeleteBuffers(1, &m_buffer));
} }
@ -115,7 +115,7 @@ bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t sampleCount,
if (samples && sampleCount && channelCount && sampleRate) if (samples && sampleCount && channelCount && sampleRate)
{ {
// Copy the new audio samples // Copy the new audio samples
mySamples.assign(samples, samples + sampleCount); m_samples.assign(samples, samples + sampleCount);
// Update the internal buffer with the new samples // Update the internal buffer with the new samples
return Update(channelCount, sampleRate); return Update(channelCount, sampleRate);
@ -143,7 +143,7 @@ bool SoundBuffer::SaveToFile(const std::string& filename) const
if (file.OpenWrite(filename, GetChannelCount(), GetSampleRate())) if (file.OpenWrite(filename, GetChannelCount(), GetSampleRate()))
{ {
// Write the samples to the opened file // Write the samples to the opened file
file.Write(&mySamples[0], mySamples.size()); file.Write(&m_samples[0], m_samples.size());
return true; return true;
} }
@ -157,14 +157,14 @@ bool SoundBuffer::SaveToFile(const std::string& filename) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Int16* SoundBuffer::GetSamples() const const Int16* SoundBuffer::GetSamples() const
{ {
return mySamples.empty() ? NULL : &mySamples[0]; return m_samples.empty() ? NULL : &m_samples[0];
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::size_t SoundBuffer::GetSampleCount() const std::size_t SoundBuffer::GetSampleCount() const
{ {
return mySamples.size(); return m_samples.size();
} }
@ -172,7 +172,7 @@ std::size_t SoundBuffer::GetSampleCount() const
unsigned int SoundBuffer::GetSampleRate() const unsigned int SoundBuffer::GetSampleRate() const
{ {
ALint sampleRate; ALint sampleRate;
ALCheck(alGetBufferi(myBuffer, AL_FREQUENCY, &sampleRate)); ALCheck(alGetBufferi(m_buffer, AL_FREQUENCY, &sampleRate));
return sampleRate; return sampleRate;
} }
@ -182,7 +182,7 @@ unsigned int SoundBuffer::GetSampleRate() const
unsigned int SoundBuffer::GetChannelCount() const unsigned int SoundBuffer::GetChannelCount() const
{ {
ALint channelCount; ALint channelCount;
ALCheck(alGetBufferi(myBuffer, AL_CHANNELS, &channelCount)); ALCheck(alGetBufferi(m_buffer, AL_CHANNELS, &channelCount));
return channelCount; return channelCount;
} }
@ -191,7 +191,7 @@ unsigned int SoundBuffer::GetChannelCount() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time SoundBuffer::GetDuration() const Time SoundBuffer::GetDuration() const
{ {
return myDuration; return m_duration;
} }
@ -200,10 +200,10 @@ SoundBuffer& SoundBuffer::operator =(const SoundBuffer& right)
{ {
SoundBuffer temp(right); SoundBuffer temp(right);
std::swap(mySamples, temp.mySamples); std::swap(m_samples, temp.m_samples);
std::swap(myBuffer, temp.myBuffer); std::swap(m_buffer, temp.m_buffer);
std::swap(myDuration, temp.myDuration); std::swap(m_duration, temp.m_duration);
std::swap(mySounds, temp.mySounds); // swap sounds too, so that they are detached when temp is destroyed std::swap(m_sounds, temp.m_sounds); // swap sounds too, so that they are detached when temp is destroyed
return *this; return *this;
} }
@ -218,8 +218,8 @@ bool SoundBuffer::Initialize(priv::SoundFile& file)
unsigned int sampleRate = file.GetSampleRate(); unsigned int sampleRate = file.GetSampleRate();
// Read the samples from the provided file // Read the samples from the provided file
mySamples.resize(sampleCount); m_samples.resize(sampleCount);
if (file.Read(&mySamples[0], sampleCount) == sampleCount) if (file.Read(&m_samples[0], sampleCount) == sampleCount)
{ {
// Update the internal buffer with the new samples // Update the internal buffer with the new samples
return Update(channelCount, sampleRate); return Update(channelCount, sampleRate);
@ -235,7 +235,7 @@ 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 // Check parameters
if (!channelCount || !sampleRate || mySamples.empty()) if (!channelCount || !sampleRate || m_samples.empty())
return false; return false;
// Find the good format according to the number of channels // Find the good format according to the number of channels
@ -249,11 +249,11 @@ bool SoundBuffer::Update(unsigned int channelCount, unsigned int sampleRate)
} }
// Fill the buffer // Fill the buffer
ALsizei size = static_cast<ALsizei>(mySamples.size()) * sizeof(Int16); ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
ALCheck(alBufferData(myBuffer, format, &mySamples[0], size, sampleRate)); ALCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
// Compute the duration // Compute the duration
myDuration = Milliseconds(1000 * mySamples.size() / sampleRate / channelCount); m_duration = Milliseconds(1000 * m_samples.size() / sampleRate / channelCount);
return true; return true;
} }
@ -262,14 +262,14 @@ bool SoundBuffer::Update(unsigned int channelCount, unsigned int sampleRate)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundBuffer::AttachSound(Sound* sound) const void SoundBuffer::AttachSound(Sound* sound) const
{ {
mySounds.insert(sound); m_sounds.insert(sound);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundBuffer::DetachSound(Sound* sound) const void SoundBuffer::DetachSound(Sound* sound) const
{ {
mySounds.erase(sound); m_sounds.erase(sound);
} }
} // namespace sf } // namespace sf

View File

@ -35,8 +35,8 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SoundBufferRecorder::OnStart() bool SoundBufferRecorder::OnStart()
{ {
mySamples.clear(); m_samples.clear();
myBuffer = SoundBuffer(); m_buffer = SoundBuffer();
return true; return true;
} }
@ -45,7 +45,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(mySamples)); std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));
return true; return true;
} }
@ -54,15 +54,15 @@ bool SoundBufferRecorder::OnProcessSamples(const Int16* samples, std::size_t sam
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundBufferRecorder::OnStop() void SoundBufferRecorder::OnStop()
{ {
if (!mySamples.empty()) if (!m_samples.empty())
myBuffer.LoadFromSamples(&mySamples[0], mySamples.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 myBuffer; return m_buffer;
} }
} // namespace sf } // namespace sf

View File

@ -50,10 +50,10 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFile::SoundFile() : SoundFile::SoundFile() :
myFile (NULL), m_file (NULL),
mySampleCount (0), m_sampleCount (0),
myChannelCount(0), m_channelCount(0),
mySampleRate (0) m_sampleRate (0)
{ {
} }
@ -62,29 +62,29 @@ mySampleRate (0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFile::~SoundFile() SoundFile::~SoundFile()
{ {
if (myFile) if (m_file)
sf_close(myFile); sf_close(m_file);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::size_t SoundFile::GetSampleCount() const std::size_t SoundFile::GetSampleCount() const
{ {
return mySampleCount; return m_sampleCount;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int SoundFile::GetChannelCount() const unsigned int SoundFile::GetChannelCount() const
{ {
return myChannelCount; return m_channelCount;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int SoundFile::GetSampleRate() const unsigned int SoundFile::GetSampleRate() const
{ {
return mySampleRate; return m_sampleRate;
} }
@ -92,22 +92,22 @@ unsigned int SoundFile::GetSampleRate() const
bool SoundFile::OpenRead(const std::string& filename) bool SoundFile::OpenRead(const std::string& filename)
{ {
// If the file is already opened, first close it // If the file is already opened, first close it
if (myFile) if (m_file)
sf_close(myFile); sf_close(m_file);
// Open the sound file // Open the sound file
SF_INFO fileInfos; SF_INFO fileInfos;
myFile = sf_open(filename.c_str(), SFM_READ, &fileInfos); m_file = sf_open(filename.c_str(), SFM_READ, &fileInfos);
if (!myFile) if (!m_file)
{ {
Err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; Err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
return false; return false;
} }
// Set the sound parameters // Set the sound parameters
myChannelCount = fileInfos.channels; m_channelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate; m_sampleRate = fileInfos.samplerate;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount; m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
return true; return true;
} }
@ -117,8 +117,8 @@ 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 the file is already opened, first close it
if (myFile) if (m_file)
sf_close(myFile); sf_close(m_file);
// Prepare the memory I/O structure // Prepare the memory I/O structure
SF_VIRTUAL_IO io; SF_VIRTUAL_IO io;
@ -128,23 +128,23 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
io.tell = &Memory::Tell; io.tell = &Memory::Tell;
// Initialize the memory data // Initialize the memory data
myMemory.DataStart = static_cast<const char*>(data); m_memory.DataStart = static_cast<const char*>(data);
myMemory.DataPtr = myMemory.DataStart; m_memory.DataPtr = m_memory.DataStart;
myMemory.TotalSize = sizeInBytes; m_memory.TotalSize = sizeInBytes;
// Open the sound file // Open the sound file
SF_INFO fileInfos; SF_INFO fileInfos;
myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &myMemory); m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &m_memory);
if (!myFile) if (!m_file)
{ {
Err() << "Failed to open sound file from memory (" << sf_strerror(myFile) << ")" << std::endl; Err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
return false; return false;
} }
// Set the sound parameters // Set the sound parameters
myChannelCount = fileInfos.channels; m_channelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate; m_sampleRate = fileInfos.samplerate;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount; m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
return true; return true;
} }
@ -154,8 +154,8 @@ 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 the file is already opened, first close it
if (myFile) if (m_file)
sf_close(myFile); sf_close(m_file);
// Prepare the memory I/O structure // Prepare the memory I/O structure
SF_VIRTUAL_IO io; SF_VIRTUAL_IO io;
@ -166,17 +166,17 @@ bool SoundFile::OpenRead(InputStream& stream)
// Open the sound file // Open the sound file
SF_INFO fileInfos; SF_INFO fileInfos;
myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &stream); m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &stream);
if (!myFile) if (!m_file)
{ {
Err() << "Failed to open sound file from stream (" << sf_strerror(myFile) << ")" << std::endl; Err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
return false; return false;
} }
// Set the sound parameters // Set the sound parameters
myChannelCount = fileInfos.channels; m_channelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate; m_sampleRate = fileInfos.samplerate;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount; m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
return true; return true;
} }
@ -186,8 +186,8 @@ 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 the file is already opened, first close it
if (myFile) if (m_file)
sf_close(myFile); sf_close(m_file);
// Find the right format according to the file extension // Find the right format according to the file extension
int format = GetFormatFromFilename(filename); int format = GetFormatFromFilename(filename);
@ -205,17 +205,17 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelCount
fileInfos.format = format | (format == SF_FORMAT_OGG ? SF_FORMAT_VORBIS : SF_FORMAT_PCM_16); fileInfos.format = format | (format == SF_FORMAT_OGG ? SF_FORMAT_VORBIS : SF_FORMAT_PCM_16);
// Open the sound file for writing // Open the sound file for writing
myFile = sf_open(filename.c_str(), SFM_WRITE, &fileInfos); m_file = sf_open(filename.c_str(), SFM_WRITE, &fileInfos);
if (!myFile) if (!m_file)
{ {
Err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; Err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
return false; return false;
} }
// Set the sound parameters // Set the sound parameters
myChannelCount = channelCount; m_channelCount = channelCount;
mySampleRate = sampleRate; m_sampleRate = sampleRate;
mySampleCount = 0; m_sampleCount = 0;
return true; return true;
} }
@ -224,8 +224,8 @@ 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 (myFile && data && sampleCount) if (m_file && data && sampleCount)
return static_cast<std::size_t>(sf_read_short(myFile, data, sampleCount)); return static_cast<std::size_t>(sf_read_short(m_file, data, sampleCount));
else else
return 0; return 0;
} }
@ -234,14 +234,14 @@ 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 (myFile && data && sampleCount) if (m_file && data && sampleCount)
{ {
// Write small chunks instead of everything at once, // Write small chunks instead of everything at once,
// to avoid a stack overflow in libsndfile (happens only with OGG format) // to avoid a stack overflow in libsndfile (happens only with OGG format)
while (sampleCount > 0) while (sampleCount > 0)
{ {
std::size_t count = sampleCount > 10000 ? 10000 : sampleCount; std::size_t count = sampleCount > 10000 ? 10000 : sampleCount;
sf_write_short(myFile, data, count); sf_write_short(m_file, data, count);
data += count; data += count;
sampleCount -= count; sampleCount -= count;
} }
@ -252,10 +252,10 @@ void SoundFile::Write(const Int16* data, std::size_t sampleCount)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundFile::Seek(Time timeOffset) void SoundFile::Seek(Time timeOffset)
{ {
if (myFile) if (m_file)
{ {
sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset.AsSeconds() * mySampleRate); sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset.AsSeconds() * m_sampleRate);
sf_seek(myFile, frameOffset, SEEK_SET); sf_seek(m_file, frameOffset, SEEK_SET);
} }
} }

View File

@ -199,11 +199,11 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SNDFILE* myFile; ///< File descriptor SNDFILE* m_file; ///< File descriptor
Memory myMemory; ///< Memory reading info Memory m_memory; ///< Memory reading info
std::size_t mySampleCount; ///< Total number of samples in the file std::size_t m_sampleCount; ///< Total number of samples in the file
unsigned int myChannelCount; ///< Number of channels used by the sound unsigned int m_channelCount; ///< Number of channels used by the sound
unsigned int mySampleRate; ///< Number of samples per second unsigned int m_sampleRate; ///< Number of samples per second
}; };
} // namespace priv } // namespace priv

View File

@ -45,9 +45,9 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundRecorder::SoundRecorder() : SoundRecorder::SoundRecorder() :
myThread (&SoundRecorder::Record, this), m_thread (&SoundRecorder::Record, this),
mySampleRate (0), m_sampleRate (0),
myIsCapturing(false) m_isCapturing(false)
{ {
priv::EnsureALInit(); priv::EnsureALInit();
} }
@ -86,10 +86,10 @@ void SoundRecorder::Start(unsigned int sampleRate)
} }
// Clear the array of samples // Clear the array of samples
mySamples.clear(); m_samples.clear();
// Store the sample rate // Store the sample rate
mySampleRate = sampleRate; m_sampleRate = sampleRate;
// Notify derived class // Notify derived class
if (OnStart()) if (OnStart())
@ -98,8 +98,8 @@ void SoundRecorder::Start(unsigned int sampleRate)
alcCaptureStart(captureDevice); alcCaptureStart(captureDevice);
// Start the capture in a new thread, to avoid blocking the main thread // Start the capture in a new thread, to avoid blocking the main thread
myIsCapturing = true; m_isCapturing = true;
myThread.Launch(); m_thread.Launch();
} }
} }
@ -108,15 +108,15 @@ void SoundRecorder::Start(unsigned int sampleRate)
void SoundRecorder::Stop() void SoundRecorder::Stop()
{ {
// Stop the capturing thread // Stop the capturing thread
myIsCapturing = false; m_isCapturing = false;
myThread.Wait(); m_thread.Wait();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int SoundRecorder::GetSampleRate() const unsigned int SoundRecorder::GetSampleRate() const
{ {
return mySampleRate; return m_sampleRate;
} }
@ -146,7 +146,7 @@ void SoundRecorder::OnStop()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundRecorder::Record() void SoundRecorder::Record()
{ {
while (myIsCapturing) while (m_isCapturing)
{ {
// Process available samples // Process available samples
ProcessCapturedSamples(); ProcessCapturedSamples();
@ -173,14 +173,14 @@ void SoundRecorder::ProcessCapturedSamples()
if (samplesAvailable > 0) if (samplesAvailable > 0)
{ {
// Get the recorded samples // Get the recorded samples
mySamples.resize(samplesAvailable); m_samples.resize(samplesAvailable);
alcCaptureSamples(captureDevice, &mySamples[0], samplesAvailable); alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);
// Forward them to the derived class // Forward them to the derived class
if (!OnProcessSamples(&mySamples[0], mySamples.size())) if (!OnProcessSamples(&m_samples[0], m_samples.size()))
{ {
// The user wants to stop the capture // The user wants to stop the capture
myIsCapturing = false; m_isCapturing = false;
} }
} }
} }

View File

@ -36,8 +36,8 @@ SoundSource::SoundSource()
{ {
priv::EnsureALInit(); priv::EnsureALInit();
ALCheck(alGenSources(1, &mySource)); ALCheck(alGenSources(1, &m_source));
ALCheck(alSourcei(mySource, AL_BUFFER, 0)); ALCheck(alSourcei(m_source, AL_BUFFER, 0));
} }
@ -46,8 +46,8 @@ SoundSource::SoundSource(const SoundSource& copy)
{ {
priv::EnsureALInit(); priv::EnsureALInit();
ALCheck(alGenSources(1, &mySource)); ALCheck(alGenSources(1, &m_source));
ALCheck(alSourcei(mySource, AL_BUFFER, 0)); ALCheck(alSourcei(m_source, AL_BUFFER, 0));
SetPitch(copy.GetPitch()); SetPitch(copy.GetPitch());
SetVolume(copy.GetVolume()); SetVolume(copy.GetVolume());
@ -61,28 +61,28 @@ SoundSource::SoundSource(const SoundSource& copy)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundSource::~SoundSource() SoundSource::~SoundSource()
{ {
ALCheck(alSourcei(mySource, AL_BUFFER, 0)); ALCheck(alSourcei(m_source, AL_BUFFER, 0));
ALCheck(alDeleteSources(1, &mySource)); ALCheck(alDeleteSources(1, &m_source));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundSource::SetPitch(float pitch) void SoundSource::SetPitch(float pitch)
{ {
ALCheck(alSourcef(mySource, AL_PITCH, pitch)); ALCheck(alSourcef(m_source, AL_PITCH, pitch));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundSource::SetVolume(float volume) void SoundSource::SetVolume(float volume)
{ {
ALCheck(alSourcef(mySource, 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(mySource, AL_POSITION, x, y, z)); ALCheck(alSource3f(m_source, AL_POSITION, x, y, z));
} }
@ -96,21 +96,21 @@ void SoundSource::SetPosition(const Vector3f& position)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundSource::SetRelativeToListener(bool relative) void SoundSource::SetRelativeToListener(bool relative)
{ {
ALCheck(alSourcei(mySource, AL_SOURCE_RELATIVE, relative)); ALCheck(alSourcei(m_source, AL_SOURCE_RELATIVE, relative));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundSource::SetMinDistance(float distance) void SoundSource::SetMinDistance(float distance)
{ {
ALCheck(alSourcef(mySource, AL_REFERENCE_DISTANCE, distance)); ALCheck(alSourcef(m_source, AL_REFERENCE_DISTANCE, distance));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundSource::SetAttenuation(float attenuation) void SoundSource::SetAttenuation(float attenuation)
{ {
ALCheck(alSourcef(mySource, AL_ROLLOFF_FACTOR, attenuation)); ALCheck(alSourcef(m_source, AL_ROLLOFF_FACTOR, attenuation));
} }
@ -118,7 +118,7 @@ void SoundSource::SetAttenuation(float attenuation)
float SoundSource::GetPitch() const float SoundSource::GetPitch() const
{ {
ALfloat pitch; ALfloat pitch;
ALCheck(alGetSourcef(mySource, AL_PITCH, &pitch)); ALCheck(alGetSourcef(m_source, AL_PITCH, &pitch));
return pitch; return pitch;
} }
@ -128,7 +128,7 @@ float SoundSource::GetPitch() const
float SoundSource::GetVolume() const float SoundSource::GetVolume() const
{ {
ALfloat gain; ALfloat gain;
ALCheck(alGetSourcef(mySource, AL_GAIN, &gain)); ALCheck(alGetSourcef(m_source, AL_GAIN, &gain));
return gain * 100.f; return gain * 100.f;
} }
@ -138,7 +138,7 @@ float SoundSource::GetVolume() const
Vector3f SoundSource::GetPosition() const Vector3f SoundSource::GetPosition() const
{ {
Vector3f position; Vector3f position;
ALCheck(alGetSource3f(mySource, AL_POSITION, &position.x, &position.y, &position.z)); ALCheck(alGetSource3f(m_source, AL_POSITION, &position.x, &position.y, &position.z));
return position; return position;
} }
@ -148,7 +148,7 @@ Vector3f SoundSource::GetPosition() const
bool SoundSource::IsRelativeToListener() const bool SoundSource::IsRelativeToListener() const
{ {
ALint relative; ALint relative;
ALCheck(alGetSourcei(mySource, AL_SOURCE_RELATIVE, &relative)); ALCheck(alGetSourcei(m_source, AL_SOURCE_RELATIVE, &relative));
return relative != 0; return relative != 0;
} }
@ -158,7 +158,7 @@ bool SoundSource::IsRelativeToListener() const
float SoundSource::GetMinDistance() const float SoundSource::GetMinDistance() const
{ {
ALfloat distance; ALfloat distance;
ALCheck(alGetSourcef(mySource, AL_REFERENCE_DISTANCE, &distance)); ALCheck(alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &distance));
return distance; return distance;
} }
@ -168,7 +168,7 @@ float SoundSource::GetMinDistance() const
float SoundSource::GetAttenuation() const float SoundSource::GetAttenuation() const
{ {
ALfloat attenuation; ALfloat attenuation;
ALCheck(alGetSourcef(mySource, AL_ROLLOFF_FACTOR, &attenuation)); ALCheck(alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &attenuation));
return attenuation; return attenuation;
} }
@ -178,7 +178,7 @@ float SoundSource::GetAttenuation() const
SoundSource::Status SoundSource::GetStatus() const SoundSource::Status SoundSource::GetStatus() const
{ {
ALint status; ALint status;
ALCheck(alGetSourcei(mySource, AL_SOURCE_STATE, &status)); ALCheck(alGetSourcei(m_source, AL_SOURCE_STATE, &status));
switch (status) switch (status)
{ {

View File

@ -40,13 +40,13 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundStream::SoundStream() : SoundStream::SoundStream() :
myThread (&SoundStream::Stream, this), m_thread (&SoundStream::Stream, this),
myIsStreaming (false), m_isStreaming (false),
myChannelCount (0), m_channelCount (0),
mySampleRate (0), m_sampleRate (0),
myFormat (0), m_format (0),
myLoop (false), m_loop (false),
mySamplesProcessed(0) m_samplesProcessed(0)
{ {
} }
@ -63,18 +63,18 @@ SoundStream::~SoundStream()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundStream::Initialize(unsigned int channelCount, unsigned int sampleRate) void SoundStream::Initialize(unsigned int channelCount, unsigned int sampleRate)
{ {
myChannelCount = channelCount; m_channelCount = channelCount;
mySampleRate = sampleRate; m_sampleRate = sampleRate;
// Deduce the format from the number of channels // Deduce the format from the number of channels
myFormat = priv::AudioDevice::GetFormatFromChannelCount(channelCount); m_format = priv::AudioDevice::GetFormatFromChannelCount(channelCount);
// Check if the format is valid // Check if the format is valid
if (myFormat == 0) if (m_format == 0)
{ {
myChannelCount = 0; m_channelCount = 0;
mySampleRate = 0; m_sampleRate = 0;
Err() << "Unsupported number of channels (" << myChannelCount << ")" << std::endl; Err() << "Unsupported number of channels (" << m_channelCount << ")" << std::endl;
} }
} }
@ -83,16 +83,16 @@ void SoundStream::Initialize(unsigned int channelCount, unsigned int sampleRate)
void SoundStream::Play() void SoundStream::Play()
{ {
// Check if the sound parameters have been set // Check if the sound parameters have been set
if (myFormat == 0) 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; return;
} }
// If the sound is already playing (probably paused), just resume it // If the sound is already playing (probably paused), just resume it
if (myIsStreaming) if (m_isStreaming)
{ {
ALCheck(alSourcePlay(mySource)); ALCheck(alSourcePlay(m_source));
return; return;
} }
@ -100,16 +100,16 @@ void SoundStream::Play()
OnSeek(Time::Zero); OnSeek(Time::Zero);
// Start updating the stream in a separate thread to avoid blocking the application // Start updating the stream in a separate thread to avoid blocking the application
mySamplesProcessed = 0; m_samplesProcessed = 0;
myIsStreaming = true; m_isStreaming = true;
myThread.Launch(); m_thread.Launch();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundStream::Pause() void SoundStream::Pause()
{ {
ALCheck(alSourcePause(mySource)); ALCheck(alSourcePause(m_source));
} }
@ -117,22 +117,22 @@ void SoundStream::Pause()
void SoundStream::Stop() void SoundStream::Stop()
{ {
// Wait for the thread to terminate // Wait for the thread to terminate
myIsStreaming = false; m_isStreaming = false;
myThread.Wait(); m_thread.Wait();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int SoundStream::GetChannelCount() const unsigned int SoundStream::GetChannelCount() const
{ {
return myChannelCount; return m_channelCount;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int SoundStream::GetSampleRate() const unsigned int SoundStream::GetSampleRate() const
{ {
return mySampleRate; return m_sampleRate;
} }
@ -142,7 +142,7 @@ 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) && myIsStreaming) if ((status == Stopped) && m_isStreaming)
status = Playing; status = Playing;
return status; return status;
@ -159,9 +159,9 @@ void SoundStream::SetPlayingOffset(Time timeOffset)
OnSeek(timeOffset); OnSeek(timeOffset);
// Restart streaming // Restart streaming
mySamplesProcessed = static_cast<Uint64>(timeOffset.AsSeconds() * mySampleRate * myChannelCount); m_samplesProcessed = static_cast<Uint64>(timeOffset.AsSeconds() * m_sampleRate * m_channelCount);
myIsStreaming = true; m_isStreaming = true;
myThread.Launch(); m_thread.Launch();
} }
@ -169,23 +169,23 @@ void SoundStream::SetPlayingOffset(Time timeOffset)
Time SoundStream::GetPlayingOffset() const Time SoundStream::GetPlayingOffset() const
{ {
ALfloat seconds = 0.f; ALfloat seconds = 0.f;
ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds)); ALCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &seconds));
return Seconds(seconds + static_cast<float>(mySamplesProcessed) / mySampleRate / myChannelCount); return Seconds(seconds + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundStream::SetLoop(bool loop) void SoundStream::SetLoop(bool loop)
{ {
myLoop = loop; m_loop = loop;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SoundStream::GetLoop() const bool SoundStream::GetLoop() const
{ {
return myLoop; return m_loop;
} }
@ -193,17 +193,17 @@ bool SoundStream::GetLoop() const
void SoundStream::Stream() void SoundStream::Stream()
{ {
// Create the buffers // Create the buffers
ALCheck(alGenBuffers(BufferCount, myBuffers)); ALCheck(alGenBuffers(BufferCount, m_buffers));
for (int i = 0; i < BufferCount; ++i) for (int i = 0; i < BufferCount; ++i)
myEndBuffers[i] = false; m_endBuffers[i] = false;
// Fill the queue // Fill the queue
bool requestStop = FillQueue(); bool requestStop = FillQueue();
// Play the sound // Play the sound
ALCheck(alSourcePlay(mySource)); ALCheck(alSourcePlay(m_source));
while (myIsStreaming) while (m_isStreaming)
{ {
// The stream has been interrupted! // The stream has been interrupted!
if (SoundSource::GetStatus() == Stopped) if (SoundSource::GetStatus() == Stopped)
@ -211,47 +211,47 @@ void SoundStream::Stream()
if (!requestStop) if (!requestStop)
{ {
// Just continue // Just continue
ALCheck(alSourcePlay(mySource)); ALCheck(alSourcePlay(m_source));
} }
else else
{ {
// End streaming // End streaming
myIsStreaming = false; m_isStreaming = false;
} }
} }
// Get the number of buffers that have been processed (ie. ready for reuse) // Get the number of buffers that have been processed (ie. ready for reuse)
ALint nbProcessed = 0; ALint nbProcessed = 0;
ALCheck(alGetSourcei(mySource, AL_BUFFERS_PROCESSED, &nbProcessed)); ALCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed));
while (nbProcessed--) while (nbProcessed--)
{ {
// Pop the first unused buffer from the queue // Pop the first unused buffer from the queue
ALuint buffer; ALuint buffer;
ALCheck(alSourceUnqueueBuffers(mySource, 1, &buffer)); ALCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
// Find its number // Find its number
unsigned int bufferNum = 0; unsigned int bufferNum = 0;
for (int i = 0; i < BufferCount; ++i) for (int i = 0; i < BufferCount; ++i)
if (myBuffers[i] == buffer) if (m_buffers[i] == buffer)
{ {
bufferNum = i; bufferNum = i;
break; break;
} }
// Retrieve its size and add it to the samples count // Retrieve its size and add it to the samples count
if (myEndBuffers[bufferNum]) if (m_endBuffers[bufferNum])
{ {
// This was the last buffer: reset the sample count // This was the last buffer: reset the sample count
mySamplesProcessed = 0; m_samplesProcessed = 0;
myEndBuffers[bufferNum] = false; m_endBuffers[bufferNum] = false;
} }
else else
{ {
ALint size, bits; ALint size, bits;
ALCheck(alGetBufferi(buffer, AL_SIZE, &size)); ALCheck(alGetBufferi(buffer, AL_SIZE, &size));
ALCheck(alGetBufferi(buffer, AL_BITS, &bits)); ALCheck(alGetBufferi(buffer, AL_BITS, &bits));
mySamplesProcessed += size / (bits / 8); m_samplesProcessed += size / (bits / 8);
} }
// Fill it and push it back into the playing queue // Fill it and push it back into the playing queue
@ -268,14 +268,14 @@ void SoundStream::Stream()
} }
// Stop the playback // Stop the playback
ALCheck(alSourceStop(mySource)); ALCheck(alSourceStop(m_source));
// Unqueue any buffer left in the queue // Unqueue any buffer left in the queue
ClearQueue(); ClearQueue();
// Delete the buffers // Delete the buffers
ALCheck(alSourcei(mySource, AL_BUFFER, 0)); ALCheck(alSourcei(m_source, AL_BUFFER, 0));
ALCheck(alDeleteBuffers(BufferCount, myBuffers)); ALCheck(alDeleteBuffers(BufferCount, m_buffers));
} }
@ -289,10 +289,10 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
if (!OnGetData(data)) if (!OnGetData(data))
{ {
// Mark the buffer as the last one (so that we know when to reset the playing position) // Mark the buffer as the last one (so that we know when to reset the playing position)
myEndBuffers[bufferNum] = true; m_endBuffers[bufferNum] = true;
// Check if the stream must loop or stop // Check if the stream must loop or stop
if (myLoop) if (m_loop)
{ {
// Return to the beginning of the stream source // Return to the beginning of the stream source
OnSeek(Time::Zero); OnSeek(Time::Zero);
@ -313,14 +313,14 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
// Fill the buffer if some data was returned // Fill the buffer if some data was returned
if (data.Samples && data.SampleCount) if (data.Samples && data.SampleCount)
{ {
unsigned int buffer = myBuffers[bufferNum]; unsigned int buffer = m_buffers[bufferNum];
// Fill the buffer // Fill the buffer
ALsizei size = static_cast<ALsizei>(data.SampleCount) * sizeof(Int16); ALsizei size = static_cast<ALsizei>(data.SampleCount) * sizeof(Int16);
ALCheck(alBufferData(buffer, myFormat, data.Samples, size, mySampleRate)); ALCheck(alBufferData(buffer, m_format, data.Samples, size, m_sampleRate));
// Push it into the sound queue // Push it into the sound queue
ALCheck(alSourceQueueBuffers(mySource, 1, &buffer)); ALCheck(alSourceQueueBuffers(m_source, 1, &buffer));
} }
return requestStop; return requestStop;
@ -347,12 +347,12 @@ void SoundStream::ClearQueue()
{ {
// Get the number of buffers still in the queue // Get the number of buffers still in the queue
ALint nbQueued; ALint nbQueued;
ALCheck(alGetSourcei(mySource, AL_BUFFERS_QUEUED, &nbQueued)); ALCheck(alGetSourcei(m_source, AL_BUFFERS_QUEUED, &nbQueued));
// Unqueue them all // Unqueue them all
ALuint buffer; ALuint buffer;
for (ALint i = 0; i < nbQueued; ++i) for (ALint i = 0; i < nbQueued; ++i)
ALCheck(alSourceUnqueueBuffers(mySource, 1, &buffer)); ALCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));
} }
} // namespace sf } // namespace sf

View File

@ -33,8 +33,8 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CircleShape::CircleShape(float radius, unsigned int pointCount) : CircleShape::CircleShape(float radius, unsigned int pointCount) :
myRadius (radius), m_radius (radius),
myPointCount(pointCount) m_pointCount(pointCount)
{ {
Update(); Update();
} }
@ -43,7 +43,7 @@ myPointCount(pointCount)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CircleShape::SetRadius(float radius) void CircleShape::SetRadius(float radius)
{ {
myRadius = radius; m_radius = radius;
Update(); Update();
} }
@ -51,21 +51,21 @@ void CircleShape::SetRadius(float radius)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float CircleShape::GetRadius() const float CircleShape::GetRadius() const
{ {
return myRadius; return m_radius;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CircleShape::SetPointCount(unsigned int count) void CircleShape::SetPointCount(unsigned int count)
{ {
myPointCount = count; m_pointCount = count;
Update(); Update();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int CircleShape::GetPointCount() const unsigned int CircleShape::GetPointCount() const
{ {
return myPointCount; return m_pointCount;
} }
@ -74,11 +74,11 @@ Vector2f CircleShape::GetPoint(unsigned int index) const
{ {
static const float pi = 3.141592654f; static const float pi = 3.141592654f;
float angle = index * 2 * pi / myPointCount - pi / 2; float angle = index * 2 * pi / m_pointCount - pi / 2;
float x = std::cos(angle) * myRadius; float x = std::cos(angle) * m_radius;
float y = std::sin(angle) * myRadius; float y = std::sin(angle) * m_radius;
return Vector2f(myRadius + x, myRadius + y); return Vector2f(m_radius + x, m_radius + y);
} }
} // namespace sf } // namespace sf

View File

@ -40,7 +40,7 @@ ConvexShape::ConvexShape(unsigned int pointCount)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ConvexShape::SetPointCount(unsigned int count) void ConvexShape::SetPointCount(unsigned int count)
{ {
myPoints.resize(count); m_points.resize(count);
Update(); Update();
} }
@ -48,14 +48,14 @@ void ConvexShape::SetPointCount(unsigned int count)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int ConvexShape::GetPointCount() const unsigned int ConvexShape::GetPointCount() const
{ {
return static_cast<unsigned int>(myPoints.size()); 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)
{ {
myPoints[index] = point; m_points[index] = point;
Update(); Update();
} }
@ -63,7 +63,7 @@ void ConvexShape::SetPoint(unsigned int index, const Vector2f& point)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f ConvexShape::GetPoint(unsigned int index) const Vector2f ConvexShape::GetPoint(unsigned int index) const
{ {
return myPoints[index]; return m_points[index];
} }
} // namespace sf } // namespace sf

View File

@ -63,10 +63,10 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Font::Font() : Font::Font() :
myLibrary (NULL), m_library (NULL),
myFace (NULL), m_face (NULL),
myStreamRec(NULL), m_streamRec(NULL),
myRefCount (NULL) m_refCount (NULL)
{ {
} }
@ -74,18 +74,18 @@ myRefCount (NULL)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Font::Font(const Font& copy) : Font::Font(const Font& copy) :
myLibrary (copy.myLibrary), m_library (copy.m_library),
myFace (copy.myFace), m_face (copy.m_face),
myStreamRec (copy.myStreamRec), m_streamRec (copy.m_streamRec),
myRefCount (copy.myRefCount), m_refCount (copy.m_refCount),
myPages (copy.myPages), m_pages (copy.m_pages),
myPixelBuffer(copy.myPixelBuffer) m_pixelBuffer(copy.m_pixelBuffer)
{ {
// Note: as FreeType doesn't provide functions for copying/cloning, // Note: as FreeType doesn't provide functions for copying/cloning,
// we must share all the FreeType pointers // we must share all the FreeType pointers
if (myRefCount) if (m_refCount)
(*myRefCount)++; (*m_refCount)++;
} }
@ -101,7 +101,7 @@ bool Font::LoadFromFile(const std::string& filename)
{ {
// Cleanup the previous resources // Cleanup the previous resources
Cleanup(); Cleanup();
myRefCount = new int(1); m_refCount = new int(1);
// Initialize FreeType // Initialize FreeType
// Note: we initialize FreeType for every font instance in order to avoid having a single // Note: we initialize FreeType for every font instance in order to avoid having a single
@ -112,11 +112,11 @@ bool Font::LoadFromFile(const std::string& filename)
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; return false;
} }
myLibrary = library; m_library = library;
// Load the new font face from the specified file // Load the new font face from the specified file
FT_Face face; FT_Face face;
if (FT_New_Face(static_cast<FT_Library>(myLibrary), filename.c_str(), 0, &face) != 0) 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; return false;
@ -130,7 +130,7 @@ bool Font::LoadFromFile(const std::string& filename)
} }
// Store the loaded font in our ugly void* :) // Store the loaded font in our ugly void* :)
myFace = face; m_face = face;
return true; return true;
} }
@ -141,7 +141,7 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
{ {
// Cleanup the previous resources // Cleanup the previous resources
Cleanup(); Cleanup();
myRefCount = new int(1); m_refCount = new int(1);
// Initialize FreeType // Initialize FreeType
// Note: we initialize FreeType for every font instance in order to avoid having a single // Note: we initialize FreeType for every font instance in order to avoid having a single
@ -152,11 +152,11 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
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; return false;
} }
myLibrary = library; m_library = library;
// Load the new font face from the specified file // Load the new font face from the specified file
FT_Face face; FT_Face face;
if (FT_New_Memory_Face(static_cast<FT_Library>(myLibrary), reinterpret_cast<const FT_Byte*>(data), static_cast<FT_Long>(sizeInBytes), 0, &face) != 0) 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; return false;
@ -170,7 +170,7 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
} }
// Store the loaded font in our ugly void* :) // Store the loaded font in our ugly void* :)
myFace = face; m_face = face;
return true; return true;
} }
@ -181,7 +181,7 @@ bool Font::LoadFromStream(InputStream& stream)
{ {
// Cleanup the previous resources // Cleanup the previous resources
Cleanup(); Cleanup();
myRefCount = new int(1); m_refCount = new int(1);
// Initialize FreeType // Initialize FreeType
// Note: we initialize FreeType for every font instance in order to avoid having a single // Note: we initialize FreeType for every font instance in order to avoid having a single
@ -192,7 +192,7 @@ bool Font::LoadFromStream(InputStream& stream)
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; return false;
} }
myLibrary = library; m_library = library;
// Prepare a wrapper for our stream, that we'll pass to FreeType callbacks // Prepare a wrapper for our stream, that we'll pass to FreeType callbacks
FT_StreamRec* rec = new FT_StreamRec; FT_StreamRec* rec = new FT_StreamRec;
@ -212,7 +212,7 @@ bool Font::LoadFromStream(InputStream& stream)
// Load the new font face from the specified stream // Load the new font face from the specified stream
FT_Face face; FT_Face face;
if (FT_Open_Face(static_cast<FT_Library>(myLibrary), &args, 0, &face) != 0) 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; return false;
@ -226,8 +226,8 @@ bool Font::LoadFromStream(InputStream& stream)
} }
// Store the loaded font in our ugly void* :) // Store the loaded font in our ugly void* :)
myFace = face; m_face = face;
myStreamRec = rec; m_streamRec = rec;
return true; return true;
} }
@ -237,7 +237,7 @@ 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 // Get the page corresponding to the character size
GlyphTable& glyphs = myPages[characterSize].Glyphs; GlyphTable& glyphs = m_pages[characterSize].Glyphs;
// Build the key by combining the code point and the bold flag // Build the key by combining the code point and the bold flag
Uint32 key = ((bold ? 1 : 0) << 31) | codePoint; Uint32 key = ((bold ? 1 : 0) << 31) | codePoint;
@ -265,7 +265,7 @@ int Font::GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) co
if (first == 0 || second == 0) if (first == 0 || second == 0)
return 0; return 0;
FT_Face face = static_cast<FT_Face>(myFace); 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))
{ {
@ -291,7 +291,7 @@ 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>(myFace); FT_Face face = static_cast<FT_Face>(m_face);
if (face && SetCurrentSize(characterSize)) if (face && SetCurrentSize(characterSize))
{ {
@ -307,7 +307,7 @@ int Font::GetLineSpacing(unsigned int characterSize) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Texture& Font::GetTexture(unsigned int characterSize) const const Texture& Font::GetTexture(unsigned int characterSize) const
{ {
return myPages[characterSize].Texture; return m_pages[characterSize].Texture;
} }
@ -316,11 +316,11 @@ Font& Font::operator =(const Font& right)
{ {
Font temp(right); Font temp(right);
std::swap(myLibrary, temp.myLibrary); std::swap(m_library, temp.m_library);
std::swap(myFace, temp.myFace); std::swap(m_face, temp.m_face);
std::swap(myPages, temp.myPages); std::swap(m_pages, temp.m_pages);
std::swap(myPixelBuffer, temp.myPixelBuffer); std::swap(m_pixelBuffer, temp.m_pixelBuffer);
std::swap(myRefCount, temp.myRefCount); std::swap(m_refCount, temp.m_refCount);
return *this; return *this;
} }
@ -352,38 +352,38 @@ const Font& Font::GetDefaultFont()
void Font::Cleanup() void Font::Cleanup()
{ {
// Check if we must destroy the FreeType pointers // Check if we must destroy the FreeType pointers
if (myRefCount) if (m_refCount)
{ {
// Decrease the reference counter // Decrease the reference counter
(*myRefCount)--; (*m_refCount)--;
// Free the resources only if we are the last owner // Free the resources only if we are the last owner
if (*myRefCount == 0) if (*m_refCount == 0)
{ {
// Delete the reference counter // Delete the reference counter
delete myRefCount; delete m_refCount;
// Destroy the font face // Destroy the font face
if (myFace) if (m_face)
FT_Done_Face(static_cast<FT_Face>(myFace)); FT_Done_Face(static_cast<FT_Face>(m_face));
// Destroy the stream rec instance, if any (must be done after FT_Done_Face!) // Destroy the stream rec instance, if any (must be done after FT_Done_Face!)
if (myStreamRec) if (m_streamRec)
delete static_cast<FT_StreamRec*>(myStreamRec); delete static_cast<FT_StreamRec*>(m_streamRec);
// Close the library // Close the library
if (myLibrary) if (m_library)
FT_Done_FreeType(static_cast<FT_Library>(myLibrary)); FT_Done_FreeType(static_cast<FT_Library>(m_library));
} }
} }
// Reset members // Reset members
myLibrary = NULL; m_library = NULL;
myFace = NULL; m_face = NULL;
myStreamRec = NULL; m_streamRec = NULL;
myRefCount = NULL; m_refCount = NULL;
myPages.clear(); m_pages.clear();
myPixelBuffer.clear(); m_pixelBuffer.clear();
} }
@ -394,7 +394,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
Glyph glyph; Glyph glyph;
// First, transform our ugly void* to a FT_Face // First, transform our ugly void* to a FT_Face
FT_Face face = static_cast<FT_Face>(myFace); FT_Face face = static_cast<FT_Face>(m_face);
if (!face) if (!face)
return glyph; return glyph;
@ -428,7 +428,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
// Apply bold if necessary -- fallback technique using bitmap (lower quality) // Apply bold if necessary -- fallback technique using bitmap (lower quality)
if (bold && !outline) if (bold && !outline)
{ {
FT_Bitmap_Embolden(static_cast<FT_Library>(myLibrary), &bitmap, weight, weight); FT_Bitmap_Embolden(static_cast<FT_Library>(m_library), &bitmap, weight, weight);
} }
// Compute the glyph's advance offset // Compute the glyph's advance offset
@ -445,7 +445,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
const unsigned int padding = 1; const unsigned int padding = 1;
// Get the glyphs page corresponding to the character size // Get the glyphs page corresponding to the character size
Page& page = myPages[characterSize]; Page& page = m_pages[characterSize];
// Find a good position for the new glyph into the texture // 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);
@ -457,7 +457,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
glyph.Bounds.Height = height + 2 * padding; glyph.Bounds.Height = height + 2 * padding;
// Extract the glyph's pixels from the bitmap // Extract the glyph's pixels from the bitmap
myPixelBuffer.resize(width * height * 4, 255); m_pixelBuffer.resize(width * height * 4, 255);
const Uint8* pixels = bitmap.buffer; const Uint8* pixels = bitmap.buffer;
if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
{ {
@ -468,7 +468,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
{ {
// The color channels remain white, just fill the alpha channel // The color channels remain white, just fill the alpha channel
std::size_t index = (x + y * width) * 4 + 3; std::size_t index = (x + y * width) * 4 + 3;
myPixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0; m_pixelBuffer[index] = ((pixels[x / 8]) & (1 << (7 - (x % 8)))) ? 255 : 0;
} }
pixels += bitmap.pitch; pixels += bitmap.pitch;
} }
@ -482,7 +482,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
{ {
// The color channels remain white, just fill the alpha channel // The color channels remain white, just fill the alpha channel
std::size_t index = (x + y * width) * 4 + 3; std::size_t index = (x + y * width) * 4 + 3;
myPixelBuffer[index] = pixels[x]; m_pixelBuffer[index] = pixels[x];
} }
pixels += bitmap.pitch; pixels += bitmap.pitch;
} }
@ -493,7 +493,7 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
unsigned int y = glyph.TextureRect.Top + padding; unsigned int y = glyph.TextureRect.Top + padding;
unsigned int width = glyph.TextureRect.Width - 2 * padding; unsigned int width = glyph.TextureRect.Width - 2 * padding;
unsigned int height = glyph.TextureRect.Height - 2 * padding; unsigned int height = glyph.TextureRect.Height - 2 * padding;
page.Texture.Update(&myPixelBuffer[0], width, height, x, y); page.Texture.Update(&m_pixelBuffer[0], width, height, x, y);
} }
// Delete the FT glyph // Delete the FT glyph
@ -577,7 +577,7 @@ bool Font::SetCurrentSize(unsigned int characterSize) const
// FT_Set_Pixel_Sizes is an expensive function, so we must call it // FT_Set_Pixel_Sizes is an expensive function, so we must call it
// only when necessary to avoid killing performances // only when necessary to avoid killing performances
FT_Face face = static_cast<FT_Face>(myFace); FT_Face face = static_cast<FT_Face>(m_face);
FT_UShort currentSize = face->size->metrics.x_ppem; FT_UShort currentSize = face->size->metrics.x_ppem;
if (currentSize != characterSize) if (currentSize != characterSize)

View File

@ -36,8 +36,8 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Image::Image() : Image::Image() :
myWidth (0), m_width (0),
myHeight(0) m_height(0)
{ {
} }
@ -47,15 +47,15 @@ myHeight(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 // Assign the new size
myWidth = width; m_width = width;
myHeight = height; m_height = height;
// Resize the pixel buffer // Resize the pixel buffer
myPixels.resize(width * height * 4); m_pixels.resize(width * height * 4);
// Fill it with the specified color // Fill it with the specified color
Uint8* ptr = &myPixels[0]; Uint8* ptr = &m_pixels[0];
Uint8* end = ptr + myPixels.size(); Uint8* end = ptr + m_pixels.size();
while (ptr < end) while (ptr < end)
{ {
*ptr++ = color.r; *ptr++ = color.r;
@ -72,20 +72,20 @@ void Image::Create(unsigned int width, unsigned int height, const Uint8* pixels)
if (pixels) if (pixels)
{ {
// Assign the new size // Assign the new size
myWidth = width; m_width = width;
myHeight = height; m_height = height;
// Copy the pixels // Copy the pixels
std::size_t size = width * height * 4; std::size_t size = width * height * 4;
myPixels.resize(size); m_pixels.resize(size);
std::memcpy(&myPixels[0], pixels, size); // faster than vector::assign std::memcpy(&m_pixels[0], pixels, size); // faster than vector::assign
} }
else else
{ {
// Create an empty image // Create an empty image
myWidth = 0; m_width = 0;
myHeight = 0; m_height = 0;
myPixels.clear(); m_pixels.clear();
} }
} }
@ -93,42 +93,42 @@ 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, myPixels, myWidth, myHeight); 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, myPixels, myWidth, myHeight); 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, myPixels, myWidth, myHeight); 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, myPixels, myWidth, myHeight); return priv::ImageLoader::GetInstance().SaveImageToFile(filename, m_pixels, m_width, m_height);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Image::GetWidth() const unsigned int Image::GetWidth() const
{ {
return myWidth; return m_width;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Image::GetHeight() const unsigned int Image::GetHeight() const
{ {
return myHeight; return m_height;
} }
@ -136,11 +136,11 @@ unsigned int Image::GetHeight() const
void Image::CreateMaskFromColor(const Color& color, Uint8 alpha) void Image::CreateMaskFromColor(const Color& color, Uint8 alpha)
{ {
// Make sure that the image is not empty // Make sure that the image is not empty
if (!myPixels.empty()) if (!m_pixels.empty())
{ {
// Replace the alpha of the pixels that match the transparent color // Replace the alpha of the pixels that match the transparent color
Uint8* ptr = &myPixels[0]; Uint8* ptr = &m_pixels[0];
Uint8* end = ptr + myPixels.size(); Uint8* end = ptr + m_pixels.size();
while (ptr < end) while (ptr < end)
{ {
if ((ptr[0] == color.r) && (ptr[1] == color.g) && (ptr[2] == color.b) && (ptr[3] == color.a)) if ((ptr[0] == color.r) && (ptr[1] == color.g) && (ptr[2] == color.b) && (ptr[3] == color.a))
@ -155,7 +155,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 // Make sure that both images are valid
if ((source.myWidth == 0) || (source.myHeight == 0) || (myWidth == 0) || (myHeight == 0)) if ((source.m_width == 0) || (source.m_height == 0) || (m_width == 0) || (m_height == 0))
return; return;
// Adjust the source rectangle // Adjust the source rectangle
@ -164,22 +164,22 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
{ {
srcRect.Left = 0; srcRect.Left = 0;
srcRect.Top = 0; srcRect.Top = 0;
srcRect.Width = source.myWidth; srcRect.Width = source.m_width;
srcRect.Height = source.myHeight; srcRect.Height = source.m_height;
} }
else else
{ {
if (srcRect.Left < 0) srcRect.Left = 0; if (srcRect.Left < 0) srcRect.Left = 0;
if (srcRect.Top < 0) srcRect.Top = 0; if (srcRect.Top < 0) srcRect.Top = 0;
if (srcRect.Width > static_cast<int>(source.myWidth)) srcRect.Width = source.myWidth; if (srcRect.Width > static_cast<int>(source.m_width)) srcRect.Width = source.m_width;
if (srcRect.Height > static_cast<int>(source.myHeight)) srcRect.Height = source.myHeight; if (srcRect.Height > static_cast<int>(source.m_height)) srcRect.Height = source.m_height;
} }
// Then find the valid bounds of the destination rectangle // Then find the valid bounds of the destination rectangle
int width = srcRect.Width; int width = srcRect.Width;
int height = srcRect.Height; int height = srcRect.Height;
if (destX + width > myWidth) width = myWidth - destX; if (destX + width > m_width) width = m_width - destX;
if (destY + height > myHeight) height = myHeight - destY; if (destY + height > m_height) height = m_height - destY;
// Make sure the destination area is valid // Make sure the destination area is valid
if ((width <= 0) || (height <= 0)) if ((width <= 0) || (height <= 0))
@ -188,10 +188,10 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
// Precompute as much as possible // Precompute as much as possible
int pitch = width * 4; int pitch = width * 4;
int rows = height; int rows = height;
int srcStride = source.myWidth * 4; int srcStride = source.m_width * 4;
int dstStride = myWidth * 4; int dstStride = m_width * 4;
const Uint8* srcPixels = &source.myPixels[0] + (srcRect.Left + srcRect.Top * source.myWidth) * 4; const Uint8* srcPixels = &source.m_pixels[0] + (srcRect.Left + srcRect.Top * source.m_width) * 4;
Uint8* dstPixels = &myPixels[0] + (destX + destY * myWidth) * 4; Uint8* dstPixels = &m_pixels[0] + (destX + destY * m_width) * 4;
// Copy the pixels // Copy the pixels
if (applyAlpha) if (applyAlpha)
@ -233,7 +233,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 = &myPixels[(x + y * myWidth) * 4]; Uint8* pixel = &m_pixels[(x + y * m_width) * 4];
*pixel++ = color.r; *pixel++ = color.r;
*pixel++ = color.g; *pixel++ = color.g;
*pixel++ = color.b; *pixel++ = color.b;
@ -244,7 +244,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 = &myPixels[(x + y * myWidth) * 4]; const Uint8* pixel = &m_pixels[(x + y * m_width) * 4];
return Color(pixel[0], pixel[1], pixel[2], pixel[3]); return Color(pixel[0], pixel[1], pixel[2], pixel[3]);
} }
@ -252,9 +252,9 @@ Color Image::GetPixel(unsigned int x, unsigned int y) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Uint8* Image::GetPixelsPtr() const const Uint8* Image::GetPixelsPtr() const
{ {
if (!myPixels.empty()) if (!m_pixels.empty())
{ {
return &myPixels[0]; return &m_pixels[0];
} }
else else
{ {
@ -267,14 +267,14 @@ const Uint8* Image::GetPixelsPtr() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Image::FlipHorizontally() void Image::FlipHorizontally()
{ {
if (!myPixels.empty()) if (!m_pixels.empty())
{ {
std::vector<Uint8> before = myPixels; std::vector<Uint8> before = m_pixels;
for (unsigned int y = 0; y < myHeight; ++y) for (unsigned int y = 0; y < m_height; ++y)
{ {
const Uint8* source = &before[y * myWidth * 4]; const Uint8* source = &before[y * m_width * 4];
Uint8* dest = &myPixels[(y + 1) * myWidth * 4 - 4]; Uint8* dest = &m_pixels[(y + 1) * m_width * 4 - 4];
for (unsigned int x = 0; x < myWidth; ++x) for (unsigned int x = 0; x < m_width; ++x)
{ {
dest[0] = source[0]; dest[0] = source[0];
dest[1] = source[1]; dest[1] = source[1];
@ -292,14 +292,14 @@ void Image::FlipHorizontally()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Image::FlipVertically() void Image::FlipVertically()
{ {
if (!myPixels.empty()) if (!m_pixels.empty())
{ {
std::vector<Uint8> before = myPixels; std::vector<Uint8> before = m_pixels;
const Uint8* source = &before[myWidth * (myHeight - 1) * 4]; const Uint8* source = &before[m_width * (m_height - 1) * 4];
Uint8* dest = &myPixels[0]; Uint8* dest = &m_pixels[0];
std::size_t rowSize = myWidth * 4; std::size_t rowSize = m_width * 4;
for (unsigned int y = 0; y < myHeight; ++y) for (unsigned int y = 0; y < m_height; ++y)
{ {
std::memcpy(dest, source, rowSize); std::memcpy(dest, source, rowSize);
source -= rowSize; source -= rowSize;

View File

@ -41,7 +41,7 @@ RectangleShape::RectangleShape(const Vector2f& size)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void RectangleShape::SetSize(const Vector2f& size) void RectangleShape::SetSize(const Vector2f& size)
{ {
mySize = size; m_size = size;
Update(); Update();
} }
@ -49,7 +49,7 @@ void RectangleShape::SetSize(const Vector2f& size)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& RectangleShape::GetSize() const const Vector2f& RectangleShape::GetSize() const
{ {
return mySize; return m_size;
} }
@ -67,9 +67,9 @@ Vector2f RectangleShape::GetPoint(unsigned int index) const
{ {
default: default:
case 0: return Vector2f(0, 0); case 0: return Vector2f(0, 0);
case 1: return Vector2f(mySize.x, 0); case 1: return Vector2f(m_size.x, 0);
case 2: return Vector2f(mySize.x, mySize.y); case 2: return Vector2f(m_size.x, m_size.y);
case 3: return Vector2f(0, mySize.y); case 3: return Vector2f(0, m_size.y);
} }
} }

View File

@ -38,9 +38,9 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTarget::RenderTarget() : RenderTarget::RenderTarget() :
myDefaultView(), m_defaultView(),
myView (), m_view (),
myCache () m_cache ()
{ {
} }
@ -65,22 +65,22 @@ void RenderTarget::Clear(const Color& color)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void RenderTarget::SetView(const View& view) void RenderTarget::SetView(const View& view)
{ {
myView = view; m_view = view;
myCache.ViewChanged = true; m_cache.ViewChanged = true;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const View& RenderTarget::GetView() const const View& RenderTarget::GetView() const
{ {
return myView; return m_view;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const View& RenderTarget::GetDefaultView() const const View& RenderTarget::GetDefaultView() const
{ {
return myDefaultView; return m_defaultView;
} }
@ -143,14 +143,14 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
// Pre-transform the vertices and store them into the vertex cache // Pre-transform the vertices and store them into the vertex cache
for (unsigned int i = 0; i < vertexCount; ++i) for (unsigned int i = 0; i < vertexCount; ++i)
{ {
Vertex& vertex = myCache.VertexCache[i]; Vertex& vertex = m_cache.VertexCache[i];
vertex.Position = states.Transform * vertices[i].Position; vertex.Position = states.Transform * vertices[i].Position;
vertex.Color = vertices[i].Color; vertex.Color = vertices[i].Color;
vertex.TexCoords = vertices[i].TexCoords; vertex.TexCoords = vertices[i].TexCoords;
} }
// Since vertices are transformed, we must use an identity transform to render them // Since vertices are transformed, we must use an identity transform to render them
if (!myCache.UseVertexCache) if (!m_cache.UseVertexCache)
ApplyTransform(Transform::Identity); ApplyTransform(Transform::Identity);
} }
else else
@ -159,16 +159,16 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
} }
// Apply the view // Apply the view
if (myCache.ViewChanged) if (m_cache.ViewChanged)
ApplyCurrentView(); ApplyCurrentView();
// Apply the blend mode // Apply the blend mode
if (states.BlendMode != myCache.LastBlendMode) if (states.BlendMode != m_cache.LastBlendMode)
ApplyBlendMode(states.BlendMode); ApplyBlendMode(states.BlendMode);
// Apply the texture // Apply the texture
Uint64 textureId = states.Texture ? states.Texture->myCacheId : 0; Uint64 textureId = states.Texture ? states.Texture->m_cacheId : 0;
if (textureId != myCache.LastTextureId) if (textureId != m_cache.LastTextureId)
ApplyTexture(states.Texture); ApplyTexture(states.Texture);
// Apply the shader // Apply the shader
@ -179,8 +179,8 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
if (useVertexCache) if (useVertexCache)
{ {
// ... and if we already used it previously, we don't need to set the pointers again // ... and if we already used it previously, we don't need to set the pointers again
if (!myCache.UseVertexCache) if (!m_cache.UseVertexCache)
vertices = myCache.VertexCache; vertices = m_cache.VertexCache;
else else
vertices = NULL; vertices = NULL;
} }
@ -207,7 +207,7 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int vertexCount,
ApplyShader(NULL); ApplyShader(NULL);
// Update the cache // Update the cache
myCache.UseVertexCache = useVertexCache; m_cache.UseVertexCache = useVertexCache;
} }
} }
@ -272,7 +272,7 @@ void RenderTarget::ResetGLStates()
ApplyTexture(NULL); ApplyTexture(NULL);
if (Shader::IsAvailable()) if (Shader::IsAvailable())
ApplyShader(NULL); ApplyShader(NULL);
myCache.UseVertexCache = false; m_cache.UseVertexCache = false;
// Set the default view // Set the default view
SetView(GetView()); SetView(GetView());
@ -284,8 +284,8 @@ void RenderTarget::ResetGLStates()
void RenderTarget::Initialize() void RenderTarget::Initialize()
{ {
// Setup the default and current views // Setup the default and current views
myDefaultView.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)));
myView = myDefaultView; m_view = m_defaultView;
// Initialize the default OpenGL render-states // Initialize the default OpenGL render-states
ResetGLStates(); ResetGLStates();
@ -296,18 +296,18 @@ void RenderTarget::Initialize()
void RenderTarget::ApplyCurrentView() void RenderTarget::ApplyCurrentView()
{ {
// Set the viewport // Set the viewport
IntRect viewport = GetViewport(myView); IntRect viewport = GetViewport(m_view);
int top = GetSize().y - (viewport.Top + viewport.Height); int top = GetSize().y - (viewport.Top + viewport.Height);
GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height)); GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height));
// Set the projection matrix // Set the projection matrix
GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glMatrixMode(GL_PROJECTION));
GLCheck(glLoadMatrixf(myView.GetTransform().GetMatrix())); GLCheck(glLoadMatrixf(m_view.GetTransform().GetMatrix()));
// Go back to model-view mode // Go back to model-view mode
GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glMatrixMode(GL_MODELVIEW));
myCache.ViewChanged = false; m_cache.ViewChanged = false;
} }
@ -343,7 +343,7 @@ void RenderTarget::ApplyBlendMode(BlendMode mode)
break; break;
} }
myCache.LastBlendMode = mode; m_cache.LastBlendMode = mode;
} }
@ -364,7 +364,7 @@ void RenderTarget::ApplyTexture(const Texture* texture)
else else
GLCheck(glBindTexture(GL_TEXTURE_2D, 0)); GLCheck(glBindTexture(GL_TEXTURE_2D, 0));
myCache.LastTextureId = texture ? texture->myCacheId : 0; m_cache.LastTextureId = texture ? texture->m_cacheId : 0;
} }

View File

@ -35,7 +35,7 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTexture::RenderTexture() : RenderTexture::RenderTexture() :
myImpl(NULL) m_impl(NULL)
{ {
} }
@ -44,7 +44,7 @@ myImpl(NULL)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTexture::~RenderTexture() RenderTexture::~RenderTexture()
{ {
delete myImpl; delete m_impl;
} }
@ -52,7 +52,7 @@ 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 // Create the texture
if (!myTexture.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; return false;
@ -62,20 +62,20 @@ bool RenderTexture::Create(unsigned int width, unsigned int height, bool depthBu
SetSmooth(false); SetSmooth(false);
// Create the implementation // Create the implementation
delete myImpl; delete m_impl;
if (priv::RenderTextureImplFBO::IsAvailable()) if (priv::RenderTextureImplFBO::IsAvailable())
{ {
// Use frame-buffer object (FBO) // Use frame-buffer object (FBO)
myImpl = new priv::RenderTextureImplFBO; m_impl = new priv::RenderTextureImplFBO;
} }
else else
{ {
// Use default implementation // Use default implementation
myImpl = new priv::RenderTextureImplDefault; m_impl = new priv::RenderTextureImplDefault;
} }
// Initialize the render texture // Initialize the render texture
if (!myImpl->Create(width, height, myTexture.myTexture, depthBuffer)) if (!m_impl->Create(width, height, m_texture.m_texture, depthBuffer))
return false; return false;
// We can now initialize the render target part // We can now initialize the render target part
@ -88,21 +88,21 @@ bool RenderTexture::Create(unsigned int width, unsigned int height, bool depthBu
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void RenderTexture::SetSmooth(bool smooth) void RenderTexture::SetSmooth(bool smooth)
{ {
myTexture.SetSmooth(smooth); m_texture.SetSmooth(smooth);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool RenderTexture::IsSmooth() const bool RenderTexture::IsSmooth() const
{ {
return myTexture.IsSmooth(); return m_texture.IsSmooth();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool RenderTexture::SetActive(bool active) bool RenderTexture::SetActive(bool active)
{ {
return myImpl && myImpl->Activate(active); return m_impl && m_impl->Activate(active);
} }
@ -112,8 +112,8 @@ void RenderTexture::Display()
// Update the target texture // Update the target texture
if (SetActive(true)) if (SetActive(true))
{ {
myImpl->UpdateTexture(myTexture.myTexture); m_impl->UpdateTexture(m_texture.m_texture);
myTexture.myPixelsFlipped = true; m_texture.m_pixelsFlipped = true;
} }
} }
@ -121,14 +121,14 @@ void RenderTexture::Display()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2u RenderTexture::GetSize() const Vector2u RenderTexture::GetSize() const
{ {
return Vector2u(myTexture.GetWidth(), myTexture.GetHeight()); return Vector2u(m_texture.GetWidth(), m_texture.GetHeight());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Texture& RenderTexture::GetTexture() const const Texture& RenderTexture::GetTexture() const
{ {
return myTexture; return m_texture;
} }

View File

@ -38,9 +38,9 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTextureImplDefault::RenderTextureImplDefault() : RenderTextureImplDefault::RenderTextureImplDefault() :
myContext(0), m_context(0),
myWidth (0), m_width (0),
myHeight (0) m_height (0)
{ {
} }
@ -50,7 +50,7 @@ myHeight (0)
RenderTextureImplDefault::~RenderTextureImplDefault() RenderTextureImplDefault::~RenderTextureImplDefault()
{ {
// Destroy the context // Destroy the context
delete myContext; delete m_context;
} }
@ -58,11 +58,11 @@ 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 // Store the dimensions
myWidth = width; m_width = width;
myHeight = height; m_height = height;
// Create the in-memory OpenGL context // Create the in-memory OpenGL context
myContext = new Context(ContextSettings(depthBuffer ? 32 : 0), width, height); m_context = new Context(ContextSettings(depthBuffer ? 32 : 0), width, height);
return true; return true;
} }
@ -71,7 +71,7 @@ bool RenderTextureImplDefault::Create(unsigned int width, unsigned int height, u
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool RenderTextureImplDefault::Activate(bool active) bool RenderTextureImplDefault::Activate(bool active)
{ {
return myContext->SetActive(active); return m_context->SetActive(active);
} }
@ -83,7 +83,7 @@ void RenderTextureImplDefault::UpdateTexture(unsigned int textureId)
// Copy the rendered pixels to the texture // Copy the rendered pixels to the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, textureId)); GLCheck(glBindTexture(GL_TEXTURE_2D, textureId));
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight)); GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height));
} }
} // namespace priv } // namespace priv

View File

@ -94,9 +94,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Context* myContext; ///< P-Buffer based context Context* m_context; ///< P-Buffer based context
unsigned int myWidth; ///< Width of the P-Buffer unsigned int m_width; ///< Width of the P-Buffer
unsigned int myHeight; ///< Height of the P-Buffer unsigned int m_height; ///< Height of the P-Buffer
}; };
} // namespace priv } // namespace priv

View File

@ -37,8 +37,8 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTextureImplFBO::RenderTextureImplFBO() : RenderTextureImplFBO::RenderTextureImplFBO() :
myFrameBuffer(0), m_frameBuffer(0),
myDepthBuffer(0) m_depthBuffer(0)
{ {
} }
@ -50,21 +50,21 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
EnsureGlContext(); EnsureGlContext();
// Destroy the depth buffer // Destroy the depth buffer
if (myDepthBuffer) if (m_depthBuffer)
{ {
GLuint depthBuffer = static_cast<GLuint>(myDepthBuffer); GLuint depthBuffer = static_cast<GLuint>(m_depthBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &depthBuffer)); GLCheck(glDeleteFramebuffersEXT(1, &depthBuffer));
} }
// Destroy the frame buffer // Destroy the frame buffer
if (myFrameBuffer) if (m_frameBuffer)
{ {
GLuint frameBuffer = static_cast<GLuint>(myFrameBuffer); GLuint frameBuffer = static_cast<GLuint>(m_frameBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer)); GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
} }
// Delete the context // Delete the context
delete myContext; delete m_context;
} }
@ -84,33 +84,33 @@ bool RenderTextureImplFBO::IsAvailable()
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 // Create the context
myContext = new Context; m_context = new Context;
// Create the framebuffer object // Create the framebuffer object
GLuint frameBuffer = 0; GLuint frameBuffer = 0;
GLCheck(glGenFramebuffersEXT(1, &frameBuffer)); GLCheck(glGenFramebuffersEXT(1, &frameBuffer));
myFrameBuffer = static_cast<unsigned int>(frameBuffer); m_frameBuffer = static_cast<unsigned int>(frameBuffer);
if (!myFrameBuffer) 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; return false;
} }
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer)); GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
// Create the depth buffer if requested // Create the depth buffer if requested
if (depthBuffer) if (depthBuffer)
{ {
GLuint depth = 0; GLuint depth = 0;
GLCheck(glGenRenderbuffersEXT(1, &depth)); GLCheck(glGenRenderbuffersEXT(1, &depth));
myDepthBuffer = static_cast<unsigned int>(depth); m_depthBuffer = static_cast<unsigned int>(depth);
if (!myDepthBuffer) 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; return false;
} }
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myDepthBuffer)); GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
GLCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height)); GLCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
GLCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, myDepthBuffer)); GLCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
} }
// Link the texture to the frame buffer // Link the texture to the frame buffer
@ -131,7 +131,7 @@ bool RenderTextureImplFBO::Create(unsigned int width, unsigned int height, unsig
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool RenderTextureImplFBO::Activate(bool active) bool RenderTextureImplFBO::Activate(bool active)
{ {
return myContext->SetActive(active); return m_context->SetActive(active);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -102,9 +102,9 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Context* myContext; ///< Needs a separate OpenGL context for not messing up the other ones Context* m_context; ///< Needs a separate OpenGL context for not messing up the other ones
unsigned int myFrameBuffer; ///< OpenGL frame buffer object unsigned int m_frameBuffer; ///< OpenGL frame buffer object
unsigned int myDepthBuffer; ///< Optional depth buffer attached to the frame buffer unsigned int m_depthBuffer; ///< Optional depth buffer attached to the frame buffer
}; };
} // namespace priv } // namespace priv

View File

@ -85,8 +85,8 @@ Shader::CurrentTextureType Shader::CurrentTexture;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Shader::Shader() : Shader::Shader() :
myShaderProgram (0), m_shaderProgram (0),
myCurrentTexture(-1) m_currentTexture(-1)
{ {
} }
@ -97,8 +97,8 @@ Shader::~Shader()
EnsureGlContext(); EnsureGlContext();
// Destroy effect program // Destroy effect program
if (myShaderProgram) if (m_shaderProgram)
GLCheck(glDeleteObjectARB(myShaderProgram)); GLCheck(glDeleteObjectARB(m_shaderProgram));
} }
@ -210,16 +210,16 @@ bool Shader::LoadFromStream(InputStream& vertexShaderStream, InputStream& fragme
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::SetParameter(const std::string& name, float x) void Shader::SetParameter(const std::string& name, float x)
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str()); GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location != -1) if (location != -1)
GLCheck(glUniform1fARB(location, x)); GLCheck(glUniform1fARB(location, x));
else else
@ -234,16 +234,16 @@ void Shader::SetParameter(const std::string& name, float x)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::SetParameter(const std::string& name, float x, float y) void Shader::SetParameter(const std::string& name, float x, float y)
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str()); GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location != -1) if (location != -1)
GLCheck(glUniform2fARB(location, x, y)); GLCheck(glUniform2fARB(location, x, y));
else else
@ -258,16 +258,16 @@ void Shader::SetParameter(const std::string& name, float x, float y)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
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 (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str()); GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location != -1) if (location != -1)
GLCheck(glUniform3fARB(location, x, y, z)); GLCheck(glUniform3fARB(location, x, y, z));
else else
@ -282,16 +282,16 @@ 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, float w) void Shader::SetParameter(const std::string& name, float x, float y, float z, float w)
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str()); GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location != -1) if (location != -1)
GLCheck(glUniform4fARB(location, x, y, z, w)); GLCheck(glUniform4fARB(location, x, y, z, w));
else else
@ -327,16 +327,16 @@ void Shader::SetParameter(const std::string& name, const Color& color)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::SetParameter(const std::string& name, const sf::Transform& transform) void Shader::SetParameter(const std::string& name, const sf::Transform& transform)
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str()); GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location != -1) if (location != -1)
GLCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.GetMatrix())); GLCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.GetMatrix()));
else else
@ -351,12 +351,12 @@ void Shader::SetParameter(const std::string& name, const sf::Transform& transfor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::SetParameter(const std::string& name, const Texture& texture) void Shader::SetParameter(const std::string& name, const Texture& texture)
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Find the location of the variable in the shader // Find the location of the variable in the shader
int location = glGetUniformLocationARB(myShaderProgram, name.c_str()); int location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (location == -1) if (location == -1)
{ {
Err() << "Texture \"" << name << "\" not found in shader" << std::endl; Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
@ -364,18 +364,18 @@ void Shader::SetParameter(const std::string& name, const Texture& texture)
} }
// Store the location -> texture mapping // Store the location -> texture mapping
TextureTable::iterator it = myTextures.find(location); TextureTable::iterator it = m_textures.find(location);
if (it == myTextures.end()) if (it == m_textures.end())
{ {
// New entry, make sure there are enough texture units // New entry, make sure there are enough texture units
static const GLint maxUnits = GetMaxTextureUnits(); static const GLint maxUnits = GetMaxTextureUnits();
if (myTextures.size() + 1 >= static_cast<std::size_t>(maxUnits)) 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; return;
} }
myTextures[location] = &texture; m_textures[location] = &texture;
} }
else else
{ {
@ -389,13 +389,13 @@ 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 (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Find the location of the variable in the shader // Find the location of the variable in the shader
myCurrentTexture = glGetUniformLocationARB(myShaderProgram, name.c_str()); m_currentTexture = glGetUniformLocationARB(m_shaderProgram, name.c_str());
if (myCurrentTexture == -1) if (m_currentTexture == -1)
Err() << "Texture \"" << name << "\" not found in shader" << std::endl; Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
} }
} }
@ -404,19 +404,19 @@ void Shader::SetParameter(const std::string& name, CurrentTextureType)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::Bind() const void Shader::Bind() const
{ {
if (myShaderProgram) if (m_shaderProgram)
{ {
EnsureGlContext(); EnsureGlContext();
// Enable the program // Enable the program
GLCheck(glUseProgramObjectARB(myShaderProgram)); GLCheck(glUseProgramObjectARB(m_shaderProgram));
// Bind the textures // Bind the textures
BindTextures(); BindTextures();
// Bind the current texture // Bind the current texture
if (myCurrentTexture != -1) if (m_currentTexture != -1)
GLCheck(glUniform1iARB(myCurrentTexture, 0)); GLCheck(glUniform1iARB(m_currentTexture, 0));
} }
} }
@ -459,11 +459,11 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
} }
// Destroy the shader if it was already created // Destroy the shader if it was already created
if (myShaderProgram) if (m_shaderProgram)
GLCheck(glDeleteObjectARB(myShaderProgram)); GLCheck(glDeleteObjectARB(m_shaderProgram));
// Create the program // Create the program
myShaderProgram = glCreateProgramObjectARB(); m_shaderProgram = glCreateProgramObjectARB();
// Create the vertex shader if needed // Create the vertex shader if needed
if (vertexShaderCode) if (vertexShaderCode)
@ -483,13 +483,13 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
Err() << "Failed to compile vertex shader:" << std::endl Err() << "Failed to compile vertex shader:" << std::endl
<< log << std::endl; << log << std::endl;
GLCheck(glDeleteObjectARB(vertexShader)); GLCheck(glDeleteObjectARB(vertexShader));
GLCheck(glDeleteObjectARB(myShaderProgram)); GLCheck(glDeleteObjectARB(m_shaderProgram));
myShaderProgram = 0; m_shaderProgram = 0;
return false; return false;
} }
// Attach the shader to the program, and delete it (not needed anymore) // Attach the shader to the program, and delete it (not needed anymore)
GLCheck(glAttachObjectARB(myShaderProgram, vertexShader)); GLCheck(glAttachObjectARB(m_shaderProgram, vertexShader));
GLCheck(glDeleteObjectARB(vertexShader)); GLCheck(glDeleteObjectARB(vertexShader));
} }
@ -511,30 +511,30 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
Err() << "Failed to compile fragment shader:" << std::endl Err() << "Failed to compile fragment shader:" << std::endl
<< log << std::endl; << log << std::endl;
GLCheck(glDeleteObjectARB(fragmentShader)); GLCheck(glDeleteObjectARB(fragmentShader));
GLCheck(glDeleteObjectARB(myShaderProgram)); GLCheck(glDeleteObjectARB(m_shaderProgram));
myShaderProgram = 0; m_shaderProgram = 0;
return false; return false;
} }
// Attach the shader to the program, and delete it (not needed anymore) // Attach the shader to the program, and delete it (not needed anymore)
GLCheck(glAttachObjectARB(myShaderProgram, fragmentShader)); GLCheck(glAttachObjectARB(m_shaderProgram, fragmentShader));
GLCheck(glDeleteObjectARB(fragmentShader)); GLCheck(glDeleteObjectARB(fragmentShader));
} }
// Link the program // Link the program
GLCheck(glLinkProgramARB(myShaderProgram)); GLCheck(glLinkProgramARB(m_shaderProgram));
// Check the link log // Check the link log
GLint success; GLint success;
GLCheck(glGetObjectParameterivARB(myShaderProgram, GL_OBJECT_LINK_STATUS_ARB, &success)); GLCheck(glGetObjectParameterivARB(m_shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &success));
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
char log[1024]; char log[1024];
GLCheck(glGetInfoLogARB(myShaderProgram, sizeof(log), 0, log)); GLCheck(glGetInfoLogARB(m_shaderProgram, sizeof(log), 0, log));
Err() << "Failed to link shader:" << std::endl Err() << "Failed to link shader:" << std::endl
<< log << std::endl; << log << std::endl;
GLCheck(glDeleteObjectARB(myShaderProgram)); GLCheck(glDeleteObjectARB(m_shaderProgram));
myShaderProgram = 0; m_shaderProgram = 0;
return false; return false;
} }
@ -545,8 +545,8 @@ bool Shader::Compile(const char* vertexShaderCode, const char* fragmentShaderCod
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shader::BindTextures() const void Shader::BindTextures() const
{ {
TextureTable::const_iterator it = myTextures.begin(); TextureTable::const_iterator it = m_textures.begin();
for (std::size_t i = 0; i < myTextures.size(); ++i) for (std::size_t i = 0; i < m_textures.size(); ++i)
{ {
GLint index = static_cast<GLsizei>(i + 1); GLint index = static_cast<GLsizei>(i + 1);
GLCheck(glUniform1iARB(it->first, index)); GLCheck(glUniform1iARB(it->first, index));

View File

@ -58,25 +58,25 @@ 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 // Recompute the texture area if requested, or if there was no texture before
if (texture && (resetRect || !myTexture)) 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 // Assign the new texture
myTexture = texture; m_texture = texture;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Texture* Shape::GetTexture() const const Texture* Shape::GetTexture() const
{ {
return myTexture; return m_texture;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::SetTextureRect(const IntRect& rect) void Shape::SetTextureRect(const IntRect& rect)
{ {
myTextureRect = rect; m_textureRect = rect;
UpdateTexCoords(); UpdateTexCoords();
} }
@ -84,14 +84,14 @@ void Shape::SetTextureRect(const IntRect& rect)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const IntRect& Shape::GetTextureRect() const const IntRect& Shape::GetTextureRect() const
{ {
return myTextureRect; return m_textureRect;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::SetFillColor(const Color& color) void Shape::SetFillColor(const Color& color)
{ {
myFillColor = color; m_fillColor = color;
UpdateFillColors(); UpdateFillColors();
} }
@ -99,14 +99,14 @@ void Shape::SetFillColor(const Color& color)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Color& Shape::GetFillColor() const const Color& Shape::GetFillColor() const
{ {
return myFillColor; return m_fillColor;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::SetOutlineColor(const Color& color) void Shape::SetOutlineColor(const Color& color)
{ {
myOutlineColor = color; m_outlineColor = color;
UpdateOutlineColors(); UpdateOutlineColors();
} }
@ -114,14 +114,14 @@ void Shape::SetOutlineColor(const Color& color)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Color& Shape::GetOutlineColor() const const Color& Shape::GetOutlineColor() const
{ {
return myOutlineColor; return m_outlineColor;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::SetOutlineThickness(float thickness) void Shape::SetOutlineThickness(float thickness)
{ {
myOutlineThickness = thickness; m_outlineThickness = thickness;
Update(); // recompute everything because the whole shape must be offset Update(); // recompute everything because the whole shape must be offset
} }
@ -129,14 +129,14 @@ void Shape::SetOutlineThickness(float thickness)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Shape::GetOutlineThickness() const float Shape::GetOutlineThickness() const
{ {
return myOutlineThickness; return m_outlineThickness;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FloatRect Shape::GetLocalBounds() const FloatRect Shape::GetLocalBounds() const
{ {
return myBounds; return m_bounds;
} }
@ -149,15 +149,15 @@ FloatRect Shape::GetGlobalBounds() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Shape::Shape() : Shape::Shape() :
myTexture (NULL), m_texture (NULL),
myTextureRect (), m_textureRect (),
myFillColor (255, 255, 255), m_fillColor (255, 255, 255),
myOutlineColor (255, 255, 255), m_outlineColor (255, 255, 255),
myOutlineThickness(0), m_outlineThickness(0),
myVertices (TrianglesFan), m_vertices (TrianglesFan),
myOutlineVertices (TrianglesStrip), m_outlineVertices (TrianglesStrip),
myInsideBounds (), m_insideBounds (),
myBounds () m_bounds ()
{ {
} }
@ -169,25 +169,25 @@ void Shape::Update()
unsigned int count = GetPointCount(); unsigned int count = GetPointCount();
if (count < 3) if (count < 3)
{ {
myVertices.Resize(0); m_vertices.Resize(0);
myOutlineVertices.Resize(0); m_outlineVertices.Resize(0);
return; return;
} }
myVertices.Resize(count + 2); // + 2 for center and repeated first point m_vertices.Resize(count + 2); // + 2 for center and repeated first point
// Position // Position
for (unsigned int i = 0; i < count; ++i) for (unsigned int i = 0; i < count; ++i)
myVertices[i + 1].Position = GetPoint(i); m_vertices[i + 1].Position = GetPoint(i);
myVertices[count + 1].Position = myVertices[1].Position; m_vertices[count + 1].Position = m_vertices[1].Position;
// Update the bounding rectangle // Update the bounding rectangle
myVertices[0] = myVertices[1]; // so that the result of GetBounds() is correct m_vertices[0] = m_vertices[1]; // so that the result of GetBounds() is correct
myInsideBounds = myVertices.GetBounds(); m_insideBounds = m_vertices.GetBounds();
// Compute the center and make it the first vertex // Compute the center and make it the first vertex
myVertices[0].Position.x = myInsideBounds.Left + myInsideBounds.Width / 2; m_vertices[0].Position.x = m_insideBounds.Left + m_insideBounds.Width / 2;
myVertices[0].Position.y = myInsideBounds.Top + myInsideBounds.Height / 2; m_vertices[0].Position.y = m_insideBounds.Top + m_insideBounds.Height / 2;
// Color // Color
UpdateFillColors(); UpdateFillColors();
@ -206,17 +206,17 @@ void Shape::Draw(RenderTarget& target, RenderStates states) const
states.Transform *= GetTransform(); states.Transform *= GetTransform();
// Render the inside // Render the inside
if (myFillColor.a > 0) if (m_fillColor.a > 0)
{ {
states.Texture = myTexture; states.Texture = m_texture;
target.Draw(myVertices, states); target.Draw(m_vertices, states);
} }
// Render the outline // Render the outline
if ((myOutlineColor.a > 0) && (myOutlineThickness > 0)) if ((m_outlineColor.a > 0) && (m_outlineThickness > 0))
{ {
states.Texture = NULL; states.Texture = NULL;
target.Draw(myOutlineVertices, states); target.Draw(m_outlineVertices, states);
} }
} }
@ -224,20 +224,20 @@ void Shape::Draw(RenderTarget& target, RenderStates states) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::UpdateFillColors() void Shape::UpdateFillColors()
{ {
for (unsigned int i = 0; i < myVertices.GetVertexCount(); ++i) for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
myVertices[i].Color = myFillColor; m_vertices[i].Color = m_fillColor;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::UpdateTexCoords() void Shape::UpdateTexCoords()
{ {
for (unsigned int i = 0; i < myVertices.GetVertexCount(); ++i) for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
{ {
float xratio = (myVertices[i].Position.x - myInsideBounds.Left) / myInsideBounds.Width; float xratio = (m_vertices[i].Position.x - m_insideBounds.Left) / m_insideBounds.Width;
float yratio = (myVertices[i].Position.y - myInsideBounds.Top) / myInsideBounds.Height; float yratio = (m_vertices[i].Position.y - m_insideBounds.Top) / m_insideBounds.Height;
myVertices[i].TexCoords.x = myTextureRect.Left + myTextureRect.Width * xratio; m_vertices[i].TexCoords.x = m_textureRect.Left + m_textureRect.Width * xratio;
myVertices[i].TexCoords.y = myTextureRect.Top + myTextureRect.Height * yratio; m_vertices[i].TexCoords.y = m_textureRect.Top + m_textureRect.Height * yratio;
} }
} }
@ -245,17 +245,17 @@ void Shape::UpdateTexCoords()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::UpdateOutline() void Shape::UpdateOutline()
{ {
unsigned int count = myVertices.GetVertexCount() - 2; unsigned int count = m_vertices.GetVertexCount() - 2;
myOutlineVertices.Resize((count + 1) * 2); m_outlineVertices.Resize((count + 1) * 2);
for (unsigned int i = 0; i < count; ++i) for (unsigned int i = 0; i < count; ++i)
{ {
unsigned int index = i + 1; unsigned int index = i + 1;
// Get the two segments shared by the current point // Get the two segments shared by the current point
Vector2f p0 = (i == 0) ? myVertices[count].Position : myVertices[index - 1].Position; Vector2f p0 = (i == 0) ? m_vertices[count].Position : m_vertices[index - 1].Position;
Vector2f p1 = myVertices[index].Position; Vector2f p1 = m_vertices[index].Position;
Vector2f p2 = myVertices[index + 1].Position; Vector2f p2 = m_vertices[index + 1].Position;
// Compute their normal // Compute their normal
Vector2f n1 = ComputeNormal(p0, p1); Vector2f n1 = ComputeNormal(p0, p1);
@ -266,27 +266,27 @@ void Shape::UpdateOutline()
Vector2f normal = -(n1 + n2) / factor; Vector2f normal = -(n1 + n2) / factor;
// Update the outline points // Update the outline points
myOutlineVertices[i * 2 + 0].Position = p1; m_outlineVertices[i * 2 + 0].Position = p1;
myOutlineVertices[i * 2 + 1].Position = p1 + normal * myOutlineThickness; m_outlineVertices[i * 2 + 1].Position = p1 + normal * m_outlineThickness;
} }
// Duplicate the first point at the end, to close the outline // Duplicate the first point at the end, to close the outline
myOutlineVertices[count * 2 + 0].Position = myOutlineVertices[0].Position; m_outlineVertices[count * 2 + 0].Position = m_outlineVertices[0].Position;
myOutlineVertices[count * 2 + 1].Position = myOutlineVertices[1].Position; m_outlineVertices[count * 2 + 1].Position = m_outlineVertices[1].Position;
// Update outline colors // Update outline colors
UpdateOutlineColors(); UpdateOutlineColors();
// Update the shape's bounds // Update the shape's bounds
myBounds = myOutlineVertices.GetBounds(); m_bounds = m_outlineVertices.GetBounds();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Shape::UpdateOutlineColors() void Shape::UpdateOutlineColors()
{ {
for (unsigned int i = 0; i < myOutlineVertices.GetVertexCount(); ++i) for (unsigned int i = 0; i < m_outlineVertices.GetVertexCount(); ++i)
myOutlineVertices[i].Color = myOutlineColor; m_outlineVertices[i].Color = m_outlineColor;
} }
} // namespace sf } // namespace sf

View File

@ -34,16 +34,16 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite() : Sprite::Sprite() :
myTexture (NULL), m_texture (NULL),
myTextureRect(0, 0, 0, 0) m_textureRect(0, 0, 0, 0)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture) : Sprite::Sprite(const Texture& texture) :
myTexture (NULL), m_texture (NULL),
myTextureRect(0, 0, 0, 0) m_textureRect(0, 0, 0, 0)
{ {
SetTexture(texture); SetTexture(texture);
} }
@ -51,8 +51,8 @@ myTextureRect(0, 0, 0, 0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture, const IntRect& rectangle) : Sprite::Sprite(const Texture& texture, const IntRect& rectangle) :
myTexture (NULL), m_texture (NULL),
myTextureRect(0, 0, 0, 0) m_textureRect(0, 0, 0, 0)
{ {
SetTexture(texture); SetTexture(texture);
SetTextureRect(rectangle); SetTextureRect(rectangle);
@ -63,20 +63,20 @@ myTextureRect(0, 0, 0, 0)
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 // Recompute the texture area if requested, or if there was no valid texture before
if (resetRect || !myTexture) if (resetRect || !m_texture)
SetTextureRect(IntRect(0, 0, texture.GetWidth(), texture.GetHeight())); SetTextureRect(IntRect(0, 0, texture.GetWidth(), texture.GetHeight()));
// Assign the new texture // Assign the new texture
myTexture = &texture; m_texture = &texture;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sprite::SetTextureRect(const IntRect& rectangle) void Sprite::SetTextureRect(const IntRect& rectangle)
{ {
if (rectangle != myTextureRect) if (rectangle != m_textureRect)
{ {
myTextureRect = rectangle; m_textureRect = rectangle;
UpdatePositions(); UpdatePositions();
UpdateTexCoords(); UpdateTexCoords();
} }
@ -87,39 +87,39 @@ void Sprite::SetTextureRect(const IntRect& rectangle)
void Sprite::SetColor(const Color& color) void Sprite::SetColor(const Color& color)
{ {
// Update the vertices' color // Update the vertices' color
myVertices[0].Color = color; m_vertices[0].Color = color;
myVertices[1].Color = color; m_vertices[1].Color = color;
myVertices[2].Color = color; m_vertices[2].Color = color;
myVertices[3].Color = color; m_vertices[3].Color = color;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Texture* Sprite::GetTexture() const const Texture* Sprite::GetTexture() const
{ {
return myTexture; return m_texture;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const IntRect& Sprite::GetTextureRect() const const IntRect& Sprite::GetTextureRect() const
{ {
return myTextureRect; return m_textureRect;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Color& Sprite::GetColor() const const Color& Sprite::GetColor() const
{ {
return myVertices[0].Color; return m_vertices[0].Color;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FloatRect Sprite::GetLocalBounds() const FloatRect Sprite::GetLocalBounds() const
{ {
float width = static_cast<float>(myTextureRect.Width); float width = static_cast<float>(m_textureRect.Width);
float height = static_cast<float>(myTextureRect.Height); float height = static_cast<float>(m_textureRect.Height);
return FloatRect(0.f, 0.f, width, height); return FloatRect(0.f, 0.f, width, height);
} }
@ -135,11 +135,11 @@ FloatRect Sprite::GetGlobalBounds() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sprite::Draw(RenderTarget& target, RenderStates states) const void Sprite::Draw(RenderTarget& target, RenderStates states) const
{ {
if (myTexture) if (m_texture)
{ {
states.Transform *= GetTransform(); states.Transform *= GetTransform();
states.Texture = myTexture; states.Texture = m_texture;
target.Draw(myVertices, 4, Quads, states); target.Draw(m_vertices, 4, Quads, states);
} }
} }
@ -147,28 +147,28 @@ void Sprite::Draw(RenderTarget& target, RenderStates states) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sprite::UpdatePositions() void Sprite::UpdatePositions()
{ {
float width = static_cast<float>(myTextureRect.Width); float width = static_cast<float>(m_textureRect.Width);
float height = static_cast<float>(myTextureRect.Height); float height = static_cast<float>(m_textureRect.Height);
myVertices[0].Position = Vector2f(0, 0); m_vertices[0].Position = Vector2f(0, 0);
myVertices[1].Position = Vector2f(0, height); m_vertices[1].Position = Vector2f(0, height);
myVertices[2].Position = Vector2f(width, height); m_vertices[2].Position = Vector2f(width, height);
myVertices[3].Position = Vector2f(width, 0); m_vertices[3].Position = Vector2f(width, 0);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sprite::UpdateTexCoords() void Sprite::UpdateTexCoords()
{ {
float left = static_cast<float>(myTextureRect.Left); float left = static_cast<float>(m_textureRect.Left);
float right = left + myTextureRect.Width; float right = left + m_textureRect.Width;
float top = static_cast<float>(myTextureRect.Top); float top = static_cast<float>(m_textureRect.Top);
float bottom = top + myTextureRect.Height; float bottom = top + m_textureRect.Height;
myVertices[0].TexCoords = Vector2f(left, top); m_vertices[0].TexCoords = Vector2f(left, top);
myVertices[1].TexCoords = Vector2f(left, bottom); m_vertices[1].TexCoords = Vector2f(left, bottom);
myVertices[2].TexCoords = Vector2f(right, bottom); m_vertices[2].TexCoords = Vector2f(right, bottom);
myVertices[3].TexCoords = Vector2f(right, top); m_vertices[3].TexCoords = Vector2f(right, top);
} }
} // namespace sf } // namespace sf

View File

@ -35,13 +35,13 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Text::Text() : Text::Text() :
myString (), m_string (),
myFont (&Font::GetDefaultFont()), m_font (&Font::GetDefaultFont()),
myCharacterSize(30), m_characterSize(30),
myStyle (Regular), m_style (Regular),
myColor (255, 255, 255), m_color (255, 255, 255),
myVertices (Quads), m_vertices (Quads),
myBounds () m_bounds ()
{ {
} }
@ -49,13 +49,13 @@ myBounds ()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Text::Text(const String& string, const Font& font, unsigned int characterSize) : Text::Text(const String& string, const Font& font, unsigned int characterSize) :
myString (string), m_string (string),
myFont (&font), m_font (&font),
myCharacterSize(characterSize), m_characterSize(characterSize),
myStyle (Regular), m_style (Regular),
myColor (255, 255, 255), m_color (255, 255, 255),
myVertices (Quads), m_vertices (Quads),
myBounds () m_bounds ()
{ {
UpdateGeometry(); UpdateGeometry();
} }
@ -64,7 +64,7 @@ myBounds ()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::SetString(const String& string) void Text::SetString(const String& string)
{ {
myString = string; m_string = string;
UpdateGeometry(); UpdateGeometry();
} }
@ -72,9 +72,9 @@ void Text::SetString(const String& string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::SetFont(const Font& font) void Text::SetFont(const Font& font)
{ {
if (myFont != &font) if (m_font != &font)
{ {
myFont = &font; m_font = &font;
UpdateGeometry(); UpdateGeometry();
} }
} }
@ -83,9 +83,9 @@ void Text::SetFont(const Font& font)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::SetCharacterSize(unsigned int size) void Text::SetCharacterSize(unsigned int size)
{ {
if (myCharacterSize != size) if (m_characterSize != size)
{ {
myCharacterSize = size; m_characterSize = size;
UpdateGeometry(); UpdateGeometry();
} }
} }
@ -94,9 +94,9 @@ void Text::SetCharacterSize(unsigned int size)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::SetStyle(Uint32 style) void Text::SetStyle(Uint32 style)
{ {
if (myStyle != style) if (m_style != style)
{ {
myStyle = style; m_style = style;
UpdateGeometry(); UpdateGeometry();
} }
} }
@ -105,11 +105,11 @@ void Text::SetStyle(Uint32 style)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::SetColor(const Color& color) void Text::SetColor(const Color& color)
{ {
if (color != myColor) if (color != m_color)
{ {
myColor = color; m_color = color;
for (unsigned int i = 0; i < myVertices.GetVertexCount(); ++i) for (unsigned int i = 0; i < m_vertices.GetVertexCount(); ++i)
myVertices[i].Color = myColor; m_vertices[i].Color = m_color;
} }
} }
@ -117,62 +117,62 @@ void Text::SetColor(const Color& color)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const String& Text::GetString() const const String& Text::GetString() const
{ {
return myString; return m_string;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Font& Text::GetFont() const const Font& Text::GetFont() const
{ {
assert(myFont != NULL); // can never be NULL, always &Font::GetDefaultFont() by default assert(m_font != NULL); // can never be NULL, always &Font::GetDefaultFont() by default
return *myFont; return *m_font;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Text::GetCharacterSize() const unsigned int Text::GetCharacterSize() const
{ {
return myCharacterSize; return m_characterSize;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32 Text::GetStyle() const Uint32 Text::GetStyle() const
{ {
return myStyle; return m_style;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Color& Text::GetColor() const const Color& Text::GetColor() const
{ {
return myColor; return m_color;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f Text::FindCharacterPos(std::size_t index) const Vector2f Text::FindCharacterPos(std::size_t index) const
{ {
assert(myFont != NULL); assert(m_font != NULL);
// Adjust the index if it's out of range // Adjust the index if it's out of range
if (index > myString.GetSize()) if (index > m_string.GetSize())
index = myString.GetSize(); index = m_string.GetSize();
// Precompute the variables needed by the algorithm // Precompute the variables needed by the algorithm
bool bold = (myStyle & Bold) != 0; bool bold = (m_style & Bold) != 0;
float hspace = static_cast<float>(myFont->GetGlyph(L' ', myCharacterSize, bold).Advance); float hspace = static_cast<float>(m_font->GetGlyph(L' ', m_characterSize, bold).Advance);
float vspace = static_cast<float>(myFont->GetLineSpacing(myCharacterSize)); float vspace = static_cast<float>(m_font->GetLineSpacing(m_characterSize));
// Compute the position // Compute the position
Vector2f position; Vector2f position;
Uint32 prevChar = 0; Uint32 prevChar = 0;
for (std::size_t i = 0; i < index; ++i) for (std::size_t i = 0; i < index; ++i)
{ {
Uint32 curChar = myString[i]; Uint32 curChar = m_string[i];
// Apply the kerning offset // Apply the kerning offset
position.x += static_cast<float>(myFont->GetKerning(prevChar, curChar, myCharacterSize)); position.x += static_cast<float>(m_font->GetKerning(prevChar, curChar, m_characterSize));
prevChar = curChar; prevChar = curChar;
// Handle special characters // Handle special characters
@ -185,7 +185,7 @@ Vector2f Text::FindCharacterPos(std::size_t index) const
} }
// For regular characters, add the advance offset of the glyph // For regular characters, add the advance offset of the glyph
position.x += static_cast<float>(myFont->GetGlyph(curChar, myCharacterSize, bold).Advance); position.x += static_cast<float>(m_font->GetGlyph(curChar, m_characterSize, bold).Advance);
} }
// Transform the position to global coordinates // Transform the position to global coordinates
@ -198,7 +198,7 @@ Vector2f Text::FindCharacterPos(std::size_t index) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FloatRect Text::GetLocalBounds() const FloatRect Text::GetLocalBounds() const
{ {
return myBounds; return m_bounds;
} }
@ -212,48 +212,48 @@ FloatRect Text::GetGlobalBounds() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::Draw(RenderTarget& target, RenderStates states) const void Text::Draw(RenderTarget& target, RenderStates states) const
{ {
assert(myFont != NULL); assert(m_font != NULL);
states.Transform *= GetTransform(); states.Transform *= GetTransform();
states.BlendMode = BlendAlpha; // alpha blending is mandatory for proper text rendering states.BlendMode = BlendAlpha; // alpha blending is mandatory for proper text rendering
states.Texture = &myFont->GetTexture(myCharacterSize); states.Texture = &m_font->GetTexture(m_characterSize);
target.Draw(myVertices, states); target.Draw(m_vertices, states);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Text::UpdateGeometry() void Text::UpdateGeometry()
{ {
assert(myFont != NULL); assert(m_font != NULL);
// Clear the previous geometry // Clear the previous geometry
myVertices.Clear(); m_vertices.Clear();
// No text: nothing to draw // No text: nothing to draw
if (myString.IsEmpty()) if (m_string.IsEmpty())
return; return;
// Compute values related to the text style // Compute values related to the text style
bool bold = (myStyle & Bold) != 0; bool bold = (m_style & Bold) != 0;
bool underlined = (myStyle & Underlined) != 0; bool underlined = (m_style & Underlined) != 0;
float italic = (myStyle & Italic) ? 0.208f : 0.f; // 12 degrees float italic = (m_style & Italic) ? 0.208f : 0.f; // 12 degrees
float underlineOffset = myCharacterSize * 0.1f; float underlineOffset = m_characterSize * 0.1f;
float underlineThickness = myCharacterSize * (bold ? 0.1f : 0.07f); float underlineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
// Precompute the variables needed by the algorithm // Precompute the variables needed by the algorithm
float hspace = static_cast<float>(myFont->GetGlyph(L' ', myCharacterSize, bold).Advance); float hspace = static_cast<float>(m_font->GetGlyph(L' ', m_characterSize, bold).Advance);
float vspace = static_cast<float>(myFont->GetLineSpacing(myCharacterSize)); float vspace = static_cast<float>(m_font->GetLineSpacing(m_characterSize));
float x = 0.f; float x = 0.f;
float y = static_cast<float>(myCharacterSize); float y = static_cast<float>(m_characterSize);
// Create one quad for each character // Create one quad for each character
Uint32 prevChar = 0; Uint32 prevChar = 0;
for (std::size_t i = 0; i < myString.GetSize(); ++i) for (std::size_t i = 0; i < m_string.GetSize(); ++i)
{ {
Uint32 curChar = myString[i]; Uint32 curChar = m_string[i];
// Apply the kerning offset // Apply the kerning offset
x += static_cast<float>(myFont->GetKerning(prevChar, curChar, myCharacterSize)); x += static_cast<float>(m_font->GetKerning(prevChar, curChar, m_characterSize));
prevChar = curChar; prevChar = curChar;
// If we're using the underlined style and there's a new line, draw a line // 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 top = y + underlineOffset;
float bottom = top + underlineThickness; float bottom = top + underlineThickness;
myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
} }
// Handle special characters // Handle special characters
@ -278,7 +278,7 @@ void Text::UpdateGeometry()
} }
// Extract the current glyph's description // Extract the current glyph's description
const Glyph& glyph = myFont->GetGlyph(curChar, myCharacterSize, bold); const Glyph& glyph = m_font->GetGlyph(curChar, m_characterSize, bold);
int left = glyph.Bounds.Left; int left = glyph.Bounds.Left;
int top = glyph.Bounds.Top; int top = glyph.Bounds.Top;
@ -291,10 +291,10 @@ void Text::UpdateGeometry()
float v2 = static_cast<float>(glyph.TextureRect.Top + glyph.TextureRect.Height); float v2 = static_cast<float>(glyph.TextureRect.Top + glyph.TextureRect.Height);
// Add a quad for the current character // Add a quad for the current character
myVertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), myColor, Vector2f(u1, v1))); m_vertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), m_color, Vector2f(u1, v1)));
myVertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), myColor, Vector2f(u2, v1))); m_vertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
myVertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), myColor, Vector2f(u2, v2))); m_vertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), m_color, Vector2f(u2, v2)));
myVertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), myColor, Vector2f(u1, v2))); m_vertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), m_color, Vector2f(u1, v2)));
// Advance to the next character // Advance to the next character
x += glyph.Advance; x += glyph.Advance;
@ -306,14 +306,14 @@ void Text::UpdateGeometry()
float top = y + underlineOffset; float top = y + underlineOffset;
float bottom = top + underlineThickness; float bottom = top + underlineThickness;
myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 1))); m_vertices.Append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
} }
// Recompute the bounding rectangle // Recompute the bounding rectangle
myBounds = myVertices.GetBounds(); m_bounds = m_vertices.GetBounds();
} }
} // namespace sf } // namespace sf

View File

@ -56,15 +56,15 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Texture::Texture() : Texture::Texture() :
myWidth (0), m_width (0),
myHeight (0), m_height (0),
myTextureWidth (0), m_textureWidth (0),
myTextureHeight(0), m_textureHeight(0),
myTexture (0), m_texture (0),
myIsSmooth (false), m_isSmooth (false),
myIsRepeated (false), m_isRepeated (false),
myPixelsFlipped(false), m_pixelsFlipped(false),
myCacheId (GetUniqueId()) m_cacheId (GetUniqueId())
{ {
} }
@ -72,17 +72,17 @@ myCacheId (GetUniqueId())
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Texture::Texture(const Texture& copy) : Texture::Texture(const Texture& copy) :
myWidth (0), m_width (0),
myHeight (0), m_height (0),
myTextureWidth (0), m_textureWidth (0),
myTextureHeight(0), m_textureHeight(0),
myTexture (0), m_texture (0),
myIsSmooth (copy.myIsSmooth), m_isSmooth (copy.m_isSmooth),
myIsRepeated (copy.myIsRepeated), m_isRepeated (copy.m_isRepeated),
myPixelsFlipped(false), m_pixelsFlipped(false),
myCacheId (GetUniqueId()) m_cacheId (GetUniqueId())
{ {
if (copy.myTexture) if (copy.m_texture)
LoadFromImage(copy.CopyToImage()); LoadFromImage(copy.CopyToImage());
} }
@ -91,11 +91,11 @@ myCacheId (GetUniqueId())
Texture::~Texture() Texture::~Texture()
{ {
// Destroy the OpenGL texture // Destroy the OpenGL texture
if (myTexture) if (m_texture)
{ {
EnsureGlContext(); EnsureGlContext();
GLuint Texture = static_cast<GLuint>(myTexture); GLuint Texture = static_cast<GLuint>(m_texture);
GLCheck(glDeleteTextures(1, &Texture)); GLCheck(glDeleteTextures(1, &Texture));
} }
} }
@ -127,33 +127,33 @@ bool Texture::Create(unsigned int width, unsigned int height)
} }
// All the validity checks passed, we can store the new texture settings // All the validity checks passed, we can store the new texture settings
myWidth = width; m_width = width;
myHeight = height; m_height = height;
myTextureWidth = textureWidth; m_textureWidth = textureWidth;
myTextureHeight = textureHeight; m_textureHeight = textureHeight;
myPixelsFlipped = false; m_pixelsFlipped = false;
EnsureGlContext(); EnsureGlContext();
// Create the OpenGL texture if it doesn't exist yet // Create the OpenGL texture if it doesn't exist yet
if (!myTexture) if (!m_texture)
{ {
GLuint texture; GLuint texture;
GLCheck(glGenTextures(1, &texture)); GLCheck(glGenTextures(1, &texture));
myTexture = static_cast<unsigned int>(texture); m_texture = static_cast<unsigned int>(texture);
} }
// Make sure that the current texture binding will be preserved // Make sure that the current texture binding will be preserved
priv::TextureSaver save; priv::TextureSaver save;
// Initialize the texture // Initialize the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); 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, myIsRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); 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, myIsRepeated ? 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, myIsSmooth ? GL_LINEAR : GL_NEAREST)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
myCacheId = GetUniqueId(); m_cacheId = GetUniqueId();
return true; return true;
} }
@ -224,10 +224,10 @@ bool Texture::LoadFromImage(const Image& image, const IntRect& area)
// Copy the pixels to the texture, row by row // Copy the pixels to the texture, row by row
const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top)); const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top));
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
for (int i = 0; i < rectangle.Height; ++i) for (int i = 0; i < rectangle.Height; ++i)
{ {
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, myWidth, 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; pixels += 4 * width;
} }
@ -244,14 +244,14 @@ bool Texture::LoadFromImage(const Image& image, const IntRect& area)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Texture::GetWidth() const unsigned int Texture::GetWidth() const
{ {
return myWidth; return m_width;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Texture::GetHeight() const unsigned int Texture::GetHeight() const
{ {
return myHeight; return m_height;
} }
@ -259,7 +259,7 @@ unsigned int Texture::GetHeight() const
Image Texture::CopyToImage() const Image Texture::CopyToImage() const
{ {
// Easy case: empty texture // Easy case: empty texture
if (!myTexture) if (!m_texture)
return Image(); return Image();
EnsureGlContext(); EnsureGlContext();
@ -268,12 +268,12 @@ Image Texture::CopyToImage() const
priv::TextureSaver save; priv::TextureSaver save;
// Create an array of pixels // Create an array of pixels
std::vector<Uint8> pixels(myWidth * myHeight * 4); std::vector<Uint8> pixels(m_width * m_height * 4);
if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight) && !myPixelsFlipped) if ((m_width == m_textureWidth) && (m_height == m_textureHeight) && !m_pixelsFlipped)
{ {
// Texture is not padded nor flipped, we can use a direct copy // Texture is not padded nor flipped, we can use a direct copy
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
} }
else else
@ -281,24 +281,24 @@ Image Texture::CopyToImage() const
// Texture is either padded or flipped, we have to use a slower algorithm // Texture is either padded or flipped, we have to use a slower algorithm
// All the pixels will first be copied to a temporary array // All the pixels will first be copied to a temporary array
std::vector<Uint8> allPixels(myTextureWidth * myTextureHeight * 4); std::vector<Uint8> allPixels(m_textureWidth * m_textureHeight * 4);
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0])); 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 // Then we copy the useful pixels from the temporary array to the final one
const Uint8* src = &allPixels[0]; const Uint8* src = &allPixels[0];
Uint8* dst = &pixels[0]; Uint8* dst = &pixels[0];
int srcPitch = myTextureWidth * 4; int srcPitch = m_textureWidth * 4;
int dstPitch = myWidth * 4; int dstPitch = m_width * 4;
// Handle the case where source pixels are flipped vertically // Handle the case where source pixels are flipped vertically
if (myPixelsFlipped) if (m_pixelsFlipped)
{ {
src += srcPitch * (myHeight - 1); src += srcPitch * (m_height - 1);
srcPitch = -srcPitch; srcPitch = -srcPitch;
} }
for (unsigned int i = 0; i < myHeight; ++i) for (unsigned int i = 0; i < m_height; ++i)
{ {
std::memcpy(dst, src, dstPitch); std::memcpy(dst, src, dstPitch);
src += srcPitch; src += srcPitch;
@ -308,7 +308,7 @@ Image Texture::CopyToImage() const
// Create the image // Create the image
Image image; Image image;
image.Create(myWidth, myHeight, &pixels[0]); image.Create(m_width, m_height, &pixels[0]);
return image; return image;
} }
@ -318,17 +318,17 @@ Image Texture::CopyToImage() const
void Texture::Update(const Uint8* pixels) void Texture::Update(const Uint8* pixels)
{ {
// Update the whole texture // Update the whole texture
Update(pixels, myWidth, myHeight, 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 <= myWidth); assert(x + width <= m_width);
assert(y + height <= myHeight); assert(y + height <= m_height);
if (pixels && myTexture) if (pixels && m_texture)
{ {
EnsureGlContext(); EnsureGlContext();
@ -336,10 +336,10 @@ void Texture::Update(const Uint8* pixels, unsigned int width, unsigned int heigh
priv::TextureSaver save; priv::TextureSaver save;
// Copy pixels from the given array to the texture // Copy pixels from the given array to the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
myPixelsFlipped = false; m_pixelsFlipped = false;
myCacheId = GetUniqueId(); m_cacheId = GetUniqueId();
} }
} }
@ -369,19 +369,19 @@ void Texture::Update(const Window& window)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
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 <= myWidth); assert(x + window.GetSize().x <= m_width);
assert(y + window.GetSize().y <= myHeight); assert(y + window.GetSize().y <= m_height);
if (myTexture && window.SetActive(true)) if (m_texture && window.SetActive(true))
{ {
// Make sure that the current texture binding will be preserved // Make sure that the current texture binding will be preserved
priv::TextureSaver save; priv::TextureSaver save;
// Copy pixels from the back-buffer to the texture // Copy pixels from the back-buffer to the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetSize().x, window.GetSize().y)); GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetSize().x, window.GetSize().y));
myPixelsFlipped = true; m_pixelsFlipped = true;
myCacheId = GetUniqueId(); m_cacheId = GetUniqueId();
} }
} }
@ -390,10 +390,10 @@ void Texture::Update(const Window& window, unsigned int x, unsigned int y)
void Texture::Bind(CoordinateType coordinateType) const void Texture::Bind(CoordinateType coordinateType) const
{ {
// Bind the texture // Bind the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
// Check if we need to define a special texture matrix // Check if we need to define a special texture matrix
if ((coordinateType == Pixels) || myPixelsFlipped) if ((coordinateType == Pixels) || m_pixelsFlipped)
{ {
GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f, GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f,
@ -404,15 +404,15 @@ void Texture::Bind(CoordinateType coordinateType) const
// setup scale factors that convert the range [0 .. size] to [0 .. 1] // setup scale factors that convert the range [0 .. size] to [0 .. 1]
if (coordinateType == Pixels) if (coordinateType == Pixels)
{ {
matrix[0] = 1.f / myTextureWidth; matrix[0] = 1.f / m_textureWidth;
matrix[5] = 1.f / myTextureHeight; matrix[5] = 1.f / m_textureHeight;
} }
// If pixels are flipped we must invert the Y axis // If pixels are flipped we must invert the Y axis
if (myPixelsFlipped) if (m_pixelsFlipped)
{ {
matrix[5] = -matrix[5]; matrix[5] = -matrix[5];
matrix[13] = static_cast<float>(myHeight / myTextureHeight); matrix[13] = static_cast<float>(m_height / m_textureHeight);
} }
// Load the matrix // Load the matrix
@ -428,20 +428,20 @@ void Texture::Bind(CoordinateType coordinateType) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Texture::SetSmooth(bool smooth) void Texture::SetSmooth(bool smooth)
{ {
if (smooth != myIsSmooth) if (smooth != m_isSmooth)
{ {
myIsSmooth = smooth; m_isSmooth = smooth;
if (myTexture) if (m_texture)
{ {
EnsureGlContext(); EnsureGlContext();
// Make sure that the current texture binding will be preserved // Make sure that the current texture binding will be preserved
priv::TextureSaver save; priv::TextureSaver save;
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
} }
} }
} }
@ -450,27 +450,27 @@ void Texture::SetSmooth(bool smooth)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Texture::IsSmooth() const bool Texture::IsSmooth() const
{ {
return myIsSmooth; return m_isSmooth;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Texture::SetRepeated(bool repeated) void Texture::SetRepeated(bool repeated)
{ {
if (repeated != myIsRepeated) if (repeated != m_isRepeated)
{ {
myIsRepeated = repeated; m_isRepeated = repeated;
if (myTexture) if (m_texture)
{ {
EnsureGlContext(); EnsureGlContext();
// Make sure that the current texture binding will be preserved // Make sure that the current texture binding will be preserved
priv::TextureSaver save; priv::TextureSaver save;
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, myIsRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); 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, myIsRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
} }
} }
} }
@ -479,7 +479,7 @@ void Texture::SetRepeated(bool repeated)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Texture::IsRepeated() const bool Texture::IsRepeated() const
{ {
return myIsRepeated; return m_isRepeated;
} }
@ -500,15 +500,15 @@ Texture& Texture::operator =(const Texture& right)
{ {
Texture temp(right); Texture temp(right);
std::swap(myWidth, temp.myWidth); std::swap(m_width, temp.m_width);
std::swap(myHeight, temp.myHeight); std::swap(m_height, temp.m_height);
std::swap(myTextureWidth, temp.myTextureWidth); std::swap(m_textureWidth, temp.m_textureWidth);
std::swap(myTextureHeight, temp.myTextureHeight); std::swap(m_textureHeight, temp.m_textureHeight);
std::swap(myTexture, temp.myTexture); std::swap(m_texture, temp.m_texture);
std::swap(myIsSmooth, temp.myIsSmooth); std::swap(m_isSmooth, temp.m_isSmooth);
std::swap(myIsRepeated, temp.myIsRepeated); std::swap(m_isRepeated, temp.m_isRepeated);
std::swap(myPixelsFlipped, temp.myPixelsFlipped); std::swap(m_pixelsFlipped, temp.m_pixelsFlipped);
myCacheId = GetUniqueId(); m_cacheId = GetUniqueId();
return *this; return *this;
} }

View File

@ -35,14 +35,14 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TextureSaver::TextureSaver() TextureSaver::TextureSaver()
{ {
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &myTextureBinding)); GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &m_textureBinding));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TextureSaver::~TextureSaver() TextureSaver::~TextureSaver()
{ {
GLCheck(glBindTexture(GL_TEXTURE_2D, myTextureBinding)); GLCheck(glBindTexture(GL_TEXTURE_2D, m_textureBinding));
} }
} // namespace priv } // namespace priv

View File

@ -64,7 +64,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
GLint myTextureBinding; ///< Texture binding to restore GLint m_textureBinding; ///< Texture binding to restore
}; };
} // namespace priv } // namespace priv

View File

@ -39,10 +39,10 @@ const Transform Transform::Identity;
Transform::Transform() Transform::Transform()
{ {
// Identity matrix // Identity matrix
myMatrix[0] = 1.f; myMatrix[4] = 0.f; myMatrix[8] = 0.f; myMatrix[12] = 0.f; m_matrix[0] = 1.f; m_matrix[4] = 0.f; m_matrix[8] = 0.f; m_matrix[12] = 0.f;
myMatrix[1] = 0.f; myMatrix[5] = 1.f; myMatrix[9] = 0.f; myMatrix[13] = 0.f; m_matrix[1] = 0.f; m_matrix[5] = 1.f; m_matrix[9] = 0.f; m_matrix[13] = 0.f;
myMatrix[2] = 0.f; myMatrix[6] = 0.f; myMatrix[10] = 1.f; myMatrix[14] = 0.f; m_matrix[2] = 0.f; m_matrix[6] = 0.f; m_matrix[10] = 1.f; m_matrix[14] = 0.f;
myMatrix[3] = 0.f; myMatrix[7] = 0.f; myMatrix[11] = 0.f; myMatrix[15] = 1.f; m_matrix[3] = 0.f; m_matrix[7] = 0.f; m_matrix[11] = 0.f; m_matrix[15] = 1.f;
} }
@ -51,17 +51,17 @@ Transform::Transform(float a00, float a01, float a02,
float a10, float a11, float a12, float a10, float a11, float a12,
float a20, float a21, float a22) float a20, float a21, float a22)
{ {
myMatrix[0] = a00; myMatrix[4] = a01; myMatrix[8] = 0.f; myMatrix[12] = a02; m_matrix[0] = a00; m_matrix[4] = a01; m_matrix[8] = 0.f; m_matrix[12] = a02;
myMatrix[1] = a10; myMatrix[5] = a11; myMatrix[9] = 0.f; myMatrix[13] = a12; m_matrix[1] = a10; m_matrix[5] = a11; m_matrix[9] = 0.f; m_matrix[13] = a12;
myMatrix[2] = 0.f; myMatrix[6] = 0.f; myMatrix[10] = 1.f; myMatrix[14] = 0.f; m_matrix[2] = 0.f; m_matrix[6] = 0.f; m_matrix[10] = 1.f; m_matrix[14] = 0.f;
myMatrix[3] = a20; myMatrix[7] = a21; myMatrix[11] = 0.f; myMatrix[15] = a22; m_matrix[3] = a20; m_matrix[7] = a21; m_matrix[11] = 0.f; m_matrix[15] = a22;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const float* Transform::GetMatrix() const const float* Transform::GetMatrix() const
{ {
return myMatrix; return m_matrix;
} }
@ -69,23 +69,23 @@ const float* Transform::GetMatrix() const
Transform Transform::GetInverse() const Transform Transform::GetInverse() const
{ {
// Compute the determinant // Compute the determinant
float det = myMatrix[0] * (myMatrix[15] * myMatrix[5] - myMatrix[7] * myMatrix[13]) - float det = m_matrix[0] * (m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) -
myMatrix[1] * (myMatrix[15] * myMatrix[4] - myMatrix[7] * myMatrix[12]) + m_matrix[1] * (m_matrix[15] * m_matrix[4] - m_matrix[7] * m_matrix[12]) +
myMatrix[3] * (myMatrix[13] * myMatrix[4] - myMatrix[5] * myMatrix[12]); m_matrix[3] * (m_matrix[13] * m_matrix[4] - m_matrix[5] * m_matrix[12]);
// Compute the inverse if the determinant is not zero // Compute the inverse if the determinant is not zero
// (don't use an epsilon because the determinant may *really* be tiny) // (don't use an epsilon because the determinant may *really* be tiny)
if (det != 0.f) if (det != 0.f)
{ {
return Transform( (myMatrix[15] * myMatrix[5] - myMatrix[7] * myMatrix[13]) / det, return Transform( (m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) / det,
-(myMatrix[15] * myMatrix[4] - myMatrix[7] * myMatrix[12]) / det, -(m_matrix[15] * m_matrix[4] - m_matrix[7] * m_matrix[12]) / det,
(myMatrix[13] * myMatrix[4] - myMatrix[5] * myMatrix[12]) / det, (m_matrix[13] * m_matrix[4] - m_matrix[5] * m_matrix[12]) / det,
-(myMatrix[15] * myMatrix[1] - myMatrix[3] * myMatrix[13]) / det, -(m_matrix[15] * m_matrix[1] - m_matrix[3] * m_matrix[13]) / det,
(myMatrix[15] * myMatrix[0] - myMatrix[3] * myMatrix[12]) / det, (m_matrix[15] * m_matrix[0] - m_matrix[3] * m_matrix[12]) / det,
-(myMatrix[13] * myMatrix[0] - myMatrix[1] * myMatrix[12]) / det, -(m_matrix[13] * m_matrix[0] - m_matrix[1] * m_matrix[12]) / det,
(myMatrix[7] * myMatrix[1] - myMatrix[3] * myMatrix[5]) / det, (m_matrix[7] * m_matrix[1] - m_matrix[3] * m_matrix[5]) / det,
-(myMatrix[7] * myMatrix[0] - myMatrix[3] * myMatrix[4]) / det, -(m_matrix[7] * m_matrix[0] - m_matrix[3] * m_matrix[4]) / det,
(myMatrix[5] * myMatrix[0] - myMatrix[1] * myMatrix[4]) / det); (m_matrix[5] * m_matrix[0] - m_matrix[1] * m_matrix[4]) / det);
} }
else else
{ {
@ -97,8 +97,8 @@ Transform Transform::GetInverse() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f Transform::TransformPoint(float x, float y) const Vector2f Transform::TransformPoint(float x, float y) const
{ {
return Vector2f(myMatrix[0] * x + myMatrix[4] * y + myMatrix[12], return Vector2f(m_matrix[0] * x + m_matrix[4] * y + m_matrix[12],
myMatrix[1] * x + myMatrix[5] * y + myMatrix[13]); m_matrix[1] * x + m_matrix[5] * y + m_matrix[13]);
} }
@ -141,8 +141,8 @@ FloatRect Transform::TransformRect(const FloatRect& rectangle) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Transform& Transform::Combine(const Transform& transform) Transform& Transform::Combine(const Transform& transform)
{ {
const float* a = myMatrix; const float* a = m_matrix;
const float* b = transform.myMatrix; const float* b = transform.m_matrix;
*this = Transform(a[0] * b[0] + a[4] * b[1] + a[12] * b[3], *this = Transform(a[0] * b[0] + a[4] * b[1] + a[12] * b[3],
a[0] * b[4] + a[4] * b[5] + a[12] * b[7], a[0] * b[4] + a[4] * b[5] + a[12] * b[7],

View File

@ -33,14 +33,14 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Transformable::Transformable() : Transformable::Transformable() :
myOrigin (0, 0), m_origin (0, 0),
myPosition (0, 0), m_position (0, 0),
myRotation (0), m_rotation (0),
myScale (1, 1), m_scale (1, 1),
myTransform (), m_transform (),
myTransformNeedUpdate (true), m_transformNeedUpdate (true),
myInverseTransform (), m_inverseTransform (),
myInverseTransformNeedUpdate(true) m_inverseTransformNeedUpdate(true)
{ {
} }
@ -54,10 +54,10 @@ Transformable::~Transformable()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::SetPosition(float x, float y) void Transformable::SetPosition(float x, float y)
{ {
myPosition.x = x; m_position.x = x;
myPosition.y = y; m_position.y = y;
myTransformNeedUpdate = true; m_transformNeedUpdate = true;
myInverseTransformNeedUpdate = true; m_inverseTransformNeedUpdate = true;
} }
@ -71,19 +71,19 @@ void Transformable::SetPosition(const Vector2f& position)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::SetRotation(float angle) void Transformable::SetRotation(float angle)
{ {
myRotation = angle; m_rotation = angle;
myTransformNeedUpdate = true; m_transformNeedUpdate = true;
myInverseTransformNeedUpdate = true; m_inverseTransformNeedUpdate = true;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::SetScale(float factorX, float factorY) void Transformable::SetScale(float factorX, float factorY)
{ {
myScale.x = factorX; m_scale.x = factorX;
myScale.y = factorY; m_scale.y = factorY;
myTransformNeedUpdate = true; m_transformNeedUpdate = true;
myInverseTransformNeedUpdate = true; m_inverseTransformNeedUpdate = true;
} }
@ -97,10 +97,10 @@ void Transformable::SetScale(const Vector2f& factors)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::SetOrigin(float x, float y) void Transformable::SetOrigin(float x, float y)
{ {
myOrigin.x = x; m_origin.x = x;
myOrigin.y = y; m_origin.y = y;
myTransformNeedUpdate = true; m_transformNeedUpdate = true;
myInverseTransformNeedUpdate = true; m_inverseTransformNeedUpdate = true;
} }
@ -114,63 +114,63 @@ void Transformable::SetOrigin(const Vector2f& origin)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& Transformable::GetPosition() const const Vector2f& Transformable::GetPosition() const
{ {
return myPosition; return m_position;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Transformable::GetRotation() const float Transformable::GetRotation() const
{ {
return myRotation; return m_rotation;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& Transformable::GetScale() const const Vector2f& Transformable::GetScale() const
{ {
return myScale; return m_scale;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& Transformable::GetOrigin() const const Vector2f& Transformable::GetOrigin() const
{ {
return myOrigin; return m_origin;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::Move(float offsetX, float offsetY) void Transformable::Move(float offsetX, float offsetY)
{ {
SetPosition(myPosition.x + offsetX, myPosition.y + offsetY); SetPosition(m_position.x + offsetX, m_position.y + offsetY);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::Move(const Vector2f& offset) void Transformable::Move(const Vector2f& offset)
{ {
SetPosition(myPosition.x + offset.x, myPosition.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(myRotation + angle); SetRotation(m_rotation + angle);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::Scale(float factorX, float factorY) void Transformable::Scale(float factorX, float factorY)
{ {
SetScale(myScale.x * factorX, myScale.y * factorY); SetScale(m_scale.x * factorX, m_scale.y * factorY);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Transformable::Scale(const Vector2f& factor) void Transformable::Scale(const Vector2f& factor)
{ {
SetScale(myScale.x * factor.x, myScale.y * factor.y); SetScale(m_scale.x * factor.x, m_scale.y * factor.y);
} }
@ -178,25 +178,25 @@ void Transformable::Scale(const Vector2f& factor)
const Transform& Transformable::GetTransform() const const Transform& Transformable::GetTransform() const
{ {
// Recompute the combined transform if needed // Recompute the combined transform if needed
if (myTransformNeedUpdate) if (m_transformNeedUpdate)
{ {
float angle = -myRotation * 3.141592654f / 180.f; float angle = -m_rotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle)); float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle)); float sine = static_cast<float>(std::sin(angle));
float sxc = myScale.x * cosine; float sxc = m_scale.x * cosine;
float syc = myScale.y * cosine; float syc = m_scale.y * cosine;
float sxs = myScale.x * sine; float sxs = m_scale.x * sine;
float sys = myScale.y * sine; float sys = m_scale.y * sine;
float tx = -myOrigin.x * sxc - myOrigin.y * sys + myPosition.x; float tx = -m_origin.x * sxc - m_origin.y * sys + m_position.x;
float ty = myOrigin.x * sxs - myOrigin.y * syc + myPosition.y; float ty = m_origin.x * sxs - m_origin.y * syc + m_position.y;
myTransform = Transform( sxc, sys, tx, m_transform = Transform( sxc, sys, tx,
-sxs, syc, ty, -sxs, syc, ty,
0.f, 0.f, 1.f); 0.f, 0.f, 1.f);
myTransformNeedUpdate = false; m_transformNeedUpdate = false;
} }
return myTransform; return m_transform;
} }
@ -204,13 +204,13 @@ const Transform& Transformable::GetTransform() const
const Transform& Transformable::GetInverseTransform() const const Transform& Transformable::GetInverseTransform() const
{ {
// Recompute the inverse transform if needed // Recompute the inverse transform if needed
if (myInverseTransformNeedUpdate) if (m_inverseTransformNeedUpdate)
{ {
myInverseTransform = GetTransform().GetInverse(); m_inverseTransform = GetTransform().GetInverse();
myInverseTransformNeedUpdate = false; m_inverseTransformNeedUpdate = false;
} }
return myInverseTransform; return m_inverseTransform;
} }
} // namespace sf } // namespace sf

View File

@ -33,16 +33,16 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
VertexArray::VertexArray() : VertexArray::VertexArray() :
myVertices (), m_vertices (),
myPrimitiveType(Points) m_primitiveType(Points)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
VertexArray::VertexArray(PrimitiveType type, unsigned int vertexCount) : VertexArray::VertexArray(PrimitiveType type, unsigned int vertexCount) :
myVertices (vertexCount), m_vertices (vertexCount),
myPrimitiveType(type) m_primitiveType(type)
{ {
} }
@ -50,72 +50,72 @@ myPrimitiveType(type)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int VertexArray::GetVertexCount() const unsigned int VertexArray::GetVertexCount() const
{ {
return static_cast<unsigned int>(myVertices.size()); return static_cast<unsigned int>(m_vertices.size());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex& VertexArray::operator [](unsigned int index) Vertex& VertexArray::operator [](unsigned int index)
{ {
return myVertices[index]; return m_vertices[index];
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vertex& VertexArray::operator [](unsigned int index) const const Vertex& VertexArray::operator [](unsigned int index) const
{ {
return myVertices[index]; return m_vertices[index];
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void VertexArray::Clear() void VertexArray::Clear()
{ {
myVertices.clear(); m_vertices.clear();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void VertexArray::Resize(unsigned int vertexCount) void VertexArray::Resize(unsigned int vertexCount)
{ {
myVertices.resize(vertexCount); m_vertices.resize(vertexCount);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void VertexArray::Append(const Vertex& vertex) void VertexArray::Append(const Vertex& vertex)
{ {
myVertices.push_back(vertex); m_vertices.push_back(vertex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void VertexArray::SetPrimitiveType(PrimitiveType type) void VertexArray::SetPrimitiveType(PrimitiveType type)
{ {
myPrimitiveType = type; m_primitiveType = type;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
PrimitiveType VertexArray::GetPrimitiveType() const PrimitiveType VertexArray::GetPrimitiveType() const
{ {
return myPrimitiveType; return m_primitiveType;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FloatRect VertexArray::GetBounds() const FloatRect VertexArray::GetBounds() const
{ {
if (!myVertices.empty()) if (!m_vertices.empty())
{ {
float left = myVertices[0].Position.x; float left = m_vertices[0].Position.x;
float top = myVertices[0].Position.y; float top = m_vertices[0].Position.y;
float right = myVertices[0].Position.x; float right = m_vertices[0].Position.x;
float bottom = myVertices[0].Position.y; float bottom = m_vertices[0].Position.y;
for (std::size_t i = 0; i < myVertices.size(); ++i) for (std::size_t i = 0; i < m_vertices.size(); ++i)
{ {
Vector2f position = myVertices[i].Position; Vector2f position = m_vertices[i].Position;
// Update left and right // Update left and right
if (position.x < left) if (position.x < left)
@ -143,8 +143,8 @@ FloatRect VertexArray::GetBounds() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void VertexArray::Draw(RenderTarget& target, RenderStates states) const void VertexArray::Draw(RenderTarget& target, RenderStates states) const
{ {
if (!myVertices.empty()) if (!m_vertices.empty())
target.Draw(&myVertices[0], static_cast<unsigned int>(myVertices.size()), myPrimitiveType, states); target.Draw(&m_vertices[0], static_cast<unsigned int>(m_vertices.size()), m_primitiveType, states);
} }
} // namespace sf } // namespace sf

View File

@ -33,12 +33,12 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
View::View() : View::View() :
myCenter (), m_center (),
mySize (), m_size (),
myRotation (0), m_rotation (0),
myViewport (0, 0, 1, 1), m_viewport (0, 0, 1, 1),
myTransformUpdated (false), m_transformUpdated (false),
myInvTransformUpdated(false) m_invTransformUpdated(false)
{ {
Reset(FloatRect(0, 0, 1000, 1000)); Reset(FloatRect(0, 0, 1000, 1000));
} }
@ -46,12 +46,12 @@ myInvTransformUpdated(false)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
View::View(const FloatRect& rectangle) : View::View(const FloatRect& rectangle) :
myCenter (), m_center (),
mySize (), m_size (),
myRotation (0), m_rotation (0),
myViewport (0, 0, 1, 1), m_viewport (0, 0, 1, 1),
myTransformUpdated (false), m_transformUpdated (false),
myInvTransformUpdated(false) m_invTransformUpdated(false)
{ {
Reset(rectangle); Reset(rectangle);
} }
@ -59,12 +59,12 @@ myInvTransformUpdated(false)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
View::View(const Vector2f& center, const Vector2f& size) : View::View(const Vector2f& center, const Vector2f& size) :
myCenter (center), m_center (center),
mySize (size), m_size (size),
myRotation (0), m_rotation (0),
myViewport (0, 0, 1, 1), m_viewport (0, 0, 1, 1),
myTransformUpdated (false), m_transformUpdated (false),
myInvTransformUpdated(false) m_invTransformUpdated(false)
{ {
} }
@ -72,11 +72,11 @@ myInvTransformUpdated(false)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::SetCenter(float x, float y) void View::SetCenter(float x, float y)
{ {
myCenter.x = x; m_center.x = x;
myCenter.y = y; m_center.y = y;
myTransformUpdated = false; m_transformUpdated = false;
myInvTransformUpdated = false; m_invTransformUpdated = false;
} }
@ -90,11 +90,11 @@ void View::SetCenter(const Vector2f& center)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::SetSize(float width, float height) void View::SetSize(float width, float height)
{ {
mySize.x = width; m_size.x = width;
mySize.y = height; m_size.y = height;
myTransformUpdated = false; m_transformUpdated = false;
myInvTransformUpdated = false; m_invTransformUpdated = false;
} }
@ -108,89 +108,89 @@ void View::SetSize(const Vector2f& size)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::SetRotation(float angle) void View::SetRotation(float angle)
{ {
myRotation = static_cast<float>(fmod(angle, 360)); m_rotation = static_cast<float>(fmod(angle, 360));
if (myRotation < 0) if (m_rotation < 0)
myRotation += 360.f; m_rotation += 360.f;
myTransformUpdated = false; m_transformUpdated = false;
myInvTransformUpdated = false; m_invTransformUpdated = false;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::SetViewport(const FloatRect& viewport) void View::SetViewport(const FloatRect& viewport)
{ {
myViewport = viewport; m_viewport = viewport;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::Reset(const FloatRect& rectangle) void View::Reset(const FloatRect& rectangle)
{ {
myCenter.x = rectangle.Left + rectangle.Width / 2.f; m_center.x = rectangle.Left + rectangle.Width / 2.f;
myCenter.y = rectangle.Top + rectangle.Height / 2.f; m_center.y = rectangle.Top + rectangle.Height / 2.f;
mySize.x = rectangle.Width; m_size.x = rectangle.Width;
mySize.y = rectangle.Height; m_size.y = rectangle.Height;
myRotation = 0; m_rotation = 0;
myTransformUpdated = false; m_transformUpdated = false;
myInvTransformUpdated = false; m_invTransformUpdated = false;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& View::GetCenter() const const Vector2f& View::GetCenter() const
{ {
return myCenter; return m_center;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vector2f& View::GetSize() const const Vector2f& View::GetSize() const
{ {
return mySize; return m_size;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float View::GetRotation() const float View::GetRotation() const
{ {
return myRotation; return m_rotation;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const FloatRect& View::GetViewport() const const FloatRect& View::GetViewport() const
{ {
return myViewport; return m_viewport;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::Move(float offsetX, float offsetY) void View::Move(float offsetX, float offsetY)
{ {
SetCenter(myCenter.x + offsetX, myCenter.y + offsetY); SetCenter(m_center.x + offsetX, m_center.y + offsetY);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::Move(const Vector2f& offset) void View::Move(const Vector2f& offset)
{ {
SetCenter(myCenter + offset); SetCenter(m_center + offset);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::Rotate(float angle) void View::Rotate(float angle)
{ {
SetRotation(myRotation + angle); SetRotation(m_rotation + angle);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void View::Zoom(float factor) void View::Zoom(float factor)
{ {
SetSize(mySize.x * factor, mySize.y * factor); SetSize(m_size.x * factor, m_size.y * factor);
} }
@ -198,29 +198,29 @@ void View::Zoom(float factor)
const Transform& View::GetTransform() const const Transform& View::GetTransform() const
{ {
// Recompute the matrix if needed // Recompute the matrix if needed
if (!myTransformUpdated) if (!m_transformUpdated)
{ {
// Rotation components // Rotation components
float angle = myRotation * 3.141592654f / 180.f; float angle = m_rotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle)); float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle)); float sine = static_cast<float>(std::sin(angle));
float tx = -myCenter.x * cosine - myCenter.y * sine + myCenter.x; float tx = -m_center.x * cosine - m_center.y * sine + m_center.x;
float ty = myCenter.x * sine - myCenter.y * cosine + myCenter.y; float ty = m_center.x * sine - m_center.y * cosine + m_center.y;
// Projection components // Projection components
float a = 2.f / mySize.x; float a = 2.f / m_size.x;
float b = -2.f / mySize.y; float b = -2.f / m_size.y;
float c = -a * myCenter.x; float c = -a * m_center.x;
float d = -b * myCenter.y; float d = -b * m_center.y;
// Rebuild the projection matrix // Rebuild the projection matrix
myTransform = Transform( a * cosine, a * sine, a * tx + c, m_transform = Transform( a * cosine, a * sine, a * tx + c,
-b * sine, b * cosine, b * ty + d, -b * sine, b * cosine, b * ty + d,
0.f, 0.f, 1.f); 0.f, 0.f, 1.f);
myTransformUpdated = true; m_transformUpdated = true;
} }
return myTransform; return m_transform;
} }
@ -228,13 +228,13 @@ const Transform& View::GetTransform() const
const Transform& View::GetInverseTransform() const const Transform& View::GetInverseTransform() const
{ {
// Recompute the matrix if needed // Recompute the matrix if needed
if (!myInvTransformUpdated) if (!m_invTransformUpdated)
{ {
myInverseTransform = GetTransform().GetInverse(); m_inverseTransform = GetTransform().GetInverse();
myInvTransformUpdated = true; m_invTransformUpdated = true;
} }
return myInverseTransform; return m_inverseTransform;
} }
} // namespace sf } // namespace sf

View File

@ -57,15 +57,15 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Ftp& myFtp; ///< Reference to the owner Ftp instance Ftp& m_ftp; ///< Reference to the owner Ftp instance
TcpSocket myDataSocket; ///< Socket used for data transfers TcpSocket m_dataSocket; ///< Socket used for data transfers
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Ftp::Response::Response(Status code, const std::string& message) : Ftp::Response::Response(Status code, const std::string& message) :
myStatus (code), m_status (code),
myMessage(message) m_message(message)
{ {
} }
@ -74,21 +74,21 @@ myMessage(message)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Ftp::Response::IsOk() const bool Ftp::Response::IsOk() const
{ {
return myStatus < 400; return m_status < 400;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Ftp::Response::Status Ftp::Response::GetStatus() const Ftp::Response::Status Ftp::Response::GetStatus() const
{ {
return myStatus; return m_status;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const std::string& Ftp::Response::GetMessage() const const std::string& Ftp::Response::GetMessage() const
{ {
return myMessage; return m_message;
} }
@ -101,7 +101,7 @@ Ftp::Response(response)
// Extract the directory from the server response // Extract the directory from the server response
std::string::size_type begin = GetMessage().find('"', 0); std::string::size_type begin = GetMessage().find('"', 0);
std::string::size_type end = GetMessage().find('"', begin + 1); std::string::size_type end = GetMessage().find('"', begin + 1);
myDirectory = GetMessage().substr(begin + 1, end - begin - 1); m_directory = GetMessage().substr(begin + 1, end - begin - 1);
} }
} }
@ -109,7 +109,7 @@ Ftp::Response(response)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const std::string& Ftp::DirectoryResponse::GetDirectory() const const std::string& Ftp::DirectoryResponse::GetDirectory() const
{ {
return myDirectory; return m_directory;
} }
@ -124,7 +124,7 @@ Ftp::Response(response)
std::string::size_type lastPos = 0; std::string::size_type lastPos = 0;
for (std::string::size_type pos = paths.find("\r\n"); pos != std::string::npos; pos = paths.find("\r\n", lastPos)) for (std::string::size_type pos = paths.find("\r\n"); pos != std::string::npos; pos = paths.find("\r\n", lastPos))
{ {
myFilenames.push_back(paths.substr(lastPos, pos - lastPos)); m_filenames.push_back(paths.substr(lastPos, pos - lastPos));
lastPos = pos + 2; lastPos = pos + 2;
} }
} }
@ -134,7 +134,7 @@ Ftp::Response(response)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const std::vector<std::string>& Ftp::ListingResponse::GetFilenames() const const std::vector<std::string>& Ftp::ListingResponse::GetFilenames() const
{ {
return myFilenames; return m_filenames;
} }
@ -149,7 +149,7 @@ Ftp::~Ftp()
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 // Connect to the server
if (myCommandSocket.Connect(server, port, timeout) != Socket::Done) if (m_commandSocket.Connect(server, port, timeout) != Socket::Done)
return Response(Response::ConnectionFailed); return Response(Response::ConnectionFailed);
// Get the response to the connection // Get the response to the connection
@ -181,7 +181,7 @@ Ftp::Response Ftp::Disconnect()
// Send the exit command // Send the exit command
Response response = SendCommand("QUIT"); Response response = SendCommand("QUIT");
if (response.IsOk()) if (response.IsOk())
myCommandSocket.Disconnect(); m_commandSocket.Disconnect();
return response; return response;
} }
@ -376,7 +376,7 @@ Ftp::Response Ftp::SendCommand(const std::string& command, const std::string& pa
commandStr = command + "\r\n"; commandStr = command + "\r\n";
// Send it to the server // Send it to the server
if (myCommandSocket.Send(commandStr.c_str(), commandStr.length()) != Socket::Done) if (m_commandSocket.Send(commandStr.c_str(), commandStr.length()) != Socket::Done)
return Response(Response::ConnectionClosed); return Response(Response::ConnectionClosed);
// Get the response // Get the response
@ -399,7 +399,7 @@ Ftp::Response Ftp::GetResponse()
// Receive the response from the server // Receive the response from the server
char buffer[1024]; char buffer[1024];
std::size_t length; std::size_t length;
if (myCommandSocket.Receive(buffer, sizeof(buffer), length) != Socket::Done) if (m_commandSocket.Receive(buffer, sizeof(buffer), length) != Socket::Done)
return Response(Response::ConnectionClosed); return Response(Response::ConnectionClosed);
// There can be several lines inside the received buffer, extract them all // There can be several lines inside the received buffer, extract them all
@ -518,7 +518,7 @@ Ftp::Response Ftp::GetResponse()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Ftp::DataChannel::DataChannel(Ftp& owner) : Ftp::DataChannel::DataChannel(Ftp& owner) :
myFtp(owner) m_ftp(owner)
{ {
} }
@ -528,7 +528,7 @@ myFtp(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) // Open a data connection in active mode (we connect to the server)
Ftp::Response response = myFtp.SendCommand("PASV"); Ftp::Response response = m_ftp.SendCommand("PASV");
if (response.IsOk()) if (response.IsOk())
{ {
// Extract the connection address and port from the response // Extract the connection address and port from the response
@ -559,7 +559,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
static_cast<Uint8>(data[3])); static_cast<Uint8>(data[3]));
// Connect the data channel to the server // Connect the data channel to the server
if (myDataSocket.Connect(address, port) == Socket::Done) if (m_dataSocket.Connect(address, port) == Socket::Done)
{ {
// Translate the transfer mode to the corresponding FTP parameter // Translate the transfer mode to the corresponding FTP parameter
std::string modeStr; std::string modeStr;
@ -571,7 +571,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
} }
// Set the transfer mode // Set the transfer mode
response = myFtp.SendCommand("TYPE", modeStr); response = m_ftp.SendCommand("TYPE", modeStr);
} }
else else
{ {
@ -592,13 +592,13 @@ void Ftp::DataChannel::Receive(std::vector<char>& data)
data.clear(); data.clear();
char buffer[1024]; char buffer[1024];
std::size_t received; std::size_t received;
while (myDataSocket.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)); std::copy(buffer, buffer + received, std::back_inserter(data));
} }
// Close the data socket // Close the data socket
myDataSocket.Disconnect(); m_dataSocket.Disconnect();
} }
@ -607,10 +607,10 @@ void Ftp::DataChannel::Send(const std::vector<char>& data)
{ {
// Send data // Send data
if (!data.empty()) if (!data.empty())
myDataSocket.Send(&data[0], data.size()); m_dataSocket.Send(&data[0], data.size());
// Close the data socket // Close the data socket
myDataSocket.Disconnect(); m_dataSocket.Disconnect();
} }
} // namespace sf } // namespace sf

View File

@ -59,40 +59,40 @@ Http::Request::Request(const std::string& uri, Method method, const std::string&
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Http::Request::SetField(const std::string& field, const std::string& value) void Http::Request::SetField(const std::string& field, const std::string& value)
{ {
myFields[ToLower(field)] = value; m_fields[ToLower(field)] = value;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Http::Request::SetMethod(Http::Request::Method method) void Http::Request::SetMethod(Http::Request::Method method)
{ {
myMethod = method; m_method = method;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Http::Request::SetUri(const std::string& uri) void Http::Request::SetUri(const std::string& uri)
{ {
myURI = uri; m_uRI = uri;
// Make sure it starts with a '/' // Make sure it starts with a '/'
if (myURI.empty() || (myURI[0] != '/')) if (m_uRI.empty() || (m_uRI[0] != '/'))
myURI.insert(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)
{ {
myMajorVersion = major; m_majorVersion = major;
myMinorVersion = minor; m_minorVersion = minor;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Http::Request::SetBody(const std::string& body) void Http::Request::SetBody(const std::string& body)
{ {
myBody = body; m_body = body;
} }
@ -103,7 +103,7 @@ std::string Http::Request::Prepare() const
// Convert the method to its string representation // Convert the method to its string representation
std::string method; std::string method;
switch (myMethod) switch (m_method)
{ {
default : default :
case Get : method = "GET"; break; case Get : method = "GET"; break;
@ -112,11 +112,11 @@ std::string Http::Request::Prepare() const
} }
// Write the first line containing the request type // Write the first line containing the request type
out << method << " " << myURI << " "; out << method << " " << m_uRI << " ";
out << "HTTP/" << myMajorVersion << "." << myMinorVersion << "\r\n"; out << "HTTP/" << m_majorVersion << "." << m_minorVersion << "\r\n";
// Write fields // Write fields
for (FieldTable::const_iterator i = myFields.begin(); i != myFields.end(); ++i) for (FieldTable::const_iterator i = m_fields.begin(); i != m_fields.end(); ++i)
{ {
out << i->first << ": " << i->second << "\r\n"; out << i->first << ": " << i->second << "\r\n";
} }
@ -125,7 +125,7 @@ std::string Http::Request::Prepare() const
out << "\r\n"; out << "\r\n";
// Add the body // Add the body
out << myBody; out << m_body;
return out.str(); return out.str();
} }
@ -134,15 +134,15 @@ 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 myFields.find(ToLower(field)) != myFields.end(); return m_fields.find(ToLower(field)) != m_fields.end();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Http::Response::Response() : Http::Response::Response() :
myStatus (ConnectionFailed), m_status (ConnectionFailed),
myMajorVersion(0), m_majorVersion(0),
myMinorVersion(0) m_minorVersion(0)
{ {
} }
@ -151,8 +151,8 @@ myMinorVersion(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 = myFields.find(ToLower(field)); FieldTable::const_iterator it = m_fields.find(ToLower(field));
if (it != myFields.end()) if (it != m_fields.end())
{ {
return it->second; return it->second;
} }
@ -167,28 +167,28 @@ 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 myStatus; return m_status;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Http::Response::GetMajorHttpVersion() const unsigned int Http::Response::GetMajorHttpVersion() const
{ {
return myMajorVersion; return m_majorVersion;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int Http::Response::GetMinorHttpVersion() const unsigned int Http::Response::GetMinorHttpVersion() const
{ {
return myMinorVersion; return m_minorVersion;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const std::string& Http::Response::GetBody() const const std::string& Http::Response::GetBody() const
{ {
return myBody; return m_body;
} }
@ -205,13 +205,13 @@ void Http::Response::Parse(const std::string& data)
(ToLower(version.substr(0, 5)) == "http/") && (ToLower(version.substr(0, 5)) == "http/") &&
isdigit(version[5]) && isdigit(version[7])) isdigit(version[5]) && isdigit(version[7]))
{ {
myMajorVersion = version[5] - '0'; m_majorVersion = version[5] - '0';
myMinorVersion = version[7] - '0'; m_minorVersion = version[7] - '0';
} }
else else
{ {
// Invalid HTTP version // Invalid HTTP version
myStatus = InvalidResponse; m_status = InvalidResponse;
return; return;
} }
} }
@ -220,12 +220,12 @@ void Http::Response::Parse(const std::string& data)
int status; int status;
if (in >> status) if (in >> status)
{ {
myStatus = static_cast<Status>(status); m_status = static_cast<Status>(status);
} }
else else
{ {
// Invalid status code // Invalid status code
myStatus = InvalidResponse; m_status = InvalidResponse;
return; return;
} }
@ -248,20 +248,20 @@ void Http::Response::Parse(const std::string& data)
value.erase(value.size() - 1); value.erase(value.size() - 1);
// Add the field // Add the field
myFields[ToLower(field)] = value; m_fields[ToLower(field)] = value;
} }
} }
// Finally extract the body // Finally extract the body
myBody.clear(); m_body.clear();
std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), std::back_inserter(myBody)); std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), std::back_inserter(m_body));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Http::Http() : Http::Http() :
myHost(), m_host(),
myPort(0) m_port(0)
{ {
} }
@ -282,27 +282,27 @@ void Http::SetHost(const std::string& host, unsigned short port)
if (protocol.substr(0, 7) == "http://") if (protocol.substr(0, 7) == "http://")
{ {
// HTTP protocol // HTTP protocol
myHostName = host.substr(7); m_hostName = host.substr(7);
myPort = (port != 0 ? port : 80); m_port = (port != 0 ? port : 80);
} }
else if (protocol == "https://") else if (protocol == "https://")
{ {
// HTTPS protocol // HTTPS protocol
myHostName = host.substr(8); m_hostName = host.substr(8);
myPort = (port != 0 ? port : 443); m_port = (port != 0 ? port : 443);
} }
else else
{ {
// Undefined protocol - use HTTP // Undefined protocol - use HTTP
myHostName = host; m_hostName = host;
myPort = (port != 0 ? port : 80); m_port = (port != 0 ? port : 80);
} }
// Remove any trailing '/' from the host name // Remove any trailing '/' from the host name
if (!myHostName.empty() && (*myHostName.rbegin() == '/')) if (!m_hostName.empty() && (*m_hostName.rbegin() == '/'))
myHostName.erase(myHostName.size() - 1); m_hostName.erase(m_hostName.size() - 1);
myHost = IpAddress(myHostName); m_host = IpAddress(m_hostName);
} }
@ -321,19 +321,19 @@ Http::Response Http::SendRequest(const Http::Request& request, Time timeout)
} }
if (!toSend.HasField("Host")) if (!toSend.HasField("Host"))
{ {
toSend.SetField("Host", myHostName); toSend.SetField("Host", m_hostName);
} }
if (!toSend.HasField("Content-Length")) if (!toSend.HasField("Content-Length"))
{ {
std::ostringstream out; std::ostringstream out;
out << toSend.myBody.size(); out << toSend.m_body.size();
toSend.SetField("Content-Length", out.str()); toSend.SetField("Content-Length", out.str());
} }
if ((toSend.myMethod == 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.myMajorVersion * 10 + toSend.myMinorVersion >= 11) && !toSend.HasField("Connection")) if ((toSend.m_majorVersion * 10 + toSend.m_minorVersion >= 11) && !toSend.HasField("Connection"))
{ {
toSend.SetField("Connection", "close"); toSend.SetField("Connection", "close");
} }
@ -342,7 +342,7 @@ Http::Response Http::SendRequest(const Http::Request& request, Time timeout)
Response received; Response received;
// Connect the socket to the host // Connect the socket to the host
if (myConnection.Connect(myHost, myPort, 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 // Convert the request to string and send it through the connected socket
std::string requestStr = toSend.Prepare(); std::string requestStr = toSend.Prepare();
@ -350,13 +350,13 @@ Http::Response Http::SendRequest(const Http::Request& request, Time timeout)
if (!requestStr.empty()) if (!requestStr.empty())
{ {
// Send it through the socket // Send it through the socket
if (myConnection.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 // Wait for the server's response
std::string receivedStr; std::string receivedStr;
std::size_t size = 0; std::size_t size = 0;
char buffer[1024]; char buffer[1024];
while (myConnection.Receive(buffer, sizeof(buffer), size) == Socket::Done) while (m_connection.Receive(buffer, sizeof(buffer), size) == Socket::Done)
{ {
receivedStr.append(buffer, buffer + size); receivedStr.append(buffer, buffer + size);
} }
@ -367,7 +367,7 @@ Http::Response Http::SendRequest(const Http::Request& request, Time timeout)
} }
// Close the connection // Close the connection
myConnection.Disconnect(); m_connection.Disconnect();
} }
return received; return received;

View File

@ -69,7 +69,7 @@ const IpAddress IpAddress::Broadcast(255, 255, 255, 255);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress::IpAddress() : IpAddress::IpAddress() :
myAddress(0) m_address(0)
{ {
// We're using 0 (INADDR_ANY) instead of INADDR_NONE to represent the invalid address, // We're using 0 (INADDR_ANY) instead of INADDR_NONE to represent the invalid address,
// because the latter is also the broadcast address (255.255.255.255); it's ok because // because the latter is also the broadcast address (255.255.255.255); it's ok because
@ -79,28 +79,28 @@ myAddress(0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress::IpAddress(const std::string& address) : IpAddress::IpAddress(const std::string& address) :
myAddress(Resolve(address)) m_address(Resolve(address))
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress::IpAddress(const char* address) : IpAddress::IpAddress(const char* address) :
myAddress(Resolve(address)) m_address(Resolve(address))
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) : IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) :
myAddress(htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3)) m_address(htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3))
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress::IpAddress(Uint32 address) : IpAddress::IpAddress(Uint32 address) :
myAddress(htonl(address)) m_address(htonl(address))
{ {
} }
@ -109,7 +109,7 @@ myAddress(htonl(address))
std::string IpAddress::ToString() const std::string IpAddress::ToString() const
{ {
in_addr address; in_addr address;
address.s_addr = myAddress; address.s_addr = m_address;
return inet_ntoa(address); return inet_ntoa(address);
} }
@ -118,7 +118,7 @@ std::string IpAddress::ToString() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32 IpAddress::ToInteger() const Uint32 IpAddress::ToInteger() const
{ {
return ntohl(myAddress); return ntohl(m_address);
} }

View File

@ -35,8 +35,8 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet::Packet() : Packet::Packet() :
myReadPos(0), m_readPos(0),
myIsValid(true) m_isValid(true)
{ {
} }
@ -54,9 +54,9 @@ void Packet::Append(const void* data, std::size_t sizeInBytes)
{ {
if (data && (sizeInBytes > 0)) if (data && (sizeInBytes > 0))
{ {
std::size_t start = myData.size(); std::size_t start = m_data.size();
myData.resize(start + sizeInBytes); m_data.resize(start + sizeInBytes);
std::memcpy(&myData[start], data, sizeInBytes); std::memcpy(&m_data[start], data, sizeInBytes);
} }
} }
@ -64,37 +64,37 @@ void Packet::Append(const void* data, std::size_t sizeInBytes)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Packet::Clear() void Packet::Clear()
{ {
myData.clear(); m_data.clear();
myReadPos = 0; m_readPos = 0;
myIsValid = true; m_isValid = true;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const char* Packet::GetData() const const char* Packet::GetData() const
{ {
return !myData.empty() ? &myData[0] : NULL; return !m_data.empty() ? &m_data[0] : NULL;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::size_t Packet::GetDataSize() const std::size_t Packet::GetDataSize() const
{ {
return myData.size(); return m_data.size();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Packet::EndOfPacket() const bool Packet::EndOfPacket() const
{ {
return myReadPos >= myData.size(); return m_readPos >= m_data.size();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet::operator BoolType() const Packet::operator BoolType() const
{ {
return myIsValid ? &Packet::CheckSize : NULL; return m_isValid ? &Packet::CheckSize : NULL;
} }
@ -114,8 +114,8 @@ Packet& Packet::operator >>(Int8& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = *reinterpret_cast<const Int8*>(GetData() + myReadPos); data = *reinterpret_cast<const Int8*>(GetData() + m_readPos);
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -127,8 +127,8 @@ Packet& Packet::operator >>(Uint8& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = *reinterpret_cast<const Uint8*>(GetData() + myReadPos); data = *reinterpret_cast<const Uint8*>(GetData() + m_readPos);
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -140,8 +140,8 @@ Packet& Packet::operator >>(Int16& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = ntohs(*reinterpret_cast<const Int16*>(GetData() + myReadPos)); data = ntohs(*reinterpret_cast<const Int16*>(GetData() + m_readPos));
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -153,8 +153,8 @@ Packet& Packet::operator >>(Uint16& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = ntohs(*reinterpret_cast<const Uint16*>(GetData() + myReadPos)); data = ntohs(*reinterpret_cast<const Uint16*>(GetData() + m_readPos));
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -166,8 +166,8 @@ Packet& Packet::operator >>(Int32& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = ntohl(*reinterpret_cast<const Int32*>(GetData() + myReadPos)); data = ntohl(*reinterpret_cast<const Int32*>(GetData() + m_readPos));
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -179,8 +179,8 @@ Packet& Packet::operator >>(Uint32& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = ntohl(*reinterpret_cast<const Uint32*>(GetData() + myReadPos)); data = ntohl(*reinterpret_cast<const Uint32*>(GetData() + m_readPos));
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -192,8 +192,8 @@ Packet& Packet::operator >>(float& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = *reinterpret_cast<const float*>(GetData() + myReadPos); data = *reinterpret_cast<const float*>(GetData() + m_readPos);
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -205,8 +205,8 @@ Packet& Packet::operator >>(double& data)
{ {
if (CheckSize(sizeof(data))) if (CheckSize(sizeof(data)))
{ {
data = *reinterpret_cast<const double*>(GetData() + myReadPos); data = *reinterpret_cast<const double*>(GetData() + m_readPos);
myReadPos += sizeof(data); m_readPos += sizeof(data);
} }
return *this; return *this;
@ -223,11 +223,11 @@ Packet& Packet::operator >>(char* data)
if ((length > 0) && CheckSize(length)) if ((length > 0) && CheckSize(length))
{ {
// Then extract characters // Then extract characters
std::memcpy(data, GetData() + myReadPos, length); std::memcpy(data, GetData() + m_readPos, length);
data[length] = '\0'; data[length] = '\0';
// Update reading position // Update reading position
myReadPos += length; m_readPos += length;
} }
return *this; return *this;
@ -245,10 +245,10 @@ Packet& Packet::operator >>(std::string& data)
if ((length > 0) && CheckSize(length)) if ((length > 0) && CheckSize(length))
{ {
// Then extract characters // Then extract characters
data.assign(GetData() + myReadPos, length); data.assign(GetData() + m_readPos, length);
// Update reading position // Update reading position
myReadPos += length; m_readPos += length;
} }
return *this; return *this;
@ -489,9 +489,9 @@ Packet& Packet::operator <<(const String& data)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Packet::CheckSize(std::size_t size) bool Packet::CheckSize(std::size_t size)
{ {
myIsValid = myIsValid && (myReadPos + size <= myData.size()); m_isValid = m_isValid && (m_readPos + size <= m_data.size());
return myIsValid; return m_isValid;
} }

View File

@ -34,9 +34,9 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Socket::Socket(Type type) : Socket::Socket(Type type) :
myType (type), m_type (type),
mySocket (priv::SocketImpl::InvalidSocket()), m_socket (priv::SocketImpl::InvalidSocket()),
myIsBlocking(true) m_isBlocking(true)
{ {
} }
@ -54,24 +54,24 @@ Socket::~Socket()
void Socket::SetBlocking(bool blocking) void Socket::SetBlocking(bool blocking)
{ {
// Apply if the socket is already created // Apply if the socket is already created
if (mySocket != priv::SocketImpl::InvalidSocket()) if (m_socket != priv::SocketImpl::InvalidSocket())
priv::SocketImpl::SetBlocking(mySocket, blocking); priv::SocketImpl::SetBlocking(m_socket, blocking);
myIsBlocking = blocking; m_isBlocking = blocking;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Socket::IsBlocking() const bool Socket::IsBlocking() const
{ {
return myIsBlocking; return m_isBlocking;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketHandle Socket::GetHandle() const SocketHandle Socket::GetHandle() const
{ {
return mySocket; return m_socket;
} }
@ -79,9 +79,9 @@ SocketHandle Socket::GetHandle() const
void Socket::Create() void Socket::Create()
{ {
// Don't create the socket if it already exists // Don't create the socket if it already exists
if (mySocket == priv::SocketImpl::InvalidSocket()) if (m_socket == priv::SocketImpl::InvalidSocket())
{ {
SocketHandle handle = socket(PF_INET, myType == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0); SocketHandle handle = socket(PF_INET, m_type == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
Create(handle); Create(handle);
} }
} }
@ -91,19 +91,19 @@ void Socket::Create()
void Socket::Create(SocketHandle handle) void Socket::Create(SocketHandle handle)
{ {
// Don't create the socket if it already exists // Don't create the socket if it already exists
if (mySocket == priv::SocketImpl::InvalidSocket()) if (m_socket == priv::SocketImpl::InvalidSocket())
{ {
// Assign the new handle // Assign the new handle
mySocket = handle; m_socket = handle;
// Set the current blocking state // Set the current blocking state
SetBlocking(myIsBlocking); SetBlocking(m_isBlocking);
if (myType == Tcp) if (m_type == Tcp)
{ {
// Disable the Nagle algorithm (ie. removes buffering of TCP packets) // Disable the Nagle algorithm (ie. removes buffering of TCP packets)
int yes = 1; int yes = 1;
if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&yes), sizeof(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; << "all your TCP packets will be buffered" << std::endl;
@ -113,7 +113,7 @@ void Socket::Create(SocketHandle handle)
{ {
// Enable broadcast by default for UDP sockets // Enable broadcast by default for UDP sockets
int yes = 1; int yes = 1;
if (setsockopt(mySocket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&yes), sizeof(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;
} }
@ -126,10 +126,10 @@ void Socket::Create(SocketHandle handle)
void Socket::Close() void Socket::Close()
{ {
// Close the socket // Close the socket
if (mySocket != priv::SocketImpl::InvalidSocket()) if (m_socket != priv::SocketImpl::InvalidSocket())
{ {
priv::SocketImpl::Close(mySocket); priv::SocketImpl::Close(m_socket);
mySocket = priv::SocketImpl::InvalidSocket(); m_socket = priv::SocketImpl::InvalidSocket();
} }
} }

View File

@ -49,7 +49,7 @@ struct SocketSelector::SocketSelectorImpl
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketSelector::SocketSelector() : SocketSelector::SocketSelector() :
myImpl(new SocketSelectorImpl) m_impl(new SocketSelectorImpl)
{ {
Clear(); Clear();
} }
@ -57,7 +57,7 @@ myImpl(new SocketSelectorImpl)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketSelector::SocketSelector(const SocketSelector& copy) : SocketSelector::SocketSelector(const SocketSelector& copy) :
myImpl(new SocketSelectorImpl(*copy.myImpl)) m_impl(new SocketSelectorImpl(*copy.m_impl))
{ {
} }
@ -66,36 +66,36 @@ myImpl(new SocketSelectorImpl(*copy.myImpl))
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketSelector::~SocketSelector() SocketSelector::~SocketSelector()
{ {
delete myImpl; delete m_impl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SocketSelector::Add(Socket& socket) void SocketSelector::Add(Socket& socket)
{ {
FD_SET(socket.GetHandle(), &myImpl->AllSockets); FD_SET(socket.GetHandle(), &m_impl->AllSockets);
int size = static_cast<int>(socket.GetHandle()); int size = static_cast<int>(socket.GetHandle());
if (size > myImpl->MaxSocket) if (size > m_impl->MaxSocket)
myImpl->MaxSocket = size; m_impl->MaxSocket = size;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SocketSelector::Remove(Socket& socket) void SocketSelector::Remove(Socket& socket)
{ {
FD_CLR(socket.GetHandle(), &myImpl->AllSockets); FD_CLR(socket.GetHandle(), &m_impl->AllSockets);
FD_CLR(socket.GetHandle(), &myImpl->SocketsReady); FD_CLR(socket.GetHandle(), &m_impl->SocketsReady);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SocketSelector::Clear() void SocketSelector::Clear()
{ {
FD_ZERO(&myImpl->AllSockets); FD_ZERO(&m_impl->AllSockets);
FD_ZERO(&myImpl->SocketsReady); FD_ZERO(&m_impl->SocketsReady);
myImpl->MaxSocket = 0; m_impl->MaxSocket = 0;
} }
@ -108,10 +108,10 @@ bool SocketSelector::Wait(Time timeout)
time.tv_usec = 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 // Initialize the set that will contain the sockets that are ready
myImpl->SocketsReady = myImpl->AllSockets; m_impl->SocketsReady = m_impl->AllSockets;
// Wait until one of the sockets is ready for reading, or timeout is reached // Wait until one of the sockets is ready for reading, or timeout is reached
int count = select(myImpl->MaxSocket + 1, &myImpl->SocketsReady, NULL, NULL, timeout != Time::Zero ? &time : NULL); int count = select(m_impl->MaxSocket + 1, &m_impl->SocketsReady, NULL, NULL, timeout != Time::Zero ? &time : NULL);
return count > 0; return count > 0;
} }
@ -120,7 +120,7 @@ bool SocketSelector::Wait(Time timeout)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SocketSelector::IsReady(Socket& socket) const bool SocketSelector::IsReady(Socket& socket) const
{ {
return FD_ISSET(socket.GetHandle(), &myImpl->SocketsReady) != 0; return FD_ISSET(socket.GetHandle(), &m_impl->SocketsReady) != 0;
} }
@ -129,7 +129,7 @@ SocketSelector& SocketSelector::operator =(const SocketSelector& right)
{ {
SocketSelector temp(right); SocketSelector temp(right);
std::swap(myImpl, temp.myImpl); std::swap(m_impl, temp.m_impl);
return *this; return *this;
} }

View File

@ -201,7 +201,7 @@ void TcpSocket::Disconnect()
Close(); Close();
// Reset the pending packet data // Reset the pending packet data
myPendingPacket = PendingPacket(); m_pendingPacket = PendingPacket();
} }
@ -305,35 +305,35 @@ Socket::Status TcpSocket::Receive(Packet& packet)
// We start by getting the size of the incoming packet // We start by getting the size of the incoming packet
Uint32 packetSize = 0; Uint32 packetSize = 0;
std::size_t received = 0; std::size_t received = 0;
if (myPendingPacket.SizeReceived < sizeof(myPendingPacket.Size)) if (m_pendingPacket.SizeReceived < sizeof(m_pendingPacket.Size))
{ {
// Loop until we've received the entire size of the packet // Loop until we've received the entire size of the packet
// (even a 4 byte variable may be received in more than one call) // (even a 4 byte variable may be received in more than one call)
while (myPendingPacket.SizeReceived < sizeof(myPendingPacket.Size)) while (m_pendingPacket.SizeReceived < sizeof(m_pendingPacket.Size))
{ {
char* data = reinterpret_cast<char*>(&myPendingPacket.Size) + myPendingPacket.SizeReceived; char* data = reinterpret_cast<char*>(&m_pendingPacket.Size) + m_pendingPacket.SizeReceived;
Status status = Receive(data, sizeof(myPendingPacket.Size) - myPendingPacket.SizeReceived, received); Status status = Receive(data, sizeof(m_pendingPacket.Size) - m_pendingPacket.SizeReceived, received);
myPendingPacket.SizeReceived += received; m_pendingPacket.SizeReceived += received;
if (status != Done) if (status != Done)
return status; return status;
} }
// The packet size has been fully received // The packet size has been fully received
packetSize = ntohl(myPendingPacket.Size); packetSize = ntohl(m_pendingPacket.Size);
} }
else else
{ {
// The packet size has already been received in a previous call // The packet size has already been received in a previous call
packetSize = ntohl(myPendingPacket.Size); packetSize = ntohl(m_pendingPacket.Size);
} }
// Loop until we receive all the packet data // Loop until we receive all the packet data
char buffer[1024]; char buffer[1024];
while (myPendingPacket.Data.size() < packetSize) while (m_pendingPacket.Data.size() < packetSize)
{ {
// Receive a chunk of data // Receive a chunk of data
std::size_t sizeToGet = std::min(static_cast<std::size_t>(packetSize - myPendingPacket.Data.size()), sizeof(buffer)); 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) if (status != Done)
return status; return status;
@ -341,18 +341,18 @@ Socket::Status TcpSocket::Receive(Packet& packet)
// Append it into the packet // Append it into the packet
if (received > 0) if (received > 0)
{ {
myPendingPacket.Data.resize(myPendingPacket.Data.size() + received); m_pendingPacket.Data.resize(m_pendingPacket.Data.size() + received);
char* begin = &myPendingPacket.Data[0] + myPendingPacket.Data.size() - received; char* begin = &m_pendingPacket.Data[0] + m_pendingPacket.Data.size() - received;
std::memcpy(begin, buffer, received); std::memcpy(begin, buffer, received);
} }
} }
// We have received all the packet data: we can copy it to the user packet // We have received all the packet data: we can copy it to the user packet
if (!myPendingPacket.Data.empty()) if (!m_pendingPacket.Data.empty())
packet.OnReceive(&myPendingPacket.Data[0], myPendingPacket.Data.size()); packet.OnReceive(&m_pendingPacket.Data[0], m_pendingPacket.Data.size());
// Clear the pending packet data // Clear the pending packet data
myPendingPacket = PendingPacket(); m_pendingPacket = PendingPacket();
return Done; return Done;
} }

View File

@ -38,7 +38,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
UdpSocket::UdpSocket() : UdpSocket::UdpSocket() :
Socket (Udp), Socket (Udp),
myBuffer(MaxDatagramSize) m_buffer(MaxDatagramSize)
{ {
} }
@ -179,12 +179,12 @@ Socket::Status UdpSocket::Receive(Packet& packet, IpAddress& remoteAddress, unsi
// Receive the datagram // Receive the datagram
std::size_t received = 0; std::size_t received = 0;
Status status = Receive(&myBuffer[0], myBuffer.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 // If we received valid data, we can copy it to the user packet
packet.Clear(); packet.Clear();
if ((status == Done) && (received > 0)) if ((status == Done) && (received > 0))
packet.OnReceive(&myBuffer[0], received); packet.OnReceive(&m_buffer[0], received);
return status; return status;
} }

View File

@ -38,7 +38,7 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Clock::Clock() : Clock::Clock() :
myStartTime(priv::ClockImpl::GetCurrentTime()) m_startTime(priv::ClockImpl::GetCurrentTime())
{ {
} }
@ -46,7 +46,7 @@ myStartTime(priv::ClockImpl::GetCurrentTime())
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time Clock::GetElapsedTime() const Time Clock::GetElapsedTime() const
{ {
return priv::ClockImpl::GetCurrentTime() - myStartTime; return priv::ClockImpl::GetCurrentTime() - m_startTime;
} }
@ -54,8 +54,8 @@ Time Clock::GetElapsedTime() const
Time Clock::Restart() Time Clock::Restart()
{ {
Time now = priv::ClockImpl::GetCurrentTime(); Time now = priv::ClockImpl::GetCurrentTime();
Time elapsed = now - myStartTime; Time elapsed = now - m_startTime;
myStartTime = now; m_startTime = now;
return elapsed; return elapsed;
} }

View File

@ -33,16 +33,16 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Lock::Lock(Mutex& mutex) : Lock::Lock(Mutex& mutex) :
myMutex(mutex) m_mutex(mutex)
{ {
myMutex.Lock(); m_mutex.Lock();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Lock::~Lock() Lock::~Lock()
{ {
myMutex.Unlock(); m_mutex.Unlock();
} }
} // namespace sf } // namespace sf

View File

@ -44,28 +44,28 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Mutex::Mutex() Mutex::Mutex()
{ {
myMutexImpl = new priv::MutexImpl; m_mutexImpl = new priv::MutexImpl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Mutex::~Mutex() Mutex::~Mutex()
{ {
delete myMutexImpl; delete m_mutexImpl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Mutex::Lock() void Mutex::Lock()
{ {
myMutexImpl->Lock(); m_mutexImpl->Lock();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Mutex::Unlock() void Mutex::Unlock()
{ {
myMutexImpl->Unlock(); m_mutexImpl->Unlock();
} }
} // namespace sf } // namespace sf

View File

@ -46,21 +46,21 @@ String::String()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(char ansiChar, const std::locale& locale) String::String(char ansiChar, const std::locale& locale)
{ {
myString += Utf32::DecodeAnsi(ansiChar, locale); m_string += Utf32::DecodeAnsi(ansiChar, locale);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(wchar_t wideChar) String::String(wchar_t wideChar)
{ {
myString += Utf32::DecodeWide(wideChar); m_string += Utf32::DecodeWide(wideChar);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(Uint32 utf32Char) String::String(Uint32 utf32Char)
{ {
myString += utf32Char; m_string += utf32Char;
} }
@ -72,8 +72,8 @@ String::String(const char* ansiString, const std::locale& locale)
std::size_t length = strlen(ansiString); std::size_t length = strlen(ansiString);
if (length > 0) if (length > 0)
{ {
myString.reserve(length + 1); m_string.reserve(length + 1);
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(myString), locale); Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(m_string), locale);
} }
} }
} }
@ -82,8 +82,8 @@ String::String(const char* ansiString, const std::locale& locale)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(const std::string& ansiString, const std::locale& locale) String::String(const std::string& ansiString, const std::locale& locale)
{ {
myString.reserve(ansiString.length() + 1); m_string.reserve(ansiString.length() + 1);
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(myString), locale); Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_string), locale);
} }
@ -95,8 +95,8 @@ String::String(const wchar_t* wideString)
std::size_t length = std::wcslen(wideString); std::size_t length = std::wcslen(wideString);
if (length > 0) if (length > 0)
{ {
myString.reserve(length + 1); m_string.reserve(length + 1);
Utf32::FromWide(wideString, wideString + length, std::back_inserter(myString)); Utf32::FromWide(wideString, wideString + length, std::back_inserter(m_string));
} }
} }
} }
@ -105,8 +105,8 @@ String::String(const wchar_t* wideString)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(const std::wstring& wideString) String::String(const std::wstring& wideString)
{ {
myString.reserve(wideString.length() + 1); m_string.reserve(wideString.length() + 1);
Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(myString)); Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(m_string));
} }
@ -114,20 +114,20 @@ String::String(const std::wstring& wideString)
String::String(const Uint32* utf32String) String::String(const Uint32* utf32String)
{ {
if (utf32String) if (utf32String)
myString = utf32String; m_string = utf32String;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(const std::basic_string<Uint32>& utf32String) : String::String(const std::basic_string<Uint32>& utf32String) :
myString(utf32String) m_string(utf32String)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(const String& copy) : String::String(const String& copy) :
myString(copy.myString) m_string(copy.m_string)
{ {
} }
@ -151,10 +151,10 @@ std::string String::ToAnsiString(const std::locale& locale) const
{ {
// Prepare the output string // Prepare the output string
std::string output; std::string output;
output.reserve(myString.length() + 1); output.reserve(m_string.length() + 1);
// Convert // Convert
Utf32::ToAnsi(myString.begin(), myString.end(), std::back_inserter(output), 0, locale); Utf32::ToAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale);
return output; return output;
} }
@ -165,10 +165,10 @@ std::wstring String::ToWideString() const
{ {
// Prepare the output string // Prepare the output string
std::wstring output; std::wstring output;
output.reserve(myString.length() + 1); output.reserve(m_string.length() + 1);
// Convert // Convert
Utf32::ToWide(myString.begin(), myString.end(), std::back_inserter(output), 0); Utf32::ToWide(m_string.begin(), m_string.end(), std::back_inserter(output), 0);
return output; return output;
} }
@ -177,7 +177,7 @@ std::wstring String::ToWideString() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String& String::operator =(const String& right) String& String::operator =(const String& right)
{ {
myString = right.myString; m_string = right.m_string;
return *this; return *this;
} }
@ -185,7 +185,7 @@ String& String::operator =(const String& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String& String::operator +=(const String& right) String& String::operator +=(const String& right)
{ {
myString += right.myString; m_string += right.m_string;
return *this; return *this;
} }
@ -193,98 +193,98 @@ String& String::operator +=(const String& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32 String::operator [](std::size_t index) const Uint32 String::operator [](std::size_t index) const
{ {
return myString[index]; return m_string[index];
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint32& String::operator [](std::size_t index) Uint32& String::operator [](std::size_t index)
{ {
return myString[index]; return m_string[index];
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::Clear() void String::Clear()
{ {
myString.clear(); m_string.clear();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::size_t String::GetSize() const std::size_t String::GetSize() const
{ {
return myString.size(); return m_string.size();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool String::IsEmpty() const bool String::IsEmpty() const
{ {
return myString.empty(); 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)
{ {
myString.erase(position, 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)
{ {
myString.insert(position, str.myString); 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 myString.find(str.myString, start); return m_string.find(str.m_string, start);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Uint32* String::GetData() const const Uint32* String::GetData() const
{ {
return myString.c_str(); return m_string.c_str();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::Iterator String::Begin() String::Iterator String::Begin()
{ {
return myString.begin(); return m_string.begin();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::ConstIterator String::Begin() const String::ConstIterator String::Begin() const
{ {
return myString.begin(); return m_string.begin();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::Iterator String::End() String::Iterator String::End()
{ {
return myString.end(); return m_string.end();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::ConstIterator String::End() const String::ConstIterator String::End() const
{ {
return myString.end(); return m_string.end();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool operator ==(const String& left, const String& right) bool operator ==(const String& left, const String& right)
{ {
return left.myString == right.myString; return left.m_string == right.m_string;
} }
@ -298,7 +298,7 @@ bool operator !=(const String& left, const String& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool operator <(const String& left, const String& right) bool operator <(const String& left, const String& right)
{ {
return left.myString < right.myString; return left.m_string < right.m_string;
} }

View File

@ -41,7 +41,7 @@ namespace sf
Thread::~Thread() Thread::~Thread()
{ {
Wait(); Wait();
delete myEntryPoint; delete m_entryPoint;
} }
@ -49,18 +49,18 @@ Thread::~Thread()
void Thread::Launch() void Thread::Launch()
{ {
Wait(); Wait();
myImpl = new priv::ThreadImpl(this); m_impl = new priv::ThreadImpl(this);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Thread::Wait() void Thread::Wait()
{ {
if (myImpl) if (m_impl)
{ {
myImpl->Wait(); m_impl->Wait();
delete myImpl; delete m_impl;
myImpl = NULL; m_impl = NULL;
} }
} }
@ -68,11 +68,11 @@ void Thread::Wait()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Thread::Terminate() void Thread::Terminate()
{ {
if (myImpl) if (m_impl)
{ {
myImpl->Terminate(); m_impl->Terminate();
delete myImpl; delete m_impl;
myImpl = NULL; m_impl = NULL;
} }
} }
@ -80,7 +80,7 @@ void Thread::Terminate()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Thread::Run() void Thread::Run()
{ {
myEntryPoint->Run(); m_entryPoint->Run();
} }
} // namespace sf } // namespace sf

View File

@ -44,7 +44,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ThreadLocal::ThreadLocal(void* value) ThreadLocal::ThreadLocal(void* value)
{ {
myImpl = new priv::ThreadLocalImpl; m_impl = new priv::ThreadLocalImpl;
SetValue(value); SetValue(value);
} }
@ -52,21 +52,21 @@ ThreadLocal::ThreadLocal(void* value)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ThreadLocal::~ThreadLocal() ThreadLocal::~ThreadLocal()
{ {
delete myImpl; delete m_impl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ThreadLocal::SetValue(void* value) void ThreadLocal::SetValue(void* value)
{ {
myImpl->SetValue(value); m_impl->SetValue(value);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void* ThreadLocal::GetValue() const void* ThreadLocal::GetValue() const
{ {
return myImpl->GetValue(); return m_impl->GetValue();
} }
} // namespace sf } // namespace sf

View File

@ -36,7 +36,7 @@ const Time Time::Zero;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time::Time() : Time::Time() :
myMicroseconds(0) m_microseconds(0)
{ {
} }
@ -44,27 +44,27 @@ myMicroseconds(0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Time::AsSeconds() const float Time::AsSeconds() const
{ {
return myMicroseconds / 1000000.f; return m_microseconds / 1000000.f;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int32 Time::AsMilliseconds() const Int32 Time::AsMilliseconds() const
{ {
return static_cast<Uint32>(myMicroseconds / 1000); return static_cast<Uint32>(m_microseconds / 1000);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 Time::AsMicroseconds() const Int64 Time::AsMicroseconds() const
{ {
return myMicroseconds; return m_microseconds;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time::Time(Int64 microseconds) : Time::Time(Int64 microseconds) :
myMicroseconds(microseconds) m_microseconds(microseconds)
{ {
} }

View File

@ -40,28 +40,28 @@ MutexImpl::MutexImpl()
pthread_mutexattr_init(&attributes); pthread_mutexattr_init(&attributes);
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&myMutex, &attributes); pthread_mutex_init(&m_mutex, &attributes);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
MutexImpl::~MutexImpl() MutexImpl::~MutexImpl()
{ {
pthread_mutex_destroy(&myMutex); pthread_mutex_destroy(&m_mutex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void MutexImpl::Lock() void MutexImpl::Lock()
{ {
pthread_mutex_lock(&myMutex); pthread_mutex_lock(&m_mutex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void MutexImpl::Unlock() void MutexImpl::Unlock()
{ {
pthread_mutex_unlock(&myMutex); pthread_mutex_unlock(&m_mutex);
} }
} // namespace priv } // namespace priv

View File

@ -72,7 +72,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
pthread_mutex_t myMutex; ///< pthread handle of the mutex pthread_mutex_t m_mutex; ///< pthread handle of the mutex
}; };
} // namespace priv } // namespace priv

View File

@ -37,11 +37,11 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ThreadImpl::ThreadImpl(Thread* owner) : ThreadImpl::ThreadImpl(Thread* owner) :
myIsActive(true) m_isActive(true)
{ {
myIsActive = pthread_create(&myThread, NULL, &ThreadImpl::EntryPoint, owner) == 0; m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::EntryPoint, owner) == 0;
if (!myIsActive) if (!m_isActive)
std::cerr << "Failed to create thread" << std::endl; std::cerr << "Failed to create thread" << std::endl;
} }
@ -49,10 +49,10 @@ myIsActive(true)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ThreadImpl::Wait() void ThreadImpl::Wait()
{ {
if (myIsActive) if (m_isActive)
{ {
assert(pthread_equal(pthread_self(), myThread) == 0); // A thread cannot wait for itself! assert(pthread_equal(pthread_self(), m_thread) == 0); // A thread cannot wait for itself!
pthread_join(myThread, NULL); pthread_join(m_thread, NULL);
} }
} }
@ -60,8 +60,8 @@ void ThreadImpl::Wait()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ThreadImpl::Terminate() void ThreadImpl::Terminate()
{ {
if (myIsActive) if (m_isActive)
pthread_cancel(myThread); pthread_cancel(m_thread);
} }

View File

@ -80,8 +80,8 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
pthread_t myThread; ///< pthread thread instance pthread_t m_thread; ///< pthread thread instance
bool myIsActive; ///< Thread state (active or inactive) bool m_isActive; ///< Thread state (active or inactive)
}; };
} // namespace priv } // namespace priv

View File

@ -35,28 +35,28 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ThreadLocalImpl::ThreadLocalImpl() ThreadLocalImpl::ThreadLocalImpl()
{ {
pthread_key_create(&myKey, NULL); pthread_key_create(&m_key, NULL);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ThreadLocalImpl::~ThreadLocalImpl() ThreadLocalImpl::~ThreadLocalImpl()
{ {
pthread_key_delete(myKey); pthread_key_delete(m_key);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ThreadLocalImpl::SetValue(void* value) void ThreadLocalImpl::SetValue(void* value)
{ {
pthread_setspecific(myKey, value); pthread_setspecific(m_key, value);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void* ThreadLocalImpl::GetValue() const void* ThreadLocalImpl::GetValue() const
{ {
return pthread_getspecific(myKey); return pthread_getspecific(m_key);
} }
} // namespace priv } // namespace priv

View File

@ -76,7 +76,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
pthread_key_t myKey; ///< Index of our thread-local storage slot pthread_key_t m_key; ///< Index of our thread-local storage slot
}; };
} // namespace priv } // namespace priv

View File

@ -35,28 +35,28 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
MutexImpl::MutexImpl() MutexImpl::MutexImpl()
{ {
InitializeCriticalSection(&myMutex); InitializeCriticalSection(&m_mutex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
MutexImpl::~MutexImpl() MutexImpl::~MutexImpl()
{ {
DeleteCriticalSection(&myMutex); DeleteCriticalSection(&m_mutex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void MutexImpl::Lock() void MutexImpl::Lock()
{ {
EnterCriticalSection(&myMutex); EnterCriticalSection(&m_mutex);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void MutexImpl::Unlock() void MutexImpl::Unlock()
{ {
LeaveCriticalSection(&myMutex); LeaveCriticalSection(&m_mutex);
} }
} // namespace priv } // namespace priv

View File

@ -72,7 +72,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CRITICAL_SECTION myMutex; ///< Win32 handle of the mutex CRITICAL_SECTION m_mutex; ///< Win32 handle of the mutex
}; };
} // namespace priv } // namespace priv

Some files were not shown because too many files have changed in this diff Show More