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

Author Topic: SFML 2.0 Clock  (Read 4643 times)

0 Members and 1 Guest are viewing this topic.

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
SFML 2.0 Clock
« on: December 05, 2011, 06:16:24 pm »
I have recently switched from 1.6 to 2.0, and have spent lots of time debugging a lot of the changes you have made, (I like a lot of them!) and one thing I came across was sf::Clock::GetElapsedTime(). It used to return in a float, which I thought was really nice. It went even further than to the nearest millisecond, and never returned a 0.0f. With it returning a Uint32, it goes to the nearest millisecond, which makes me sad. :( Here's why.
I'm programming a server and client for a little game I'm making to mess around with. The server has a main thread constantly accepting new players, removing them, and updating them (with a mutex! :D) and then I have the second thread which is doing nothing but looping through and ticking all of the connected players. Everything was working fine, until I switched to sfml 2.0 with the clocks. I updated all of my floats to sf::Uint32 and because it returns with seconds, and my computer can tick everything so fast, it usually returns at 0, which makes everyone connected sit at a stand-still. (I would go back to sfml-1.6, but I really like 2.0 a lot better with the changes, and the pesky Socket.Bind(0); doesn't work with sfml-1.6. That's why I switched.)

So... I don't really know what to do with this problem. My people need to move, but I don't want a static number to move the players with.
Thanks for your help! :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 Clock
« Reply #1 on: December 05, 2011, 07:31:25 pm »
0 means less than 1 millisecond. Updating more than 1000 times per second is definitely a waste of CPU, just limit your update to something that makes sense, such as 60 ms if it's display, or even less if it's physics or network messages.
Laurent Gomila - SFML developer

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
SFML 2.0 Clock
« Reply #2 on: December 05, 2011, 09:09:16 pm »
Alright. That's understandable. Thanks! =D
Also, I do want to say something else about the threading in 2.0. I get lots of weird results when I try to make a thread sometimes. Last night I spent like an hour just trying to make a thread. I didn't know you had to get rid of the parameters of your function to pass a thread on it. I found it out last night through trial and error. :P But when I do the same thing on the client, it tells me something about invalid parameters on with a functor. I don't know what's causing it, but if you'd like an error message with some source, I could give it to you. :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 Clock
« Reply #3 on: December 05, 2011, 09:25:10 pm »
Have you read the documentation? Everything's clearly explained.
Laurent Gomila - SFML developer

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
SFML 2.0 Clock
« Reply #4 on: December 05, 2011, 09:40:37 pm »
Well, I remembered the documentation after I fixed the thread the first time, last night. I tried it again this morning, and it doesn't work. The only difference between the two programs is when I try to make the thread in a class function, it doesn't work, and won't let me run it on another class function.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 Clock
« Reply #5 on: December 05, 2011, 10:32:18 pm »
Can you show your code?
Laurent Gomila - SFML developer

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
SFML 2.0 Clock
« Reply #6 on: December 09, 2011, 09:15:47 pm »
Well, It's all in a class called "Core" Which does most of my stuff in my game. I don't really like doing it all in the main function/file.
I get this error (In Code::Blocks)
Code: [Select]
||=== Client, Debug ===|
In member function 'void sf::priv::ThreadFunctor<T>::Run() [with T = void (Core::*)()]':|Core.cpp|152|instantiated from here|
c:\sfml\sfml2\include\SFML\System\Thread.inl|39|error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctor<void (Core::*)()>*)this)->sf::priv::ThreadFunctor<void (Core::*)()>::myFunctor (...)', e.g. '(... ->* ((sf::priv::ThreadFunctor<void (Core::*)()>*)this)->sf::priv::ThreadFunctor<void (Core::*)()>::myFunctor) (...)'|
||=== Build finished: 1 errors, 0 warnings ===|

My code is
Code: [Select]
sf::Thread networkingThread(&Core::thread);
    networkingThread.Launch();
Inside my initialization function. I tried getting rid of the Core:: in front of it, since it's already declared in the header file..
Idk. Maybe I'm doing something really stupid and I can't make threads inside classes, but it doesn't seem like it should be a problem..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 Clock
« Reply #7 on: December 09, 2011, 09:19:17 pm »
Read the sf::Thread doc please. Especially this part:
Quote
// example 2: member function

There's an example so you can clearly see what's wrong in your own code.
Laurent Gomila - SFML developer

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
SFML 2.0 Clock
« Reply #8 on: December 09, 2011, 09:39:40 pm »
Doah...  :( I'm sorry for my stupidity... Haha.  :oops:

 

anything