Changed the naming convention for public member variables/functions and free functions (using lowerCase instead of UpperCase)

This commit is contained in:
Laurent Gomila 2012-03-11 19:10:37 +01:00
parent ff5b69d312
commit 14ac411542
200 changed files with 4302 additions and 4320 deletions

View file

@ -15,10 +15,10 @@
/// \param Window Target window to initialize
///
////////////////////////////////////////////////////////////
void Initialize(sf::Window& window)
void initialize(sf::Window& window)
{
// Activate the window
window.SetActive();
window.setActive();
// Setup OpenGL states
// Set color and depth clear value
@ -43,10 +43,10 @@ void Initialize(sf::Window& window)
/// \param elapsedTime Time elapsed since the last draw
///
////////////////////////////////////////////////////////////
void Draw(sf::Window& window, float elapsedTime)
void draw(sf::Window& window, float elapsedTime)
{
// Activate the window
window.SetActive();
window.setActive();
// Clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -160,8 +160,8 @@ int main()
sf::Clock clock;
// Initialize our views
Initialize(SFMLView1);
Initialize(SFMLView2);
initialize(SFMLView1);
initialize(SFMLView2);
// Start the event loop
bool running = true;
@ -184,12 +184,12 @@ int main()
}
// Draw something into our views
Draw(SFMLView1, clock.GetElapsedTime().AsSeconds());
Draw(SFMLView2, clock.GetElapsedTime().AsSeconds() * 0.3f);
draw(SFMLView1, clock.getElapsedTime().asSeconds());
draw(SFMLView2, clock.getElapsedTime().asSeconds() * 0.3f);
// Display the views on screen
SFMLView1.Display();
SFMLView2.Display();
SFMLView1.display();
SFMLView2.display();
}
// Close the display

View file

@ -13,7 +13,7 @@
////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
{
return stream << response.GetStatus() << response.GetMessage();
return stream << response.getStatus() << response.getMessage();
}
@ -36,9 +36,9 @@ int main()
// Connect to the server
sf::Ftp server;
sf::Ftp::Response connectResponse = server.Connect(address);
sf::Ftp::Response connectResponse = server.connect(address);
std::cout << connectResponse << std::endl;
if (!connectResponse.IsOk())
if (!connectResponse.isOk())
return EXIT_FAILURE;
// Ask for user name and password
@ -49,9 +49,9 @@ int main()
std::cin >> password;
// Login to the server
sf::Ftp::Response loginResponse = server.Login(user, password);
sf::Ftp::Response loginResponse = server.login(user, password);
std::cout << loginResponse << std::endl;
if (!loginResponse.IsOk())
if (!loginResponse.isOk())
return EXIT_FAILURE;
// Main menu
@ -91,18 +91,18 @@ int main()
case 1 :
{
// Print the current server directory
sf::Ftp::DirectoryResponse response = server.GetWorkingDirectory();
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
std::cout << response << std::endl;
std::cout << "Current directory is " << response.GetDirectory() << std::endl;
std::cout << "Current directory is " << response.getDirectory() << std::endl;
break;
}
case 2 :
{
// Print the contents of the current server directory
sf::Ftp::ListingResponse response = server.GetDirectoryListing();
sf::Ftp::ListingResponse response = server.getDirectoryListing();
std::cout << response << std::endl;
std::vector<std::string> filenames = response.GetFilenames();
std::vector<std::string> filenames = response.getFilenames();
for (std::vector<std::string>::const_iterator it = filenames.begin(); it != filenames.end(); ++it)
std::cout << *it << std::endl;
break;
@ -114,7 +114,7 @@ int main()
std::string directory;
std::cout << "Choose a directory: ";
std::cin >> directory;
std::cout << server.ChangeDirectory(directory) << std::endl;
std::cout << server.changeDirectory(directory) << std::endl;
break;
}
@ -124,7 +124,7 @@ int main()
std::string directory;
std::cout << "Name of the directory to create: ";
std::cin >> directory;
std::cout << server.CreateDirectory(directory) << std::endl;
std::cout << server.createDirectory(directory) << std::endl;
break;
}
@ -134,7 +134,7 @@ int main()
std::string directory;
std::cout << "Name of the directory to remove: ";
std::cin >> directory;
std::cout << server.DeleteDirectory(directory) << std::endl;
std::cout << server.deleteDirectory(directory) << std::endl;
break;
}
@ -146,7 +146,7 @@ int main()
std::cin >> source;
std::cout << "New name: ";
std::cin >> destination;
std::cout << server.RenameFile(source, destination) << std::endl;
std::cout << server.renameFile(source, destination) << std::endl;
break;
}
@ -156,7 +156,7 @@ int main()
std::string filename;
std::cout << "Name of the file to remove: ";
std::cin >> filename;
std::cout << server.DeleteFile(filename) << std::endl;
std::cout << server.deleteFile(filename) << std::endl;
break;
}
@ -168,7 +168,7 @@ int main()
std::cin >> filename;
std::cout << "Directory to download the file to: ";
std::cin >> directory;
std::cout << server.Download(filename, directory) << std::endl;
std::cout << server.download(filename, directory) << std::endl;
break;
}
@ -180,7 +180,7 @@ int main()
std::cin >> filename;
std::cout << "Directory to upload the file to (relative to current directory): ";
std::cin >> directory;
std::cout << server.Upload(filename, directory) << std::endl;
std::cout << server.upload(filename, directory) << std::endl;
break;
}
@ -195,7 +195,7 @@ int main()
// Disconnect from the server
std::cout << "Disconnecting from server..." << std::endl;
std::cout << server.Disconnect() << std::endl;
std::cout << server.disconnect() << std::endl;
// Wait until the user presses 'enter' key
std::cout << "Press enter to exit..." << std::endl;

View file

@ -16,11 +16,11 @@ int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.SetVerticalSyncEnabled(true);
window.setVerticalSyncEnabled(true);
// Create a sprite for the background
sf::Texture backgroundTexture;
if (!backgroundTexture.LoadFromFile("resources/background.jpg"))
if (!backgroundTexture.loadFromFile("resources/background.jpg"))
return EXIT_FAILURE;
sf::Sprite background(backgroundTexture);
@ -30,11 +30,11 @@ int main()
GLuint texture = 0;
{
sf::Image image;
if (!image.LoadFromFile("resources/texture.jpg"))
if (!image.loadFromFile("resources/texture.jpg"))
return EXIT_FAILURE;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getWidth(), image.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
@ -58,49 +58,49 @@ int main()
sf::Clock clock;
// Start game loop
while (window.IsOpen())
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.type == sf::Event::Closed)
window.close();
// Escape key : exit
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
window.Close();
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
window.close();
// Adjust the viewport when the window is resized
if (event.Type == sf::Event::Resized)
glViewport(0, 0, event.Size.Width, event.Size.Height);
if (event.type == sf::Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
// Draw the background
window.PushGLStates();
window.Draw(background);
window.PopGLStates();
window.pushGLStates();
window.draw(background);
window.popGLStates();
// Activate the window before using OpenGL commands.
// This is useless here because we have only one window which is
// always the active one, but don't forget it if you use multiple windows
window.SetActive();
window.setActive();
// Clear the depth buffer
glClear(GL_DEPTH_BUFFER_BIT);
// We get the position of the mouse cursor, so that we can move the box accordingly
float x = sf::Mouse::GetPosition(window).x * 200.f / window.GetSize().x - 100.f;
float y = -sf::Mouse::GetPosition(window).y * 200.f / window.GetSize().y + 100.f;
float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(x, y, -100.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 50.f, 1.f, 0.f, 0.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 30.f, 0.f, 1.f, 0.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 90.f, 0.f, 0.f, 1.f);
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
// Draw a cube
float size = 20.f;
@ -139,15 +139,15 @@ int main()
glEnd();
// Draw some text on top of our OpenGL object
window.PushGLStates();
window.pushGLStates();
sf::Text text("SFML / OpenGL demo");
text.SetColor(sf::Color(255, 255, 255, 170));
text.SetPosition(250.f, 450.f);
window.Draw(text);
window.PopGLStates();
text.setColor(sf::Color(255, 255, 255, 170));
text.setPosition(250.f, 450.f);
window.draw(text);
window.popGLStates();
// Finally, display the rendered frame on screen
window.Display();
window.display();
}
// Don't forget to destroy our texture

View file

@ -28,54 +28,54 @@ int main()
// Create the window of the application
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
window.SetVerticalSyncEnabled(true);
window.setVerticalSyncEnabled(true);
// Load the sounds used in the game
sf::SoundBuffer ballSoundBuffer;
if (!ballSoundBuffer.LoadFromFile("resources/ball.wav"))
if (!ballSoundBuffer.loadFromFile("resources/ball.wav"))
return EXIT_FAILURE;
sf::Sound ballSound(ballSoundBuffer);
// Create the left paddle
sf::RectangleShape leftPaddle;
leftPaddle.SetSize(paddleSize - sf::Vector2f(3, 3));
leftPaddle.SetOutlineThickness(3);
leftPaddle.SetOutlineColor(sf::Color::Black);
leftPaddle.SetFillColor(sf::Color(100, 100, 200));
leftPaddle.SetOrigin(paddleSize / 2.f);
leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
leftPaddle.setOutlineThickness(3);
leftPaddle.setOutlineColor(sf::Color::Black);
leftPaddle.setFillColor(sf::Color(100, 100, 200));
leftPaddle.setOrigin(paddleSize / 2.f);
// Create the right paddle
sf::RectangleShape rightPaddle;
rightPaddle.SetSize(paddleSize - sf::Vector2f(3, 3));
rightPaddle.SetOutlineThickness(3);
rightPaddle.SetOutlineColor(sf::Color::Black);
rightPaddle.SetFillColor(sf::Color(200, 100, 100));
rightPaddle.SetOrigin(paddleSize / 2.f);
rightPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
rightPaddle.setOutlineThickness(3);
rightPaddle.setOutlineColor(sf::Color::Black);
rightPaddle.setFillColor(sf::Color(200, 100, 100));
rightPaddle.setOrigin(paddleSize / 2.f);
// Create the ball
sf::CircleShape ball;
ball.SetRadius(ballRadius - 3);
ball.SetOutlineThickness(3);
ball.SetOutlineColor(sf::Color::Black);
ball.SetFillColor(sf::Color::White);
ball.SetOrigin(ballRadius / 2, ballRadius / 2);
ball.setRadius(ballRadius - 3);
ball.setOutlineThickness(3);
ball.setOutlineColor(sf::Color::Black);
ball.setFillColor(sf::Color::White);
ball.setOrigin(ballRadius / 2, ballRadius / 2);
// Load the text font
sf::Font font;
if (!font.LoadFromFile("resources/sansation.ttf"))
if (!font.loadFromFile("resources/sansation.ttf"))
return EXIT_FAILURE;
// Initialize the pause message
sf::Text pauseMessage;
pauseMessage.SetFont(font);
pauseMessage.SetCharacterSize(40);
pauseMessage.SetPosition(170.f, 150.f);
pauseMessage.SetColor(sf::Color::White);
pauseMessage.SetString("Welcome to SFML pong!\nPress space to start the game");
pauseMessage.setFont(font);
pauseMessage.setCharacterSize(40);
pauseMessage.setPosition(170.f, 150.f);
pauseMessage.setColor(sf::Color::White);
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
// Define the paddles properties
sf::Clock AITimer;
const sf::Time AITime = sf::Seconds(0.1f);
const sf::Time AITime = sf::seconds(0.1f);
const float paddleSpeed = 400.f;
float rightPaddleSpeed = 0.f;
const float ballSpeed = 400.f;
@ -83,22 +83,22 @@ int main()
sf::Clock clock;
bool isPlaying = false;
while (window.IsOpen())
while (window.isOpen())
{
// Handle events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Window closed or escape key pressed: exit
if ((event.Type == sf::Event::Closed) ||
((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape)))
if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
{
window.Close();
window.close();
break;
}
// Space key pressed: play
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Space))
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
{
if (!isPlaying)
{
@ -106,9 +106,9 @@ int main()
isPlaying = true;
// Reset the position of the paddles and ball
leftPaddle.SetPosition(10 + paddleSize.x / 2, gameHeight / 2);
rightPaddle.SetPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
ball.SetPosition(gameWidth / 2, gameHeight / 2);
leftPaddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2);
rightPaddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
ball.setPosition(gameWidth / 2, gameHeight / 2);
// Reset the ball angle
do
@ -123,34 +123,34 @@ int main()
if (isPlaying)
{
float deltaTime = clock.Restart().AsSeconds();
float deltaTime = clock.restart().asSeconds();
// Move the player's paddle
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up) &&
(leftPaddle.GetPosition().y - paddleSize.y / 2 > 5.f))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) &&
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
{
leftPaddle.Move(0.f, -paddleSpeed * deltaTime);
leftPaddle.move(0.f, -paddleSpeed * deltaTime);
}
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down) &&
(leftPaddle.GetPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
{
leftPaddle.Move(0.f, paddleSpeed * deltaTime);
leftPaddle.move(0.f, paddleSpeed * deltaTime);
}
// Move the computer's paddle
if (((rightPaddleSpeed < 0.f) && (rightPaddle.GetPosition().y - paddleSize.y / 2 > 5.f)) ||
((rightPaddleSpeed > 0.f) && (rightPaddle.GetPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
{
rightPaddle.Move(0.f, rightPaddleSpeed * deltaTime);
rightPaddle.move(0.f, rightPaddleSpeed * deltaTime);
}
// Update the computer's paddle direction according to the ball position
if (AITimer.GetElapsedTime() > AITime)
if (AITimer.getElapsedTime() > AITime)
{
AITimer.Restart();
if (ball.GetPosition().y + ballRadius > rightPaddle.GetPosition().y + paddleSize.y / 2)
AITimer.restart();
if (ball.getPosition().y + ballRadius > rightPaddle.getPosition().y + paddleSize.y / 2)
rightPaddleSpeed = paddleSpeed;
else if (ball.GetPosition().y - ballRadius < rightPaddle.GetPosition().y - paddleSize.y / 2)
else if (ball.getPosition().y - ballRadius < rightPaddle.getPosition().y - paddleSize.y / 2)
rightPaddleSpeed = -paddleSpeed;
else
rightPaddleSpeed = 0.f;
@ -158,82 +158,82 @@ int main()
// Move the ball
float factor = ballSpeed * deltaTime;
ball.Move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
// Check collisions between the ball and the screen
if (ball.GetPosition().x - ballRadius < 0.f)
if (ball.getPosition().x - ballRadius < 0.f)
{
isPlaying = false;
pauseMessage.SetString("You lost !\nPress space to restart or\nescape to exit");
pauseMessage.setString("You lost !\nPress space to restart or\nescape to exit");
}
if (ball.GetPosition().x + ballRadius > 800)
if (ball.getPosition().x + ballRadius > 800)
{
isPlaying = false;
pauseMessage.SetString("You won !\nPress space to restart or\nescape to exit");
pauseMessage.setString("You won !\nPress space to restart or\nescape to exit");
}
if (ball.GetPosition().y - ballRadius < 0.f)
if (ball.getPosition().y - ballRadius < 0.f)
{
ballSound.Play();
ballSound.play();
ballAngle = -ballAngle;
ball.SetPosition(ball.GetPosition().x, ballRadius + 0.1f);
ball.setPosition(ball.getPosition().x, ballRadius + 0.1f);
}
if (ball.GetPosition().y + ballRadius > gameHeight)
if (ball.getPosition().y + ballRadius > gameHeight)
{
ballSound.Play();
ballSound.play();
ballAngle = -ballAngle;
ball.SetPosition(ball.GetPosition().x, gameHeight - ballRadius - 0.1f);
ball.setPosition(ball.getPosition().x, gameHeight - ballRadius - 0.1f);
}
// Check the collisions between the ball and the paddles
// Left Paddle
if (ball.GetPosition().x - ballRadius < leftPaddle.GetPosition().x + paddleSize.x / 2 &&
ball.GetPosition().x - ballRadius > leftPaddle.GetPosition().x &&
ball.GetPosition().y + ballRadius >= leftPaddle.GetPosition().y - paddleSize.y / 2 &&
ball.GetPosition().y - ballRadius <= leftPaddle.GetPosition().y + paddleSize.y / 2)
if (ball.getPosition().x - ballRadius < leftPaddle.getPosition().x + paddleSize.x / 2 &&
ball.getPosition().x - ballRadius > leftPaddle.getPosition().x &&
ball.getPosition().y + ballRadius >= leftPaddle.getPosition().y - paddleSize.y / 2 &&
ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2)
{
if (ball.GetPosition().y > leftPaddle.GetPosition().y)
if (ball.getPosition().y > leftPaddle.getPosition().y)
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
else
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
ballSound.Play();
ball.SetPosition(leftPaddle.GetPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.GetPosition().y);
ballSound.play();
ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y);
}
// Right Paddle
if (ball.GetPosition().x + ballRadius > rightPaddle.GetPosition().x - paddleSize.x / 2 &&
ball.GetPosition().x + ballRadius < rightPaddle.GetPosition().x &&
ball.GetPosition().y + ballRadius >= rightPaddle.GetPosition().y - paddleSize.y / 2 &&
ball.GetPosition().y - ballRadius <= rightPaddle.GetPosition().y + paddleSize.y / 2)
if (ball.getPosition().x + ballRadius > rightPaddle.getPosition().x - paddleSize.x / 2 &&
ball.getPosition().x + ballRadius < rightPaddle.getPosition().x &&
ball.getPosition().y + ballRadius >= rightPaddle.getPosition().y - paddleSize.y / 2 &&
ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2)
{
if (ball.GetPosition().y > rightPaddle.GetPosition().y)
if (ball.getPosition().y > rightPaddle.getPosition().y)
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
else
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
ballSound.Play();
ball.SetPosition(rightPaddle.GetPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.GetPosition().y);
ballSound.play();
ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y);
}
}
// Clear the window
window.Clear(sf::Color(50, 200, 50));
window.clear(sf::Color(50, 200, 50));
if (isPlaying)
{
// Draw the paddles and the ball
window.Draw(leftPaddle);
window.Draw(rightPaddle);
window.Draw(ball);
window.draw(leftPaddle);
window.draw(rightPaddle);
window.draw(ball);
}
else
{
// Draw the pause message
window.Draw(pauseMessage);
window.draw(pauseMessage);
}
// Display things on screen
window.Display();
window.display();
}
return EXIT_SUCCESS;

View file

@ -19,34 +19,34 @@ public :
{
}
const std::string& GetName() const
const std::string& getName() const
{
return m_name;
}
void Load()
void load()
{
m_isLoaded = 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 (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 (m_isLoaded)
{
OnDraw(target, states);
onDraw(target, states);
}
else
{
sf::Text error("Shader not\nsupported");
error.SetPosition(320.f, 200.f);
error.SetCharacterSize(36);
target.Draw(error, states);
error.setPosition(320.f, 200.f);
error.setCharacterSize(36);
target.draw(error, states);
}
}
@ -61,9 +61,9 @@ protected :
private :
// Virtual functions to be implemented in derived effects
virtual bool OnLoad() = 0;
virtual void OnUpdate(float time, float x, float y) = 0;
virtual void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
virtual bool onLoad() = 0;
virtual void onUpdate(float time, float x, float y) = 0;
virtual void onDraw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
private :

View file

@ -20,30 +20,30 @@ public :
{
}
bool OnLoad()
bool onLoad()
{
// Load the texture and initialize the sprite
if (!m_texture.LoadFromFile("resources/background.jpg"))
if (!m_texture.loadFromFile("resources/background.jpg"))
return false;
m_sprite.SetTexture(m_texture);
m_sprite.setTexture(m_texture);
// Load the shader
if (!m_shader.LoadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
return false;
m_shader.SetParameter("texture", sf::Shader::CurrentTexture);
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
return true;
}
void OnUpdate(float, float x, float y)
void onUpdate(float, float x, float y)
{
m_shader.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 = &m_shader;
target.Draw(m_sprite, states);
states.shader = &m_shader;
target.draw(m_sprite, states);
}
private:
@ -66,10 +66,10 @@ public :
{
}
bool OnLoad()
bool onLoad()
{
// Create the text
m_text.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"
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
"Donec fringilla scelerisque mauris et viverra.\n"
@ -87,27 +87,27 @@ public :
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\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");
m_text.SetCharacterSize(22);
m_text.SetPosition(30, 20);
m_text.setCharacterSize(22);
m_text.setPosition(30, 20);
// Load the shader
if (!m_shader.LoadFromFile("resources/wave.vert", "resources/blur.frag"))
if (!m_shader.loadFromFile("resources/wave.vert", "resources/blur.frag"))
return false;
return true;
}
void OnUpdate(float time, float x, float y)
void onUpdate(float time, float x, float y)
{
m_shader.SetParameter("wave_phase", time);
m_shader.SetParameter("wave_amplitude", x * 40, y * 40);
m_shader.SetParameter("blur_radius", (x + y) * 0.008f);
m_shader.setParameter("wave_phase", time);
m_shader.setParameter("wave_amplitude", x * 40, y * 40);
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 = &m_shader;
target.Draw(m_text, states);
states.shader = &m_shader;
target.draw(m_text, states);
}
private:
@ -129,10 +129,10 @@ public :
{
}
bool OnLoad()
bool onLoad()
{
// Create the points
m_points.SetPrimitiveType(sf::Points);
m_points.setPrimitiveType(sf::Points);
for (int i = 0; i < 40000; ++i)
{
float x = static_cast<float>(std::rand() % 800);
@ -140,29 +140,29 @@ public :
sf::Uint8 r = std::rand() % 255;
sf::Uint8 g = std::rand() % 255;
sf::Uint8 b = std::rand() % 255;
m_points.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
if (!m_shader.LoadFromFile("resources/storm.vert", "resources/blink.frag"))
if (!m_shader.loadFromFile("resources/storm.vert", "resources/blink.frag"))
return false;
return true;
}
void OnUpdate(float time, float x, float y)
void onUpdate(float time, float x, float y)
{
float radius = 200 + std::cos(time) * 150;
m_shader.SetParameter("storm_position", x * 800, y * 600);
m_shader.SetParameter("storm_inner_radius", radius / 3);
m_shader.SetParameter("storm_total_radius", radius);
m_shader.SetParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
m_shader.setParameter("storm_position", x * 800, y * 600);
m_shader.setParameter("storm_inner_radius", radius / 3);
m_shader.setParameter("storm_total_radius", radius);
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 = &m_shader;
target.Draw(m_points, states);
states.shader = &m_shader;
target.draw(m_points, states);
}
private:
@ -184,24 +184,24 @@ public :
{
}
bool OnLoad()
bool onLoad()
{
// Create the off-screen surface
if (!m_surface.Create(800, 600))
if (!m_surface.create(800, 600))
return false;
m_surface.SetSmooth(true);
m_surface.setSmooth(true);
// Load the textures
if (!m_backgroundTexture.LoadFromFile("resources/sfml.png"))
if (!m_backgroundTexture.loadFromFile("resources/sfml.png"))
return false;
m_backgroundTexture.SetSmooth(true);
if (!m_entityTexture.LoadFromFile("resources/devices.png"))
m_backgroundTexture.setSmooth(true);
if (!m_entityTexture.loadFromFile("resources/devices.png"))
return false;
m_entityTexture.SetSmooth(true);
m_entityTexture.setSmooth(true);
// Initialize the background sprite
m_backgroundSprite.SetTexture(m_backgroundTexture);
m_backgroundSprite.SetPosition(135, 100);
m_backgroundSprite.setTexture(m_backgroundTexture);
m_backgroundSprite.setPosition(135, 100);
// Load the moving entities
for (int i = 0; i < 6; ++i)
@ -211,37 +211,37 @@ public :
}
// Load the shader
if (!m_shader.LoadFromFile("resources/edge.frag", sf::Shader::Fragment))
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
return false;
m_shader.SetParameter("texture", sf::Shader::CurrentTexture);
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
return true;
}
void OnUpdate(float time, float x, float y)
void onUpdate(float time, float x, float y)
{
m_shader.SetParameter("edge_threshold", 1 - (x + y) / 2);
m_shader.setParameter("edge_threshold", 1 - (x + y) / 2);
// Update the position of the moving entities
for (std::size_t i = 0; i < m_entities.size(); ++i)
{
float x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
float y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
m_entities[i].SetPosition(x, y);
m_entities[i].setPosition(x, y);
}
// Render the updated scene to the off-screen surface
m_surface.Clear(sf::Color::White);
m_surface.Draw(m_backgroundSprite);
m_surface.clear(sf::Color::White);
m_surface.draw(m_backgroundSprite);
for (std::size_t i = 0; i < m_entities.size(); ++i)
m_surface.Draw(m_entities[i]);
m_surface.Display();
m_surface.draw(m_entities[i]);
m_surface.display();
}
void OnDraw(sf::RenderTarget& target, sf::RenderStates states) const
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.Shader = &m_shader;
target.Draw(sf::Sprite(m_surface.GetTexture()), states);
states.shader = &m_shader;
target.draw(sf::Sprite(m_surface.getTexture()), states);
}
private:
@ -265,7 +265,7 @@ int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
window.SetVerticalSyncEnabled(true);
window.setVerticalSyncEnabled(true);
// Create the effects
std::vector<Effect*> effects;
@ -277,50 +277,50 @@ int main()
// Initialize them
for (std::size_t i = 0; i < effects.size(); ++i)
effects[i]->Load();
effects[i]->load();
// Create the messages background
sf::Texture textBackgroundTexture;
if (!textBackgroundTexture.LoadFromFile("resources/text-background.png"))
if (!textBackgroundTexture.loadFromFile("resources/text-background.png"))
return EXIT_FAILURE;
sf::Sprite textBackground(textBackgroundTexture);
textBackground.SetPosition(0, 520);
textBackground.SetColor(sf::Color(255, 255, 255, 200));
textBackground.setPosition(0, 520);
textBackground.setColor(sf::Color(255, 255, 255, 200));
// Load the messages font
sf::Font font;
if (!font.LoadFromFile("resources/sansation.ttf"))
if (!font.loadFromFile("resources/sansation.ttf"))
return EXIT_FAILURE;
// Create the description text
sf::Text description("Current effect: " + effects[current]->GetName(), font, 20);
description.SetPosition(10, 530);
description.SetColor(sf::Color(80, 80, 80));
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
description.setPosition(10, 530);
description.setColor(sf::Color(80, 80, 80));
// Create the instructions text
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
instructions.SetPosition(280, 555);
instructions.SetColor(sf::Color(80, 80, 80));
instructions.setPosition(280, 555);
instructions.setColor(sf::Color(80, 80, 80));
// Start the game loop
sf::Clock clock;
while (window.IsOpen())
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Close window: exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.type == sf::Event::Closed)
window.close();
if (event.Type == sf::Event::KeyPressed)
if (event.type == sf::Event::KeyPressed)
{
switch (event.Key.Code)
switch (event.key.code)
{
// Escape key: exit
case sf::Keyboard::Escape:
window.Close();
window.close();
break;
// Left arrow key: previous shader
@ -329,7 +329,7 @@ int main()
current = effects.size() - 1;
else
current--;
description.SetString("Current effect: " + effects[current]->GetName());
description.setString("Current effect: " + effects[current]->getName());
break;
// Right arrow key: next shader
@ -338,7 +338,7 @@ int main()
current = 0;
else
current++;
description.SetString("Current effect: " + effects[current]->GetName());
description.setString("Current effect: " + effects[current]->getName());
break;
default:
@ -348,23 +348,23 @@ int main()
}
// Update the current example
float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetSize().x;
float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetSize().y;
effects[current]->Update(clock.GetElapsedTime().AsSeconds(), x, y);
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
// Clear the window
window.Clear(sf::Color(255, 128, 0));
window.clear(sf::Color(255, 128, 0));
// Draw the current example
window.Draw(*effects[current]);
window.draw(*effects[current]);
// Draw the text
window.Draw(textBackground);
window.Draw(instructions);
window.Draw(description);
window.draw(textBackground);
window.draw(instructions);
window.draw(description);
// Finally, display the rendered frame on screen
window.Display();
window.display();
}
// delete the effects

View file

@ -6,10 +6,10 @@
#include <cstdlib>
void RunTcpServer(unsigned short Port);
void RunTcpClient(unsigned short Port);
void RunUdpServer(unsigned short Port);
void RunUdpClient(unsigned short Port);
void runTcpServer(unsigned short port);
void runTcpClient(unsigned short port);
void runUdpServer(unsigned short port);
void runUdpClient(unsigned short port);
////////////////////////////////////////////////////////////
@ -37,17 +37,17 @@ int main()
{
// Test the TCP protocol
if (who == 's')
RunTcpServer(port);
runTcpServer(port);
else
RunTcpClient(port);
runTcpClient(port);
}
else
{
// Test the unconnected UDP protocol
if (who == 's')
RunUdpServer(port);
runUdpServer(port);
else
RunUdpClient(port);
runUdpClient(port);
}
// Wait until the user presses 'enter' key

View file

@ -11,32 +11,32 @@
/// send a message and wait for the answer.
///
////////////////////////////////////////////////////////////
void RunTcpServer(unsigned short port)
void runTcpServer(unsigned short port)
{
// Create a server socket to accept new connections
sf::TcpListener listener;
// Listen to the given port for incoming connections
if (listener.Listen(port) != sf::Socket::Done)
if (listener.listen(port) != sf::Socket::Done)
return;
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
// Wait for a connection
sf::TcpSocket socket;
if (listener.Accept(socket) != sf::Socket::Done)
if (listener.accept(socket) != sf::Socket::Done)
return;
std::cout << "Client connected: " << socket.GetRemoteAddress() << std::endl;
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
// Send a message to the connected client
const char out[] = "Hi, I'm the server";
if (socket.Send(out, sizeof(out)) != sf::Socket::Done)
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
return;
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
// Receive a message back from the client
char in[128];
std::size_t received;
if (socket.Receive(in, sizeof(in), received) != sf::Socket::Done)
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return;
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
}
@ -47,7 +47,7 @@ void RunTcpServer(unsigned short port)
/// welcome message and send an answer.
///
////////////////////////////////////////////////////////////
void RunTcpClient(unsigned short port)
void runTcpClient(unsigned short port)
{
// Ask for the server address
sf::IpAddress server;
@ -62,20 +62,20 @@ void RunTcpClient(unsigned short port)
sf::TcpSocket socket;
// Connect to the server
if (socket.Connect(server, port) != sf::Socket::Done)
if (socket.connect(server, port) != sf::Socket::Done)
return;
std::cout << "Connected to server " << server << std::endl;
// Receive a message from the server
char in[128];
std::size_t received;
if (socket.Receive(in, sizeof(in), received) != sf::Socket::Done)
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return;
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
// Send an answer to the server
const char out[] = "Hi, I'm a client";
if (socket.Send(out, sizeof(out)) != sf::Socket::Done)
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
return;
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
}

View file

@ -10,13 +10,13 @@
/// Launch a server, wait for a message, send an answer.
///
////////////////////////////////////////////////////////////
void RunUdpServer(unsigned short port)
void runUdpServer(unsigned short port)
{
// Create a socket to receive a message from anyone
sf::UdpSocket socket;
// Listen to messages on the specified port
if (socket.Bind(port) != sf::Socket::Done)
if (socket.bind(port) != sf::Socket::Done)
return;
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
@ -25,13 +25,13 @@ void RunUdpServer(unsigned short port)
std::size_t received;
sf::IpAddress sender;
unsigned short senderPort;
if (socket.Receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
// Send an answer to the client
const char out[] = "Hi, I'm the server";
if (socket.Send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
}
@ -41,7 +41,7 @@ void RunUdpServer(unsigned short port)
/// Send a message to the server, wait for the answer
///
////////////////////////////////////////////////////////////
void RunUdpClient(unsigned short port)
void runUdpClient(unsigned short port)
{
// Ask for the server address
sf::IpAddress server;
@ -57,7 +57,7 @@ void RunUdpClient(unsigned short port)
// Send a message to the server
const char out[] = "Hi, I'm a client";
if (socket.Send(out, sizeof(out), server, port) != sf::Socket::Done)
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
return;
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
@ -66,7 +66,7 @@ void RunUdpClient(unsigned short port)
std::size_t received;
sf::IpAddress sender;
unsigned short senderPort;
if (socket.Receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
}

View file

@ -11,31 +11,31 @@
/// Play a sound
///
////////////////////////////////////////////////////////////
void PlaySound()
void playSound()
{
// Load a sound buffer from a wav file
sf::SoundBuffer buffer;
if (!buffer.LoadFromFile("resources/canary.wav"))
if (!buffer.loadFromFile("resources/canary.wav"))
return;
// Display sound informations
std::cout << "canary.wav :" << std::endl;
std::cout << " " << buffer.GetDuration().AsSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.GetChannelCount() << " channels" << std::endl;
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
// Create a sound instance and play it
sf::Sound sound(buffer);
sound.Play();
sound.play();
// Loop while the sound is playing
while (sound.GetStatus() == sf::Sound::Playing)
while (sound.getStatus() == sf::Sound::Playing)
{
// Leave some CPU time for other processes
sf::Sleep(sf::Milliseconds(100));
sf::sleep(sf::milliseconds(100));
// Display the playing position
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset().AsSeconds() << " sec ";
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec ";
std::cout << std::flush;
}
std::cout << std::endl << std::endl;
@ -46,30 +46,30 @@ void PlaySound()
/// Play a music
///
////////////////////////////////////////////////////////////
void PlayMusic()
void playMusic()
{
// Load an ogg music file
sf::Music music;
if (!music.OpenFromFile("resources/orchestral.ogg"))
if (!music.openFromFile("resources/orchestral.ogg"))
return;
// Display music informations
std::cout << "orchestral.ogg :" << std::endl;
std::cout << " " << music.GetDuration().AsSeconds() << " seconds" << std::endl;
std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.GetChannelCount() << " channels" << std::endl;
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
// Play it
music.Play();
music.play();
// Loop while the music is playing
while (music.GetStatus() == sf::Music::Playing)
while (music.getStatus() == sf::Music::Playing)
{
// Leave some CPU time for other processes
sf::Sleep(sf::Milliseconds(100));
sf::sleep(sf::milliseconds(100));
// Display the playing position
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.GetPlayingOffset().AsSeconds() << " sec ";
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.getPlayingOffset().asSeconds() << " sec ";
std::cout << std::flush;
}
std::cout << std::endl;
@ -85,10 +85,10 @@ void PlayMusic()
int main()
{
// Play a sound
PlaySound();
playSound();
// Play a music
PlayMusic();
playMusic();
// Wait until the user presses 'enter' key
std::cout << "Press enter to exit..." << std::endl;

View file

@ -16,7 +16,7 @@
int main()
{
// Check that the device can capture audio
if (sf::SoundRecorder::IsAvailable() == false)
if (sf::SoundRecorder::isAvailable() == false)
{
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
return EXIT_SUCCESS;
@ -36,19 +36,19 @@ int main()
sf::SoundBufferRecorder recorder;
// Audio capture is done in a separate thread, so we can block the main thread while it is capturing
recorder.Start(sampleRate);
recorder.start(sampleRate);
std::cout << "Recording... press enter to stop";
std::cin.ignore(10000, '\n');
recorder.Stop();
recorder.stop();
// Get the buffer containing the captured data
const sf::SoundBuffer& buffer = recorder.GetBuffer();
const sf::SoundBuffer& buffer = recorder.getBuffer();
// Display captured sound informations
std::cout << "Sound information :" << std::endl;
std::cout << " " << buffer.GetDuration().AsSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.GetSampleRate() << " samples / seconds" << std::endl;
std::cout << " " << buffer.GetChannelCount() << " channels" << std::endl;
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.getSampleRate() << " samples / seconds" << std::endl;
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
// Choose what to do with the recorded sound data
char choice;
@ -64,23 +64,23 @@ int main()
std::getline(std::cin, filename);
// Save the buffer
buffer.SaveToFile(filename);
buffer.saveToFile(filename);
}
else
{
// Create a sound instance and play it
sf::Sound sound(buffer);
sound.Play();
sound.play();
// Wait until finished
while (sound.GetStatus() == sf::Sound::Playing)
while (sound.getStatus() == sf::Sound::Playing)
{
// Display the playing position
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset().AsSeconds() << " sec";
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec";
std::cout << std::flush;
// Leave some CPU time for other threads
sf::Sleep(sf::Milliseconds(100));
sf::sleep(sf::milliseconds(100));
}
}

View file

@ -38,9 +38,9 @@ private :
/// /see SoundRecorder::OnStart
///
////////////////////////////////////////////////////////////
virtual bool OnStart()
virtual bool onStart()
{
if (m_socket.Connect(m_host, m_port) == sf::Socket::Done)
if (m_socket.connect(m_host, m_port) == sf::Socket::Done)
{
std::cout << "Connected to server " << m_host << std::endl;
return true;
@ -55,30 +55,30 @@ private :
/// /see SoundRecorder::ProcessSamples
///
////////////////////////////////////////////////////////////
virtual bool OnProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
virtual bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
{
// Pack the audio samples into a network packet
sf::Packet packet;
packet << audioData;
packet.Append(samples, sampleCount * sizeof(sf::Int16));
packet.append(samples, sampleCount * sizeof(sf::Int16));
// Send the audio packet to the server
return m_socket.Send(packet) == sf::Socket::Done;
return m_socket.send(packet) == sf::Socket::Done;
}
////////////////////////////////////////////////////////////
/// /see SoundRecorder::OnStop
///
////////////////////////////////////////////////////////////
virtual void OnStop()
virtual void onStop()
{
// Send a "end-of-stream" packet
sf::Packet packet;
packet << endOfStream;
m_socket.Send(packet);
m_socket.send(packet);
// Close the socket
m_socket.Disconnect();
m_socket.disconnect();
}
////////////////////////////////////////////////////////////
@ -95,10 +95,10 @@ private :
/// start sending him audio data
///
////////////////////////////////////////////////////////////
void DoClient(unsigned short port)
void doClient(unsigned short port)
{
// Check that the device can capture audio
if (sf::SoundRecorder::IsAvailable() == false)
if (sf::SoundRecorder::isAvailable() == false)
{
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
return;
@ -122,8 +122,8 @@ void DoClient(unsigned short port)
std::cin.ignore(10000, '\n');
// Start capturing audio data
recorder.Start(44100);
recorder.start(44100);
std::cout << "Recording... press enter to stop";
std::cin.ignore(10000, '\n');
recorder.Stop();
recorder.stop();
}

View file

@ -30,37 +30,37 @@ public :
m_hasFinished(false)
{
// Set the sound parameters
Initialize(1, 44100);
initialize(1, 44100);
}
////////////////////////////////////////////////////////////
/// Run the server, stream audio data from the client
///
////////////////////////////////////////////////////////////
void Start(unsigned short port)
void start(unsigned short port)
{
if (!m_hasFinished)
{
// Listen to the given port for incoming connections
if (m_listener.Listen(port) != sf::Socket::Done)
if (m_listener.listen(port) != sf::Socket::Done)
return;
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
// Wait for a connection
if (m_listener.Accept(m_client) != sf::Socket::Done)
if (m_listener.accept(m_client) != sf::Socket::Done)
return;
std::cout << "Client connected: " << m_client.GetRemoteAddress() << std::endl;
std::cout << "Client connected: " << m_client.getRemoteAddress() << std::endl;
// Start playback
Play();
play();
// Start receiving audio data
ReceiveLoop();
receiveLoop();
}
else
{
// Start playback
Play();
play();
}
}
@ -70,7 +70,7 @@ private :
/// /see SoundStream::OnGetData
///
////////////////////////////////////////////////////////////
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
if ((m_offset >= m_samples.size()) && m_hasFinished)
@ -78,7 +78,7 @@ private :
// No new data has arrived since last update : wait until we get some
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
// (don't forget that we run in two separate threads)
@ -88,8 +88,8 @@ private :
}
// Fill audio data to pass to the stream
data.Samples = &m_tempBuffer[0];
data.SampleCount = m_tempBuffer.size();
data.samples = &m_tempBuffer[0];
data.sampleCount = m_tempBuffer.size();
// Update the playing offset
m_offset += m_tempBuffer.size();
@ -101,22 +101,22 @@ private :
/// /see SoundStream::OnSeek
///
////////////////////////////////////////////////////////////
virtual void OnSeek(sf::Time timeOffset)
virtual void onSeek(sf::Time timeOffset)
{
m_offset = timeOffset.AsMilliseconds() * GetSampleRate() * GetChannelCount() / 1000;
m_offset = timeOffset.asMilliseconds() * getSampleRate() * getChannelCount() / 1000;
}
////////////////////////////////////////////////////////////
/// Get audio data from the client until playback is stopped
///
////////////////////////////////////////////////////////////
void ReceiveLoop()
void receiveLoop()
{
while (!m_hasFinished)
{
// Get waiting audio data from the network
sf::Packet packet;
if (m_client.Receive(packet) != sf::Socket::Done)
if (m_client.receive(packet) != sf::Socket::Done)
break;
// Extract the message ID
@ -126,8 +126,8 @@ private :
if (id == audioData)
{
// Extract audio samples from the packet, and append it to our samples buffer
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(packet.GetData() + 1);
std::size_t sampleCount = (packet.GetDataSize() - 1) / sizeof(sf::Int16);
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(packet.getData() + 1);
std::size_t sampleCount = (packet.getDataSize() - 1) / sizeof(sf::Int16);
// 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)
@ -169,17 +169,17 @@ private :
/// a connected client
///
////////////////////////////////////////////////////////////
void DoServer(unsigned short port)
void doServer(unsigned short port)
{
// Build an audio stream to play sound data as it is received through the network
NetworkAudioStream audioStream;
audioStream.Start(port);
audioStream.start(port);
// Loop until the sound playback is finished
while (audioStream.GetStatus() != sf::SoundStream::Stopped)
while (audioStream.getStatus() != sf::SoundStream::Stopped)
{
// Leave some CPU time for other threads
sf::Sleep(sf::Milliseconds(100));
sf::sleep(sf::milliseconds(100));
}
std::cin.ignore(10000, '\n');
@ -189,12 +189,12 @@ void DoServer(unsigned short port)
std::cin.ignore(10000, '\n');
// Replay the sound (just to make sure replaying the received data is OK)
audioStream.Play();
audioStream.play();
// Loop until the sound playback is finished
while (audioStream.GetStatus() != sf::SoundStream::Stopped)
while (audioStream.getStatus() != sf::SoundStream::Stopped)
{
// Leave some CPU time for other threads
sf::Sleep(sf::Milliseconds(100));
sf::sleep(sf::milliseconds(100));
}
}

View file

@ -11,8 +11,8 @@
// Function prototypes
// (I'm too lazy to put them into separate headers...)
////////////////////////////////////////////////////////////
void DoClient(unsigned short port);
void DoServer(unsigned short port);
void doClient(unsigned short port);
void doServer(unsigned short port);
////////////////////////////////////////////////////////////
@ -34,12 +34,12 @@ int main()
if (who == 's')
{
// Run as a server
DoServer(port);
doServer(port);
}
else
{
// Run as a client
DoClient(port);
doClient(port);
}
// Wait until the user presses 'enter' key

View file

@ -13,7 +13,7 @@ HWND button;
/// Function called whenever one of our windows receives a message
///
////////////////////////////////////////////////////////////
LRESULT CALLBACK OnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
@ -52,7 +52,7 @@ INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
// Define a class for our main window
WNDCLASS windowClass;
windowClass.style = 0;
windowClass.lpfnWndProc = &OnEvent;
windowClass.lpfnWndProc = &onEvent;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = instance;
@ -77,12 +77,12 @@ INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
// Load some textures to display
sf::Texture texture1, texture2;
if (!texture1.LoadFromFile("resources/image1.jpg") || !texture2.LoadFromFile("resources/image2.jpg"))
if (!texture1.loadFromFile("resources/image1.jpg") || !texture2.loadFromFile("resources/image2.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite1(texture1);
sf::Sprite sprite2(texture2);
sprite1.SetOrigin(texture1.GetWidth() / 2.f, texture1.GetHeight() / 2.f);
sprite1.SetPosition(sprite1.GetOrigin());
sprite1.setOrigin(texture1.getWidth() / 2.f, texture1.getHeight() / 2.f);
sprite1.setPosition(sprite1.getOrigin());
// Create a clock for measuring elapsed time
sf::Clock clock;
@ -100,23 +100,23 @@ INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
}
else
{
float time = clock.GetElapsedTime().AsSeconds();
float time = clock.getElapsedTime().asSeconds();
// Clear views
SFMLView1.Clear();
SFMLView2.Clear();
SFMLView1.clear();
SFMLView2.clear();
// Draw sprite 1 on view 1
sprite1.SetRotation(time * 100);
SFMLView1.Draw(sprite1);
sprite1.setRotation(time * 100);
SFMLView1.draw(sprite1);
// Draw sprite 2 on view 2
sprite2.SetPosition(std::cos(time) * 100.f, 0.f);
SFMLView2.Draw(sprite2);
sprite2.setPosition(std::cos(time) * 100.f, 0.f);
SFMLView2.draw(sprite2);
// Display each view on screen
SFMLView1.Display();
SFMLView2.Display();
SFMLView1.display();
SFMLView2.display();
}
}

View file

@ -34,29 +34,29 @@ int main()
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start the game loop
while (window.IsOpen())
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.type == sf::Event::Closed)
window.close();
// Escape key : exit
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
window.Close();
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
window.close();
// Resize event : adjust viewport
if (event.Type == sf::Event::Resized)
glViewport(0, 0, event.Size.Width, event.Size.Height);
if (event.type == sf::Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
// Activate the window before using OpenGL commands.
// This is useless here because we have only one window which is
// always the active one, but don't forget it if you use multiple windows
window.SetActive();
window.setActive();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -65,9 +65,9 @@ int main()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 50, 1.f, 0.f, 0.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 30, 0.f, 1.f, 0.f);
glRotatef(clock.GetElapsedTime().AsSeconds() * 90, 0.f, 0.f, 1.f);
glRotatef(clock.getElapsedTime().asSeconds() * 50, 1.f, 0.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 30, 0.f, 1.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 90, 0.f, 0.f, 1.f);
// Draw a cube
glBegin(GL_QUADS);
@ -111,7 +111,7 @@ int main()
glEnd();
// Finally, display the rendered frame on screen
window.Display();
window.display();
}
return EXIT_SUCCESS;