Hi everyone,
tl;dr : is this normal ?
First of all, let me say SFML is a great library.
I've started to read this great book here :
https://www.packtpub.com/game-development/sfml-game-developmentI really like the overall architecture which is developped in this book, and the philosophy behind it. I even agree on most of your formatting style choices ! Ahaha.
Anyway I'm now delving into chapter 4 (input handling) and noticed I had slow FPS when drawing my background texture, which by the way seems to repeat itself badly (see the picture)
You can see I'm running
46 FPS and that I have a black line on top of every desert picture.
Now if I comment the code section where I add that background to the scene graph, here is what happens :
void World::_buildScene()
{
// Init layers
for (std::size_t i = 0; i < LayerCount; ++i)
{
SceneNode::Ptr layer(new SceneNode());
_sceneLayers[i] = layer.get();
_sceneGraph.attachChild(std::move(layer));
}
// Init background
//sf::Texture & texture = _textures.get(Textures::Desert);
//sf::IntRect textureRect(_worldBounds);
//texture.setRepeated(true);
// Adding background sprite
//std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode{texture, textureRect});
//backgroundSprite->setPosition(_worldBounds.left, _worldBounds.top);
//_sceneLayers[Background]->attachChild(std::move(backgroundSprite));
// Adding player aircraft
std::unique_ptr<Aircraft> leader(new Aircraft{Aircraft::Eagle, _textures});
_playerAircraft = leader.get();
...
As you can see I'm now running at
more than 450 FPS.
I guess I could hope for a small improvement on the FPS rate, removing my background texture, but it seems quite exagerated.
Here is how SpriteNodes are drawn :
void SpriteNode::_drawCurrent(sf::RenderTarget & target, sf::RenderStates states) const
{
target.draw(_sprite, states);
}
Here is how ScenesNodes are updated and drawn (SpriteNode inherits from them) :
void SceneNode::_updateCurrent(sf::Time)
{
// lel
}
void SceneNode::_updateChildren(sf::Time dt)
{
for (const Ptr & child : _children)
child->update(dt);
}
void SceneNode::draw(sf::RenderTarget & target, sf::RenderStates states) const
{
states.transform *= getTransform();
_drawCurrent(target, states);
_drawChildren(target, states);
}
void SceneNode::_drawCurrent(sf::RenderTarget &, sf::RenderStates) const
{
}
void SceneNode::_drawChildren(sf::RenderTarget & target, sf::RenderStates states) const
{
for (const Ptr & child : _children)
child->draw(target, states);
}
If you haven't read this book, believe me it's really cool !
You can see how background is loaded in that method I've commented earlier.
I'm compiling using mingw-w64 under msys2 on Windows. I've compiled SFML myself using this toolchain. I've got a poor PC though, having an i3 @ 1.90Ghz and one of those NVIDIA GeForce 710M.
My question is :
Have I done something wrong, or is it the best performance I can achieve given my system ?Thanks for your time,
Artexflow
(I'm obviously sorry if this has no place in this forum section)