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

Author Topic: sf.Keyboard.is_key_pressed() expensive?  (Read 6245 times)

0 Members and 1 Guest are viewing this topic.

Veritas

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Email
sf.Keyboard.is_key_pressed() expensive?
« on: June 08, 2014, 10:15:15 pm »
I was wondering, is sf.Keyboard.is_key_pressed() expensive?
My tests lag considerably when there are 70+ controllable objects at a time (about 300 calls).
The profiler showed that 90% of the time was spent in the is_key_pressed() function so either I am doing something wrong or the function is expensive (after many calls that is).
"Lasciate ogni speranza, voi ch'entrate"

saluk

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: sf.Keyboard.is_key_pressed() expensive?
« Reply #1 on: August 07, 2014, 09:40:01 pm »
One question: Why do you have 70 objects checking for keypresses? What kind of game do you control 70 objects at a time?

If you really need to have this many objects controllable at once, you could optimize by saving the result of is_key_pressed each frame and just checking the variable.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf.Keyboard.is_key_pressed() expensive?
« Reply #2 on: August 07, 2014, 09:52:40 pm »
I can't understand why, in one cycle, you'd want to call isKeyPressed 300 times as it's highly unlikely that the keyboard has that many keys.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything