1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 22:18:30 +02:00
VVVVVV/desktop_version/src/KeyPoll.h
Info Teddy 5a316d65e6 Allow using help/graphics/music/game/key/map/obj everywhere
This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and
`obj` essentially static global objects that can be used everywhere.
This is useful in case we ever need to add a new function in the future,
so we don't have to bother with passing a new argument in which means we
have to pass a new argument in to the function that calls that function
which means having to pass a new argument into the function that calls
THAT function, etc. which is a real headache when working on fan mods of
the source code.

Note that this changes NONE of the existing function signatures, it
merely just makes those variables accessible everywhere in the same way
`script` and `ed` are.

Also note that some classes had to be initialized after the filesystem
was initialized, but C++ would keep initializing them before the
filesystem got initialized, because I *had* to put them at the top of
`main.cpp`, or else they wouldn't be global variables.

The only way to work around this was to use entityclass's initialization
style (which I'm pretty sure entityclass of all things doesn't need to
be initialized this way), where you actually initialize the class in an
`init()` function, and so then you do `graphics.init()` after the
filesystem initialization, AFTER doing `Graphics graphics` up at the
top.

I've had to do this for `graphics` (but only because its child
GraphicsResources `grphx` needs to be initialized this way), `music`,
and `game`. I don't think this will affect anything. Other than that,
`help`, `key`, and `map` are still using the C++-intended method of
having ClassName::ClassName() functions.
2020-01-29 07:58:23 -05:00

87 lines
1.5 KiB
C++

#ifndef KEYPOLL_H
#define KEYPOLL_H
#include <string>
#include <vector>
#include <map> // FIXME: I should feel very bad for using C++ -flibit
#include "SDL.h"
enum Kybrd
{
KEYBOARD_UP = SDLK_UP,
KEYBOARD_DOWN = SDLK_DOWN,
KEYBOARD_LEFT = SDLK_LEFT,
KEYBOARD_RIGHT = SDLK_RIGHT,
KEYBOARD_ENTER = SDLK_RETURN,
KEYBOARD_SPACE = SDLK_SPACE,
KEYBOARD_w = SDLK_w,
KEYBOARD_s = SDLK_s,
KEYBOARD_a = SDLK_a,
KEYBOARD_d = SDLK_d,
KEYBOARD_m = SDLK_m,
KEYBOARD_v = SDLK_v,
KEYBOARD_z = SDLK_z,
KEYBOARD_BACKSPACE = SDLK_BACKSPACE
};
class KeyPoll
{
public:
std::map<SDL_Keycode, bool> keymap;
bool isActive;
bool resetWindow;
bool escapeWasPressedPreviously;
bool quitProgram;
bool toggleFullscreen;
int sensitivity;
void setSensitivity(int _value);
KeyPoll();
void enabletextentry();
void disabletextentry();
void Poll();
bool isDown(SDL_Keycode key);
bool isUp(SDL_Keycode key);
bool isDown(std::vector<SDL_GameControllerButton> buttons);
bool isDown(SDL_GameControllerButton button);
bool controllerButtonDown();
bool controllerWantsLeft(bool includeVert);
bool controllerWantsRight(bool includeVert);
int leftbutton, rightbutton, middlebutton;
int mx, my;
bool textentrymode;
int keyentered, keybufferlen;
bool pressedbackspace;
std::string keybuffer;
bool linealreadyemptykludge;
private:
std::map<SDL_JoystickID, SDL_GameController*> controllers;
std::map<SDL_GameControllerButton, bool> buttonmap;
int xVel, yVel;
bool useFullscreenSpaces;
Uint32 wasFullscreen;
};
extern KeyPoll key;
#endif /* KEYPOLL_H */