* Create the subsystem for keybindings.
This commit is contained in:
jean.chalard
2010-02-14 13:21:12 +00:00
parent 4913eec2fb
commit 56ce4a14ae
38 changed files with 2154 additions and 1477 deletions
+100 -51
View File
@@ -16,6 +16,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <queue>
#include <map>
#include "JTypes.h"
@@ -23,27 +25,25 @@
//#define _MP3_ENABLED_
#ifdef WIN32
#if defined(WIN32)
#include <windows.h>
void JGEControl();
BOOL JGEGetKeyState(int key);
bool JGEGetButtonState(u32 button);
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
#elif LINUX
void JGEControl();
BOOL JGEGetKeyState(int key);
bool JGEGetButtonState(u32 button);
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
typedef WPARAM LocalKeySym;
#elif defined(LINUX)
#include <X11/XKBlib.h>
typedef KeySym LocalKeySym;
#else
typedef u32 LocalKeySym;
#endif
bool JGEGetButtonState(const JButton button);
bool JGEGetButtonClick(const JButton button);
void JGECreateDefaultBindings();
int JGEGetTime();
u8 JGEGetAnalogX();
u8 JGEGetAnalogY();
#if !defined(WIN32) && !defined(LINUX)
#include <pspgu.h>
#include <pspkernel.h>
@@ -77,46 +77,32 @@ class JGE
{
private:
JApp *mApp;
// JResourceManager *mResourceManager;
// JFileSystem* mFileSystem;
// JParticleSystem* mParticleSystem;
// JMotionSystem* mMotionSystem;
#if defined (WIN32) || defined (LINUX)
float mDeltaTime;
JMusic *mCurrentMusic;
#else
SceCtrlData mCtrlPad;
u32 mOldButtons;
u32 mVeryOldButtons;
u64 mLastTime;
u32 mTickFrequency;
#endif
bool mDone;
float mDelta;
bool mDebug;
bool mPaused;
char mDebuggingMsg[256];
bool mCriticalAssert;
const char *mAssertFile;
int mAssertLine;
u32 tickFrequency;
static JGE* mInstance;
static std::queue<JButton> keyBuffer;
static std::multimap<LocalKeySym, JButton> keyBinds;
typedef std::multimap<LocalKeySym, JButton>::iterator keycodes_it;
friend void Run();
public:
//////////////////////////////////////////////////////////////////////////
@@ -128,10 +114,9 @@ class JGE
static void Destroy();
void Init();
void Run();
void End();
void Update();
void Update(float);
void Render();
void Pause();
@@ -154,7 +139,7 @@ class JGE
//////////////////////////////////////////////////////////////////////////
/// Return frame rate.
///
/// @note This is just 1.0f/GetDelat().
/// @note This is just 1.0f/GetDelta().
///
/// @return Number of frames per second.
//////////////////////////////////////////////////////////////////////////
@@ -167,29 +152,78 @@ class JGE
///
/// @return Button state.
//////////////////////////////////////////////////////////////////////////
bool GetButtonState(u32 button);
bool GetButtonState(JButton button);
//////////////////////////////////////////////////////////////////////////
/// Check if a button is down the first time.
/// THIS DOES NOT WORK RELIABLY. DO NOT USE THIS.
/// USE ReadButton() INSTEAD.
///
/// @param button - Button id.
///
/// @return Button state.
//////////////////////////////////////////////////////////////////////////
bool GetButtonClick(u32 button);
bool GetButtonClick(JButton button);
//////////////////////////////////////////////////////////////////////////
/// Get the next keypress.
///
/// @return Next pressed button, or 0 if none.
//////////////////////////////////////////////////////////////////////////
u32 ReadButton();
JButton ReadButton();
//////////////////////////////////////////////////////////////////////////
/// Bind an actual key to a symbolic button. A key can be bound to
/// several buttons and even several times to the same button (for
/// double clicks on one button, for example.
///
/// @param keycode - The local code of the key
/// @param button - The button to bind it to
///
/// @return The number of bound keys so far
//////////////////////////////////////////////////////////////////////////
u32 BindKey(LocalKeySym keycode, JButton button);
//////////////////////////////////////////////////////////////////////////
/// Undo a binding.
/// If the second parameter is omitted, remove all bindings to this key ;
/// else, remove exactly once the binding from this key to this button.
///
/// @param keycode - The local code of the key
/// @param button - The button
///
/// @return The number of still bound keys
//////////////////////////////////////////////////////////////////////////
u32 UnbindKey(LocalKeySym keycode, JButton button);
u32 UnbindKey(LocalKeySym keycode);
//////////////////////////////////////////////////////////////////////////
/// Clear bindings.
/// This removes ALL bindings. Take care to re-bind keys after doing it.
///
//////////////////////////////////////////////////////////////////////////
void ClearBindings();
//////////////////////////////////////////////////////////////////////////
/// Reset bindings.
/// This resets ALL bindings to their default value.
///
//////////////////////////////////////////////////////////////////////////
void ResetBindings();
//////////////////////////////////////////////////////////////////////////
/// Iterators for bindings.
//////////////////////////////////////////////////////////////////////////
typedef std::multimap<LocalKeySym, JButton>::const_iterator keybindings_it;
keybindings_it KeyBindings_begin();
keybindings_it KeyBindings_end();
//////////////////////////////////////////////////////////////////////////
/// Reset the input buffer.
/// This is necessary because there might be phases when GetButtonState
/// or GetButtonClick are used, thereby accumulating keypresses in the
/// key buffer.
/// This is necessary because there might be phases when only
/// GetButtonState is used, thereby accumulating keypresses
/// in the key buffer.
///
//////////////////////////////////////////////////////////////////////////
void ResetInput();
@@ -208,13 +242,28 @@ class JGE
//////////////////////////////////////////////////////////////////////////
u8 GetAnalogY();
//////////////////////////////////////////////////////////////////////////
/// Simulate a keypress, or a keyhold/release.
///
//////////////////////////////////////////////////////////////////////////
void PressKey(const LocalKeySym);
void PressKey(const JButton);
void HoldKey(const LocalKeySym);
void HoldKey(const JButton);
void HoldKey_NoRepeat(const LocalKeySym);
void HoldKey_NoRepeat(const JButton);
void ReleaseKey(const LocalKeySym);
void ReleaseKey(const JButton);
//////////////////////////////////////////////////////////////////////////
/// Get if the system is ended or not.
/// Get if the system is ended/paused or not.
///
/// @return Status of the system.
//////////////////////////////////////////////////////////////////////////
bool IsDone() { return mDone; }
bool IsPaused() { return mPaused; }
//////////////////////////////////////////////////////////////////////////
@@ -235,7 +284,7 @@ class JGE
void Assert(const char *filename, long lineNumber);
#if defined (WIN32) || defined (LINUX)
void SetDelta(int delta);
void SetDelta(float delta);
#endif
protected: