mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-01-11 18:00:34 +00:00
oldstyle joystick: smoothening input, ignoring next input
This commit is contained in:
parent
cb4ce17598
commit
cacfa8dee9
@ -392,6 +392,7 @@ EX void initConfig() {
|
||||
|
||||
addsaver(vid.joyvalue, "vid.joyvalue", 4800);
|
||||
addsaver(vid.joyvalue2, "vid.joyvalue2", 5600);
|
||||
addsaver(vid.joysmooth, "vid.joysmooth", 200);
|
||||
addsaver(vid.joypanthreshold, "vid.joypanthreshold", 2500);
|
||||
addsaver(vid.joypanspeed, "vid.joypanspeed", ISPANDORA ? 0.0001 : 0);
|
||||
addsaver(autojoy, "autojoy");
|
||||
@ -1358,6 +1359,7 @@ EX void showJoyConfig() {
|
||||
dialog::addSelItem(XLAT("first joystick: execute movement threshold"), its(vid.joyvalue2), 'b');
|
||||
dialog::addSelItem(XLAT("second joystick: pan threshold"), its(vid.joypanthreshold), 'c');
|
||||
dialog::addSelItem(XLAT("second joystick: panning speed"), fts(vid.joypanspeed * 1000), 'd');
|
||||
dialog::addSelItem(XLAT("smoothen"), its(vid.joysmooth) + " ms", 'e');
|
||||
|
||||
dialog::addBreak(50);
|
||||
dialog::addBack();
|
||||
@ -1380,6 +1382,8 @@ EX void showJoyConfig() {
|
||||
}
|
||||
else if(uni == 'd')
|
||||
dialog::editNumber(vid.joypanspeed, 0, 1e-2, 1e-5, 1e-4, XLAT("second joystick: panning speed"), "");
|
||||
else if(uni == 'e')
|
||||
dialog::editNumber(vid.joypanspeed, 0, 2000, 20, 200, XLAT("smoothen"), "large values help if the joystick is imprecise");
|
||||
|
||||
else if(doexiton(sym, uni)) popScreen();
|
||||
};
|
||||
|
23
control.cpp
23
control.cpp
@ -213,6 +213,9 @@ EX void closeJoysticks() {
|
||||
numsticks = 0;
|
||||
}
|
||||
|
||||
int joytime;
|
||||
EX bool joy_ignore_next = false;
|
||||
|
||||
EX void checkjoy() {
|
||||
DEBB(DF_GRAPH, ("check joy"));
|
||||
if(!DEFAULTCONTROL) return;
|
||||
@ -227,15 +230,27 @@ EX void checkjoy() {
|
||||
int curstate = sq < joyvalue1 ? 0 : sq < joyvalue2 ? 1 : 2;
|
||||
if(curstate != laststate) flashMessages(), laststate = curstate;
|
||||
|
||||
static int lt = ticks;
|
||||
int delta = ticks - lt;
|
||||
lt = ticks;
|
||||
|
||||
if(autojoy) {
|
||||
if(sq < joyvalue1) { if(joydir.d >= 0) movepcto(joydir); joydir.d = -1; return; }
|
||||
if(sq < joyvalue1) { if(joydir.d >= 0 && !joy_ignore_next) movepcto(joydir); joydir.d = -1; joytime = 0; joy_ignore_next = false; return; }
|
||||
if(sq < joyvalue2 && joydir.d == -1) return;
|
||||
}
|
||||
else {
|
||||
if(sq < joyvalue1) { joydir.d = -1; return; }
|
||||
}
|
||||
|
||||
joydir = vectodir(tangent_length(point2(jx, jy), 0.01));
|
||||
auto new_joydir = vectodir(tangent_length(point2(jx, jy), 0.01));
|
||||
if(new_joydir.d == joydir.d && new_joydir.subdir == joydir.subdir) {
|
||||
joytime += delta;
|
||||
if(joytime > vid.joysmooth) joytime = vid.joysmooth;
|
||||
}
|
||||
else {
|
||||
joytime -= delta;
|
||||
if(joytime < 0) joytime = -joytime, joydir = new_joydir;
|
||||
}
|
||||
}
|
||||
|
||||
EX void checkpanjoy(double t) {
|
||||
@ -715,6 +730,9 @@ EX void mainloopiter() {
|
||||
achievement_pump();
|
||||
while(SDL_PollEvent(&ev)) handle_event(ev);
|
||||
fix_mouseh();
|
||||
#if CAP_SDLJOY
|
||||
if(joydir.d != -1) checkjoy();
|
||||
#endif
|
||||
}
|
||||
|
||||
EX void handle_event(SDL_Event& ev) {
|
||||
@ -785,6 +803,7 @@ EX void handle_event(SDL_Event& ev) {
|
||||
else if(ev.type == SDL_JOYBUTTONDOWN && normal && DEFAULTCONTROL) {
|
||||
flashMessages();
|
||||
movepcto(joydir);
|
||||
joy_ignore_next = true;
|
||||
checkjoy();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user