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

Pages: [1]
1
General / Re: Drawing 100 items per frame cuts FPS by 400?
« on: December 18, 2012, 02:53:52 pm »
I stand corrected.  Thanks for catching that :P

2
General / Re: Drawing 100 items per frame cuts FPS by 400?
« on: December 18, 2012, 01:57:38 pm »
So, I'm getting:
100 FPS in Release mode with my code
350 FPS in Release mode with your code with the better memory management

I knew that I was being careless with allocation and deallocation each frame, but didn't think it had too huge of a bearing on my outcome.  This test shows me that my CPU/GPU specs are much more of a limiting factor since you're seeing a 10 times faster frame rate with the same code.

Also, I was only deleting things that I had allocated with 'new' (the two char[] pointers).  Unless you mean the things that were being implicitly deleted in my drawString() method every time the method ended and they went out of scope?  Are those implicit deallocations more costly?

Thanks for the help!

3
General / Drawing 100 items per frame cuts FPS by 400?
« on: December 18, 2012, 05:00:23 am »
Hi, I'm new to both SFML and C++ development (from C#/Java background) and I want to know if I'm doing something wrong that is negatively affecting my frame time.
I have a method that draws the current FPS in a new sf::Text, and I call this method ~100 times per frame.  This brings the app to 100 FPS.  However, when I was drawing the sf::Text object 1 time per frame, I was seeing 500 FPS.

This FPS drop is way more dramatic than I expected.  If this were a 2D tile-based game that has 10x10 tiles in your line-of-sight, that could be 100 sprites drawn per second and when you consider the Tile layer, Item layer, Player layer, Effects layer... I don't see how this would handle it.  That is unless drawing Sprites is somehow much cheaper/faster.

I'm using Windows XP, Visual C++ 2010 Express.
Dell Inspiron 6000 laptop (7 years old?), Intel processor 1.73GHz, integrated graphics.

Are CPU and GPU specs my problem?  :-X

#include <cstdlib>
#include "stdafx.h"
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\System.hpp"
#include "SFML\System\Time.hpp"
using namespace std;

void drawString(std::string s, float x, float y, sf::RenderWindow* window)
{
        sf::String sfString(s);
        sf::Text sfText;
        sfText.setString(sfString);
        sfText.setPosition(x,y);
        (*window).draw(sfText);
}
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
        sf::RenderWindow *pwindow = &window;
        window.setVerticalSyncEnabled(true); // call it once, after creating the window
        sf::Clock fps_clock;
        while(window.isOpen())
        {
                window.clear(sf::Color::Black);
                // show fps
                char *fps_str = new char[30];
                char *ct_str = new char[30];
                float frame_time = fps_clock.restart().asSeconds();
                float fps = 1.f / frame_time;
                sprintf(fps_str, "FPS: %.1f", fps);
                // draw text a few times...
                for(int i=0; i<19; i++)
                        for(int j=0; j<5; j++)
                                drawString(fps_str,j*160,i*30, pwindow);
                delete fps_str;
                delete ct_str;
                window.display();
                sf::sleep(sf::milliseconds(0));
        }
        delete pwindow;
        return 0;
}

Pages: [1]
anything