mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-27 17:23:02 +02:00
Keep input repeat timings independent of FPS
This commit is contained in:
parent
cb46b53982
commit
d4d2b7c7cb
3 changed files with 822 additions and 801 deletions
File diff suppressed because it is too large
Load diff
|
@ -20,11 +20,12 @@
|
|||
*/
|
||||
|
||||
#include "input.h"
|
||||
#include "config.h"
|
||||
#include "sharedstate.h"
|
||||
#include "eventthread.h"
|
||||
#include "keybindings.h"
|
||||
#include "exception.h"
|
||||
#include "util.h"
|
||||
#include "input/keybindings.h"
|
||||
#include "util/exception.h"
|
||||
#include "util/util.h"
|
||||
|
||||
#include <SDL_scancode.h>
|
||||
#include <SDL_keyboard.h>
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include <SDL_clipboard.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <unordered_map>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -679,6 +681,9 @@ struct InputPrivate
|
|||
unsigned int repeatCount;
|
||||
unsigned int rawRepeatCount;
|
||||
|
||||
unsigned int repeatStart;
|
||||
unsigned int repeatDelay;
|
||||
|
||||
struct
|
||||
{
|
||||
int active;
|
||||
|
@ -690,6 +695,16 @@ struct InputPrivate
|
|||
int active;
|
||||
} dir8Data;
|
||||
|
||||
void recalcRepeatTime(unsigned int fps) {
|
||||
double framems = 1.f / fps;
|
||||
|
||||
// Approximate time in milliseconds
|
||||
double start = (rgssVer >= 2) ? 0.375 : 0.400;
|
||||
double delay = 0.100;
|
||||
|
||||
repeatStart = ceil(start / framems);
|
||||
repeatDelay = ceil(delay / framems);
|
||||
}
|
||||
|
||||
InputPrivate(const RGSSThreadData &rtData)
|
||||
{
|
||||
|
@ -699,6 +714,10 @@ struct InputPrivate
|
|||
/* Main thread should have these posted by now */
|
||||
checkBindingChange(rtData);
|
||||
|
||||
int fps = rtData.config.fixedFramerate;
|
||||
if (!fps) fps = (rgssVer >= 2) ? 60 : 40;
|
||||
recalcRepeatTime(fps);
|
||||
|
||||
states = stateArray;
|
||||
statesOld = stateArray + BUTTON_CODE_COUNT;
|
||||
|
||||
|
@ -789,15 +808,7 @@ struct InputPrivate
|
|||
b.triggered = (rawStates[scancode] && !rawStatesOld[scancode]);
|
||||
b.released = (!rawStates[scancode] && rawStatesOld[scancode]);
|
||||
|
||||
bool repeated = false;
|
||||
if (scancode == rawRepeating)
|
||||
{
|
||||
if (rgssVer >= 2)
|
||||
repeated = rawRepeatCount >= 23 && ((rawRepeatCount+1) % 6) == 0;
|
||||
else
|
||||
repeated = rawRepeatCount >= 15 && ((rawRepeatCount+1) % 4) == 0;
|
||||
}
|
||||
b.repeated = repeated;
|
||||
b.repeated = rawRepeatCount >= repeatStart && ((rawRepeatCount+1) % repeatDelay) == 0;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
@ -1090,6 +1101,10 @@ Input::Input(const RGSSThreadData &rtData)
|
|||
p = new InputPrivate(rtData);
|
||||
}
|
||||
|
||||
void Input::recalcRepeat(unsigned int fps) {
|
||||
p->recalcRepeatTime(fps);
|
||||
}
|
||||
|
||||
void Input::update()
|
||||
{
|
||||
shState->checkShutdown();
|
||||
|
@ -1121,12 +1136,14 @@ void Input::update()
|
|||
{
|
||||
p->repeatCount++;
|
||||
|
||||
/*
|
||||
bool repeated;
|
||||
if (rgssVer >= 2)
|
||||
repeated = p->repeatCount >= 23 && ((p->repeatCount+1) % 6) == 0;
|
||||
else
|
||||
repeated = p->repeatCount >= 15 && ((p->repeatCount+1) % 4) == 0;
|
||||
|
||||
*/
|
||||
bool repeated = p->repeatCount >= p->repeatStart && ((p->repeatCount+1) & p->repeatDelay) == 0;
|
||||
p->getState(p->repeating).repeated |= repeated;
|
||||
|
||||
return;
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
MouseLeft = 38, MouseMiddle = 39, MouseRight = 40
|
||||
};
|
||||
|
||||
void recalcRepeat(unsigned int fps);
|
||||
|
||||
void update();
|
||||
|
||||
std::vector<std::string> getBindings(ButtonCode code);
|
||||
|
|
Loading…
Add table
Reference in a new issue