mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-04 18:52:51 +00:00
redesigned the actionsspressed/lactionspressed system into action_states
This commit is contained in:
parent
53ef0889b8
commit
0dc842f648
115
multi.cpp
115
multi.cpp
@ -109,6 +109,15 @@ EX namespace multi {
|
|||||||
"world overview", "review your quest", "inventory", "main menu"
|
"world overview", "review your quest", "inventory", "main menu"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum pancmds {
|
||||||
|
// 0..3
|
||||||
|
panUp, panRight, panDown, panLeft,
|
||||||
|
// 4..10
|
||||||
|
panRotateLeft, panRotateRight, panHome, panWorldOverview, panReviewQuest, panInventory, panMenu,
|
||||||
|
// 11..12
|
||||||
|
panScrollForward, panScrollBackward
|
||||||
|
};
|
||||||
|
|
||||||
vector<string> pancmds3 = {
|
vector<string> pancmds3 = {
|
||||||
"look up", "look right", "look down", "look left",
|
"look up", "look right", "look down", "look left",
|
||||||
"rotate left", "rotate right", "home",
|
"rotate left", "rotate right", "home",
|
||||||
@ -118,8 +127,9 @@ EX namespace multi {
|
|||||||
|
|
||||||
#if HDR
|
#if HDR
|
||||||
#define SHMUPAXES_BASE 4
|
#define SHMUPAXES_BASE 4
|
||||||
#define SHMUPAXES ((SHMUPAXES_BASE) + 4 * (MAXPLAYER))
|
#define SHMUPAXES_PER_PLAYER 4
|
||||||
#define SHMUPAXES_CUR ((SHMUPAXES_BASE) + 4 * playercfg)
|
#define SHMUPAXES ((SHMUPAXES_BASE) + SHMUPAXES_PER_PLAYER * (MAXPLAYER))
|
||||||
|
#define SHMUPAXES_CUR ((SHMUPAXES_BASE) + SHMUPAXES_PER_PLAYER * playercfg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EX const char* axemodes[SHMUPAXES] = {
|
EX const char* axemodes[SHMUPAXES] = {
|
||||||
@ -579,11 +589,29 @@ enum pcmds {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EX int actionspressed[NUMACT], axespressed[SHMUPAXES], lactionpressed[NUMACT];
|
EX array<int, SHMUPAXES> axe_states;
|
||||||
|
|
||||||
|
EX array<int,SHMUPAXES_PER_PLAYER>& axes_for(int pid) {
|
||||||
|
return * (array<int,SHMUPAXES_PER_PLAYER>*) (&axe_states[SHMUPAXES_BASE + pid*SHMUPAXES_PER_PLAYER]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if HDR
|
||||||
|
struct action_state {
|
||||||
|
int held, last;
|
||||||
|
bool pressed() { return held > last; }
|
||||||
|
operator bool() { return held; }
|
||||||
|
operator int() { return held; }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EX array<action_state, NUMACT> action_states_flat;
|
||||||
|
|
||||||
|
#if HDR
|
||||||
|
static array<array<action_state, 16>, 8>& action_states = reinterpret_cast<array<array<action_state, 16>, 8>&> (action_states_flat);
|
||||||
|
#endif
|
||||||
|
|
||||||
void pressaction(int id) {
|
void pressaction(int id) {
|
||||||
if(id >= 0 && id < NUMACT)
|
if(id >= 0 && id < NUMACT) action_states_flat[id].held++;
|
||||||
actionspressed[id]++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EX int key_to_scan(int sym) {
|
EX int key_to_scan(int sym) {
|
||||||
@ -796,11 +824,9 @@ EX void get_actions(config& scfg) {
|
|||||||
#if !ISMOBILE
|
#if !ISMOBILE
|
||||||
const Uint8 *keystate = SDL12_GetKeyState(NULL);
|
const Uint8 *keystate = SDL12_GetKeyState(NULL);
|
||||||
|
|
||||||
for(int i=0; i<NUMACT; i++)
|
for(auto& a: action_states_flat) a.last = a.held, a.held = 0;
|
||||||
lactionpressed[i] = actionspressed[i],
|
|
||||||
actionspressed[i] = 0;
|
|
||||||
|
|
||||||
for(int i=0; i<SHMUPAXES; i++) axespressed[i] = 0;
|
for(int i=0; i<SHMUPAXES; i++) axe_states[i] = 0;
|
||||||
|
|
||||||
for(int i=0; i<KEYSTATES; i++) if(keystate[i])
|
for(int i=0; i<KEYSTATES; i++) if(keystate[i])
|
||||||
pressaction(scfg.keyaction[i]);
|
pressaction(scfg.keyaction[i]);
|
||||||
@ -825,13 +851,17 @@ EX void get_actions(config& scfg) {
|
|||||||
int dz = scfg.deadzoneval[j][b];
|
int dz = scfg.deadzoneval[j][b];
|
||||||
if(value > dz) value -= dz; else if(value < -dz) value += dz;
|
if(value > dz) value -= dz; else if(value < -dz) value += dz;
|
||||||
else value = 0;
|
else value = 0;
|
||||||
axespressed[scfg.axeaction[j][b] % SHMUPAXES] += value;
|
axe_states[scfg.axeaction[j][b] % SHMUPAXES] += value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HDR
|
||||||
|
static constexpr int pantable = 3;
|
||||||
|
#endif
|
||||||
|
|
||||||
EX void handleInput(int delta, config &scfg) {
|
EX void handleInput(int delta, config &scfg) {
|
||||||
#if CAP_SDL
|
#if CAP_SDL
|
||||||
double d = delta / 500.;
|
double d = delta / 500.;
|
||||||
@ -842,34 +872,34 @@ EX void handleInput(int delta, config &scfg) {
|
|||||||
|
|
||||||
if(keystate[SDL12(SDLK_LCTRL, SDL_SCANCODE_LCTRL)] || keystate[SDL12(SDLK_RCTRL, SDL_SCANCODE_RCTRL)]) d /= 5;
|
if(keystate[SDL12(SDLK_LCTRL, SDL_SCANCODE_LCTRL)] || keystate[SDL12(SDLK_RCTRL, SDL_SCANCODE_RCTRL)]) d /= 5;
|
||||||
|
|
||||||
double panx =
|
auto& act = action_states[pantable];
|
||||||
actionspressed[49] - actionspressed[51] + axespressed[2] / 32000.0;
|
|
||||||
double pany =
|
|
||||||
actionspressed[50] - actionspressed[48] + axespressed[3] / 32000.0;
|
|
||||||
|
|
||||||
double panspin = actionspressed[52] - actionspressed[53];
|
double panx = act[panRight].held - act[panLeft].held + axe_states[2] / 32000.0;
|
||||||
|
double pany = act[panDown].held - act[panUp].held + axe_states[3] / 32000.0;
|
||||||
|
|
||||||
double panmove = actionspressed[59] - actionspressed[60];
|
double panspin = act[panRotateLeft].held - act[panRotateRight].held;
|
||||||
|
|
||||||
|
double panmove = act[panScrollForward].held - act[panScrollBackward].held;
|
||||||
|
|
||||||
if(GDIM == 3)
|
if(GDIM == 3)
|
||||||
panmove += axespressed[1] / 32000.0;
|
panmove += axe_states[1] / 32000.0;
|
||||||
else
|
else
|
||||||
panspin += axespressed[1] / 32000.0;
|
panspin += axe_states[1] / 32000.0;
|
||||||
|
|
||||||
if(actionspressed[54]) { centerplayer = -1, playermoved = true; centerpc(100); }
|
if(act[panHome]) { centerplayer = -1, playermoved = true; centerpc(100); }
|
||||||
|
|
||||||
if(actionspressed[55] && !lactionpressed[55])
|
if(act[panWorldOverview].pressed())
|
||||||
get_o_key().second();
|
get_o_key().second();
|
||||||
|
|
||||||
if(actionspressed[56] && !lactionpressed[56])
|
if(act[panReviewQuest].pressed())
|
||||||
showMissionScreen();
|
showMissionScreen();
|
||||||
|
|
||||||
#if CAP_INV
|
#if CAP_INV
|
||||||
if(actionspressed[57] && !lactionpressed[57] && inv::on)
|
if(act[panInventory].pressed() && inv::on)
|
||||||
pushScreen(inv::show);
|
pushScreen(inv::show);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(actionspressed[58] && !lactionpressed[58])
|
if(act[panMenu].pressed())
|
||||||
pushScreen(showGameMenu);
|
pushScreen(showGameMenu);
|
||||||
|
|
||||||
panx *= d;
|
panx *= d;
|
||||||
@ -967,27 +997,30 @@ EX void handleInput(int delta, config &scfg) {
|
|||||||
|
|
||||||
cpid = i;
|
cpid = i;
|
||||||
|
|
||||||
int b = 16*tableid[cpid];
|
int id = tableid[cpid];
|
||||||
for(int ik=0; ik<8; ik++) if(actionspressed[b+ik]) playermoved = true;
|
auto& act = action_states[id];
|
||||||
for(int ik=0; ik<16; ik++) if(actionspressed[b+ik] && !lactionpressed[b+ik])
|
|
||||||
|
for(int ik=0; ik<8; ik++) if(act[ik]) playermoved = true;
|
||||||
|
for(int ik=0; ik<16; ik++) if(act[ik].pressed())
|
||||||
multi::combo[i] = false;
|
multi::combo[i] = false;
|
||||||
|
|
||||||
bool anypressed = false;
|
bool anypressed = false;
|
||||||
|
|
||||||
int jb = 4*tableid[cpid];
|
auto &axes = axes_for(cpid);
|
||||||
|
|
||||||
for(int ik=0; ik<4; ik++)
|
for(int ik=0; ik<4; ik++)
|
||||||
if(axespressed[jb+ik])
|
if(axes[ik])
|
||||||
anypressed = true, playermoved = true, multi::combo[i] = false;
|
anypressed = true, playermoved = true, multi::combo[i] = false;
|
||||||
|
|
||||||
double mdx =
|
double mdx =
|
||||||
(actionspressed[b+0] + actionspressed[b+2] - actionspressed[b+1] - actionspressed[b+3]) * .7 +
|
(act[0] + act[2] - act[1] - act[3]) * .7 +
|
||||||
actionspressed[b+pcMoveRight] - actionspressed[b+pcMoveLeft] + axespressed[jb]/30000.;
|
act[pcMoveRight] - act[pcMoveLeft] + axes[0]/30000.;
|
||||||
double mdy =
|
double mdy =
|
||||||
(actionspressed[b+3] + actionspressed[b+2] - actionspressed[b+1] - actionspressed[b+0]) * .7 +
|
(act[3] + act[2] - act[1] - act[0]) * .7 +
|
||||||
actionspressed[b+pcMoveDown] - actionspressed[b+pcMoveUp] + axespressed[jb+1]/30000.;
|
act[pcMoveDown] - act[pcMoveUp] + axes[1]/30000.;
|
||||||
|
|
||||||
if((actionspressed[b+pcMoveRight] && actionspressed[b+pcMoveLeft]) ||
|
if((act[pcMoveRight] && act[pcMoveLeft]) ||
|
||||||
(actionspressed[b+pcMoveUp] && actionspressed[b+pcMoveDown]))
|
(act[pcMoveUp] && act[pcMoveDown]))
|
||||||
multi::mdx[i] = multi::mdy[i] = 0;
|
multi::mdx[i] = multi::mdy[i] = 0;
|
||||||
|
|
||||||
multi::mdx[i] = multi::mdx[i] * (1 - delta / 1000.) + mdx * delta / 2000.;
|
multi::mdx[i] = multi::mdx[i] * (1 - delta / 1000.) + mdx * delta / 2000.;
|
||||||
@ -1001,11 +1034,10 @@ EX void handleInput(int delta, config &scfg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(multi::actionspressed[b+pcFire] ||
|
if(act[pcFire] ||(act[pcMoveLeft] && act[pcMoveRight]))
|
||||||
(multi::actionspressed[b+pcMoveLeft] && multi::actionspressed[b+pcMoveRight]))
|
|
||||||
multi::combo[i] = true, multi::whereto[i].d = MD_WAIT;
|
multi::combo[i] = true, multi::whereto[i].d = MD_WAIT;
|
||||||
|
|
||||||
if(multi::actionspressed[b+pcFace])
|
if(act[pcFace])
|
||||||
multi::whereto[i].d = MD_UNDECIDED;
|
multi::whereto[i].d = MD_UNDECIDED;
|
||||||
|
|
||||||
cwt.at = multi::player[i].at;
|
cwt.at = multi::player[i].at;
|
||||||
@ -1014,22 +1046,21 @@ EX void handleInput(int delta, config &scfg) {
|
|||||||
multi::whereto[i].tgt = multi::ccat[i];
|
multi::whereto[i].tgt = multi::ccat[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(multi::actionspressed[b+pcFaceFire] && activePlayers() > 1) {
|
if(act[pcFaceFire] && activePlayers() > 1) {
|
||||||
addMessage(XLAT("Left the game."));
|
addMessage(XLAT("Left the game."));
|
||||||
multi::leaveGame(i);
|
multi::leaveGame(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(actionspressed[b+pcDrop] ||
|
if(act[pcDrop] || (act[pcMoveUp] && act[pcMoveDown]))
|
||||||
(multi::actionspressed[b+pcMoveUp] && multi::actionspressed[b+pcMoveDown]))
|
|
||||||
multi::combo[i] = true, multi::whereto[i].d = MD_DROP;
|
multi::combo[i] = true, multi::whereto[i].d = MD_DROP;
|
||||||
|
|
||||||
if(actionspressed[b+pcCenter]) {
|
if(act[pcCenter]) {
|
||||||
centerplayer = cpid; centerpc(100); playermoved = true;
|
centerplayer = cpid; centerpc(100); playermoved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(multi::whereto[i].d == MD_UNDECIDED) alldecided = false;
|
if(multi::whereto[i].d == MD_UNDECIDED) alldecided = false;
|
||||||
|
|
||||||
for(int ik=0; ik<16; ik++) if(actionspressed[b+ik]) anypressed = true;
|
for(int ik=0; ik<16; ik++) if(act[ik]) anypressed = true;
|
||||||
|
|
||||||
if(anypressed) alldecided = false, needinput = false;
|
if(anypressed) alldecided = false, needinput = false;
|
||||||
else multi::mdx[i] = multi::mdy[i] = 0;
|
else multi::mdx[i] = multi::mdy[i] = 0;
|
||||||
|
29
shmup.cpp
29
shmup.cpp
@ -764,22 +764,21 @@ void movePlayer(monster *m, int delta) {
|
|||||||
// silence warning that facemouse unused
|
// silence warning that facemouse unused
|
||||||
}
|
}
|
||||||
|
|
||||||
int b = 16*tableid[cpid];
|
auto& act = action_states[tableid[cpid]];
|
||||||
|
auto& axes = axes_for(cpid);
|
||||||
|
|
||||||
for(int i=(WDIM == 3 ? 4 : 0); i<8; i++) if(actionspressed[b+i]) playermoved = true;
|
for(int i=(WDIM == 3 ? 4 : 0); i<8; i++) if(act[i]) playermoved = true;
|
||||||
|
for(int i=0; i<4; i++) if(axes[i]) playermoved = true;
|
||||||
int jb = 4*tableid[cpid];
|
|
||||||
for(int i=0; i<4; i++) if(axespressed[jb+i]) playermoved = true;
|
|
||||||
|
|
||||||
#if !ISMOBILE
|
#if !ISMOBILE
|
||||||
mgo = actionspressed[b+pcForward] - actionspressed[b+pcBackward] + axespressed[jb+2]/30000.;
|
mgo = act[pcForward] - act[pcBackward] + axes[2]/30000.;
|
||||||
mturn = actionspressed[b+pcTurnLeft] - actionspressed[b+pcTurnRight] + axespressed[jb+3]/30000.;
|
mturn = act[pcTurnLeft] - act[pcTurnRight] + axes[3]/30000.;
|
||||||
mdx = actionspressed[b+pcMoveRight] - actionspressed[b+pcMoveLeft] + axespressed[jb]/30000.;
|
mdx = act[pcMoveRight] - act[pcMoveLeft] + axes[0]/30000.;
|
||||||
mdy = actionspressed[b+pcMoveDown] - actionspressed[b+pcMoveUp] + axespressed[jb+1]/30000.;
|
mdy = act[pcMoveDown] - act[pcMoveUp] + axes[1]/30000.;
|
||||||
|
|
||||||
shotkey = actionspressed[b+pcFire] || actionspressed[b+pcFaceFire];
|
shotkey = act[pcFire] || act[pcFaceFire];
|
||||||
facemouse = actionspressed[b+pcFace] || actionspressed[b+pcFaceFire];
|
facemouse = act[pcFace] || act[pcFaceFire];
|
||||||
dropgreen = actionspressed[b+pcDrop];
|
dropgreen = act[pcDrop];
|
||||||
|
|
||||||
#else
|
#else
|
||||||
mdx = mdy = mgo = mturn = 0;
|
mdx = mdy = mgo = mturn = 0;
|
||||||
@ -814,7 +813,7 @@ void movePlayer(monster *m, int delta) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(actionspressed[b+pcOrbPower] && !lactionpressed[b+pcOrbPower] && mouseover && !m->dead) {
|
if(act[pcOrbPower].pressed() && mouseover && !m->dead) {
|
||||||
cwt.at = m->base;
|
cwt.at = m->base;
|
||||||
targetRangedOrb(mouseover, roKeyboard);
|
targetRangedOrb(mouseover, roKeyboard);
|
||||||
}
|
}
|
||||||
@ -822,7 +821,7 @@ void movePlayer(monster *m, int delta) {
|
|||||||
#if !ISMOBILE
|
#if !ISMOBILE
|
||||||
if(haveRangedOrb() && !m->dead) {
|
if(haveRangedOrb() && !m->dead) {
|
||||||
cwt.at = m->base;
|
cwt.at = m->base;
|
||||||
if(actionspressed[b+pcOrbKey] && !lactionpressed[b+pcOrbKey])
|
if(act[pcOrbKey].pressed())
|
||||||
keyresult[cpid] = targetRangedOrbKey(roKeyboard);
|
keyresult[cpid] = targetRangedOrbKey(roKeyboard);
|
||||||
else
|
else
|
||||||
keyresult[cpid] = targetRangedOrbKey(roCheck);
|
keyresult[cpid] = targetRangedOrbKey(roCheck);
|
||||||
@ -833,7 +832,7 @@ void movePlayer(monster *m, int delta) {
|
|||||||
|
|
||||||
bool stdracing = racing::on && !inertia_based;
|
bool stdracing = racing::on && !inertia_based;
|
||||||
|
|
||||||
if(actionspressed[b+pcCenter]) {
|
if(act[pcCenter]) {
|
||||||
if(!racing::on) {
|
if(!racing::on) {
|
||||||
centerplayer = cpid; centerpc(100); playermoved = true;
|
centerplayer = cpid; centerpc(100); playermoved = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user