src/Input.hh
author terom
Wed, 17 Dec 2008 00:40:22 +0000
changeset 381 9b35bc329d23
parent 319 9f6a838d58c4
child 389 e74c1820fbd2
permissions -rw-r--r--
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
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,
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    71
};
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    72
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    73
/**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    74
 * Bitmask of InputFlagBits
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    75
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    76
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
    77
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    78
/**
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    79
 * Bitmask of PlayerInputBits
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    80
 *
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    81
 * @see PlayerInputBit
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    82
 */
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
    83
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
    84
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    85
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    86
 * Bitmask for GuiInputBits
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
 * @see GuiInputBit
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    89
 */
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
    90
typedef uint16_t GuiInput;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    91
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
    92
/**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    93
 * Keymap definition struct
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
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
    96
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    97
     * 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
    98
     */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
    99
    BitEnumType input;
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
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   102
     * Flags to use
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
     * @see InputFlagBits
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
    InputFlags flags;
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
    /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   109
     * 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
   110
     */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   111
    int keycodes[2];
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
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
 * 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
   117
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   118
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
   119
        BitEnumType value;
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   120
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   121
        /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   122
         * 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
   123
         */
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   124
        TimeMS expire;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   125
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   126
    public:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   127
        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
   128
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   129
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   130
         * 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
   131
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   132
        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
   133
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   134
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   135
         * 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
   136
         * zero.
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   137
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   138
        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
   139
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   140
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
 * 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
   143
 * 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
   144
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   145
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
   146
    private:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   147
        TimeMS expire;
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   148
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   149
        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
   150
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   151
        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
   152
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   153
        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
   154
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   155
    public:
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
         * 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
   158
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   159
        InputKeyRepeatQueue (TimeMS expire);
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
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   162
         * 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
   163
         *
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   164
         * 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
   165
         * 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
   166
         */
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   167
        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
   168
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   169
        /**
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   170
         * 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
   171
         */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   172
        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
   173
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   174
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   175
         * 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
   176
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   177
        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
   178
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   179
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   180
         * 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
   181
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   182
        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
   183
};
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   184
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
 * 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
   187
 */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   188
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
   189
    private:
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   190
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   191
         * 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
   192
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   193
        CL_InputDevice &keyboard;
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
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   196
         * 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
   197
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   198
        InputKeymapEntry<BitEnumType> *keymap;
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
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   201
         * 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
   202
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   203
        BitMaskType 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
        /**
319
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   206
         * 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
   207
         */
9f6a838d58c4 improve input handling further, ROPE_THROW and DIG don't repeat at all now
terom
parents: 311
diff changeset
   208
        BitMaskType prev_value;
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
        /**
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   211
         * 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
   212
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   213
        TimeMS dt;
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
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   216
         * The KeyRepeatQueue
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
        InputKeyRepeatQueue<BitEnumType> queue;
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
    public:
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
         * 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
   223
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   224
        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
   225
    
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   226
    private: 
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
         * 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
   229
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   230
         * 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
   231
         * 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
   232
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   233
         * @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
   234
         * @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
   235
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   236
        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
   237
    
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   238
    public:
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
         * 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
   241
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   242
        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
   243
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   244
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   245
         * 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
   246
         *
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   247
         * @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
   248
         * @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
   249
         */
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   250
        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
   251
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   252
};
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   253
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
   254
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 237
diff changeset
   255
 * 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
   256
 */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   257
class Input {
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   258
    protected:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   259
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   260
         * 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
   261
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   262
        CL_InputDevice &keyboard;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   263
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   264
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   265
         * Our update timer
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
        Timer 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
        CL_SlotContainer slots;
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
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   272
         * Our PlayerInput
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
        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
   275
        
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   276
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   277
         * Our GuiInput
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
        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
   280
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   281
    public:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   282
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   283
         * 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
   284
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   285
        Input (CL_InputDevice &keyboard);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   286
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   287
    public:
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   288
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   289
         * Reads the current PlayerInput value via mask, and the length of the input via dt
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   290
         */
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   291
        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
   292
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   293
        /**
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 300
diff changeset
   294
         * 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
   295
         */
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   296
        GuiInput readGuiInput (void);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   297
};
230
78cf0cd69af4 better input handling
terom
parents: 229
diff changeset
   298
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   299
#endif