Add speedometer widget, speed cheat (#1775)

This commit is contained in:
ceski 2024-07-04 19:28:40 -07:00 committed by GitHub
parent 835603dbaa
commit 82bc0e839a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 51 additions and 1 deletions

View File

@ -6,6 +6,7 @@ sttime topleft
coord topright
fps topright
cmd bottomright
speed bottomcenter
hud 1
rate topleft
@ -19,6 +20,7 @@ sttime bottomleft
coord topright
fps topright
cmd bottomright
speed bottomcenter
hud 2
rate topleft
@ -32,3 +34,4 @@ sttime bottomleft
coord topright
fps topright
cmd bottomright
speed bottomcenter

View File

@ -100,6 +100,9 @@ Toggle printing the FPS in the upper right corner.
`RATE`
Toggle the display of rendering stats, including frame rate and the current number of segs, visplanes, and sprites.
`SPEED`
Toggle the speedometer. Repeating the cheat cycles through different units: map units per second, kilometers per hour, and miles per hour.
## Beta cheats
These cheats only work in MBF `-beta` emulation mode.

View File

@ -30,6 +30,7 @@ Possible values for the HUD widget names:
* "fps" or "rate"
* "cmd" or "commands"
* "compact"
* "speed"
Possible values for the widget position keywords:
@ -57,6 +58,7 @@ sttime topleft
coord topright
fps topright
cmd bottomright
speed bottomcenter
hud 1
rate topleft
@ -70,6 +72,7 @@ sttime bottomleft
coord topright
fps topright
cmd bottomright
speed bottomcenter
hud 2
rate topleft
@ -83,6 +86,7 @@ sttime bottomleft
coord topright
fps topright
cmd bottomright
speed bottomcenter
```
An alternative approach to the distributed HUD, using absolute screen coordinates, could look like this:
@ -104,6 +108,8 @@ fps 224 16
The "title" widget is only visible if the Automap is enabled. The "monsec", "sttime" and "coord" widgets are only visible if they are explicitly enabled in the Options menu (separately for Automap and HUD). The "fps" widget is only visible if the SHOWFPS cheat is enabled.
The "speed" widget is only visible if the SPEED cheat is enabled. Repeating the cheat cycles through different units.
The "compact" widget is a minimal widget showing only health, armor and ammo information. It is enabled by default in the minimal Boom HUD mode.
A centered widget does not allow for any other left or right aligned widget on the same line.

View File

@ -143,9 +143,10 @@ static hu_multiline_t w_coord;
static hu_multiline_t w_fps;
static hu_multiline_t w_rate;
static hu_multiline_t w_cmd;
static hu_multiline_t w_speed;
#define MAX_HUDS 3
#define MAX_WIDGETS 16
#define MAX_WIDGETS 20
static hu_widget_t widgets[MAX_HUDS][MAX_WIDGETS];
@ -518,6 +519,7 @@ static void HU_widget_build_sttime(void);
static void HU_widget_build_title (void);
static void HU_widget_build_weapon (void);
static void HU_widget_build_compact (void);
static void HU_widget_build_speed(void);
static hu_multiline_t *w_stats;
@ -641,6 +643,10 @@ void HU_Start(void)
// Draw command history bottom up.
w_cmd.bottomup = true;
HUlib_init_multiline(&w_speed, 1,
&boom_font, colrngs[hudcolor_xyco],
NULL, HU_widget_build_speed);
HU_set_centered_message();
HU_disable_all_widgets();
@ -1367,6 +1373,24 @@ static void HU_widget_build_cmd(void)
HU_BuildCommandHistory(&w_cmd);
}
int speedometer;
static void HU_widget_build_speed(void)
{
static const double factor[] = {TICRATE, 2.4003, 525.0 / 352.0};
static const char *units[] = {"ups", "km/h", "mph"};
const int type = speedometer - 1;
const double dx = FIXED2DOUBLE(plr->mo->x - plr->mo->oldx);
const double dy = FIXED2DOUBLE(plr->mo->y - plr->mo->oldy);
const double dz = FIXED2DOUBLE(plr->mo->z - plr->mo->oldz);
const double speed = sqrt(dx*dx + dy*dy + dz*dz) * factor[type];
M_snprintf(hud_stringbuffer, sizeof(hud_stringbuffer), "\x1b%c%.*f \x1b%c%s",
'0' + CR_GRAY, type && speed ? 1 : 0, speed,
'0' + CR_ORIG, units[type]);
HUlib_add_string_to_cur_line(&w_speed, hud_stringbuffer);
}
// [crispy] print a bar indicating demo progress at the bottom of the screen
boolean HU_DemoProgressBar(boolean force)
{
@ -1642,6 +1666,7 @@ void HU_Ticker(void)
HU_cond_build_widget(&w_fps, plr->cheats & CF_SHOWFPS);
HU_cond_build_widget(&w_rate, plr->cheats & CF_RENDERSTATS);
HU_cond_build_widget(&w_cmd, STRICTMODE(hud_command_history));
HU_cond_build_widget(&w_speed, STRICTMODE(speedometer > 0));
if (hud_displayed &&
scaledviewheight == SCREENHEIGHT &&
@ -1902,6 +1927,7 @@ static const struct {
{"fps", NULL, &w_fps},
{"rate", NULL, &w_rate},
{"cmd", "commands", &w_cmd},
{"speed", NULL, &w_speed},
{NULL},
};

View File

@ -101,6 +101,8 @@ void HU_BindHUDVariables(void);
byte* HU_ColorByHealth(int health, int maxhealth, boolean invul);
extern int speedometer;
#endif
//----------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@
#include "doomdef.h"
#include "doomstat.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "info.h"
#include "m_cheat.h"
#include "m_fixed.h"
@ -107,6 +108,7 @@ static void cheat_reveal_item();
static void cheat_autoaim(); // killough 7/19/98
static void cheat_tst();
static void cheat_showfps(); // [FG] FPS counter widget
static void cheat_speed();
//-----------------------------------------------------------------------------
//
@ -324,6 +326,9 @@ struct cheat_s cheat[] = {
{"showfps", NULL, always,
{cheat_showfps} },
{"speed", NULL, always,
{cheat_speed} },
{NULL} // end-of-list marker
};
@ -335,6 +340,11 @@ static void cheat_showfps()
plyr->cheats ^= CF_SHOWFPS;
}
static void cheat_speed()
{
speedometer = STRICTMODE((speedometer + 1) % 4);
}
// killough 7/19/98: Autoaiming optional in beta emulation mode
static void cheat_autoaim()
{