From aa0080039f089b2c30e074da683eb6142f41dcf0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 22 Aug 2022 00:08:52 +0200 Subject: [PATCH] - refactored coordinate display to have a single unified printing function. The games will now only return the data, this has also been added for Exhumed. Printing will now be in actual map units, not build's internal mixed format. --- source/core/gamecvars.cpp | 11 ++++++++++- source/core/gamestruct.h | 2 +- source/games/blood/src/blood.h | 2 +- source/games/blood/src/view.cpp | 10 +++------- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/game_misc.cpp | 12 ++---------- source/games/exhumed/src/exhumed.cpp | 8 ++++++++ source/games/exhumed/src/exhumed.h | 1 + source/games/sw/src/draw.cpp | 11 ++--------- source/games/sw/src/game.h | 2 +- 10 files changed, 30 insertions(+), 31 deletions(-) diff --git a/source/core/gamecvars.cpp b/source/core/gamecvars.cpp index dd53cd347..4dcc037a8 100644 --- a/source/core/gamecvars.cpp +++ b/source/core/gamecvars.cpp @@ -232,7 +232,16 @@ ADD_STAT(fps) ADD_STAT(coord) { - return gi->GetCoordString(); + auto coord = gi->GetCoordinates(); + FString out; + if (coord.first.X < DBL_MAX) + { + out.AppendFormat("X: %d ", int(coord.first.X)); + out.AppendFormat("Y: %d ", int(coord.first.Y)); + out.AppendFormat("Z: %d ", int(coord.first.Z)); + out.AppendFormat("Angle: %d\n", int(coord.second.Degrees())); + } + return out; } CUSTOM_CVARD(Int, r_showfps, 0, 0, "show the frame rate counter") diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 96a1621ae..6fac7be74 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -91,7 +91,7 @@ struct GameInterface virtual void SerializeGameState(FSerializer& arc) {} virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} - virtual FString GetCoordString() { return "'stat coord' not implemented"; } + virtual std::pair GetCoordinates() { return {}; } virtual void ExitFromMenu() { throw CExitEvent(0); } virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; } virtual void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) {} diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index f75c9b86c..5044e9d25 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -121,7 +121,7 @@ struct GameInterface : public ::GameInterface void MenuOpened() override; void MenuClosed() override; bool CanSave() override; - FString GetCoordString() override; + std::pair GetCoordinates() override; ReservedSpace GetReservedScreenSpace(int viewsize) override; void UpdateSounds() override; void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index d3798fbc8..1c0760d12 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -847,14 +847,10 @@ bool GameInterface::GenerateSavePic() return true; } -FString GameInterface::GetCoordString() +std::pair GameInterface::GetCoordinates() { - FString out; - - out.Format("pos= %d, %d, %d - angle = %2.3f", - gMe->actor->int_pos().X, gMe->actor->int_pos().Y, gMe->actor->int_pos().Z, gMe->actor->spr.int_ang() * BAngToDegree); - - return out; + if (!gMe || !gMe->actor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); + return std::make_pair(gMe->actor->spr.pos, gMe->actor->spr.angle); } diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 08964199a..b07842303 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -35,7 +35,7 @@ struct GameInterface : public ::GameInterface FSavegameInfo GetSaveSig() override; double SmallFontScale() override { return isRR() ? 0.5 : 1.; } void SerializeGameState(FSerializer& arc) override; - FString GetCoordString() override; + std::pair GetCoordinates() override; void ExitFromMenu() override; ReservedSpace GetReservedScreenSpace(int viewsize) override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 4a5631ac0..17e4f9962 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -55,19 +55,11 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -FString GameInterface::GetCoordString() +std::pair GameInterface::GetCoordinates() { - int snum = screenpeek; - FString out; - - out.Format("pos= %2.3f, %2.3f, %2.3f - angle = %2.3f - sector = %d, lotag = %d, hitag = %d", - ps[snum].pos.X, ps[snum].pos.Y, ps[snum].pos.Z, ps[snum].angle.ang.Degrees(), sectnum(ps[snum].cursector), - ps[snum].cursector->lotag, ps[snum].cursector->hitag); - - return out; + return std::make_pair(ps[screenpeek].pos, ps[screenpeek].angle.ang); } - GameStats GameInterface::getStats() { player_struct* p = &ps[myconnectindex]; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 78acdbbb1..1d7717fdf 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -600,6 +600,14 @@ bool GameInterface::CanSave() return new GameInterface; } +std::pair GameInterface::GetCoordinates() +{ + auto pPlayerActor = PlayerList[nLocalPlayer].pActor; + if (!pPlayerActor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); + return std::make_pair(pPlayerActor->spr.pos, pPlayerActor->spr.angle); +} + + void DExhumedActor::Serialize(FSerializer& arc) { Super::Serialize(arc); diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 2c5d4a510..56c814931 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -239,6 +239,7 @@ struct GameInterface : public ::GameInterface vec3_t chaseCamPos(DAngle ang, fixedhoriz horiz) { return vec3_t(int(-ang.Cos() * 1536.), int(-ang.Sin() * 1536.), (horiz.asq16() * 3) >> 10); } void processSprites(tspriteArray& tsprites, int viewx, int viewy, int viewz, DAngle viewang, double smoothRatio) override; int GetCurrentSkill() override; + std::pair GetCoordinates() override; ::GameStats getStats() override; }; diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 4c53178e4..21ffe50c9 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1017,19 +1017,12 @@ void CircleCamera(int *nx, int *ny, int *nz, sectortype** vsect, DAngle *nang, f *nang = ang; } -FString GameInterface::GetCoordString() +std::pair GameInterface::GetCoordinates() { PLAYER* pp = Player + myconnectindex; - FString out; - out.AppendFormat("POSX:%d ", pp->int_ppos().X); - out.AppendFormat("POSY:%d ", pp->int_ppos().Y); - out.AppendFormat("POSZ:%d ", pp->int_ppos().Z); - out.AppendFormat("ANG:%d\n", pp->angle.ang.Buildang()); - - return out; + return std::make_pair(pp->pos, pp->angle.ang); } - void PrintSpriteInfo(PLAYER* pp) { const int Y_STEP = 7; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 994c76b1d..64b6d604d 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1953,7 +1953,7 @@ struct GameInterface : public ::GameInterface FSavegameInfo GetSaveSig() override; void SerializeGameState(FSerializer& arc); void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } - FString GetCoordString() override; + std::pair GetCoordinates() override; ReservedSpace GetReservedScreenSpace(int viewsize) override; void UpdateSounds() override; void ErrorCleanup() override;