Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Peter P.

Pages: [1]
1
General / Re: Ubuntu - Speed Issues
« on: November 26, 2015, 05:22:24 pm »
I did factor in my monitors refresh rate (I don't see how this would be related to vsync), still everything was a bit slow and not as fluent as it should be. (in retrospect the "hundredfold" increase on arch was a bit of an exxageration). I just finished building SFML on my main OS (Debian) and now it seems to work out fine.
That does the trick for me, still, thanks for the advice.

Edit: Wait a minute I believe my brain just malfunctioned, I now remember how vsync works :D
And it's not enabled by default things are going too fast for that. Still not "that" fast... are there any benchmark programs for SFML that I could try running to see how my computer performs overall?

2
General / Ubuntu - Speed Issues
« on: November 26, 2015, 01:31:16 am »
Hello folks,

I recently started looking for a C++ Multimedia library and decided to give SFML a try. I have built SFML on Xubuntu 14.04 utilizing Cmake according to official websites instructions. So far so good. I have now implemented a very basic version of the first code example given in the book 'SFML game developement', which is a circle moving about when one of the 'wasd' keys is pressed.

Now this does work, however,  since I have not attempted to regulate the circle's speed, I would have expected it to move very rapidly. In reality it takes about 20 seconds for the circle to cross my screen.

I guess the program is very crudely implemented, also I do not have a dedicated graphics-card (my laptop has an Intel 4400 built in). Still I can't believe this sort of behavior is to be expected. I actually compiled the same program on another laptop running arch and the framerate increased about a hundredfold.

Is there anything I might be missing?

Here's the code, pretty much straight from the book.

//The game.h header
class Game
{
    public:
        Game();
        void run();

    private:
        void processEvents();
        void handlePlayerInput(sf::Keyboard::Key, bool);
        void update();
        void render();
   
        sf::RenderWindow mWindow;
        sf::CircleShape mPlayer;
       
        bool mIsMovingUp;
        bool mIsMovingDown;
        bool mIsMovingLeft;
        bool mIsMovingRight;
};


//The implementation
#include<SFML/Graphics.hpp>
#include "game.h"

Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application")
, mIsMovingUp(false), mIsMovingDown(false), mIsMovingLeft(false), mIsMovingRight(false)
, mPlayer()
{
    mWindow.setKeyRepeatEnabled(false);
       
    mPlayer.setRadius(40.f);
    mPlayer.setPosition(100.f, 100.f);
    mPlayer.setFillColor(sf::Color::Cyan);
}

void Game::run()
{
    while (mWindow.isOpen())
    {
        processEvents();
        update();
        render();
    }
}

void Game::render()
{
    mWindow.clear();
    mWindow.draw(mPlayer);
    mWindow.display();
}

void Game::processEvents()
{
    static sf::Event event;

    if (mWindow.pollEvent(event))
    {
        switch (event.type)
        {
            case sf::Event::KeyPressed:
                handlePlayerInput(event.key.code, true);
                break;
            case sf::Event::KeyReleased:
                handlePlayerInput(event.key.code, false);
                break;
            case sf::Event::Closed:
                mWindow.close();
                break;
        }
    }
}

void Game::handlePlayerInput(sf::Keyboard::Key key, bool isPressed)
{
    if (key == sf::Keyboard::W)
            mIsMovingUp = isPressed;

    else if (key == sf::Keyboard::S)
            mIsMovingDown = isPressed;

    else if (key == sf::Keyboard::A)
            mIsMovingLeft = isPressed;

    else if (key == sf::Keyboard::D)
            mIsMovingRight = isPressed;
}

void Game::update()
{
    sf::Vector2f movement(0.f, 0.f);

    if (mIsMovingUp)
        movement.y -= 1.0f;    
    if (mIsMovingDown)
        movement.y += 1.0f;
    if (mIsMovingLeft)
        movement.x -= 1.0f;
    if (mIsMovingRight)
        movement.x += 1.0f;

    mPlayer.move(movement);
}

//The main function
#include <SFML/Graphics.hpp>
#include "game.h"

int main()
{

    Game game;
    game.run();
   
    return 0;
}
 

Pages: [1]