Page 1 of 1
KeyPress' onReleased alternative
Posted: Tue Dec 09, 2008 2:37 pm
by turshija
Here is my way of onReleased alternative ...
I am sure there is something more elegant and better Kjell and JPH are using...

Posted: Tue Dec 16, 2008 2:25 pm
by Kjell
Hi turshija,
Attached ( both exe and source ) is the system I have been using* for quite some while now. The example uses the following structure.
Input[Slots,Keys,Events]
- Slots being the amount of Player Slots you want to support.
- Keys being the amount of Keys you want to check.
- Events being the amount of Events each Key uses.
Since there's currently no function to read out the length of one of the dimensions a array has, the lengths are stored in Constants. In the example this is InputSlots = 2 ( for 2 Players ), InputKeys = 4 ( 4 Keys each, Arrow keys for P1 / WASD for P2 ) and InputEvents = 4 ( 4 Events per Key ).
Event[0] is just the current state of the Key, in Event[3] ( which is referred to as InputEvents-1 ) the state of the Key as it was the last frame is stored, while Event[1] is reserved for a OnPressed event, and Event[2] for OnReleased.
The EXE uses a low framerate ( 15 fps ) to make the OnPressed / OnReleased and LastFrame values more easy to distinguish.
Have fun ~
K
*Didn't work in Beta 1.9.4 because of a 3D Array bug, make sure you get 1.9.5
Posted: Tue Dec 16, 2008 2:43 pm
by turshija
dude, I'm always amazed by your ideas ...
When will you release something ?

I'm sure you have something really nice somewhere on your hard disk ...

Posted: Tue Jan 06, 2009 10:55 pm
by Kjell
Since the 2009 Beta release and the introduction of the "For-statement" you can just use ZExpressions ( without any repeat components ) to reset and process the values. So for the provided example ..
Reset
Code: Select all
for(U=0; U<Input.SizeDim1; ++U)
{
for(V=0; V<Input.SizeDim2; ++V)
{
Input[U,V,Input.SizeDim3-1] = Input[U,V,0];
for(W=0; W<Input.SizeDim3-1; ++W)
{
Input[U,V,W] = 0;
}
}
}
Events
Code: Select all
for(U=0; U<Input.SizeDim1; ++U)
{
for(V=0; V<Input.SizeDim2; ++V)
{
if(Input[U,V,0] == 1 && Input[U,V,Input.SizeDim3-1] == 0){Input[U,V,1] = 1;}
if(Input[U,V,0] == 0 && Input[U,V,Input.SizeDim3-1] == 1){Input[U,V,2] = 1;}
}
}
Not only does this make your Project Tree less cluttered, it also gives you a performance boost of about 40%.
K
single slot input setup
Posted: Sun Aug 23, 2009 1:20 pm
by jph_wacheski
I have started using this setup for all my input,. as it provides a greater detail with the OnPressed, OnReleased, and LastFrame info. However I did not have a use for the 'slots' (is that for a split-screen two player game?) so just to simpify it a bit, I hacked that part off,. . find this attached for those who are interested in the same.
Thanks for your logic work Kj!
Posted: Sun Aug 23, 2009 2:13 pm
by Kjell
Hey jph,
Yea, you only need the additional dimension when your game supports more then one player, otherwise a 2D Array is sufficient.
By the way, there's a slight performance benefit when you're using local variables opposed to global. Also, when dealing with Keyboard / Joypad Button input, integers ( since booleans aren't supported ) are more appropriate then floats.
+ I use RST / UVW / XYZ variable combinations in relation to their according array dimensions, so for a 2D Array I'd go with U and V ( not V & W )
K