SFML community forums

Help => General => Topic started by: Dreamflask on February 21, 2015, 10:46:57 pm

Title: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Dreamflask on February 21, 2015, 10:46:57 pm
Hey guys,
currently i am in programming a map editor for a project and i programming it along with the SFML Game Development Book.
My problem is that when i load 65k tiles then my FPS is equal 1 ~ 2 ...
In my TileNode class i already checked if my tiles intersec with our view an it is working
void TileSprite::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const {
//Not the best way i know...
        sf::Vector2u wSize = target.getSize();
        sf::Vector2f vPos = target.getView().getCenter();
        sf::FloatRect rect{
                vPos.x - (wSize.x / 2.f), vPos.y - (wSize.y / 2.f), (float) wSize.x, (float) wSize.y
        };
        if (getBoundingRect().intersects(rect)) {
                target.draw(mSprite, states);
                target.draw(*mLayerDisplay, states);
                target.draw(*mPositionDisplay, states);
                target.draw(*mBlockDisplay, states);
        }
}

I really doesn't know why this FPS lag is occuring, but i can think it could happen from the derived class function:
void SceneNode::draw(sf::RenderTarget& target, sf::RenderStates states) const {
        // Apply transform of current node
        states.transform *= getTransform();
       
        // Draw node and children with changed transform
        drawCurrent(target, states);
        drawChildren(target, states);

        // Draw bounding rectangle - disabled by default
        drawBoundingRect(target, states);      
}

Can sombody help me to fix this?
I'm really saddened :S
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: eXpl0it3r on February 22, 2015, 12:26:55 am
65k tiles can be quite a number and it's not what the SFML Game Development book's code was written for.

Anyways one can speculate all you want but it's useless, because all you need for your problem is a profiler.
Run it through your debugger and you'll know where the bottleneck is.
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Glocke on February 24, 2015, 03:00:11 pm
because all you need for your problem is a profiler.
You're right. But those tipps can be hard to follow if you're new to the topic ;)

@Dreamflask: In case you don't know how to do, view http://www.thegeekstuff.com/2012/08/gprof-tutorial/ (http://www.thegeekstuff.com/2012/08/gprof-tutorial/). It also works with clang, but I haven't tested it on other system then linux.

Hope that helps :)
Kind regards
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: eXpl0it3r on February 24, 2015, 03:57:14 pm
Pointing out one possible tool doesn't really help either. What if no Linux is involved?

Debugging, profiling, linking, building, these are all things one need to master when learning C++ and the SFML forum does its best to help and yet we won't provide detailed guides on stuff people should already (partially) know when working with SFML. ;)
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Glocke on February 24, 2015, 04:14:37 pm
What if no Linux is involved?
I'm not suppose to be God :D Just giving my cent for some scenarios ^^

Debugging, profiling, linking, building, these are all things one need to master when learning C++ and the SFML forum does its best to help and yet we won't provide detailed guides on stuff people should already (partially) know when working with SFML. ;)
Of course. But many beginners do not struggle with all those topics - they want to start. I just want to help those to get started (in the particular scenario using Linux).
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Jesper Juhl on February 24, 2015, 10:03:38 pm
I fail to see your point.
Regardless of your goal and the OS / Compiler you are using it is a fact that in order to be able to successfully accomplish anything with C++ (and by extension SFML) you need to:
 - Know the difference between the pre-processing, compiling, assembling, linking and runtime phases of your program as well as what tools apply to which phase.
 - know how to operate a debugger
 - know how to operate a profiler
This applies regardless of using Linux, Windows, OS X as your OS and using GCC, Clang, ICC or VC as your compiler etc etc.
That's just basic stuff you have to know before you try writing professional code using C++ and before using external libraries (SFML or others).   Yes - lots of work - that's just how it is - nothing you can do but study ;-) ..
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Glocke on February 25, 2015, 08:54:07 am
I fail to see your point.
Regardless of your goal and the OS / Compiler you are using it is a fact that in order to be able to successfully accomplish anything with C++ (and by extension SFML) you need to.
My point is, that not eveybody who learns coding isn't that familar with all these tools and toolchains. The intend to start programming is making small pieces of software (e.g. small games). Working on "how to use the tools" before starting with the actual intend is hard from the point of motivation. So learning the tools while doing the actual intended activity seems more suitable for many beginners.
So, in my opinion starting with SFML without knowing about all tools (you might be able to use the debugger but not the profiler? that's ok!). The important fact is: Having the will to develop your own development skills (including tool knowledge). And helping beginners is (at least in my opinion) one of the goals of forums.

Of course "profile your code" is help. But I like to support beginners a bit more if possible.

Hope you understand (not accept at all; not necessary) my point now :) But I thing we shouldn't discuss this philosophy at this thread.... The author's intend was another one :)

Kind regards
Glocke
Title: Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
Post by: Jesper Juhl on February 25, 2015, 10:51:36 am
I get your point :)