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

Author Topic: Main while loop is not executing  (Read 7611 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #15 on: January 22, 2013, 08:37:23 pm »
I know I'm not supposed to use macro's, but that isn't going to solve the problem now, is it?

Granted that it may not solve the problem, but still it doesn't hurt. It's better to cultivate good habits than bad ones.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #16 on: January 22, 2013, 08:41:37 pm »
Os and compiler? Did you try using debugger to see if the code executes?
The fact that adding line to the loop fixes it makes me think you have your compiler settings wrong and it optimized out entire loop for some reason. I'm probably wrong but that'd be really cool.

Quote
So? You can do all the 3D magic with OpenGL and use SFML just as context creator and optional audio output. ;)
But then you'd not use clear(), especially not in sf::Window :)
Quote
Where's the pure C when he's using SFML, a C++ library? (I probably didn't get that joke...)
Knowing c++ isn't prerequisite for knowing OpenGL, he might be experienced C coder, migrating to c++. Joke: Carmack had around 10 years of experience in OpenGL and C and none in c++ at the point of beginning id tech 4(Doom 3, Quake 4, everything before was just C) engine that was his (company) first real c++ project.

If you want to reply to that send me a pm, enough goofing in this thread.
« Last Edit: January 22, 2013, 08:50:49 pm by FRex »
Back to C++ gamedev with SFML in May 2023

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Main while loop is not executing
« Reply #17 on: January 22, 2013, 09:15:18 pm »
os is windows, and i'm using visual studio c++ professional 2012.
If this would be a compiler setting (which I actually would doubt), what could I do to change it?
In debugger the code does execute and updates the title.

// edit
Another thing I just realised:
If I do add a line which prints out some text, I get a very high amount of frames per second (over a 1000). even though vertical sync is set on. Shouldn't vertical sync limit it to 60 frames?
« Last Edit: January 22, 2013, 09:20:59 pm by genzm »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #18 on: January 22, 2013, 09:22:40 pm »
Use sf::Time instead of unsigned and do +=clock.restart() on it, you can compare them easily too, you can do like time<=sf::miliseconds(FPS_PDATE) or something. I suspect your loop goes over 1000x per second, miliseconds get truanced in C/C++ int way to 0 and debugger stepping slowed that down and let clock build few miliseconds up. If you don't know what change I'm talking about tell me and I'll make change for you to try.

Vsync can be forced off in setting for GPU and I think it only affects fullscreen.
Back to C++ gamedev with SFML in May 2023

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Main while loop is not executing
« Reply #19 on: January 22, 2013, 09:27:08 pm »
Use sf::Time instead of unsigned and do +=clock.restart() on it, you can compare them easily too, you can do like time<=sf::miliseconds(FPS_PDATE) or something. I suspect your loop goes over 1000x per second, miliseconds get truanced in C/C++ int way to 0 and debugger stepping slowed that down and let clock build few miliseconds up. If you don't know what change I'm talking about tell me and I'll make change for you to try.

Vsync can be forced off in setting for GPU and I think it only affects fullscreen.

I'm not really sure what you want to change. But indeed, when using
window.setFramerateLimit(60);
It all works just fine. I still don't really see why this solves my problem, but I'm glad I'm getting some progress.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #20 on: January 22, 2013, 09:30:01 pm »
sf::Time fps_counter;
while (true)
    {
        fps_counter += c.restart();
        ++fps;
        if(fps_counter >= sf::milliseconds(FPS_REFRESH)) {
            char buffer[32];
            int av = (int) (fps * 1000) / fps_counter.asMiliseconds();
            sprintf(buffer, "%d - frames per second", av);
            window.setTitle(buffer);

            // reset
            fps_counter = sf::Time::Zero;
            fps = 0;
        }

        //draw();

        window.display();
    }
Back to C++ gamedev with SFML in May 2023

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Main while loop is not executing
« Reply #21 on: January 22, 2013, 09:34:49 pm »
Oh, I see, like that :P

I tried it and it executes the loop. This is off course a better use than a simple integer.
Thanks for the tip.
But I still don't really understand why this fixed it :/

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #22 on: January 22, 2013, 09:36:53 pm »
1. Loop is going too fast, clock gains some fraction of milisecond.
2. Get that fraction as int = rounded down to 0.
3. Reset Clock.
4. Repeat.

Console io, debugger and setFramerateLimit slowed loop down enough to build up more than fraction of milisecond in clock so it wasn't truanced to 0.
Back to C++ gamedev with SFML in May 2023

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Main while loop is not executing
« Reply #23 on: January 22, 2013, 09:40:09 pm »
Ok, this would explain why the title isn't updated.
But the rest of the loop (the commented draw() function), and other steps like controls,...
They should still be executed?

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Main while loop is not executing
« Reply #24 on: January 22, 2013, 09:42:13 pm »
Yes, and display() is getting executed.
Back to C++ gamedev with SFML in May 2023

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Main while loop is not executing
« Reply #25 on: January 22, 2013, 09:44:52 pm »
Oh no sorry, I see.
The functions I wrote for example to check controls, all used this int to know the difference in time. Since there was no difference, nothing changed.
So, that's solved :P
Thanks for all the help everyone. I wouldn't have found it by myself.

 

anything