2020-09-28 04:15:06 +02:00
|
|
|
#define KEY_DEFINITION
|
2020-01-01 21:29:24 +01:00
|
|
|
#include "KeyPoll.h"
|
2020-07-19 21:43:29 +02:00
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2022-12-01 07:30:16 +01:00
|
|
|
#include "Alloc.h"
|
2023-03-20 02:12:49 +01:00
|
|
|
#include "ButtonGlyphs.h"
|
2023-08-18 04:57:54 +02:00
|
|
|
#include "Constants.h"
|
Call VVV_exit() when SDL_QUIT is received
This fixes a regression introduced by #535 where a quit signal (e.g.
Ctrl-C) sent to the window while the game was in unfocus pause wouldn't
close the game.
One problem was that key.quitProgram would only be checked when control
flow switched back to the outer loop in main(), which would only happen
when the loop order state machine switched to a delta function. As the
unfocused func table didn't have any delta functions, this means
key.quitProgram would never be checked.
So a naïve solution to this would just be to add a no-op delta func
entry to the unfocused func table. However, we then run into a separate
issue where a delta function at the end of a func list never reassigns
the active funcs, causing the game to be stuck in the unfocus pause
forever. Active func reassignment only happens after fixed funcs. So
then a naïve solution after that would be to simply add a no-op fixed
func entry after that. And indeed, that would fix the whole issue.
However, I want to do things the right way. And this does not seem like
the right way. Even putting aside the separate last-func-being-delta
issue, it mandates that every func list needs a delta function. Which
seems quite unnecessary to me.
Another solution I considered was copy-pasting the key.quitProgram check
to the inner loops, or adding some sort of signal propagation to
the inner loops - implemented by copy-pasting checks after each loop -
so we didn't need to copy-paste key.quitProgram... but that seems really
messy, too.
So, I realized that we could throw away key.quitProgram, and simply call
VVV_exit() directly when we receive an SDL_QUIT event. This fixes the
issue, this removes an unnecessary middleman variable, and it's pretty
cleanly and simply the right thing to do.
2021-04-02 00:24:14 +02:00
|
|
|
#include "Exit.h"
|
2020-07-19 21:43:29 +02:00
|
|
|
#include "Game.h"
|
Split glitchrunner mode into multiple versions
Previously, turning glitchrunner mode on essentially locked you to
emulating 2.0, and turning it off just meant normal 2.3 behavior. But
what if you wanted 2.2 behavior instead? Well, that's what I had to ask
when a TAS of mine would desync in 2.3 because of the two-frame delay
fix (glitchrunner off), but would also desync because of 2.0 warp lines
(glitchrunner on).
What I've done is made it so there are three states to glitchrunner mode
now: 2.0 (previously just the "on" state), 2.2 (previously a state you
couldn't use), and "off". Furthermore, I made it an enum, so in case
future versions of the game patch out more glitches, we can add them to
the enum (and the only other thing we have to update is a lookup table
in GlitchrunnerMode.c). Also, 2.2 glitches exist in 2.0, so you'll want
to use GlitchrunnerMode_less_than_or_equal() to check glitchrunner
version.
2021-08-05 02:09:49 +02:00
|
|
|
#include "GlitchrunnerMode.h"
|
2020-07-19 21:43:29 +02:00
|
|
|
#include "Graphics.h"
|
2022-12-30 22:57:24 +01:00
|
|
|
#include "Localization.h"
|
|
|
|
#include "LocalizationStorage.h"
|
2020-07-19 21:43:29 +02:00
|
|
|
#include "Music.h"
|
Extern `gameScreen`, remove `screenbuffer`
I know earlier I removed the gameScreen extern in favor of using
screenbuffer, but that was only to be consistent. After further
consideration, I have found that it's actually really stupid.
There's no reason to be accessing it through screenbuffer, and it's
probably an artifact of 2.0-2.2 passing stack-allocated otherwise-global
classes everywhere through function arguments. Also, it leads to stupid
bugs where screenbuffer could potentially be NULL, which has already
resulted in various annoying crashes in the past. Although those could
be fixed by simply initializing screenbuffer at the very top of main(),
but, why not just scrap the whole thing anyway?
So that's what I'm doing.
As a nice side effect, I've removed the transitive include of Screen.h
from Graphics.h. This could've been done already since it only includes
it for the pointer anyway, but it's still good to do it now.
2021-12-25 08:56:47 +01:00
|
|
|
#include "Screen.h"
|
2023-02-23 04:13:51 +01:00
|
|
|
#include "UTF8.h"
|
2021-02-24 00:21:29 +01:00
|
|
|
#include "Vlogging.h"
|
2020-07-19 21:43:29 +02:00
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
int inline KeyPoll::getThreshold(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
switch (sensitivity)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 28000;
|
|
|
|
case 1:
|
|
|
|
return 16000;
|
|
|
|
case 2:
|
|
|
|
return 8000;
|
|
|
|
case 3:
|
|
|
|
return 4000;
|
|
|
|
case 4:
|
|
|
|
return 2000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 8000;
|
2020-11-13 02:16:18 +01:00
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
KeyPoll::KeyPoll(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
xVel = 0;
|
|
|
|
yVel = 0;
|
|
|
|
// 0..5
|
|
|
|
sensitivity = 2;
|
2020-01-01 21:29:24 +01:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
keybuffer="";
|
|
|
|
leftbutton=0; rightbutton=0; middlebutton=0;
|
2023-08-18 04:57:54 +02:00
|
|
|
mousex = 0;
|
|
|
|
mousey = 0;
|
2021-09-07 03:56:39 +02:00
|
|
|
resetWindow = 0;
|
|
|
|
pressedbackspace=false;
|
2020-01-01 21:29:24 +01:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
linealreadyemptykludge = false;
|
Fix resumemusic/musicfadein not working
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.
2020-06-27 10:31:09 +02:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
isActive = true;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
void KeyPoll::enabletextentry(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
keybuffer="";
|
|
|
|
SDL_StartTextInput();
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
void KeyPoll::disabletextentry(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
SDL_StopTextInput();
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
bool KeyPoll::textentry(void)
|
Axe manual state trackers and use SDL_IsTextInputActive()
After looking at pull request #446, I got a bit annoyed that we have TWO
variables, key.textentrymode and ed.textentry, that we rolled ourselves
to track the state of something SDL already provides us a function to
easily query: SDL_IsTextInputActive(). We don't need to have either of
these two variables, and we shouldn't.
So that's what I do in this patch. Both variables have been axed in
favor of using this function, and I just made a wrapper out of it, named
key.textentry().
For bonus points, this gets rid of the ugly NO_CUSTOM_LEVELS and
NO_EDITOR ifdef in main.cpp, since text entry is enabled when entering
the script list and disabled when exiting it. This makes the code there
easier to read, too.
Furthermore, apparently key.textentrymode was initialized to *true*
instead of false... for whatever reason. But that's gone now, too.
Now, you'd think there wouldn't be any downside to using
SDL_IsTextInputActive(). After all, it's a function that SDL itself
provides, right?
Wrong. For whatever reason, it seems like text input is active *from the
start of the program*, meaning that what would happen is I would go into
the editor, and find that I can't move around nor place tiles nor
anything else. Then I would press Esc, and then suddenly become able to
do those things I wanted to do before.
I have no idea why the above happens, but all I can do is to just insert
an SDL_StopTextInput() immediately after the SDL_Init() in main.cpp. Of
course, I have to surround it with an SDL_IsTextInputActive() check to
make sure I don't do anything extraneous by stopping input when it's
already stopped.
2020-08-13 08:43:25 +02:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
return SDL_IsTextInputActive() == SDL_TRUE;
|
Axe manual state trackers and use SDL_IsTextInputActive()
After looking at pull request #446, I got a bit annoyed that we have TWO
variables, key.textentrymode and ed.textentry, that we rolled ourselves
to track the state of something SDL already provides us a function to
easily query: SDL_IsTextInputActive(). We don't need to have either of
these two variables, and we shouldn't.
So that's what I do in this patch. Both variables have been axed in
favor of using this function, and I just made a wrapper out of it, named
key.textentry().
For bonus points, this gets rid of the ugly NO_CUSTOM_LEVELS and
NO_EDITOR ifdef in main.cpp, since text entry is enabled when entering
the script list and disabled when exiting it. This makes the code there
easier to read, too.
Furthermore, apparently key.textentrymode was initialized to *true*
instead of false... for whatever reason. But that's gone now, too.
Now, you'd think there wouldn't be any downside to using
SDL_IsTextInputActive(). After all, it's a function that SDL itself
provides, right?
Wrong. For whatever reason, it seems like text input is active *from the
start of the program*, meaning that what would happen is I would go into
the editor, and find that I can't move around nor place tiles nor
anything else. Then I would press Esc, and then suddenly become able to
do those things I wanted to do before.
I have no idea why the above happens, but all I can do is to just insert
an SDL_StopTextInput() immediately after the SDL_Init() in main.cpp. Of
course, I have to surround it with an SDL_IsTextInputActive() check to
make sure I don't do anything extraneous by stopping input when it's
already stopped.
2020-08-13 08:43:25 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 07:26:34 +01:00
|
|
|
void KeyPoll::toggleFullscreen(void)
|
|
|
|
{
|
Extern `gameScreen`, remove `screenbuffer`
I know earlier I removed the gameScreen extern in favor of using
screenbuffer, but that was only to be consistent. After further
consideration, I have found that it's actually really stupid.
There's no reason to be accessing it through screenbuffer, and it's
probably an artifact of 2.0-2.2 passing stack-allocated otherwise-global
classes everywhere through function arguments. Also, it leads to stupid
bugs where screenbuffer could potentially be NULL, which has already
resulted in various annoying crashes in the past. Although those could
be fixed by simply initializing screenbuffer at the very top of main(),
but, why not just scrap the whole thing anyway?
So that's what I'm doing.
As a nice side effect, I've removed the transitive include of Screen.h
from Graphics.h. This could've been done already since it only includes
it for the pointer anyway, but it's still good to do it now.
2021-12-25 08:56:47 +01:00
|
|
|
gameScreen.toggleFullScreen();
|
2021-09-07 03:56:39 +02:00
|
|
|
|
|
|
|
keymap.clear(); /* we lost the input due to a new window. */
|
|
|
|
if (GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2))
|
|
|
|
{
|
|
|
|
game.press_left = false;
|
|
|
|
game.press_right = false;
|
|
|
|
game.press_action = true;
|
|
|
|
game.press_map = false;
|
|
|
|
}
|
2021-03-17 07:26:34 +01:00
|
|
|
}
|
|
|
|
|
2021-04-17 07:46:43 +02:00
|
|
|
static int changemousestate(
|
2021-09-07 03:56:39 +02:00
|
|
|
int timeout,
|
|
|
|
const bool show,
|
|
|
|
const bool hide
|
2021-04-17 07:46:43 +02:00
|
|
|
) {
|
2021-09-07 03:56:39 +02:00
|
|
|
int prev;
|
|
|
|
int new_;
|
|
|
|
|
|
|
|
if (timeout > 0)
|
|
|
|
{
|
|
|
|
return --timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we want to both show and hide at the same time, prioritize showing */
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
new_ = SDL_ENABLE;
|
|
|
|
}
|
|
|
|
else if (hide)
|
|
|
|
{
|
|
|
|
new_ = SDL_DISABLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = SDL_ShowCursor(SDL_QUERY);
|
|
|
|
|
|
|
|
if (prev == new_)
|
|
|
|
{
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_ShowCursor(new_);
|
|
|
|
|
|
|
|
switch (new_)
|
|
|
|
{
|
|
|
|
case SDL_DISABLE:
|
|
|
|
timeout = 0;
|
|
|
|
break;
|
|
|
|
case SDL_ENABLE:
|
|
|
|
timeout = 30;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeout;
|
2021-04-17 07:46:43 +02:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
void KeyPoll::Poll(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2023-08-18 04:57:54 +02:00
|
|
|
static int raw_mousex = 0;
|
|
|
|
static int raw_mousey = 0;
|
2021-09-07 03:56:39 +02:00
|
|
|
static int mousetoggletimeout = 0;
|
|
|
|
bool showmouse = false;
|
|
|
|
bool hidemouse = false;
|
|
|
|
bool altpressed = false;
|
|
|
|
bool fullscreenkeybind = false;
|
2023-08-22 15:52:53 +02:00
|
|
|
SDL_GameController *controller = NULL;
|
2021-09-07 03:56:39 +02:00
|
|
|
SDL_Event evt;
|
|
|
|
while (SDL_PollEvent(&evt))
|
|
|
|
{
|
|
|
|
switch (evt.type)
|
|
|
|
{
|
|
|
|
/* Keyboard Input */
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
{
|
|
|
|
keymap[evt.key.keysym.sym] = true;
|
|
|
|
|
|
|
|
if (evt.key.keysym.sym == SDLK_BACKSPACE)
|
|
|
|
{
|
|
|
|
pressedbackspace = true;
|
|
|
|
}
|
2020-03-13 00:29:03 +01:00
|
|
|
|
2020-03-13 00:00:18 +01:00
|
|
|
#ifdef __APPLE__ /* OSX prefers the command keys over the alt keys. -flibit */
|
2021-09-07 03:56:39 +02:00
|
|
|
altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI];
|
2020-01-01 21:29:24 +01:00
|
|
|
#else
|
2021-09-07 03:56:39 +02:00
|
|
|
altpressed = keymap[SDLK_LALT] || keymap[SDLK_RALT];
|
2020-01-01 21:29:24 +01:00
|
|
|
#endif
|
2021-09-07 03:56:39 +02:00
|
|
|
bool returnpressed = evt.key.keysym.sym == SDLK_RETURN;
|
|
|
|
bool fpressed = evt.key.keysym.sym == SDLK_f;
|
|
|
|
bool f11pressed = evt.key.keysym.sym == SDLK_F11;
|
|
|
|
if ((altpressed && (returnpressed || fpressed)) || f11pressed)
|
|
|
|
{
|
|
|
|
fullscreenkeybind = true;
|
|
|
|
}
|
|
|
|
|
2022-12-30 22:57:24 +01:00
|
|
|
if (loc::show_translator_menu && evt.key.keysym.sym == SDLK_F12 && !evt.key.repeat)
|
|
|
|
{
|
|
|
|
/* Reload language files */
|
|
|
|
loc::loadtext(false);
|
Add support for translatable sprites
Language folders can now have a graphics folder, with these files:
- sprites.png and flipsprites.png: spritesheets which contain
translated versions of the word enemies and checkpoints
- spritesmask.xml: an XML file containing all the sprites that should
be copied from the translated sprites and flipsprites images to
the original sprites/flipsprites.
This means that the translated spritesheets don't have to contain ALL
sprites - they only have to contain the translated ones. When loading
them, the game assembles a combined spritesheet with translated sprites
replacing English ones as needed, and this sheet is used to visually
substitute the normal sprites at rendering time.
It's important to note that even if 32x32 enemies have pixel-perfect
hitboxes, this is only a visual change. This has been discussed several
times on Discord - basically we don't want to give people unfair
advantages or disadvantages because of their language setting, or
change existing gameplay and speedruns tactics, which may depend on the
exact pixel arrangements of the enemies. Therefore, the hitboxes are
still based on the English sprites. This should be basically
unnoticeable for casual players, especially with some thought from
translators and artists, but there will be an option in the speedrunner
menu to display the original sprites all the time.
I removed the `VVV_freefunc(SDL_FreeSurface, *tilesheet)` in
make_array() in Graphics.cpp, which frees grphx.im_sprites_surf and
grphx.im_flipsprites_surf. Since GraphicsResources::destroy() already
frees these, it looks like the only purpose the one in make_array()
serves is to do it earlier. But now we need them again later (when
switching languages) so let's just not free them early.
2023-09-27 03:53:36 +02:00
|
|
|
graphics.grphx.init_translations();
|
2023-06-04 00:29:02 +02:00
|
|
|
music.playef(Sound_COIN);
|
2022-12-30 22:57:24 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 02:12:49 +01:00
|
|
|
BUTTONGLYPHS_keyboard_set_active(true);
|
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
if (textentry())
|
|
|
|
{
|
|
|
|
if (evt.key.keysym.sym == SDLK_BACKSPACE && !keybuffer.empty())
|
|
|
|
{
|
2023-02-23 04:13:51 +01:00
|
|
|
keybuffer.erase(UTF8_backspace(keybuffer.c_str(), keybuffer.length()));
|
2021-09-07 03:56:39 +02:00
|
|
|
if (keybuffer.empty())
|
|
|
|
{
|
|
|
|
linealreadyemptykludge = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( evt.key.keysym.sym == SDLK_v &&
|
|
|
|
keymap[SDLK_LCTRL] )
|
|
|
|
{
|
|
|
|
char* text = SDL_GetClipboardText();
|
|
|
|
if (text != NULL)
|
|
|
|
{
|
|
|
|
keybuffer += text;
|
2022-12-01 07:30:16 +01:00
|
|
|
VVV_free(text);
|
2021-09-07 03:56:39 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-31 02:18:07 +01:00
|
|
|
else if ( evt.key.keysym.sym == SDLK_x &&
|
|
|
|
keymap[SDLK_LCTRL] )
|
|
|
|
{
|
|
|
|
if (SDL_SetClipboardText(keybuffer.c_str()) == 0)
|
|
|
|
{
|
|
|
|
keybuffer = "";
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 03:56:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_KEYUP:
|
|
|
|
keymap[evt.key.keysym.sym] = false;
|
|
|
|
if (evt.key.keysym.sym == SDLK_BACKSPACE)
|
|
|
|
{
|
|
|
|
pressedbackspace = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
if (!altpressed)
|
|
|
|
{
|
|
|
|
keybuffer += evt.text.text;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Mouse Input */
|
|
|
|
case SDL_MOUSEMOTION:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.motion.x;
|
|
|
|
raw_mousey = evt.motion.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
switch (evt.button.button)
|
|
|
|
{
|
|
|
|
case SDL_BUTTON_LEFT:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
leftbutton = 1;
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_RIGHT:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
rightbutton = 1;
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_MIDDLE:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
middlebutton = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
switch (evt.button.button)
|
|
|
|
{
|
|
|
|
case SDL_BUTTON_LEFT:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
leftbutton=0;
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_RIGHT:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
rightbutton=0;
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_MIDDLE:
|
2023-08-18 04:57:54 +02:00
|
|
|
raw_mousex = evt.button.x;
|
|
|
|
raw_mousey = evt.button.y;
|
2021-09-07 03:56:39 +02:00
|
|
|
middlebutton=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Controller Input */
|
|
|
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
|
|
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = true;
|
2023-03-20 02:12:49 +01:00
|
|
|
BUTTONGLYPHS_keyboard_set_active(false);
|
2023-08-22 15:52:53 +02:00
|
|
|
|
|
|
|
controller = controllers[evt.cbutton.which];
|
2023-12-01 18:08:26 +01:00
|
|
|
BUTTONGLYPHS_update_layout(controller);
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
case SDL_CONTROLLERBUTTONUP:
|
|
|
|
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = false;
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
|
|
{
|
|
|
|
const int threshold = getThreshold();
|
|
|
|
switch (evt.caxis.axis)
|
|
|
|
{
|
|
|
|
case SDL_CONTROLLER_AXIS_LEFTX:
|
|
|
|
if ( evt.caxis.value > -threshold &&
|
|
|
|
evt.caxis.value < threshold )
|
|
|
|
{
|
|
|
|
xVel = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xVel = (evt.caxis.value > 0) ? 1 : -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_CONTROLLER_AXIS_LEFTY:
|
|
|
|
if ( evt.caxis.value > -threshold &&
|
|
|
|
evt.caxis.value < threshold )
|
|
|
|
{
|
|
|
|
yVel = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
yVel = (evt.caxis.value > 0) ? 1 : -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-03-20 02:12:49 +01:00
|
|
|
BUTTONGLYPHS_keyboard_set_active(false);
|
2023-08-22 15:52:53 +02:00
|
|
|
|
|
|
|
controller = controllers[evt.caxis.which];
|
2023-12-01 18:08:26 +01:00
|
|
|
BUTTONGLYPHS_update_layout(controller);
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_CONTROLLERDEVICEADDED:
|
|
|
|
{
|
2023-08-22 15:52:53 +02:00
|
|
|
controller = SDL_GameControllerOpen(evt.cdevice.which);
|
2021-09-07 03:56:39 +02:00
|
|
|
vlog_info(
|
|
|
|
"Opened SDL_GameController ID #%i, %s",
|
|
|
|
evt.cdevice.which,
|
2023-08-22 15:52:53 +02:00
|
|
|
SDL_GameControllerName(controller)
|
2021-09-07 03:56:39 +02:00
|
|
|
);
|
2023-08-22 15:52:53 +02:00
|
|
|
controllers[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller))] = controller;
|
2023-03-20 02:12:49 +01:00
|
|
|
BUTTONGLYPHS_keyboard_set_active(false);
|
2023-12-01 18:08:26 +01:00
|
|
|
BUTTONGLYPHS_update_layout(controller);
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_CONTROLLERDEVICEREMOVED:
|
|
|
|
{
|
2023-08-22 15:52:53 +02:00
|
|
|
controller = controllers[evt.cdevice.which];
|
2021-09-07 03:56:39 +02:00
|
|
|
controllers.erase(evt.cdevice.which);
|
2023-08-22 15:52:53 +02:00
|
|
|
vlog_info("Closing %s", SDL_GameControllerName(controller));
|
|
|
|
SDL_GameControllerClose(controller);
|
2023-03-20 02:12:49 +01:00
|
|
|
if (controllers.empty())
|
|
|
|
{
|
|
|
|
BUTTONGLYPHS_keyboard_set_active(true);
|
|
|
|
}
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Window Events */
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
switch (evt.window.event)
|
|
|
|
{
|
|
|
|
/* Window Resize */
|
|
|
|
case SDL_WINDOWEVENT_RESIZED:
|
|
|
|
if (SDL_GetWindowFlags(
|
|
|
|
SDL_GetWindowFromID(evt.window.windowID)
|
|
|
|
) & SDL_WINDOW_INPUT_FOCUS)
|
|
|
|
{
|
|
|
|
resetWindow = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Window Focus */
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
if (!game.disablepause)
|
|
|
|
{
|
|
|
|
isActive = true;
|
|
|
|
if ((!game.disableaudiopause || !game.disabletemporaryaudiopause) && music.currentsong != -1)
|
|
|
|
{
|
|
|
|
music.resume();
|
|
|
|
music.resumeef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
|
|
|
|
{
|
|
|
|
if (wasFullscreen)
|
|
|
|
{
|
Extern `gameScreen`, remove `screenbuffer`
I know earlier I removed the gameScreen extern in favor of using
screenbuffer, but that was only to be consistent. After further
consideration, I have found that it's actually really stupid.
There's no reason to be accessing it through screenbuffer, and it's
probably an artifact of 2.0-2.2 passing stack-allocated otherwise-global
classes everywhere through function arguments. Also, it leads to stupid
bugs where screenbuffer could potentially be NULL, which has already
resulted in various annoying crashes in the past. Although those could
be fixed by simply initializing screenbuffer at the very top of main(),
but, why not just scrap the whole thing anyway?
So that's what I'm doing.
As a nice side effect, I've removed the transitive include of Screen.h
from Graphics.h. This could've been done already since it only includes
it for the pointer anyway, but it's still good to do it now.
2021-12-25 08:56:47 +01:00
|
|
|
gameScreen.isWindowed = false;
|
2021-09-07 03:56:39 +02:00
|
|
|
SDL_SetWindowFullscreen(
|
|
|
|
SDL_GetWindowFromID(evt.window.windowID),
|
|
|
|
SDL_WINDOW_FULLSCREEN_DESKTOP
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_DisableScreenSaver();
|
2023-01-07 19:28:07 +01:00
|
|
|
gameScreen.recacheTextures();
|
2021-09-07 03:56:39 +02:00
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
if (!game.disablepause)
|
|
|
|
{
|
|
|
|
isActive = false;
|
|
|
|
if (!game.disableaudiopause || !game.disabletemporaryaudiopause)
|
|
|
|
{
|
|
|
|
music.pause();
|
|
|
|
music.pauseef();
|
|
|
|
}
|
|
|
|
}
|
2021-03-31 21:12:13 +02:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
|
|
|
|
{
|
Extern `gameScreen`, remove `screenbuffer`
I know earlier I removed the gameScreen extern in favor of using
screenbuffer, but that was only to be consistent. After further
consideration, I have found that it's actually really stupid.
There's no reason to be accessing it through screenbuffer, and it's
probably an artifact of 2.0-2.2 passing stack-allocated otherwise-global
classes everywhere through function arguments. Also, it leads to stupid
bugs where screenbuffer could potentially be NULL, which has already
resulted in various annoying crashes in the past. Although those could
be fixed by simply initializing screenbuffer at the very top of main(),
but, why not just scrap the whole thing anyway?
So that's what I'm doing.
As a nice side effect, I've removed the transitive include of Screen.h
from Graphics.h. This could've been done already since it only includes
it for the pointer anyway, but it's still good to do it now.
2021-12-25 08:56:47 +01:00
|
|
|
wasFullscreen = !gameScreen.isWindowed;
|
|
|
|
gameScreen.isWindowed = true;
|
2021-09-07 03:56:39 +02:00
|
|
|
SDL_SetWindowFullscreen(
|
|
|
|
SDL_GetWindowFromID(evt.window.windowID),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
SDL_EnableScreenSaver();
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Mouse Focus */
|
|
|
|
case SDL_WINDOWEVENT_ENTER:
|
|
|
|
SDL_DisableScreenSaver();
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_LEAVE:
|
|
|
|
SDL_EnableScreenSaver();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Quit Event */
|
|
|
|
case SDL_QUIT:
|
|
|
|
VVV_exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (evt.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if (evt.key.repeat == 0)
|
|
|
|
{
|
|
|
|
hidemouse = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
|
|
hidemouse = true;
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
showmouse = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mousetoggletimeout = changemousestate(
|
|
|
|
mousetoggletimeout,
|
|
|
|
showmouse,
|
|
|
|
hidemouse
|
|
|
|
);
|
|
|
|
|
|
|
|
if (fullscreenkeybind)
|
|
|
|
{
|
|
|
|
toggleFullscreen();
|
|
|
|
}
|
2023-08-18 04:57:54 +02:00
|
|
|
|
|
|
|
if (gameScreen.scalingMode == SCALING_STRETCH)
|
|
|
|
{
|
|
|
|
/* In this mode specifically, we have to fix the mouse coordinates */
|
|
|
|
int actualscreenwidth;
|
|
|
|
int actualscreenheight;
|
|
|
|
gameScreen.GetScreenSize(&actualscreenwidth, &actualscreenheight);
|
|
|
|
|
|
|
|
mousex = raw_mousex * SCREEN_WIDTH_PIXELS / actualscreenwidth;
|
|
|
|
mousey = raw_mousey * SCREEN_HEIGHT_PIXELS / actualscreenheight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mousex = raw_mousex;
|
|
|
|
mousey = raw_mousey;
|
|
|
|
}
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::isDown(SDL_Keycode key)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
return keymap[key];
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::isDown(std::vector<SDL_GameControllerButton> buttons)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
for (size_t i = 0; i < buttons.size(); i += 1)
|
|
|
|
{
|
|
|
|
if (buttonmap[buttons[i]])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::isDown(SDL_GameControllerButton button)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
return buttonmap[button];
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
bool KeyPoll::controllerButtonDown(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
for (
|
|
|
|
SDL_GameControllerButton button = SDL_CONTROLLER_BUTTON_A;
|
|
|
|
button < SDL_CONTROLLER_BUTTON_DPAD_UP;
|
|
|
|
button = (SDL_GameControllerButton) (button + 1)
|
|
|
|
) {
|
|
|
|
if (isDown(button))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::controllerWantsLeft(bool includeVert)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
return ( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_LEFT] ||
|
|
|
|
xVel < 0 ||
|
|
|
|
( includeVert &&
|
|
|
|
( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_UP] ||
|
|
|
|
yVel < 0 ) ) );
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::controllerWantsRight(bool includeVert)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
return ( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_RIGHT] ||
|
|
|
|
xVel > 0 ||
|
|
|
|
( includeVert &&
|
|
|
|
( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_DOWN] ||
|
|
|
|
yVel > 0 ) ) );
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
2022-12-30 22:57:24 +01:00
|
|
|
|
|
|
|
bool KeyPoll::controllerWantsUp(void)
|
|
|
|
{
|
|
|
|
return buttonmap[SDL_CONTROLLER_BUTTON_DPAD_UP] || yVel < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyPoll::controllerWantsDown(void)
|
|
|
|
{
|
|
|
|
return buttonmap[SDL_CONTROLLER_BUTTON_DPAD_DOWN] || yVel > 0;
|
|
|
|
}
|