src/Input.hh
author Tero Marttila <terom@fixme.fi>
Wed, 21 Jan 2009 03:33:35 +0200
branchnew_graphics
changeset 411 106aaf6eadfe
parent 389 e74c1820fbd2
child 421 b5b9d2aafdcb
permissions -rw-r--r--
there's a grain of truth in the new graphics code now...
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
#ifndef INPUT_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     2
#define INPUT_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     3
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
     4
#include "Timer.hh"
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
     5
#include "Types.hh"
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
     6
230
78cf0cd69af4 better input handling
terom
parents: 229
diff changeset
     7
#include <ClanLib/Display/input_device.h>
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
     8
#include <ClanLib/Display/keys.h>
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
     9
#include <queue>
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    10
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    11
// const TimeMS INPUT_INTERVAL_MS = 20;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    12
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    13
/**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    14
 * Flags to control input behaviour
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    15
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    16
enum InputFlagBits {
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    17
    /** Default */
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    18
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    19
    /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    20
     * The bit is not limited, i.e. it is set every time if it's present
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    21
     */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    22
    INPUT_FLAG_UNLIMITED    = 0x0000,
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    23
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    24
    /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    25
     * The bit is repeat-limited using INPUT_REPEAT_DELAY
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    26
     */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    27
    INPUT_FLAG_SLOWREPEAT   = 0x0001,
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    28
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    29
    /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    30
     * The bit is repeat-limited using an infinite delay, i.e. you must release the key to trigger it again
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    31
     */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
    32
    INPUT_FLAG_NOREPEAT     = 0x0002,
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    33
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    34
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    35
/**
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    36
 * The bits used in the PlayerInput bitmask, each represents a separate action handled by LocalPlayer::handleInput.
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    37
 *
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    38
 * @see LocalPlayer::handleInput
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    39
 */
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    40
enum PlayerInputBit {
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    41
    INPUT_NONE          = 0x0000,
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    42
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    43
    INPUT_AIM_UP        = 0x0001,
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    44
    INPUT_AIM_DOWN      = 0x0002,
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    45
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    46
    INPUT_MOVE_LEFT     = 0x0004,
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    47
    INPUT_MOVE_RIGHT    = 0x0008,
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    48
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    49
    INPUT_JUMP          = 0x0010,
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    50
    INPUT_DIG           = 0x0020,
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    51
    INPUT_SHOOT         = 0x0040,
237
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    52
    INPUT_CHANGE_NEXT   = 0x0080,
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    53
    INPUT_CHANGE_PREV   = 0x0100,
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    54
    INPUT_ROPE          = 0x0200,
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    55
    INPUT_UNROPE        = 0x0400,
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    56
    INPUT_ROPE_UP       = 0x0800,
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 235
diff changeset
    57
    INPUT_ROPE_DOWN     = 0x1000,
300
417183866f35 suicide key and respawning
terom
parents: 283
diff changeset
    58
417183866f35 suicide key and respawning
terom
parents: 283
diff changeset
    59
    INPUT_SUICIDE       = 0x2000,
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    60
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    61
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    62
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    63
 * The bits used in the GuiInput bitmask, each represents something handled locally by Graphics.
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    64
 */
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    65
enum GuiInputBit {
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    66
    GUI_INPUT_NONE              = 0x0000,
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    67
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    68
    GUI_INPUT_QUIT              = 0x0001,
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    69
    GUI_INPUT_DISPLAY_WEAPON    = 0x0002,
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    70
    GUI_INPUT_DEBUG_PLAYER      = 0x0004,
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 319
diff changeset
    71
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 319
diff changeset
    72
    GUI_INPUT_TOGGLE_FULLSCREEN = 0x0008,
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    73
};
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    74
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    75
/**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    76
 * Bitmask of InputFlagBits
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    77
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    78
typedef uint8_t InputFlags;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    79
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    80
/**
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    81
 * Bitmask of PlayerInputBits
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    82
 *
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    83
 * @see PlayerInputBit
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    84
 */
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    85
typedef uint16_t PlayerInput;
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    86
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    87
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    88
 * Bitmask for GuiInputBits
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    89
 *
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    90
 * @see GuiInputBit
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    91
 */
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    92
typedef uint16_t GuiInput;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    93
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    94
/**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    95
 * Keymap definition struct
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    96
 */
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    97
template <typename BitEnumType> struct InputKeymapEntry {
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    98
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    99
     * The input bit to set if present
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   100
     */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   101
    BitEnumType input;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   102
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   103
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   104
     * Flags to use
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   105
     *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   106
     * @see InputFlagBits
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   107
     */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   108
    InputFlags flags;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   109
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   110
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   111
     * Up to two keycodes to check
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   112
     */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   113
    int keycodes[2];
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   114
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   115
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   116
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   117
/**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   118
 * A InputKeyRepeatQueue entry, this contains the input bit value itself, and then the remaining expire time
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   119
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   120
template <typename BitEnumType> struct InputKeyRepeatEntry {
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   121
        BitEnumType value;
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   122
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   123
        /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   124
         * The remaining expire time. If this is zero, it never expires
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   125
         */
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   126
        TimeMS expire;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   127
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   128
    public:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   129
        InputKeyRepeatEntry (BitEnumType value, TimeMS expire);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   130
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   131
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   132
         * Since priority_queue always gives the greatest item, the one with the longest expire is the least item
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   133
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   134
        bool operator< (const struct InputKeyRepeatEntry &other);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   135
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   136
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   137
         * Decrements expire, returning true if it has now expired, false otherwise. Always returns false if expire is
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   138
         * zero.
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   139
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   140
        bool updateExpired (TimeMS dt);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   141
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   142
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   143
/**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   144
 * A InputKeyRepeatQueue maintains a list of InputKeyRepeatEntry's, lets you add new input values, find old ones,
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   145
 * and update the list
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   146
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   147
template <typename BitEnumType> class InputKeyRepeatQueue {
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   148
    private:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   149
        TimeMS expire;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   150
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   151
        typedef InputKeyRepeatEntry<BitEnumType> entry_type;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   152
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   153
        std::list<entry_type> list;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   154
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   155
        typedef typename std::list<entry_type>::iterator list_iterator;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   156
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   157
    public:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   158
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   159
         * Constructs this queue to contain entries with the given expiry time
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   160
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   161
        InputKeyRepeatQueue (TimeMS expire);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   162
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   163
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   164
         * Push a new input bit onto the queue.
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   165
         *
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   166
         * If expire is true, the bit will automatically expire after our expire time, otherwise, it iwll never expire
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   167
         * until forget()'d
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   168
         */
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   169
        void push (BitEnumType bit, bool expire = true);
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   170
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   171
        /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   172
         * Remove any entry for the given bit
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   173
         */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   174
        void forget (BitEnumType bit);
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   175
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   176
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   177
         * Checks if the given input is in the queue
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   178
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   179
        bool find (BitEnumType bit);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   180
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   181
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   182
         * Updates the list, removing expired items
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   183
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   184
        void update (TimeMS dt);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   185
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   186
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   187
/**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   188
 * An InputHandler uses an InputKeymapEntry to maintain a BitMaskType of current inputs
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   189
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   190
template <typename BitEnumType, typename BitMaskType> class InputHandler {
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   191
    private:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   192
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   193
         * The keyboard that we read input from
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   194
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   195
        CL_InputDevice &keyboard;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   196
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   197
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   198
         * The keymap that we use
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   199
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   200
        InputKeymapEntry<BitEnumType> *keymap;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   201
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   202
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   203
         * The current bitmask value
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   204
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   205
        BitMaskType value;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   206
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   207
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   208
         * The previous value, used to detect key-up. This also includes keys that were filtered out
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   209
         */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   210
        BitMaskType prev_value;
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   211
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   212
        /**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   213
         * How long the bitmask was held...
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   214
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   215
        TimeMS dt;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   216
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   217
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   218
         * The KeyRepeatQueue
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   219
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   220
        InputKeyRepeatQueue<BitEnumType> queue;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   221
    
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   222
    public:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   223
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   224
         * Constructs the InputHandler using the given keyboard, keymap and key-repeat expire time
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   225
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   226
        InputHandler (CL_InputDevice &keyboard, InputKeymapEntry<BitEnumType> *keymap, TimeMS keyrepeat_expire);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   227
    
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   228
    private: 
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   229
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   230
         * Returns true if the keycode is valid, false if not.
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   231
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   232
         * A positive keycode requires that the keycode be active, a negative keycode that the keycode be inactive,
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   233
         * and a zero keycode always returns true.
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   234
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   235
         * @param keycode A positive keycode to check that it's set, negative keycode to check that it's not set, or zero
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   236
         * @returns bool true if positive+set/negavtive+notset/zero, false otherwise
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   237
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   238
        bool checkKeycode (int keycode);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   239
    
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   240
    public:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   241
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   242
         * Updates the keyrepeat queue
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   243
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   244
        void update (TimeMS dt);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   245
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   246
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   247
         * Reads the current input mask value and length into mask and dt, and reset ours to zero
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   248
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   249
         * @param mask our BitMaskType value is returned using this
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   250
         * @param dt how long the input was held for
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   251
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   252
        void readValue (BitMaskType &mask, TimeMS &dt);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   253
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   254
};
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   255
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
   256
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
   257
 * Handles reading input from a keyboard and mapping it to PlayerInput/GuiInput bitmasks
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
   258
 */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   259
class Input {
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   260
    protected:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   261
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   262
         * The keyboard device that we use
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   263
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   264
        CL_InputDevice &keyboard;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   265
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   266
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   267
         * Our update timer
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   268
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   269
        Timer update_timer;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   270
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   271
        CL_SlotContainer slots;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   272
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   273
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   274
         * Our PlayerInput
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   275
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   276
        InputHandler<PlayerInputBit, PlayerInput> player;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   277
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   278
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   279
         * Our GuiInput
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   280
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   281
        InputHandler<GuiInputBit, GuiInput> gui;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   282
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   283
    public:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   284
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   285
         * Build the input handler using the given keyboard and the default keymaps
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   286
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   287
        Input (CL_InputDevice &keyboard);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   288
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   289
    public:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   290
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   291
         * Reads the current PlayerInput value via mask, and the length of the input via dt
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   292
         */
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   293
        void readPlayerInput (PlayerInput &mask, TimeMS &dt);
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   294
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   295
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   296
         * Reads the current GuiInput mask and returns it
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   297
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   298
        GuiInput readGuiInput (void);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   299
};
230
78cf0cd69af4 better input handling
terom
parents: 229
diff changeset
   300
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   301
#endif