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

Author Topic: [SOLVED]disabling text causes fps drop  (Read 1499 times)

0 Members and 1 Guest are viewing this topic.

Grabek

  • Newbie
  • *
  • Posts: 5
    • View Profile
[SOLVED]disabling text causes fps drop
« on: July 18, 2018, 01:17:15 pm »
I'm programming a simple game in SFML/C++/Code::blocks. I wrote a simple "dev-console" which basically prints out in the corner fps, position, number of logic/ graphics loops etc. Everything works fine until I hide it, then fps fall down from 60(blocked max) to around 15. Why disabling writing function causes so much fps drop? (shouldn't disabling it speed things up a little?)

Declarations:

sf::Text consoletxt;
sf::Font font;
if (!font.loadFromFile("Times_New_Roman.ttf"))
    std::cout<<"Error loading font Times New Roman"<<std::endl;
consoletxt.setFont(font);
consoletxt.setFillColor(sf::Color(255,255,255,255));
consoletxt.setCharacterSize(14);
consoletxt.setOutlineColor(sf::Color(0,0,0,192));
consoletxt.setOutlineThickness(1);
bool console = true;

Code below: upon switching console = false; fps drops from 60 to 15

tm = t.asMilliseconds();
    fps += 1000/tm;
    if (console == true)
    {
        consoletxt.setString("Last loop time: " + doubleToString(tm));
        consoletxt.setPosition(0,0);
        window.draw(consoletxt);
        consoletxt.setString("Fps: " + intToString(1000/tm) + " Average fps: " + intToString(fps/logicLoops));
        consoletxt.setPosition(0,15);
        window.draw(consoletxt);
        consoletxt.setString("objects[0].x: " + doubleToString(objects[0].x));
        consoletxt.setPosition(0,30);
        window.draw(consoletxt);
        consoletxt.setString("objects[0].y: " + doubleToString(objects[0].y));
        consoletxt.setPosition(0,45);
        window.draw(consoletxt);
        consoletxt.setString("Angle radians/degrees: " + doubleToString(cam_angle) + " | " + intToString((int)(cam_angle*180/pi)));
        consoletxt.setPosition(0,60);
        window.draw(consoletxt);
        consoletxt.setString("Logical Loops: " + doubleToString(logicLoops) + " Graphics loops: " + doubleToString(graphicsLoops) + " Difference: " + doubleToString(logicLoops - graphicsLoops - 1));
        consoletxt.setPosition(0,75);
        window.draw(consoletxt);
        consoletxt.setString("Variable test: " + doubleToString(cos(cam_angle*180/3.1415)));
        consoletxt.setPosition(0,585);
        //window.draw(consoletxt);
    }
« Last Edit: July 19, 2018, 06:34:20 pm by Grabek »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: disabling text causes fps drop
« Reply #1 on: July 18, 2018, 01:23:27 pm »
How do you display the FPS output if you hide the console?
Laurent Gomila - SFML developer

Grabek

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: disabling text causes fps drop
« Reply #2 on: July 18, 2018, 01:27:18 pm »
I'm seeing "tearing", pretty easy to notice when fps drops from 60 to 15.
I've read fps by moving it's displaying function, out of console scope.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: disabling text causes fps drop
« Reply #3 on: July 18, 2018, 01:31:31 pm »
Quote
I've read fps by moving it's displaying function, out of console scope.
Can you show the code? Did you change anything else?
Laurent Gomila - SFML developer

Grabek

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: disabling text causes fps drop
« Reply #4 on: July 18, 2018, 01:48:10 pm »
I've commented out rest of the code part by part, to check whether something else causes this fps drop. It points out, that this 'if block' somehow causes this drop, but I have no idea why hiding it causes this drop? If it is hidden, then less operations are being performed, so why fps drops?

I've tried to move parts of code from if block, out of it. But it gives non linear expectations. Like every single line of text hidden, causes squared impact.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: disabling text causes fps drop
« Reply #5 on: July 18, 2018, 02:00:31 pm »
It's hard to help without more information. You should try to provide a complete and minimal code that reproduces the problem.

As you said, performances should not drop when you draw less stuff, so there's something strange and it probably hides somewhere else in your code.
Laurent Gomila - SFML developer

Grabek

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: disabling text causes fps drop
« Reply #6 on: July 19, 2018, 03:23:02 pm »
I updated SFML from 2.4 to current 2.5 and it seems it was some kind of SFML malfunction. But know, although switching console on and off doesn't influence FPS, it stays at steady 37. Strange thing is, that in debug mode fps is steady 60 and in release it's 37. Why debug mode is running better? I'm using code::blocks IDE.
Thank you for answer, especially you Laurent.

Grabek

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: disabling text causes fps drop
« Reply #7 on: July 19, 2018, 06:33:17 pm »
Problem solved. Updating SFML from 2.4 to 2.5 helped. Plus (what's worth pointing out) version 2.5 should NOT have "jpeg" in dependency!

 

anything