api extensions: api discussion

A project to port LÖVE to Android handhelds
User avatar
ghoulsblade
Party member
Posts: 111
Joined: Sun Oct 31, 2010 6:11 pm

api extensions: api discussion

Post by ghoulsblade »

How should phone/android specific api extensions be made accessible ?

things like multi-touch, sensors like accellerometer, magnetic field (compass?), orientation (gravity?), gps, light
and possibly stuff like phone specific popup notifcations, home/menu button overrides, maybe opening map and browser apps...

currently the love-android apk makes them available as love.phone.getSensorList() etc,
including new user-defined callbacks like

function love.phone.touch (action,data) ... end -- for multitouch
function love.phone.sensorevent (sensorid,data) ... end

is there interest/need to agree on common naming/api schemes now for possible future projects like iphone ?
are there maybe love2d ports for handheld devices that already have apis like that ?

possibly interesting links regarding sensor and multitouch abstraction in the android java sdk :
http://developer.android.com/reference/ ... Event.html
http://developer.android.com/reference/ ... ensor.html
http://developer.android.com/reference/ ... Event.html (touch)
love-android - gamejams
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: api extensions: api discussion

Post by josefnpat »

There also needs to be a way to test these functions on the computer.

Installing a Gyrometer on my computer does not sound like a cup of tea.
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: api extensions: api discussion

Post by Taehl »

Just as an initial suggestion...

Code: Select all

-- love sensor functions:

love.sensor.getTouches(n)	-- returns the x and y coordinate of touch-point n (or nil,nil). If n is nil, returns a vararg of all touch point pairs
love.sensor.getCompass()	-- returns the the compass sensor's numbers
love.sensor.getOrientation()	-- returns the orientation sensor's numbers
love.sensor.getGPS()		-- returns the coordinates from the GPS
love.sensor.getLight()		-- returns the lightness level, from 0 to 1 (divide lux by 120000)

-- other functions:

love.android.showToast(message, long)	-- displays a Toast of message. If long is true, then make the toast long, else short.
love.android.startActivity(n, ...)		-- summons an Activity via an Intent. I have no idea what parameters this should have, honestly. Getting data to the Activity would be great.
love.android.getActivityResults(n)	-- returns the results Activity n may have sent (vararg), or nil


-- new callbacks:

function love.androidHome() end		-- called when the Home button is pressed (a good time for saving the game)
function love.androidMenu() end		-- called when the Menu button is pressed
function love.androidBack() end		-- called when the Back button is pressed (another good time for saving the game)
function love.androidFind() end		-- called when the Find button is pressed
One thing I think is very important is for Love-Android itself to maintain a best estimate for stuff like GPS data, and return the best estimate instead of raw data. This is not a wheel every Love game should have to reinvent.

Also, maybe it would be a good idea to have callbacks for onCreate, onStart, onRestart, onResume, onPause, onStop, and onDestroy events?

Also, should Love-Android expose the remapCoordinateSystem function? Food for thought.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: api extensions: api discussion

Post by tentus »

Taehl wrote:

Code: Select all

function love.androidHome() end		-- called when the Home button is pressed (a good time for saving the game)
function love.androidMenu() end		-- called when the Menu button is pressed
function love.androidBack() end		-- called when the Back button is pressed (another good time for saving the game)
function love.androidFind() end		-- called when the Find button is pressed
Shouldn't there be two functions for each of those, a pressed and a released version? That'd be more in keeping with Love, and more flexible.
Kurosuke needs beta testers
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: api extensions: api discussion

Post by Taehl »

I would agree with that... But I don't think Android tells you pressed/released status, it just fires off a function when pressed.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: api extensions: api discussion

Post by thelinx »

A callback for every button is stupid, imho.

Just tie it in with love.keyboard.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    ...
  end
end
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: api extensions: api discussion

Post by TechnoCat »

thelinx wrote:A callback for every button is stupid, imho.

Just tie it in with love.keyboard.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    ...
  end
end
I like this if a function that virtually presses the homekey is provided. Otherwise it might be hard to get the default function.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    love.mobile.pressHome()
  end
end
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: api extensions: api discussion

Post by thelinx »

???????????????
User avatar
ghoulsblade
Party member
Posts: 111
Joined: Sun Oct 31, 2010 6:11 pm

Re: api extensions: api discussion

Post by ghoulsblade »

as expected the home key is on purpose left outside the control of the application :
http://groups.google.com/group/android- ... 3f5e8c8013

it might be possible to at least detect it or similar using (android) activity:onUserLeaveHint()
http://developer.android.com/reference/ ... Hint%28%29
love-android - gamejams
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: api extensions: api discussion

Post by Taehl »

Oh, I just realized: It would be really good to know what kind of a screen a game is on - QVGA or whatnot. So it's important that love.graphics.getHeight and and such all work. I guess you'd need to disable love.graphics.setMode, though.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Locked

Who is online

Users browsing this forum: No registered users and 48 guests