From f530732c462314848aed4f0f99cccd7c721b2e05 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Jul 2020 15:03:09 +0200 Subject: [PATCH] - adjustments for input --- source/games/duke/src/actors.cpp | 20 +++++++--- source/games/duke/src/player.cpp | 11 ++++-- source/games/duke/src/player.h | 1 + source/games/duke/src/player_d.cpp | 58 ++++++++++++++++++----------- source/games/duke/src/player_r.cpp | 60 +++++++++++++++--------------- source/games/duke/src/types.h | 7 ++-- 6 files changed, 94 insertions(+), 63 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 9e80782fe..46eafff2e 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -444,7 +444,12 @@ void moveplayers(void) //Players execute(i, s->yvel, otherx); + //thisPlayer.smoothcamera = false; + //p->q16angvel = G_GetQ16AngleDelta(pPlayer->oq16ang, pPlayer->q16ang); p->oq16ang = p->q16ang; + p->oq16horiz = p->q16horiz; + p->oq16horizoff = p->q16horizoff; + if (ud.multimode > 1) if (sprite[ps[otherp].i].extra > 0) @@ -459,6 +464,12 @@ void moveplayers(void) //Players } } } + + if (p->actorsqu >= 0) + { + p->addang(getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2, true); + } + if (ud.god) { s->extra = max_player_health; @@ -467,7 +478,6 @@ void moveplayers(void) //Players p->jetpack_amount = 1599; } - if (s->extra > 0) { // currently alive... @@ -491,7 +501,7 @@ void moveplayers(void) //Players { int ang = p->getang(); ang += getincangle(ang, getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1; - p->setang(ang & 2047); + p->setang(ang & 2047, true); } } @@ -750,7 +760,7 @@ void movecrane(int i, int crane) s->owner = -2; ps[p].on_crane = i; spritesound(isRR() ? 390 : DUKE_GRUNT, ps[p].i); - ps[p].setang(s->ang + 1024); + ps[p].setang(s->ang + 1024, true); } else { @@ -2674,7 +2684,7 @@ void handle_se00(int i, int LASERLINE) if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1) { - ps[p].addang(l * q); + ps[p].addang(l * q, true); ps[p].posz += zchange; @@ -2866,7 +2876,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].bobposx += m; ps[p].bobposy += x; - ps[p].addang(q); + ps[p].addang(q, true); if (numplayers > 1) { diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 82dc29dc3..833b49885 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -348,7 +348,12 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli if (p->knee_incs > 0) { p->knee_incs++; +#ifndef SYNCINPUT + g_player[snum].horizSkew = -48; + g_player[snum].horizRecenter = true; +#else p->addhoriz(-48); +#endif p->return_to_center = 9; if (p->knee_incs > 15) { @@ -381,8 +386,6 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli } p->actorsqu = -1; } - else if (p->actorsqu >= 0) - p->addang(getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2); } } @@ -745,10 +748,12 @@ void playerCenterView(int snum) if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) { p->return_to_center = 9; +#ifndef SYNCINPUT + g_player[snum].horizRecenter = true; +#endif } } -#pragma message("input stuff begins here") void horizAngleAdjust(int snum, int delta) { #ifndef SYNCINPUT // for per-frame input diff --git a/source/games/duke/src/player.h b/source/games/duke/src/player.h index 8a7719a63..b4aca8a2d 100644 --- a/source/games/duke/src/player.h +++ b/source/games/duke/src/player.h @@ -53,6 +53,7 @@ typedef struct double lastInputTicks; bool lookLeft; bool lookRight; + bool horizRecenter; } playerdata_t; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index adbfaa2ea..9668a4a52 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1562,6 +1562,10 @@ static void operateJetpack(int snum, ESyncBits sb_snum, int psectlotag, int fz, p->pycount &= 2047; p->pyoff = sintable[p->pycount] >> 7; +#ifndef SYNCINPUT + g_player[snum].horizSkew = 0; +#endif + if (p->jetpack_on < 11) { p->jetpack_on++; @@ -2586,10 +2590,10 @@ static void processweapon(int snum, ESyncBits sb_snum, int psect) void processinput_d(int snum) { - int j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y; + int j, i, k, doubvel, fz, cz, hz, lz, truefdist; char shrunk; ESyncBits sb_snum; - short psect, psectlotag, tempsect, pi; + short psect, psectlotag, pi; struct player_struct* p; spritetype* s; @@ -2597,8 +2601,10 @@ void processinput_d(int snum) pi = p->i; s = &sprite[pi]; +#ifndef SYNCINPUT g_player[snum].horizAngleAdjust = 0; g_player[snum].horizSkew = 0; +#endif sb_snum = PlayerInputBits(snum, SKB_ALL); @@ -2635,17 +2641,15 @@ void processinput_d(int snum) hittype[pi].floorz = fz; hittype[pi].ceilingz = cz; -#pragma message("input stuff begins here") -#if 0 // disabled input +#ifdef SYNCINPUT p->oq16horiz = p->q16horiz; p->oq16horizoff = p->q16horizoff; -#endif - if (p->aim_mode == 0 && p->on_ground && psectlotag != 2 && (sector[psect].floorstat & 2)) + if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2)) { - x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); - y = p->posy + (sintable[p->getang() & 2047] >> 5); - tempsect = psect; + int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); + int y = p->posy + (sintable[p->getang() & 2047] >> 5); + short tempsect = psect; updatesector(x, y, &tempsect); if (tempsect >= 0) @@ -2657,7 +2661,7 @@ void processinput_d(int snum) } if (p->q16horizoff > 0) p->q16horizoff -= ((p->q16horizoff >> 3) + FRACUNIT); else if (p->q16horizoff < 0) p->q16horizoff += (((-p->q16horizoff) >> 3) + FRACUNIT); -#pragma message("input stuff ends here") +#endif if (hz >= 0 && (hz & 49152) == 49152) { @@ -2712,9 +2716,10 @@ void processinput_d(int snum) return; } - if (s->extra <= 0) + if (s->extra <= 0 && !ud.god) { playerisdead(snum, psectlotag, fz, cz); + return; } if (p->transporter_hold > 0) @@ -2747,10 +2752,8 @@ void processinput_d(int snum) doubvel = TICSPERFRAME; #ifdef SYNCINPUT - if (p->q16rotscrnang > 0) p->q16rotscrnang -= ((p->q16rotscrnang >> 1) + 1); - else if (p->q16rotscrnang < 0) p->q16rotscrnang += (((-p->q16rotscrnang) >> 1) + 1); - - p->q16look_ang -= p->q16look_ang >> 2; + p->q16rotscrnang -= (p->q16rotscrnang >> 1); if (p->q16rotscrnang < FRACUNIT) p->q16rotscrnang = 0; + p->q16look_ang -= p->q16look_ang >> 2; if (p->q16look_ang < FRACUNIT) p->q16look_ang = 0; #endif if (sb_snum & SKB_LOOK_LEFT) @@ -2810,7 +2813,7 @@ void processinput_d(int snum) i = 40; - if (psectlotag == 2) + if (psectlotag == ST_2_UNDERWATER) { underwater(snum, sb_snum, psect, fz, cz); } @@ -2819,7 +2822,7 @@ void processinput_d(int snum) { operateJetpack(snum, sb_snum, psectlotag, fz, cz, shrunk); } - else if (psectlotag != 2) + else if (psectlotag != ST_2_UNDERWATER) { movement(snum, sb_snum, psect, fz, cz, shrunk, truefdist); } @@ -2849,8 +2852,8 @@ void processinput_d(int snum) if (psectlotag == 2) p->angvel = (tempang - (tempang >> 3)) * sgn(doubvel); else p->angvel = tempang * sgn(doubvel); - p->ang += p->angvel; - p->ang &= 2047; + p->addang(p->angvel); + p->q16ang &= (2048<crack_time = 777; } @@ -3060,6 +3063,11 @@ HORIZONLY: fi.activatebysector(psect, pi); } +#ifndef SYNCINPUT + if (p->return_to_center > 0) + p->return_to_center--; +#endif + // center_view if (sb_snum & SKB_CENTER_VIEW || p->hard_landing) { @@ -3081,13 +3089,14 @@ HORIZONLY: { // aim_down playerAimDown(snum, sb_snum); } +#ifdef SYNCINPUT if (p->return_to_center > 0) if ((sb_snum & (SKB_LOOK_UP| SKB_LOOK_DOWN)) == 0) { p->return_to_center--; p->q16horiz += 33*FRACUNIT - (p->q16horiz / 3); } - +#endif if (p->hard_landing > 0) { #ifndef SYNCINPUT @@ -3107,7 +3116,14 @@ HORIZONLY: if (p->horizoff > -5 && p->horizoff < 5) p->horizoff = 0; } - horiz = clamp(horiz, HORIZ_MIN, HORIZ_MAX); + p->horiz = clamp(p->horiz, HORIZ_MIN, HORIZ_MAX); + + if (centerHoriz) + { + if (p->gethoriz() > 95 && pPlayer->gethoriz() < 105) pPlayer->sethoriz(100); + if (p->gethorizoff() > -5 && pPlayer->gethorizoff < 5) pPlayer->sethorizoff(0); + } + #endif //Shooting code/changes diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index b186c4fcc..b05c00350 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3383,10 +3383,10 @@ static void processweapon(int snum, ESyncBits sb_snum, int psect) void processinput_r(int snum) { - int j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y, var60; + int j, i, k, doubvel, fz, cz, hz, lz, truefdist, var60; char shrunk; ESyncBits sb_snum; - short psect, psectlotag, tempsect, pi; + short psect, psectlotag, pi; struct player_struct* p; spritetype* s; @@ -3476,14 +3476,12 @@ void processinput_r(int snum) #ifdef SYNCINPUT p->oq16horiz = p->q16horiz; p->oq16horizoff = p->q16horizoff; -#endif -#pragma message("input stuff begins here") - if (p->aim_mode == 0 && p->on_ground && psectlotag != 2 && (sector[psect].floorstat & 2)) + if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2)) { - x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); - y = p->posy + (sintable[p->getang() & 2047] >> 5); - tempsect = psect; + int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); + int y = p->posy + (sintable[p->getang() & 2047] >> 5); + short tempsect = psect; updatesector(x, y, &tempsect); if (tempsect >= 0) @@ -3495,7 +3493,7 @@ void processinput_r(int snum) } if (p->q16horizoff > 0) p->q16horizoff -= ((p->q16horizoff >> 3) + FRACUNIT); else if (p->q16horizoff < 0) p->q16horizoff += (((-p->q16horizoff) >> 3) + FRACUNIT); -#pragma message("input stuff ends here") +#endif if (hz >= 0 && (hz & 49152) == 49152) { @@ -3607,9 +3605,10 @@ void processinput_r(int snum) return; } - if (s->extra <= 0) + if (s->extra <= 0 && !ud.god) { playerisdead(snum, psectlotag, fz, cz); + return; } if (p->transporter_hold > 0) @@ -3641,10 +3640,8 @@ void processinput_r(int snum) doubvel = TICSPERFRAME; #ifdef SYNCINPUT - if (p->q16rotscrnang > 0) p->q16rotscrnang -= ((p->q16rotscrnang >> 1) + 1); - else if (p->q16rotscrnang < 0) p->q16rotscrnang += (((-p->q16rotscrnang) >> 1) + 1); - - p->q16look_ang -= p->q16look_ang >> 2; + p->q16rotscrnang -= (p->q16rotscrnang >> 1); if (p->q16rotscrnang < FRACUNIT) p->q16rotscrnang = 0; + p->q16look_ang -= p->q16look_ang >> 2; if (p->q16look_ang < FRACUNIT) p->q16look_ang = 0; #endif if ((sb_snum & SKB_LOOK_LEFT) && !p->OnMotorcycle) @@ -3723,19 +3720,7 @@ void processinput_r(int snum) i = 40; - if (psectlotag == 17) - { - int tmp; - tmp = getanimationgoal(§or[p->cursectnum].floorz); - if (tmp >= 0) - { - if (!S_CheckSoundPlaying(p->i, 432)) - spritesound(432, pi); - } - else - stopsound(432); - } - else if (isRRRA() && psectlotag == 18) + if (psectlotag == ST_17_PLATFORM_UP || (isRRRA() && psectlotag == ST_18_ELEVATOR_DOWN)) { int tmp; tmp = getanimationgoal(§or[p->cursectnum].floorz); @@ -3757,11 +3742,11 @@ void processinput_r(int snum) p->pyoff = sintable[p->pycount] >> 7; } - if (psectlotag == 2) + if (psectlotag == ST_2_UNDERWATER) { underwater(snum, sb_snum, psect, fz, cz); } - else if (psectlotag != 2) + else if (psectlotag != ST_2_UNDERWATER) { movement(snum, sb_snum, psect, fz, cz, shrunk, truefdist); } @@ -4116,6 +4101,11 @@ HORIZONLY: return; } +#ifndef SYNCINPUT + if (p->return_to_center > 0) + p->return_to_center--; +#endif + if (sb_snum & SKB_CENTER_VIEW || p->hard_landing) { playerCenterView(snum); @@ -4144,13 +4134,14 @@ HORIZONLY: p->recoil -= d; p->addhoriz(-d); } +#ifdef SYNCINPUT else if (p->return_to_center > 0) if ((sb_snum & (SKB_LOOK_UP| SKB_LOOK_DOWN)) == 0) { p->return_to_center--; p->q16horiz += 33*FRACUNIT - (p->q16horiz / 3); } - +#endif if (p->hard_landing > 0) { #ifndef SYNCINPUT @@ -4170,7 +4161,14 @@ HORIZONLY: if (p->horizoff > -5 && p->horizoff < 5) p->horizoff = 0; } - horiz = clamp(horiz, HORIZ_MIN, HORIZ_MAX); + p->horiz = clamp(p->horiz, HORIZ_MIN, HORIZ_MAX); + + if (centerHoriz && !p->recoil) + { + if (p->gethoriz() > 95 && pPlayer->gethoriz() < 105) pPlayer->sethoriz(100); + if (p->gethorizoff() > -5 && pPlayer->gethorizoff < 5) pPlayer->sethorizoff(0); + } + #endif //Shooting code/changes diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 6c1da35bf..d3fded064 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -90,7 +90,8 @@ struct player_struct }; // input handles angle and horizon as fixed16 numbers. We need to account for that as well. - fixed_t q16ang, oq16ang, q16horiz, q16horizoff, q16rotscrnang, q16look_ang; // oq16horiz, oq16horizoff, orotscrnang, ; // These three are currently not used but may be again later. + fixed_t q16ang, q16horiz, q16horizoff, q16rotscrnang, q16look_ang; + fixed_t oq16ang, oq16horiz, oq16horizoff, oq16rotscrnang; // These are only needed with synchronous mouse input. fixed_t one_eighty_target; // using a bit field for this to save a bit of space. @@ -199,8 +200,8 @@ struct player_struct void addrotscrnang(int b) { q16rotscrnang += b << FRACBITS; } int getang() { return q16ang >> FRACBITS; } int getoang() { return oq16ang >> FRACBITS; } - void setang(int v) { q16ang = v << FRACBITS; } - void addang(int v) { q16ang = (q16ang + (v << FRACBITS)) & ((2048 << FRACBITS) - 1); } + void setang(int v, bool smooth = false) { q16ang = v << FRACBITS; } + void addang(int v, bool smooth = false) { q16ang = (q16ang + (v << FRACBITS)) & ((2048 << FRACBITS) - 1); } void setoang(int v) { oq16ang = v << FRACBITS; } void addhoriz(int v) { q16horiz += (v << FRACBITS); } void addhorizoff(int v) { q16horiz += (v << FRACBITS); }