User Tools

Site Tools


homebrew:engines:penjin:simplejoy

SimpleJoy

About

SimpleJoy is a class created for Penjin, with the aim of simplifying cross platform control. It uses a simple scripting format, decribed below, to map controls to an abstract internal joypad. This joypad can then be very simply be updated and polled and the programmer doesn't need to worry about which physical device to check.

Usage

Penjin will setup some preset controls if no custom script is provided. To load in a mapping script in your Penjin based application, you simply use this function in SimpleJoy:

PENJIN_ERRORS loadControlMap(CRstring filename);

If you want to load a control map script into a compiled Penjin application, you can do this via the commandline:

PENJIN_APP -C scripts/myControls.cmf

Example

SimpleJoy joy;
joy.loadControlMap("scripts/myJoy.cmf"); 

And here is an example of a CMF file itself - The format will be explained shortly:

;   PS2 - using Poke PS2 controller USB Adaptor 
;   DEVICE:type,id;
DEVICE:JOYSTICK,0;
;   KEY:action,key;
AXIS:LEFTSTICK_X,0;
AXIS:LEFTSTICK_Y,1;
AXIS:RIGHTSTICK_X,2;
AXIS:RIGHTSTICK_Y,3;
DIGITAL_AXIS:LEFT,4,-1;
DIGITAL_AXIS:RIGHT,4,1;
DIGITAL_AXIS:UP,5,-1;
DIGITAL_AXIS:DOWN,5,1;
BUTTON:A,3;
BUTTON:B,1;
BUTTON:X,2;
BUTTON:Y,0;
BUTTON:L,6;
BUTTON:R,7;
BUTTON:SELECT,9;
BUTTON:START,8;
DEVICE_END:;
END:;

Syntax Overview

  1. Keywords are typed in capitals.
  2. A Colon “:” signifies the start of the variables in the command.
  3. Commands are written with no spaces.
  4. Variables are separated by commas “,”.
  5. All strings variables come first, then all numerical variables.

Comments

Commenting is available through using semi-colons, “;”. Anything after the “;” is discarded until the next line. If you place the “;” at the very beginning of the line, you can write what you want following it.

;This is an OK comment
;   COMMENT IS HERE!!!!
AXIS:LEFTSTICK_X,0;  This line maps Axis 0 of the physical joystick to the Left X axis of the Penjin joystick
;   The above line has a valid command and a valid comment!
writing anything you want without a semi colon is wrong... don't do this... people have died.

Devices

Devices are the physical controls you attach to the computer. We need to tell SimpleJoy about the type of device we want to map and the relevant buttons. We do this with the DEVICE keyword and the following device types (KEYBOARD, MOUSE, JOYSTICK). You also specify the device number, which is normally just 0. Finally you need to end the device description with DEVICE_END:;

DEVICE:JOYSTICK,0;
;   Buttons are mapped here.
DEVICE_END:;
DEVICE:KEYBOARD,0;
;   Keys are mapped here.
DEVICE_END:;
DEVICE:MOUSE,0;
;   Mouse buttons and axes are mapped here.
DEVICE_END:;
END:;

Mapping Buttons to SimpleJoy Button Targets

This relatively straightforward. The code goes in between the DEVICE and DEVICE_END lines.

JoyPads

You can find out the button layout of your pad using the joystick option in the control panel in WinXP, etc or something like jscalibrator in linux.

DEVICE:JOYSTICK,0;
BUTTON:UP,0;   Map **button 0** on the JoyPad to **UP** on SimpleJoy
DEVICE_END:;
END:;
Keyboards

A full keyboard keyword listing can be seen at the end of the page.

DEVICE:KEYBOARD,0;
KEY:UP,UP;         Map **UP cursor key** on the keyboard to **UP** on SimpleJoy
KEY:A,RIGHT_SHIFT; Map **right shift key** on the keyboard to **A** on SimpleJoy
DEVICE_END:;
END:;
Mice
DEVICE:MOUSE,0;
BUTTON:X,0;         Map **left button** on the mouse to **X** on SimpleJoy
DEVICE_END:;
END:;

Mapping Axes to SimpleJoy Button Targets

This relatively straightforward. The code goes in between the DEVICE and DEVICE_END lines as with buttons.

JoyPads

You can find out the axis layout of your pad using the joystick option in the control panel in WinXP, etc or something like jscalibrator in linux.

DEVICE:JOYSTICK,0;
AXIS:LEFTSTICK_X,0;      Map **axis 0** on the JoyPad to **left stick's X axis** on SimpleJoy
DIGITAL_AXIS:LEFT,4,-1;  Map **axis 4** on the JoyPad to **LEFT** on SimpleJoy with a trigger value of -1
DEVICE_END:;
END:;

:!:DIGITAL_AXIS is to map an axis to a button. Some Dpads work as an axis and this works around that problem.

Mice
DEVICE:MOUSE,0;
AXIS:MOUSE_Y,1;         Map **axis 1(Y axis)** on the mouse to **mouse y axis** on SimpleJoy
DEVICE_END:;
END:;

Appendices

SimpleJoy Device Targets

KEYBOARD
MOUSE
JOYSTICK

SimpleJoy Button Targets

SimpleJoy uses its own internal joypad layout to which buttons can be mapped. Here are all the SimpleJoy buttons that can be mapped to:

UP
DOWN
LEFT
RIGHT
UPLEFT
UPRIGHT
DOWNLEFT
DOWNRIGHT
A
B
X
Y 
L
R
VOLUP
VOLDOWN
START
SELECT
CLICK
LID
LEFTSTICK_X
LEFTSTICK_Y
RIGHTSTICK_X
RIGHTSTICK_Y
MOUSE_X
MOUSE_Y
MOUSE_LEFT
MOUSE_CENTRE
MOUSE_RIGHT

SimpleJoy Mapping Types

AXIS
DIGITAL_AXIS
BUTTON
KEY
HAT

SimpleJoy Keyboard Keys

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Y
Z
&
*
@
`
\
BACKSPACE
BREAK
CAPS
^
CLEAR
COLON
COMMA
COMPOSE
DELETE
$
DOWN
END
=
ESCAPE
EURO
!
F1
F10
F11
F12
F13
F14
F15
F2
F3
F4
F5
F6
F7
F8
F9
>
#
HELP
HOME
INSERT
KP_0
KP_1
KP_2
KP_3
KP_4
KP_5
KP_6
KP_7
KP_8
KP_9
KP_/
KP_ENTER
KP_=
KP_-
KP_*
KP_.
KP_+
LEFT_ALT
LEFT_CTRL
LEFT
[
(
<
LEFT_META
LEFT_SHIFT
MENU
-
MODE
NUMLOCK
PAGEDOWN
PAGEUP
PAUSE
.
+
POWER
PRINT
?
'
"
RIGHT_ALT
RIGHT_CTRL
RETURN
RIGHT
]
)
RIGHT_META
RIGHT_SHIFT
SCROLL_LOCK
SEMICOLON
/
SPACE
SYSTEM_REQUEST
TAB
_
UNDO
UP
You could leave a comment if you were logged in.
homebrew/engines/penjin/simplejoy.txt · Last modified: 2010/04/29 23:47 by pokeparadox