Checking Game Controls Existence


Eniko

Raving Python fangirl
Joined
Sep 29, 2008
Messages
641
Age
41
Location
Netherlands
Website
purplepirates.darksiren.net
How could I go about programatically checking for the existence of the Pandora's gaming controls, or just to see if my code is running on the Pandora period? I tried using os.uname() but that didn't turn up anything terribly unique. I'd like to for instance remap the default controls automatically if it's being run on a Pandora.
 
Eniko said:
How could I go about programatically checking for the existence of the Pandora's gaming controls, or just to see if my code is running on the Pandora period? I tried using os.uname() but that didn't turn up anything terribly unique. I'd like to for instance remap the default controls automatically if it's being run on a Pandora.
I would go with conditionnal compilation (I mean using #ifdef and a -D gcc option) as your games will be packaged as pnd file.
 
Last edited by a moderator:
  1. You can't use conditional compilation in Python.
  2. That is a GOOD THING, because conditional compilation is horribly broken and makes portable code unportable.
To check for the Pandora environment? Just add a flag when you put your program in a PND that says "--platform=pandora" or something. Then your game can have a couple of profiles that it chooses from at runtime, and it chooses the platform depending on that flag.
 
Could also go pythonic - duck typing. (acts like a duck, call it a duck) - check for the bits you need, and work if present. Could check for device names to be present, and use them if so.

Jeffphone
 
skeezix said:
Could also go pythonic - duck typing. (acts like a duck, call it a duck) - check for the bits you need, and work if present. Could check for device names to be present, and use them if so.
Hmm yeah, this is what most pythons would choose to do, but I don't understand how it's supposed to work? (please enlighten me)
Say that you have a class Controller (Just off the top of my head, but, y'know, time, lack of):
Code:
class Controller:
    def addListener(listener): pass
    def removeListener(listener): pass

    # ...

    def init():
        if SomeClass.hasPandoraDeviceFile:
            SomeClass.onPandoraDeviceInteract(callAllListeners)
        else:
            ask('Is it really up to me to decide what to use instead of the Pandora controller?')
            followupQuestion('Should I really be checking for every platform available? Go through all alternatives?')
            giveUp()
            exit()
To me, this is just asking for trouble. A more object-oriented approach would be what I'd choose...
Code:
import os.path

class PandoraController:
    def available(): os.path.isfile('/dev/pandora/...')
    def addListener(listener): pass
    def removeListener(listener): pass

class KeyboardController:
    def available(): true
    def addListener(listener): pass
    def removeListener(listener): pass
...and then you'd have fall back chains etc. Kinda difficult to do properly in Python, because Python doesn't have static typing (Why?? Such a horrible design choice to use dynamic typing ;)) but it's possible.
Of course I'm just blabbering and you skeezix would probably have done what I did, and I just misunderstood what you meant.
 
Last edited by a moderator:
skeezix said:
Could also go pythonic - duck typing. (acts like a duck, call it a duck) - check for the bits you need, and work if present. Could check for device names to be present, and use them if so.

Jeffphone
Well that was my first thought, but I don't know what to check for. How do I check for device names to be present?
 
Last edited by a moderator:
The problem with conditional compilation is that it then becomes a pandora specific build, and wouldn't be something that would exist in the angstrom repo (or even the ubuntu-arm). Then again, it seems that quite a lot of projects would benefit from some small tweaks (things like dialogue size, not just key bindings), so I'm not sure where this is best managed. Will projects accept this sort of thing in their mainline code base?
 
Back
Top