mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-09-29 01:37:23 +02:00
facb079b35
It seems like they were unfinished. This commit makes them properly work. When a track is stopped with stopmusic() or musicfadeout(), resumemusic() will resume from where the track stopped. musicfadein() does the same but does it with a gradual fade instead of suddenly playing it at full volume. I changed several interfaces around for this. First, setting currentsong to -1 when music is stopped is handled in the hook callback that gets called by SDL_mixer whenever the music stops. Otherwise, it'd be problematic if currentsong was set to -1 when the song starts fading out instead of when the song actually ends. Also, music.play() has a few optional arguments now, to reduce the copying-and-pasting of music code. Lastly, we have to roll our own tracker of music length by using SDL_GetPerformanceCounter(), because there's no way to get the music position if a song fades out. (We could implicitly keep the music position if we abruptly stopped the song using Mix_PauseMusic(), and resume it using Mix_ResumeMusic(), but ignoring the fact that those two functions are also used on the unfocus-pause (which, as it turns out, is basically a non-issue because the unfocus-pause can use some other functions), there's no equivalent for fading out, i.e. there's no "fade out and pause when it fully fades out" function in SDL_mixer.) And then we have to account for the unfocus-pause in our manual tracker. Other than that, these commands are now fully functional.
91 lines
1.6 KiB
C++
91 lines
1.6 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"
|
|
|
|
#include "Screen.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_n = SDLK_n,
|
|
|
|
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;
|
|
|
|
Uint64 pauseStart;
|
|
|
|
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 */
|