mirror of https://github.com/adamdruppe/arsd.git
dox
This commit is contained in:
parent
8131c41440
commit
3132e05f0f
|
@ -31,9 +31,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
override void update(Duration deltaTime) {
|
override bool update(Duration deltaTime) {
|
||||||
x += 1;
|
x += 1;
|
||||||
y += 1;
|
y += 1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
override SimpleWindow getWindow() {
|
override SimpleWindow getWindow() {
|
||||||
|
@ -100,7 +101,8 @@ class GameHelperBase {
|
||||||
abstract void drawFrame();
|
abstract void drawFrame();
|
||||||
|
|
||||||
/// Implement this to update. The deltaTime tells how much real time has passed since the last update.
|
/// Implement this to update. The deltaTime tells how much real time has passed since the last update.
|
||||||
abstract void update(Duration deltaTime);
|
/// Returns true if anything changed, which will queue up a redraw
|
||||||
|
abstract bool update(Duration deltaTime);
|
||||||
//abstract void fillAudioBuffer(short[] buffer);
|
//abstract void fillAudioBuffer(short[] buffer);
|
||||||
|
|
||||||
/// Returns the main game window. This function will only be
|
/// Returns the main game window. This function will only be
|
||||||
|
@ -155,6 +157,14 @@ void runGame(T : GameHelperBase)(T game, int maxUpdateRate = 20, int maxRedrawRa
|
||||||
|
|
||||||
delegate (KeyEvent ke) {
|
delegate (KeyEvent ke) {
|
||||||
game.keyboardState[ke.hardwareCode] = ke.pressed;
|
game.keyboardState[ke.hardwareCode] = ke.pressed;
|
||||||
|
/*
|
||||||
|
switch(ke.key) {
|
||||||
|
case Key.UpArrow:
|
||||||
|
game.joysticks[0]
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
*/
|
||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
17
joystick.d
17
joystick.d
|
@ -167,6 +167,8 @@ version(linux) {
|
||||||
// I'd just use my xbox controller.
|
// I'd just use my xbox controller.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// For Linux only, reads the latest joystick events into the change buffer, if available.
|
||||||
|
/// It is non-blocking
|
||||||
void readJoystickEvents(int fd) {
|
void readJoystickEvents(int fd) {
|
||||||
js_event event;
|
js_event event;
|
||||||
|
|
||||||
|
@ -312,6 +314,7 @@ int enableJoystickInput(
|
||||||
// return 0;
|
// return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
void closeJoysticks() {
|
void closeJoysticks() {
|
||||||
version(linux) {
|
version(linux) {
|
||||||
foreach(ref fd; joystickFds) {
|
foreach(ref fd; joystickFds) {
|
||||||
|
@ -330,33 +333,36 @@ void closeJoysticks() {
|
||||||
} else static assert(0);
|
} else static assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
struct JoystickUpdate {
|
struct JoystickUpdate {
|
||||||
|
///
|
||||||
int player;
|
int player;
|
||||||
|
|
||||||
JoystickState old;
|
JoystickState old;
|
||||||
JoystickState current;
|
JoystickState current;
|
||||||
|
|
||||||
// changes from last update
|
/// changes from last update
|
||||||
bool buttonWasJustPressed(Button button) {
|
bool buttonWasJustPressed(Button button) {
|
||||||
return buttonIsPressed(button) && !oldButtonIsPressed(button);
|
return buttonIsPressed(button) && !oldButtonIsPressed(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ditto
|
||||||
bool buttonWasJustReleased(Button button) {
|
bool buttonWasJustReleased(Button button) {
|
||||||
return !buttonIsPressed(button) && oldButtonIsPressed(button);
|
return !buttonIsPressed(button) && oldButtonIsPressed(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is normalized down to a 16 step change
|
/// this is normalized down to a 16 step change
|
||||||
// and ignores a dead zone near the middle
|
/// and ignores a dead zone near the middle
|
||||||
short axisChange(Axis axis) {
|
short axisChange(Axis axis) {
|
||||||
return cast(short) (axisPosition(axis) - oldAxisPosition(axis));
|
return cast(short) (axisPosition(axis) - oldAxisPosition(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
// current state
|
/// current state
|
||||||
bool buttonIsPressed(Button button) {
|
bool buttonIsPressed(Button button) {
|
||||||
return buttonIsPressedHelper(button, ¤t);
|
return buttonIsPressedHelper(button, ¤t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: UP is negative!
|
/// Note: UP is negative!
|
||||||
short axisPosition(Axis axis, short digitalFallbackValue = short.max) {
|
short axisPosition(Axis axis, short digitalFallbackValue = short.max) {
|
||||||
return axisPositionHelper(axis, ¤t, digitalFallbackValue);
|
return axisPositionHelper(axis, ¤t, digitalFallbackValue);
|
||||||
}
|
}
|
||||||
|
@ -521,6 +527,7 @@ struct JoystickUpdate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
JoystickUpdate getJoystickUpdate(int player) {
|
JoystickUpdate getJoystickUpdate(int player) {
|
||||||
static JoystickState[4] previous;
|
static JoystickState[4] previous;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue