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 - nominos

Pages: [1]
1
System / Re: multi-threaded drawing
« on: June 03, 2014, 06:38:10 pm »
Looks dangerous. No synchronization between the threads.

Why do you even need/want threads?
Unless you have a very good use-case/strong need for threads (and experience with them and C++) then they are very likely to cause you far more trouble than gain.

See also:
 http://en.sfml-dev.org/forums/index.php?topic=15018.msg106017#msg106017
 http://en.sfml-dev.org/forums/index.php?topic=14113.msg100559#msg100559
I probably need to read more about threads.. I thought that they are much easier.

The reason why I want threads is that I can simplify my code and more importantly to speed up the game because I have to do CPU-intensive stuff like path finding.

2
System / multi-threaded drawing
« on: June 03, 2014, 06:10:51 pm »
Why isn't the code below working correctly? By not working I mean that it isn't fluent like if I would manage everything in the main thread. I just want to seperate the game logic and the rendering. I am very new to SFML and threads in general. Could somebody help me here? Thanks!

Code: [Select]
#include <SFML/Graphics.hpp>

void renderingThread(sf::RenderWindow* window, sf::Shape* shape)
{
    while (window->isOpen())
    {
        window->clear();
        window->draw(*shape);
        window->display();
    }
}

int main()
{
    // create the window (remember: it's safer to create it in the main thread due to OS limitations)
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    // deactivate its OpenGL context
    window.setActive(false);

    // launch the rendering thread
    sf::Thread thread(std::bind(&renderingThread, &window, &shape));
    thread.launch();

    while (window.isOpen())
    {
            shape.move(0.000001f,0.f);
    }

    return 0;
}
(code is taken from http://www.sfml-dev.org/tutorials/2.1/graphics-draw.php#drawing-from-threads and http://www.sfml-dev.org/tutorials/2.1/start-linux.php#compiling-a-sfml-program)

Pages: [1]
anything