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

Pages: [1]
1
General / Re: Confused About Performance
« on: February 05, 2014, 06:13:54 pm »
Vsync is disabled. The CPU is an A6-4400M (2.7Ghz). The GPU is a dual-graphics setup, with an HD 7520G + HD 7470 M. But, regardless, my issue isn't that SFML is performing poorly (200 FPS is fine and dandy); it's that it is performing extremely poorly relative to another program that should, in theory, be slower, despite the fact that it is actually doing even less. I will post the relevant sections of code below. Some things are commented out because they are disabled for testing purposes.

Initialization

#include "Game.h"
#include <iostream>
#include "GameObject.h"
#include "Player.h"
#include <sstream>

Game::Game() :
    state(State::PLAYING),
    window(sf::VideoMode(640, 480), "SFML window"),
    renderTexture(),
    renderSprite(),
    tickRate(30),
    fpsLimit(0),
    fpsUpdateTicker(0),
    fpsUpdateRate(0.5),
    fpsDrawLoopCounter(0),
    vSyncOn(false),
    gameUpdateTicker(0),
    secondsPassed(0),
    isRunning(true),
    gameClock(),
    world(),
    lastReportedFPS(0) {
    window.setFramerateLimit(fpsLimit);
    window.setVerticalSyncEnabled(vSyncOn);
    systemFont.loadFromFile("fonts/Arcadepix Plus.ttf");
}

Basic game loop

void Game::play() {
    state = State::PLAYING;
    while(isRunning) {
        secondsPassed = gameClock.getElapsedTime().asSeconds();
        gameClock.restart();
        //input();
        if (state == State::PLAYING) {
            gameUpdateTicker += secondsPassed;
            while (gameUpdateTicker >= 1.0 / tickRate) {
                gameUpdateTicker -= 1.0 / tickRate;
                //update();
            }
        } else if (state == State::PAUSED) {
            //pause the game
        }
        draw();
        fpsUpdate();
    }
    quit();
}

Draw function
void Game::draw() {
    fpsDrawLoopCounter++;
    window.clear();
    std::vector<GameObject *>::const_iterator it = world.get_objectList().begin();
    while (it != world.get_objectList().end()) {
        window.draw((**it).get_sprite());
        ++it;
    }
    std::stringstream ss;
    ss << "FPS: " << lastReportedFPS << std::endl;
    if (state == State::PAUSED) {
        ss << "PAUSED" << std::endl;
    }
    sf::Text fpsText(ss.str(), systemFont, 16);
    fpsText.setPosition(10, 10);
    window.draw(fpsText);
    window.display();
}

FPS counter

void Game::fpsUpdate() {
    fpsUpdateTicker += secondsPassed;
    if (fpsUpdateTicker > fpsUpdateRate) {
        fpsUpdateTicker -= fpsUpdateRate;
        lastReportedFPS = fpsDrawLoopCounter / fpsUpdateRate;
        fpsDrawLoopCounter = 0;
    }
}
 

Nothing else effects the code in a meaningful way. a Game object is created and .play() is called.

2
General / Confused About Performance
« on: February 05, 2014, 05:28:41 pm »
Hi.

I use Game Maker: Studio quite a bit for prototyping and rapid development, but I also have some experience with C++ and Python. I've been playing with SFML and implemented a window, sprite, and keyboard movement. It's all very basic. However, I've noticed that my Game Maker: Studio project runs at about 1000FPS on my hardware. Pretty damn fast. I figured a game written and compiled in C++ would be just a good, if not better (Game Maker: Studio uses a scripting language called GML). At 640x480, drawing one sprite, without double buffering or anything like that, I get about 950-960 FPS. Okay, so far so good. I'm surprised it's a bit lower, but it's not a big deal. However, when I maximize the window, I drop to 260 FPS. Again, this is while only drawing a single 32x32 image. Game Maker: Studio does not seem to suffer from this issue. My PySFML version, nets me about 350 FPS (it's about half as fast as the C++ version from what I can tell), but drops down to 150 FPS when I maximize the window.

I am lead to believe I have implemented something incorrectly, as such pitiful framerates without much drawing going on make the prospect of developing a full project dubious at best.

I've included the draw method from my C++ method. As you can see I also draw text to the screen in both versions. I am not the best C++ programmer, so I apologize if it's painful to read.

void Game::draw() {
    fpsDrawLoopCounter++;
    window.clear();
    std::vector<GameObject *>::const_iterator it = world.get_objectList().begin();
    while (it != world.get_objectList().end()) {
        window.draw((**it).get_sprite());
        ++it;
    }
    std::stringstream ss;
    ss << "FPS: " << lastReportedFPS << std::endl;
    if (state == State::PAUSED) {
        ss << "PAUSED" << std::endl;
    }
    sf::Text fpsText(ss.str(), systemFont, 16);
    fpsText.setPosition(10, 10);
    window.draw(fpsText);
    window.display();
}

Beyond this there is not much going on.

3
Python / Sprite without texture
« on: January 23, 2014, 03:16:30 am »
Perhaps I missed this in the documentation, but earlier I was trying to create a Sprite without a texture. I have a GameObject object which has a Sprite object, but I want to set the texture afterwards by pulling it from a texture manager (still not sure how I'm going to implement this). However, it seems I cannot create a Sprite without a texture! Why is this so? The C++ bindings allowed this. Using None creates a giant white square...

4
General / Re: Low FPS with ~1000 objects
« on: January 21, 2014, 07:36:37 pm »
The program can go slow because you're setting the radio, the position and color of each of the objects, each frame

You are correct Alejandro, and I had missed that. Moving the color out of the loop shot the fps way up. Above 60 with 5000 objects. Thanks.

5
General / Re: Low FPS with ~1000 objects
« on: January 21, 2014, 06:07:42 pm »
you must use vertexArrays to manage your objects better

This doesn't explain why Python can draw 4000 circles without a problem, but the C++ version (which is in release and optimized) performs worse with fewer. There is an error in my C++ code.

6
General / Re: Low FPS with ~1000 objects
« on: January 21, 2014, 05:05:29 pm »
It is because (most likely) you are making ~1000+ individual draw calls each frame to the GPU. You need to take a look at the vertex array tutorial to reduce your draw calls.  ;)

Huh... I'll have to do a bit of reading, because so far I don't really understand vertex arrays, and am confused as to how to get them to play nicely with sprites or, in this case, just a simple shape.\

UPDATE: So, I tried the Python bindings for SFML, and although my code isn't exactly the same, it has no problem drawing 2000 objects at 120fps. Whereas my C++ version barely manages 30fps. Clearly something is wrong here!

7
General / Low FPS with ~1000 objects
« on: January 21, 2014, 04:23:56 pm »
I'm relatively new to both C++ and SFML. I've been slowly working my way through building a small game, but I feel as though my FPS is much lower than it should be. I am using SFML2, and when running my game with 1000 instances of the Player object, I get ~30 fps. This seems very low to me when I read about people drawing tens of thousands of bouncing cubes before their framerate dips like that. It is possible that it is just a hardware limitation, but I would appreciate it if someone would look over my code. The instances are created in the constructor of the World object. I have included all the code as well as the C::B project file.

Here is my draw method. It is slightly modified from the version in the .zip. I have also disabled calls up update() for testing purposes. As a note, my Python version handles drawing 4000+ circles at 60fps.

void Game::draw() {
    fpsDrawLoopCounter++;
    window.clear();
    std::stringstream ss;
    ss << "FPS: " << lastReportedFPS << std::endl;
    if (state == State::PAUSED) {
        ss << "PAUSED" << std::endl;
    }
    sf::Text fpsText(ss.str(), systemFont, 16);
    fpsText.setPosition(10, 10);
    window.draw(fpsText);
    sf::CircleShape s;
    std::vector<GameObject *>::const_iterator it = world.get_objectList().begin();
    while (it != world.get_objectList().end()) {
        //window.draw((**it).get_sprite());
        s.setRadius(10);
        s.setPosition((**it).get_sprite().getPosition());
        s.setFillColor(sf::Color::Green);
        window.draw(s);
        ++it;
    }
    window.display();
}

https://www.dropbox.com/s/wg9skyyyw7st9z0/FirstGame.zip

Pages: [1]
anything