2008-12-03 05:40:16 +00:00
|
|
|
#ifndef INPUT_H_
|
|
|
|
#define INPUT_H_
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
#include <stdint.h>
|
2010-08-22 03:07:46 +00:00
|
|
|
#include "bearing.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* \defgroup TetrisInputDefinesPublic Input: Public constants
|
|
|
|
*/
|
|
|
|
/*@{*/
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
/***********
|
|
|
|
* defines *
|
|
|
|
***********/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** number of levels */
|
2009-06-12 06:24:04 +00:00
|
|
|
#define TETRIS_INPUT_LEVELS 30
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup TetrisInputTypes Input: Data types
|
|
|
|
*/
|
|
|
|
/*@{*/
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
/*********
|
|
|
|
* types *
|
|
|
|
*********/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* allowed input values
|
|
|
|
*/
|
2011-02-25 04:31:34 +00:00
|
|
|
enum tetris_input_command
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
TETRIS_INCMD_LEFT, /**< move piece left */
|
|
|
|
TETRIS_INCMD_RIGHT, /**< move piece right */
|
|
|
|
TETRIS_INCMD_DOWN, /**< lower piece by one row */
|
|
|
|
TETRIS_INCMD_ROT_CW, /**< rotate clockwise */
|
|
|
|
TETRIS_INCMD_ROT_CCW, /**< rotate counter clockwise */
|
|
|
|
TETRIS_INCMD_DROP, /**< move piece to the ground immediately */
|
|
|
|
TETRIS_INCMD_GRAVITY, /**< piece gets pulled by gravity */
|
|
|
|
TETRIS_INCMD_PAUSE, /**< pause the game */
|
|
|
|
TETRIS_INCMD_NONE /**< idle (must alway be the last one) */
|
2011-02-25 04:31:34 +00:00
|
|
|
};
|
|
|
|
#ifdef NDEBUG
|
|
|
|
typedef uint8_t tetris_input_command_t;
|
|
|
|
#else
|
|
|
|
typedef enum tetris_input_command tetris_input_command_t;
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* values which influence the gravity time limit for a piece
|
|
|
|
*/
|
2011-02-25 04:31:34 +00:00
|
|
|
enum tetris_input_pace
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
TETRIS_INPACE_HOVERING, /**< normal falling pace */
|
|
|
|
TETRIS_INPACE_GLIDING /**< guarantees a minimum docking time to avoid
|
|
|
|
accidentally docked pieces in higher levels */
|
2011-02-25 04:31:34 +00:00
|
|
|
};
|
|
|
|
#ifdef NDEBUG
|
|
|
|
typedef uint8_t tetris_input_pace_t;
|
|
|
|
#else
|
|
|
|
typedef enum tetris_input_pace tetris_input_pace_t;
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* data structure for the input module
|
|
|
|
*/
|
2011-02-25 04:31:34 +00:00
|
|
|
typedef struct tetris_input
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* current level (determines falling speed)
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
uint8_t nLevel;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* Amount of loop cycles between forced piece movements. This value gets
|
|
|
|
* set via the tetris_input_setLevel() function.
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
uint8_t nMaxCycles;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* This counter keeps track of the number of loop cycles which have been
|
|
|
|
* done since the last forced piece movement. It gets reset if it either
|
|
|
|
* reaches a well defined value (causing a gravity command to be issued)
|
|
|
|
* or the player has moved down the piece herself/himself.
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
uint8_t nLoopCycles;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* Amount of loop cycles in which the same command has been issued
|
|
|
|
* consecutively. It gets reset if either the current command differs from
|
|
|
|
* the last one or a well-defined value has been reached (thereby
|
|
|
|
* regulating the pace of the key repeat as commands are only processed
|
|
|
|
* if that value is reached).
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
int8_t nRepeatCount;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* Keeps track of the number of loop cycles which have been run while in
|
|
|
|
* pause mode. As soon as a well defined value is reached, the game
|
|
|
|
* continues (in case someone paused the game and forgot to resume it).
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
uint16_t nPauseCount;
|
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* last real command (important for key repeat and chatter protection)
|
|
|
|
*/
|
|
|
|
tetris_input_command_t cmdRawLast;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* last mapped command (important for key repeat)
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
tetris_input_command_t cmdLast;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Every command has its own counter. A command is ignored as long as its
|
|
|
|
* counter is unequal to 0. A counter gets set to a specific value (or 0)
|
|
|
|
* if the button of the corresponding command has been released by the
|
|
|
|
* player. All counters get decremented by one every loop cycle until they
|
|
|
|
* are zero. This is used to work against joystick chatter. Look at the
|
|
|
|
* TETRIS_INPUT_CHATTER_TICKS_... constants in input.c for the initial
|
|
|
|
* values of these counters.
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
uint8_t nIgnoreCmdCounter[TETRIS_INCMD_NONE];
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
/**
|
2010-08-22 03:07:46 +00:00
|
|
|
* bearing of the bucket (for mapping directions)
|
2010-04-01 03:11:59 +00:00
|
|
|
*/
|
2010-08-22 03:07:46 +00:00
|
|
|
tetris_bearing_t nBearing;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
tetris_input_t;
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup TetrisInputRelated Input: Interface functions
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
/****************************
|
|
|
|
* construction/destruction *
|
|
|
|
****************************/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* constructs an input object for André's borg
|
|
|
|
* @return pointer to a newly created input object
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2010-04-01 03:11:59 +00:00
|
|
|
tetris_input_t *tetris_input_construct(void);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* destructs an input object
|
|
|
|
* @param pIn pointer to the input object which should be destructed
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2011-02-06 22:56:26 +00:00
|
|
|
inline static void tetris_input_destruct(tetris_input_t *pIn)
|
|
|
|
{
|
|
|
|
assert(pIn != NULL);
|
|
|
|
free(pIn);
|
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
* input related functions *
|
|
|
|
***************************/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* retrieves commands from joystick or loop interval
|
|
|
|
* @param pIn pointer to an input object
|
|
|
|
* @param nPace falling pace
|
|
|
|
* @return see definition of tetris_input_command_t
|
|
|
|
* @see definition of tetris_input_pace_t
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
|
|
|
tetris_input_command_t tetris_input_getCommand(tetris_input_t *pIn,
|
2010-04-01 03:11:59 +00:00
|
|
|
tetris_input_pace_t nPace);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* modifies time interval of input events
|
|
|
|
* @param pIn pointer to an input object
|
2010-08-22 03:07:46 +00:00
|
|
|
* @param nLvl requested level (0 <= nLvl <= TETRIS_INPUT_LEVELS - 1)
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
|
|
|
void tetris_input_setLevel(tetris_input_t *pIn,
|
|
|
|
uint8_t nLvl);
|
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* resets the key repeat count for the down key
|
|
|
|
* @param pIn pointer to an input object
|
2009-06-12 06:24:04 +00:00
|
|
|
*/
|
|
|
|
void tetris_input_resetDownKeyRepeat(tetris_input_t *pIn);
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
/**
|
2010-08-22 03:07:46 +00:00
|
|
|
* set the bearing for mapping the direction controls
|
2010-04-01 03:11:59 +00:00
|
|
|
* @param pIn pointer to an input object
|
2010-08-22 03:07:46 +00:00
|
|
|
* @param nBearing requested bearing
|
2010-04-01 03:11:59 +00:00
|
|
|
*/
|
2010-08-22 03:07:46 +00:00
|
|
|
void tetris_input_setBearing(tetris_input_t *pIn,
|
|
|
|
tetris_bearing_t nBearing);
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
/*@}*/
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
#endif /*INPUT_H_*/
|