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

Author Topic: SFML Game Development Book (Scennode Pattern with 65k tiles)  (Read 2701 times)

0 Members and 1 Guest are viewing this topic.

Dreamflask

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML Game Development Book (Scennode Pattern with 65k tiles)
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #2 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/. It also works with clang, but I haven't tested it on other system then linux.

Hope that helps :)
Kind regards
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #3 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #4 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).
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #5 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 ;-) ..
« Last Edit: February 24, 2015, 10:31:18 pm by Jesper Juhl »

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #6 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
« Last Edit: February 25, 2015, 08:56:21 am by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML Game Development Book (Scennode Pattern with 65k tiles)
« Reply #7 on: February 25, 2015, 10:51:36 am »
I get your point :)

 

anything