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

Pages: [1]
1
General / Re: Simple math
« on: August 07, 2020, 10:21:40 pm »
I know the boolean operator || in programming generally means OR ("if A || B is true do...") so I think this wouldn't compile on a program. I think this forum is meant for questions related to SFML and such, so I don't think you'll get much help here. Maybe try reddit? Sorry bud.

2
General / Re: Threading problem
« on: August 05, 2020, 05:53:15 pm »
Threading did add some problems. My project is an adaptation of the tinyraycaster by ssloy on github, which takes a 2D maze and creates a crude 3D view of inside the maze a la 1980's FPS. I think the concurrent access is to blame for why the walls now ripple when I move ::). I didn't know how threads handled arguments or about std::ref. Thank you, Laurent.

3
General / Threading problem
« on: August 05, 2020, 04:05:44 pm »
I am using Windows 10, Visual Studio IDE
I've been trying to experiment with threading in a practice project that I tinker with. I'd like to make a separate thread to handle mouse/keyboard input via a function:

void PlayerInput(sf::RenderWindow& window, float& player_x, float& player_y, float& player_a, float& player_ya) {
    if (sf::Mouse::getPosition(window).x < 100) { player_a -= 3.5 * M_PI / 360; }
    if (sf::Mouse::getPosition(window).x > 900) { player_a += 3.5 * M_PI / 360; }
    if (sf::Mouse::getPosition(window).y < 100) { player_ya += 3.5 * M_PI / 360; }
    if (sf::Mouse::getPosition(window).y > 400) { player_ya -= 3.5 * M_PI / 360; }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
        player_x += .08 * cos(player_a);
        player_y += .08 * sin(player_a);
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
        player_x -= .08 * cos(player_a);
        player_y -= .08 * sin(player_a);
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
        player_x -= .08 * cos(player_a + (M_PI / 2));
        player_y -= .08 * sin(player_a + (M_PI / 2));
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
        player_x -= .08 * cos(player_a - (M_PI / 2));
        player_y -= .08 * sin(player_a - (M_PI / 2));
    }
...

std::thread thread1(PlayerInput, window, player_x, player_y, player_a, player_ya);

However, whenever I put this into a std::thread, I get several errors like "failed to specialize function template", "no matching overloaded function found", "no overloaded function takes 6 arguments". If I try sf::Thread it complains that 'no instance of constructor "sf::Thread::Thread" matches argument list' " I understand that threads are fairly advanced, but is there an easy explanation for what I'm doing wrong? Is it because the window is one of the arguments? The function works fine outside of a thread.

Pages: [1]