From 3132e05f0f00ef30da31a7dbafa4d7f5203ae4a0 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 23 Mar 2019 18:05:42 -0400 Subject: [PATCH] dox --- gamehelpers.d | 14 ++++++++++++-- joystick.d | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gamehelpers.d b/gamehelpers.d index dd86c02..c2c8d42 100644 --- a/gamehelpers.d +++ b/gamehelpers.d @@ -31,9 +31,10 @@ } int x, y; - override void update(Duration deltaTime) { + override bool update(Duration deltaTime) { x += 1; y += 1; + return true; } override SimpleWindow getWindow() { @@ -100,7 +101,8 @@ class GameHelperBase { abstract void drawFrame(); /// 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); /// 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) { game.keyboardState[ke.hardwareCode] = ke.pressed; + /* + switch(ke.key) { + case Key.UpArrow: + game.joysticks[0] + break; + default: + } + */ // FIXME } ); diff --git a/joystick.d b/joystick.d index 27c4a09..7a76069 100644 --- a/joystick.d +++ b/joystick.d @@ -167,6 +167,8 @@ version(linux) { // 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) { js_event event; @@ -312,6 +314,7 @@ int enableJoystickInput( // return 0; } +/// void closeJoysticks() { version(linux) { foreach(ref fd; joystickFds) { @@ -330,33 +333,36 @@ void closeJoysticks() { } else static assert(0); } +/// struct JoystickUpdate { + /// int player; JoystickState old; JoystickState current; - // changes from last update + /// changes from last update bool buttonWasJustPressed(Button button) { return buttonIsPressed(button) && !oldButtonIsPressed(button); } + /// ditto bool buttonWasJustReleased(Button button) { return !buttonIsPressed(button) && oldButtonIsPressed(button); } - // this is normalized down to a 16 step change - // and ignores a dead zone near the middle + /// this is normalized down to a 16 step change + /// and ignores a dead zone near the middle short axisChange(Axis axis) { return cast(short) (axisPosition(axis) - oldAxisPosition(axis)); } - // current state + /// current state bool buttonIsPressed(Button button) { return buttonIsPressedHelper(button, ¤t); } - // Note: UP is negative! + /// Note: UP is negative! short axisPosition(Axis axis, short digitalFallbackValue = short.max) { return axisPositionHelper(axis, ¤t, digitalFallbackValue); } @@ -521,6 +527,7 @@ struct JoystickUpdate { } } +/// JoystickUpdate getJoystickUpdate(int player) { static JoystickState[4] previous;