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

Author Topic: sf::RenderWindow draw() not updating sf::Sprite move() (Player movement).  (Read 1933 times)

0 Members and 1 Guest are viewing this topic.

Snizzlenose

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
I'm trying to separate my code into different threads, using C++11 <thread>, namely player movement to make it consistent and not dependent on the speed of  the game loop. 
The game builds and runs in debug mode (VS2013) but the problem I'm facing is that my player sprite's position, a red rectangle, is not being updated on my window despite it's position is getting registered back-end, printing my test outputs in the console, and interacting with my collision function. 
The movement works when I put world.player.movement in the game loop (note: not world.movement). 
Any ideas why it doesn't work and suggestions to fix it?

Github link: https://github.com/Snizzlenose/2D-SFML-shooter 

main.cpp
(click to show/hide)

World.h 
(click to show/hide)

World.cpp 
(click to show/hide)

Player.h 
(click to show/hide)

Player.cpp 
(click to show/hide)

Ground.h 
(click to show/hide)

Ground.cpp 
(click to show/hide)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10990
    • View Profile
    • development blog
    • Email
I'm trying to separate my code into different threads, using C++11 <thread>, namely player movement to make it consistent and not dependent on the speed of  the game loop.
Don't.

You may think it's a good idea and may think it will make things "independent", but truth is, it will make everything a lot more complicated and it won't even be independent.
Multi-threading is an advanced topic and needs a lot of knowledge on synchronization and parallel programming in general. Additionally you need to have all the object's logic updated before rendering a frame, thus making the whole parallel part totally useless.

There are a lot of threads on the forum talking about if you're interested.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Snizzlenose

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
I'm trying to separate my code into different threads, using C++11 <thread>, namely player movement to make it consistent and not dependent on the speed of  the game loop.
Don't.

You may think it's a good idea and may think it will make things "independent", but truth is, it will make everything a lot more complicated and it won't even be independent.
Multi-threading is an advanced topic and needs a lot of knowledge on synchronization and parallel programming in general. Additionally you need to have all the object's logic updated before rendering a frame, thus making the whole parallel part totally useless.

There are a lot of threads on the forum talking about if you're interested.

Oh okay, I figured threads was a set and forget kind of thing, but if they need a lot more work, they're unneeded for a simple game like mine. 
Should I worry about player movement being inconsistent as more computation is required in the main gameloop, as I'm essentially teleporting the sprite every loop individual loop?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor