Thread: [Plib-users] Don't Do This!
Brought to you by:
sjbaker
From: Steve B. <sjb...@ai...> - 2001-12-31 03:29:08
|
I'm not a happy person. :-( This is not so much a cry for help - as a warning for others in the future: I've been playing around with a multiplayer game (perhaps going in the direction of "Super Smash Bros'" on N64 and Game Cube). I've got to the point of dividing the screen into two, three or four chunks and rendering four cute little penguins - each of which can move independantly with a camera that follows along. I had all of it working with the controls for each player assigned from a config file (eg Player 1: MoveNorth = W, MoveSouth = Z, MoveEast = W, MoveWest = S Jump = Q, Fire = E Player 2: MoveNorth = I, MoveSouth = M, MoveEast = J, MoveWest = K Jump = U, Fire = O ...that kind of thing). So, if you are player 2, you hold down 'I' to move north, 'I' and 'J' together to move northwest. It all worked well in testing - but the first time my son and I tried to actually play together, we noticed that sometimes our keystrokes would be ignored. If player 1 moves NorthEast (holding down W and S) then the 'I' key (player 2's command to move North) wouldn't work. I puzzled about what might be wrong with my code - but eventually (after some questions to the LinuxGameDev mailing list and a bit of web surfing) discovered that this is a hardware limitation of the PC keyboard! Aaaaggghhhh!!!! I hadn't noticed it when testing because with just me pushing one or two keys, I never hit the combinations that cause problems. This suprised me a lot (which is why I'm writing this email - so that others don't fall into the same trap). The rule is approximately that if you hold down three keys that form the corners of a rectangle on the keyboards 'scan matrix' (E, C and I for example) then depending on the age of your keyboard, you'll either find that the third key you press will be ignored *or* the key at the fourth corner of that rectangle will appear to be pressed even though it isn't! I thought for a while about picking keys that didn't form the corners of such squares (eg E, C and G work at the same time) - but rapidly realised that I couldn't come up with anything remotely ergonomic in that way...not even for two players - let alone three or four! So now I have to rethink this in terms of two players using joysticks, one using the keyboard and another using the mouse. The trouble with that is that *very* few people have two joysticks and it's hard to make the controls fair when the players have different controllers. Grumble, grumble, grumble.... (If you want to try what I've written so far, you can grab it from: http://www.sjbaker.org/steve/tuxfighter.tgz ...the code is mostly from TuxAQFH - much cleaned up. Run it with "./src/tuxfighter -n 2" for two players, "-n 4" for four players, etc the control characters are displayed to stdout on startup and can be changed in data/players.dat - there is no way to use the numeric or arrow pads or function keys yet - but they have the same problems as the main keyboard). ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Christian M. <ma...@Ch...> - 2001-12-31 12:39:56
|
Steve Baker wrote: > > I puzzled about what might be wrong with my code - but eventually > (after some questions to the LinuxGameDev mailing list and a bit of > web surfing) discovered that this is a hardware limitation of the PC > keyboard! > > Aaaaggghhhh!!!! > > I hadn't noticed it when testing because with just me pushing one > or two keys, I never hit the combinations that cause problems. > > This suprised me a lot (which is why I'm writing this email - so that > others don't fall into the same trap). > > The rule is approximately that if you hold down three keys that form > the corners of a rectangle on the keyboards 'scan matrix' (E, C and I > for example) then depending on the age of your keyboard, you'll either > find that the third key you press will be ignored *or* the key at the > fourth corner of that rectangle will appear to be pressed even though > it isn't! > [...] Have you tried a USB keyboard? I could imagine that they aren't using the old style method. And if that doesn'T work it's possible to try 2 USB or 1 USB and 1 PS/2 keyboard, etc. CU, Christian -- The idea is to die young as late as possible. -- Ashley Montague Whoever that is/was; (c) by Douglas Adams would have been better... |
From: Steve B. <sjb...@ai...> - 2001-12-31 21:48:08
|
Christian Mayer wrote: > Have you tried a USB keyboard? I could imagine that they aren't using > the old style method. And if that doesn'T work it's possible to try 2 > USB or 1 USB and 1 PS/2 keyboard, etc. I don't think they'll be any different from the regular kind. The problem isn't in how the data is transmitted from the keyboard to the PC (that's basically just a serial protocol). The problem is that the decoder chip in the keyboard has only a limited number of pins (not one per key) so it has to scan the keyboard using a row-column setup. When you have two keys held down, two row lines are connected to two column lines. When you press down a third key that shared the same row as one of those keys and the same column as the other, there is no way for the keyboard controller chip to know which of the two keys were pressed. Since the controller doesn't know which you pressed, it sends neither of them (unless it's a really old keyboard controller chip - in which case it sends *both*...Eeeek!) I wrote up an Omniverous Biped FAQ item about this: http://www.sjbaker.org/steve/omniv/index.html ...check out "Keyboards Are Evil". ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: <ha...@sl...> - 2002-01-01 01:39:53
|
>I wrote up an Omniverous Biped FAQ item about this: > > http://www.sjbaker.org/steve/omniv/index.html > >...check out "Keyboards Are Evil". Now, not to disagree with what you've figured out, as I'm sure it's correct, but... Whats weird is I've seen several older windows games that did exactly this, with two players. One in particular was action based, kinda like a player versus player asteroids game. I wish I could remember the name. You picked a space ship (each had different speeds/weapons/etc). You had to thrust, rotate and fire - all sharing the same keyboard. -- Brian |
From: Steve B. <sjb...@ai...> - 2002-01-01 04:30:25
|
ha...@sl... wrote: > > >I wrote up an Omniverous Biped FAQ item about this: > > > > http://www.sjbaker.org/steve/omniv/index.html > > > >...check out "Keyboards Are Evil". > > Now, not to disagree with what you've figured out, as I'm sure it's > correct, but... Whats weird is I've seen several older windows games that > did exactly this, with two players. One in particular was action based, > kinda like a player versus player asteroids game. I wish I could > remember the name. You picked a space ship (each had different > speeds/weapons/etc). You had to thrust, rotate and fire - all sharing > the same keyboard. I didn't say it was impossible - if you pick the right keys, it can work. (eg Q,W,E,R as Turnleft/Thrust/TurnRight/Fire for player 1, Y,U,I,O as the same for player 2...that works just fine). Also, if you make the game so that a quick tap on the keyboard is all you need then it's *unlikely* (but not impossible) for something to go wrong. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Christian M. <ma...@Ch...> - 2002-01-01 13:33:04
|
Steve Baker wrote: > > ha...@sl... wrote: > > > > >I wrote up an Omniverous Biped FAQ item about this: > > > > > > http://www.sjbaker.org/steve/omniv/index.html > > > > > >...check out "Keyboards Are Evil". > > > > Now, not to disagree with what you've figured out, as I'm sure it's > > correct, but... Whats weird is I've seen several older windows games that > > did exactly this, with two players. One in particular was action based, > > kinda like a player versus player asteroids game. I wish I could > > remember the name. You picked a space ship (each had different > > speeds/weapons/etc). You had to thrust, rotate and fire - all sharing > > the same keyboard. > > I didn't say it was impossible - if you pick the right keys, it can work. > > (eg Q,W,E,R as Turnleft/Thrust/TurnRight/Fire for player 1, > Y,U,I,O as the same for player 2...that works just fine). Does the num pad count extra? If that's so than two players should be possible. CU, Christian -- The idea is to die young as late as possible. -- Ashley Montague Whoever that is/was; (c) by Douglas Adams would have been better... |
From: Steve B. <sjb...@ai...> - 2002-01-01 16:27:09
|
Christian Mayer wrote: > > Steve Baker wrote: > > > > ha...@sl... wrote: > > > > > > >I wrote up an Omniverous Biped FAQ item about this: > > > > > > > > http://www.sjbaker.org/steve/omniv/index.html > > > > > > > >...check out "Keyboards Are Evil". > > > > > > Now, not to disagree with what you've figured out, as I'm sure it's > > > correct, but... Whats weird is I've seen several older windows games that > > > did exactly this, with two players. One in particular was action based, > > > kinda like a player versus player asteroids game. I wish I could > > > remember the name. You picked a space ship (each had different > > > speeds/weapons/etc). You had to thrust, rotate and fire - all sharing > > > the same keyboard. > > > > I didn't say it was impossible - if you pick the right keys, it can work. > > > > (eg Q,W,E,R as Turnleft/Thrust/TurnRight/Fire for player 1, > > Y,U,I,O as the same for player 2...that works just fine). > > Does the num pad count extra? If that's so than two players should be > possible. If you look at my FAQ: http://www.sjbaker.org/steve/omniv/index.html You'll see a table at the bottom of the page showing (for my keyboards at least) what the decoder's matrix looks like. It predicts that holding down (for example) 'R' and 'T' will block 4,5,6,7,8,9 and + on the keypad...<tries it>...and it does! Really, no keys are immune to the effect. You just have to *carefully* pick keys that either all occupy different rows - or all occupy different columns. So, looking at that table in the FAQ, you'll see that there are 8 rows and 18 columns. Ack! I accidentally typed my table in 'sideways'...and I'm *certainly* not going to type it in again. Tables are a pain in HTML!. Conclusion: You can have at most 18 keys active in the game. However, it gets worse. Some columns of the matrix only have wierd keys like Left-Meta or Right-Meta that are something of a pain to read in most window libraries...and which can have unintended consequences. (You wouldn't want to write a game that could result in player 1 pressing Ctrl, Player 2 pressing Alt and Player 3 pressing Del or Backspace in the heat of the action!!) So, if we eliminate the columns containing only 'dangerous' keys, we have 14 or maybe 15 keys left (depending on what 'PrintScreen' does). That's certainly not enough for a four player mode for my game - and even in 3 player mode, one of the players has to uses SysRequest/PrintScreen as one of his keys in order to have 5 keys each - and I really wanted at least six keys per player (North,South,East,West,Jump,Fire) and had really hoped for something like 10 or 15 per player. So, I'm left with two player mode as the only possible setup and only seven keys each. I can do a *little* better by knowing that you won't often want to press North and South together - or East and West together...but still, I should try to ensure that when a player does that by mistake, it doesn't mess up his competitor. There would also be *easy* scope for covert cheating! Just hold down the right key combination to block the other player's Fire button! The game could actually detect that and flash up a "CHEAT!" warning. Another way to increase the number of commands per player would be to write the code in a way that would discourage holding some of the keys down for a long time. For example, if holding down the 'Jump' button for more than some small amount of time caused the player to trip and fall flat on his face, then I could use more than one key in that column, accepting the small probability of a short-term key lock-out. There is also the issue of i18n. There are at least a dozen keyboard layouts in the world - and some (such as the 'AZERTY' design which has A and Z where most people would expect Q and W to be) will need different key assignments...then there are people who remapped their keyboards and swapped the keycaps around to do a Dvorjak layout or something. Most worrying of all is that I've only tested this out on the four keyboards I have at home (Casio laptop, Fujitsu laptop and two different no-name ergonomic 'split' keyboards). There is no reason at all why some other brand might not have a different keyboard decoder with a different key matrix. The PC and it's software wouldn't care - but the combinations of keys that would lock out could be totally different. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Cameron M. <li...@to...> - 2002-01-01 00:06:45
|
* sjb...@ai... (Steve Baker) [2001.12.30 21:32]: > The rule is approximately that if you hold down three keys that form > the corners of a rectangle on the keyboards 'scan matrix' (E, C and I > for example) then depending on the age of your keyboard, you'll either > find that the third key you press will be ignored *or* the key at the > fourth corner of that rectangle will appear to be pressed even though > it isn't! Hmm...that is weird. > I thought for a while about picking keys that didn't form the corners > of such squares (eg E, C and G work at the same time) - but rapidly > realised that I couldn't come up with anything remotely ergonomic > in that way...not even for two players - let alone three or four! > > So now I have to rethink this in terms of two players using joysticks, > one using the keyboard and another using the mouse. You want four people using the same keyboard? Have you had too much egg nog? :-) Seriously though, I don't think I've ever played a PC game where more than two people used the keyboard at the same time, and it seems impracticle to think people would want to in the first place. Anyway, I wasn't aware of the goofy PC keyboard behavior you are brought up. Thanks for bringing it up... -- Cameron Moore |
From: Steve B. <sjb...@ai...> - 2002-01-01 00:23:03
|
Cameron Moore wrote: > > * sjb...@ai... (Steve Baker) [2001.12.30 21:32]: > > The rule is approximately that if you hold down three keys that form > > the corners of a rectangle on the keyboards 'scan matrix' (E, C and I > > for example) then depending on the age of your keyboard, you'll either > > find that the third key you press will be ignored *or* the key at the > > fourth corner of that rectangle will appear to be pressed even though > > it isn't! > > Hmm...that is weird. Yes - exactly. > You want four people using the same keyboard? Have you had too much > egg nog? :-) Well, no - but once you've written it for two players, it's only two more lines of code to allow three or four. > Seriously though, I don't think I've ever played a PC > game where more than two people used the keyboard at the same time... It emerges that there is a *reason* for that! :-( > and it seems impracticle to think people would want to in the first place. You'd be suprised what kids will do. We've played glTron that way - it's a blast! > Anyway, I wasn't aware of the goofy PC keyboard behavior you are brought > up. Thanks for bringing it up... I didn't want anyone else to suffer that amount of pain! ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Adam S. <ada...@ho...> - 2002-01-14 20:31:23
|
Hello All - > I've got to the point of dividing the screen into two, three or four=20 > chunks and rendering four cute little penguins - each of which can move > independantly with a camera that follows along. I had all of it workin= g > with the controls for each player assigned from a config file (eg=20 >=20 > Player 1: MoveNorth =3D W, MoveSouth =3D Z, MoveEast =3D W, MoveWest = =3D S > Jump =3D Q, Fire =3D E > Player 2: MoveNorth =3D I, MoveSouth =3D M, MoveEast =3D J, MoveWest = =3D K > Jump =3D U, Fire =3D O I've been thinking about this for a while, and as far as I can tell, this should work in all situations, except if a person tries to go north, south, and east or west at the same time, which shouldn't happen unless a player is really discombobulated: Player 1: MoveNorth =3D 2, MoveSouth =3D W, MoveEast =3D E, MoveWest =3D= Q Jump =3D 5, Fire =3D G Player 2: MoveNorth =3D 0, MoveSouth =3D P, MoveEast =3D [, MoveWest =3D= O Jump =3D 8, Fire =3D M Every once in a while, my fingers get a super power, and I'm able to hit <north or south>, <west or east>, Jump, and Fire for both players and it works! :-D Thanks for pointing that out! --=20 Real programmers don't comment their code. It was hard to write, it should be hard to understand. /|| Adam Seyfarth <http://members.home.net/adam.seyfarth/> ||\ = /"\ /=AB|| <cl...@us...> ASCII Ribbon, HTML-free email ||=BB= \ \ / \=AB|| GU d-- s+: a---- C++ UL+>+++ P-- L++ E-- W++ N++ o K- w-- ||=BB= / X \|| O M- V- PE- Y PGP- t 5 X R tv+ b+ DI+ D+ G e-- h! !r !y+ ||/ = / \ |
From: Steve B. <sjb...@ai...> - 2002-01-15 01:40:39
|
Adam Seyfarth wrote: > I've been thinking about this for a while, and as far as I can > tell, this should work in all situations, except if a person tries to go > north, south, and east or west at the same time, which shouldn't happen > unless a player is really discombobulated: > > Player 1: MoveNorth = 2, MoveSouth = W, MoveEast = E, MoveWest = Q > Jump = 5, Fire = G > Player 2: MoveNorth = 0, MoveSouth = P, MoveEast = [, MoveWest = O > Jump = 8, Fire = M Yes - that's not a bad set - I've been using: Player 1: MoveNorth = 2, MoveSouth = W, MoveEast = 3, MoveWest = 1 Jump = Q, Fire = E (With other moves mapped to 4/5/R/T) Player 2: MoveNorth = J, MoveSouth = M, MoveEast = K, MoveWest = H Jump = N, Fire = < (With other moves mapped to L/;/>/? ...and I've given up on the idea of four players. Because one player is confined to the top two rows and the other to the bottom two, they can't interfere with each other. They *can* lock themselves out of some keys (eg Jumping or shooting whilst moving South-East or South-West is bad). I think your combo avoids that - but it hurts my head to try to prove it! I have one of those sexy split keyboards (try one if you havn't - you'll never go back once you're used to it) - and this mapping works out nicely with each player confined to two rows and all the columns on one side of the split. The *ultra* bad news is that I have definite evidence that some PC keyboards are scanned differently from others so there probably isn't a bullet-proof combination that'll work for everyone. One of our no-name keyboards at work has Y,H,N and T,G,B on the same column scan and another has Y,H,N sharing with Q,A,Z - so I think I'm basically *doomed*. I'm just going to document what I know and make the keyboard controls completely programmable. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |