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

Author Topic: sf::Key::Code::Count issue  (Read 8854 times)

0 Members and 2 Guests are viewing this topic.

MrDoomMaster

  • Newbie
  • *
  • Posts: 26
    • View Profile
sf::Key::Code::Count issue
« on: February 04, 2008, 08:17:40 pm »
Hi,

I may be completely misunderstanding something, but the sf::Key::Code::Count enumerated member doesn't seem valid. For most of the enumerations in sf::Key::Code, they've been given explicit values. Thus, the 'count' member actually gives a number over 300, when there are only about 60+ enumerations.

This seems like an error and I thought I'd bring it up.

Lord Delvin

  • Jr. Member
  • **
  • Posts: 68
    • ICQ Messenger - 166781460
    • View Profile
sf::Key::Code::Count issue
« Reply #1 on: February 04, 2008, 08:45:58 pm »
its not an error, as there are unnamed keys.
In my tuned version i've set this to 0xFFFF to be able to get keys with unicode names;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Key::Code::Count issue
« Reply #2 on: February 05, 2008, 02:16:47 am »
Yep, this is actually just an upper bound, not the exact count of keys. It's mostly used when you want to define an array of keys.
Laurent Gomila - SFML developer

MrDoomMaster

  • Newbie
  • *
  • Posts: 26
    • View Profile
sf::Key::Code::Count issue
« Reply #3 on: February 05, 2008, 06:11:03 pm »
Quote from: "Laurent"
Yep, this is actually just an upper bound, not the exact count of keys. It's mostly used when you want to define an array of keys.


Yes, but it is inconsistent and misleading. I was using it to generate an array of key presses. Normally a "count" member in an enumeration is a count of all physical members in the enumeration. A prerequisite of this is that all of the enumerated members be numbered in ascending order starting from 0.

If you take a look at the other enumerations in the same file, you'll notice that the 'count' member actually does represent the physical count of enumeration members.

Now that you've explained the purpose of the Count member in Key::Code I understand that it isn't a bug. However it might be a good idea to create a detailed comment for that member. It deserves some textual explanation since, as I've pointed out, it is inconsistent.

I'm also curious why you even explicitly assign values to the enumerations. SFML is supposedly portable, so I don't think you are mapping them to Microsoft Virtual Key Codes. It also seems like SFML supports other key inputs that aren't explicitly defined in the Key::Code enumeration (I'm judging this by the implementation of the enum, it skips large ranges of numbers).

Thanks for your feedback. If you could address my few other questions I don't believe this would be an issue for me anymore.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Key::Code::Count issue
« Reply #4 on: February 06, 2008, 01:52:07 am »
In fact, the only reason is to map characters code to their ASCII code (sf::Key::A == 'a').

As the value of 'a' and all other characters can't be known (it could be 97 with ASCII, or something else with EBCDIC), I just can't fill the gaps with other codes and need to restart from a safe upper bound for the other values of the enum, which is 256 (I guess I could use 128 as well).
Laurent Gomila - SFML developer

MrDoomMaster

  • Newbie
  • *
  • Posts: 26
    • View Profile
sf::Key::Code::Count issue
« Reply #5 on: February 06, 2008, 05:59:12 pm »
Quote from: "Laurent"
In fact, the only reason is to map characters code to their ASCII code (sf::Key::A == 'a').

As the value of 'a' and all other characters can't be known (it could be 97 with ASCII, or something else with EBCDIC), I just can't fill the gaps with other codes and need to restart from a safe upper bound for the other values of the enum, which is 256 (I guess I could use 128 as well).


Why not allow your key code enumerations to be automatically numbered by the compiler? Is there actually a specific reason to assign the ASCII values?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Key::Code::Count issue
« Reply #6 on: February 07, 2008, 02:03:12 am »
It's just good to be able to directly convert to the corresponding character -- when it's a character.
Laurent Gomila - SFML developer

 

anything