antirez / load81

SDL based Lua programming environment for kids similar to Codea
BSD 2-Clause "Simplified" License
647 stars 64 forks source link

Feature: Joystick support for up to 4 Devices. #39

Open seclorum opened 12 years ago

seclorum commented 12 years ago

This patch adds Joystick support to LOAD81. It allows up to 4 devices to be used within the Lua environment, and for that purpose adds a new global Lua table called 'joystick', with fields x, y, and name, where:

x = X-axis value of the joystick y = Y-axis value of the joystick name = name of the joystick device

This patch has been mainly targeted at Open Pandora users, where the onboard nubs are featured as independent high-resolution joysticks. For that reason, complete button support is not finished - but will be added in another patch shortly.

Tested on Open Pandora hardware, and Macbook Pro with paired iControlpad controllers. On Open Pandora hardware, joysticks will be named thus:

joystick[1].name = "gpio-keys" (Special feature of Open Pandora, for hardware hackers mostly) joystick[2].name = "nub0" (The Left nub) joystick[3].name = "nub1" (The Right nub)

seclorum commented 12 years ago

Also, please see new examples/joysticks.lua for demo purposes.

antirez commented 12 years ago

I definitely like the idea of supporting joysticks, but I think the exported API may be more consistent with what we have currently, more info ASAP, but I've some ideas :) I wonder if there is a way for me to simulate a joystick on osx or Linux...

Thanks!

seclorum commented 12 years ago

I'm sorry I don't quite understand what you mean by the exported API - do you mean the joysticks[] table, or something? I'm rather eager to get this merged so I can move on to other things while using joysticks (this works really nicely on Open Pandora and OSX with iControlpad) so if you could clear up whats blocking this merge, it'd be helpful.

antirez commented 12 years ago

This is what I need to merge it:

Thanks! Salvatore

seclorum commented 12 years ago

Okay I will work on these points and submit a new patch shortly. Thanks for the feedback.

seclorum commented 12 years ago

Re: Removal of additional newlines before return in sdlInit() and createFrameBuffer() that was out of the scope of the patch.

Can we come up with an indent config, or comment-string for vim or something, that solves this code-formatting issue? I'm an "indent -kr -ts4" kind of guy, and those returns might be the result of that .. maybe you have a rule for the indent cmd that we should use to enforce formatting? (this way I could run the rule before checkins, and still have our own local preferences for indentation/layout..)

seclorum commented 12 years ago

Re: updateJoystick(State|Name)() should use setTableField() instead, that is now generically able to set fields of global tables. If this is not possible at least the two functions should be unified because they do a very similar thing.

There is a difference between the API's. " setTableFieldNumber sets a "table.field = number", whereas updateJoystickState goes "table[int].field = number".

Alas, there is probably a way to nest the lua atoms, I confess to not having the fortitude to know how to do that yet, but perhaps it would instead be better to refactor updateJoystickState[Name,Number] to be API calls "setTableIndexedFieldNumber" and "setTableIndexedFieldString" and use them elsewhere as well?