Skip to content

Commit ca175f2

Browse files
committed
Implement generic-tranmap system
1 parent 0126922 commit ca175f2

File tree

9 files changed

+136
-132
lines changed

9 files changed

+136
-132
lines changed

CHANGELOG.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,13 @@
11
## New Features
22

3-
- **_Slow Motion_ button**
4-
- **Extra gibbing with high-damage projectiles and BFG tracers**
5-
- **_Group Repeated Messages_ setting**
6-
- **_'TRAILS'_ cheat**, to show hitscan trails
7-
- **Color settings** from International Doom
3+
None.
84

95
## Changes
106

11-
- **Merged changes from the following Woof! releases:**
12-
- [Woof! 15.0.0](https://github.com/fabiangreffrath/woof/releases/tag/woof_15.0.0), note:
13-
- NUGHUD now partially uses SBARDEF as its backend, which may cause some rendering differences
14-
- Integrated periodic auto saves into the save/load menus
15-
- Maintained key blink, message list, message duration, and chat-message duration settings [1]
16-
- Turned optional vertical layout for _Stats_ and _Coordinates_ widgets into SBARDEF fields
17-
- Removed `show_ssg` (now default behavior), `alt_arms` and `hud_highlight_weapon` settings
18-
- Renamed `#_bobbing_percentage` to `#_bobbing_pct` [2]
19-
- Renamed `show_berserk` to `sts_show_berserk` [2]
20-
- Moved `sts_show_berserk` menu item to _Status Bar/HUD_ setup menu
21-
- Revised the descriptions of many of Nugget's new CVARs
22-
- [Woof! 15.0.1](https://github.com/fabiangreffrath/woof/releases/tag/woof_15.0.1)
23-
- Also merged the ouch-face fix from Woof! post-15.0.1
24-
- **Messages in the message list now have individual durations**
25-
- **Made the minimap customizable through SBARDEF and NUGHUD**
26-
- **Improved FOV-based sky stretching**
27-
- **Smoother FOV effects**
28-
- **Allowed orbiting around freecam mobj**
29-
- **Replaced `translucent_pspr(_pct)` with `pspr_translucency_pct`** [2]
30-
- **Made _Screen Wipe Speed Percentage_ setting affect the _Fizzle_ fade**
31-
- **Raised maximum _Rewind Depth_ to 3000**
32-
- **Gave shadow to the _Pause_ graphic when using _HUD/Menu Shadows_**
33-
- **Removed _Physical [Weapon] Recoil_ menu item**
7+
- Nugget's translucency features now use translucency maps from a shared pool,
8+
potentially improving program startup time in exchange for stutters
9+
when enabling said features for the first time since launch
3410

3511
## Bug Fixes
3612

37-
- **Desync involving lost-soul charge attack**
38-
- **Potential recursive spawning of blood splats when crushing with _Bloodier Gibbing_ enabled** (fixes `strg.wad`)
39-
- **FOV going below 1 degree and beyond 180 degrees**
40-
- **_Double autoaim range_ setting doubling range of BFG tracers**
41-
- **FOV effects disabling interpolation of weapon sprites**
42-
- **Crash when loading WADs with empty lumps between `C_#` markers** (fixes `nt_rc1.wad`)
43-
- **Characters not being drawn near right side of the screen in setup menus**
44-
- **Shadows not being drawn for HUD icons when using Boom font**
45-
- **Enemies potentially firing explosive-hitscan shots**
46-
47-
**[1].** Not necessarily with the same CVARs; existing config files may be affected.
48-
49-
**[2].** This will affect existing config files.
13+
None.

src/hu_crosshair.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void HU_DrawCrosshair(void)
272272

273273
// [Nugget] NUGHUD
274274
const int y = crosshair.y + (nughud.viewoffset * STRICTMODE(ST_GetNughudOn()));
275+
byte *const xhair_tranmap = R_GetGenericTranMap(hud_crosshair_tran_pct);
275276

276277
if (crosshair.patch)
277278
{

src/mn_setup.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ static void NuggetResetWeaponInertia(void)
19341934

19351935
void WeaponFlashTrans(void)
19361936
{
1937-
R_InitTranMapEx(&pspr_tranmap, pspr_translucency_pct);
1937+
R_GetGenericTranMap(pspr_translucency_pct);
19381938
}
19391939

19401940
static setup_menu_t weap_settings4[] =
@@ -2153,7 +2153,7 @@ static const char *hudcolor_strings[] = {
21532153
// [Nugget] Translucent crosshair
21542154
void CrosshairTrans(void)
21552155
{
2156-
R_InitTranMapEx(&xhair_tranmap, hud_crosshair_tran_pct);
2156+
R_GetGenericTranMap(hud_crosshair_tran_pct);
21572157
}
21582158

21592159
#define XH_X (H_X - 13) // [Nugget] Tweaked
@@ -2370,7 +2370,8 @@ void MN_DrawStatusHUD(void)
23702370
int y = M_Y + M_SPC + M_SPC / 2 - SHORT(patch->height) / 2 - 1; // [Nugget] Adjusted
23712371

23722372
// [Nugget] Translucent crosshair
2373-
V_DrawPatchTRTL2(x, y, patch, colrngs[hud_crosshair_color], xhair_tranmap);
2373+
V_DrawPatchTRTL2(x, y, patch, colrngs[hud_crosshair_color],
2374+
R_GetGenericTranMap(hud_crosshair_tran_pct));
23742375
}
23752376

23762377
// If the Reset Button has been selected, an "Are you sure?" message
@@ -3820,6 +3821,11 @@ setup_menu_t gen_settings7[] = {
38203821

38213822
// Page 8 --------------------------------------------------------------------
38223823

3824+
static void ShadowTrans(void)
3825+
{
3826+
R_GetGenericTranMap(hud_menu_shadows_filter_pct);
3827+
}
3828+
38233829
static const char *fake_contrast_strings[] = {
38243830
"Off", "Smooth", "Vanilla", NULL
38253831
};
@@ -3832,7 +3838,7 @@ setup_menu_t gen_settings8[] = {
38323838

38333839
{"Backdrop For All Menus", S_ONOFF, N_X, M_SPC, {"menu_background_all"}},
38343840
{"No Palette Tint in Menus", S_ONOFF |S_STRICT, N_X, M_SPC, {"no_menu_tint"}},
3835-
{"HUD/Menu Shadows", S_ONOFF, N_X, M_SPC, {"hud_menu_shadows"}},
3841+
{"HUD/Menu Shadows", S_ONOFF, N_X, M_SPC, {"hud_menu_shadows"}, .action = ShadowTrans},
38363842
{"Flip Levels", S_ONOFF, N_X, M_SPC, {"flip_levels"}},
38373843
{"No Berserk Tint", S_ONOFF |S_STRICT, N_X, M_SPC, {"no_berserk_tint"}},
38383844
{"No Radiation Suit Tint", S_ONOFF |S_STRICT, N_X, M_SPC, {"no_radsuit_tint"}},

src/p_map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <math.h>
5252
#include "g_game.h"
5353
#include "p_tick.h"
54+
#include "r_data.h"
5455

5556
static mobj_t *tmthing;
5657
static int tmflags;
@@ -152,7 +153,7 @@ void P_SpawnHitscanTrail(fixed_t x, fixed_t y, fixed_t z,
152153
puff->alttics += (P_AproxDistance(xdist, ydist) >> FRACBITS) / 128;
153154

154155
puff->flags |= MF_NOGRAVITY;
155-
puff->tranmap = trail_tranmap;
156+
puff->tranmap = R_GetGenericTranMap(25);
156157
}
157158
}
158159

src/r_data.c

Lines changed: 105 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,91 @@
5252
// [Nugget]
5353
#include "hu_crosshair.h"
5454

55+
// [Nugget] /-----------------------------------------------------------------
56+
57+
// Brought from below
58+
#define TSC 12 /* number of fixed point digits in filter percent */
59+
60+
static byte *R_InitGenericTranMap(const int filter_pct)
61+
{
62+
I_Printf(VB_DEBUG, "R_InitGenericTranMap: %i%%", filter_pct);
63+
64+
unsigned char *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
65+
66+
long pal[3][256], pal_w1[3][256], tot[256];
67+
68+
const long w1 = ((unsigned long) filter_pct << TSC) / 100;
69+
70+
{
71+
register int i = 255;
72+
register const unsigned char *p = playpal + 255*3;
73+
74+
do {
75+
register long t, d;
76+
77+
pal_w1[0][i] = (pal[0][i] = t = p[0]) * w1;
78+
d = t*t;
79+
80+
pal_w1[1][i] = (pal[1][i] = t = p[1]) * w1;
81+
d += t*t;
82+
83+
pal_w1[2][i] = (pal[2][i] = t = p[2]) * w1;
84+
d += t*t;
85+
p -= 3;
86+
87+
tot[i] = d << (TSC - 1);
88+
} while (--i >= 0);
89+
}
90+
91+
const long w2 = (1l << TSC) - w1;
92+
byte *tmap = Z_Malloc(256*256, PU_STATIC, 0), *tp = tmap;
93+
94+
for (int i = 0; i < 256; i++)
95+
{
96+
const long r1 = pal[0][i] * w2;
97+
const long g1 = pal[1][i] * w2;
98+
const long b1 = pal[2][i] * w2;
99+
100+
for (int j = 0; j < 256; j++, tp++)
101+
{
102+
register int color = 255;
103+
register long err;
104+
105+
const long r = pal_w1[0][j] + r1,
106+
g = pal_w1[1][j] + g1,
107+
b = pal_w1[2][j] + b1;
108+
109+
long best = LONG_MAX;
110+
111+
do {
112+
if ((err = tot[color] - pal[0][color]*r - pal[1][color]*g - pal[2][color]*b) < best)
113+
{
114+
best = err;
115+
*tp = color;
116+
}
117+
} while (--color >= 0);
118+
}
119+
}
120+
121+
Z_ChangeTag(playpal, PU_CACHE);
122+
123+
return tmap;
124+
}
125+
126+
// 0% and 100% are trivial, but we'll allow them for now
127+
static byte *generic_tranmaps[101] = { NULL };
128+
129+
byte *R_GetGenericTranMap(const int filter_pct)
130+
{
131+
byte **const tmap = &generic_tranmaps[filter_pct];
132+
133+
if (!*tmap) { *tmap = R_InitGenericTranMap(filter_pct); }
134+
135+
return *tmap;
136+
}
137+
138+
// [Nugget] -----------------------------------------------------------------/
139+
55140
//
56141
// Graphics.
57142
// DOOM graphics for walls and sprites
@@ -933,7 +1018,7 @@ int R_ColormapNumForName(const char *name)
9331018

9341019
int tran_filter_pct = 66; // filter percent
9351020

936-
#define TSC 12 /* number of fixed point digits in filter percent */
1021+
// [Nugget] Moved `TSC` macro above
9371022

9381023
void R_InitTranMap(int progress)
9391024
{
@@ -1079,71 +1164,6 @@ void R_InitTranMap(int progress)
10791164
}
10801165
}
10811166

1082-
// [Nugget]
1083-
void R_InitTranMapEx(byte **const tmap, const int filter_pct)
1084-
{
1085-
if (*tmap == NULL) { *tmap = Z_Malloc(256*256, PU_STATIC, 0); }
1086-
1087-
long pal[3][256], tot[256], pal_w1[3][256];
1088-
1089-
long w1 = ((unsigned long) filter_pct << TSC) / 100;
1090-
long w2 = (1l << TSC) - w1;
1091-
1092-
unsigned char *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
1093-
1094-
{
1095-
register int i = 255;
1096-
register const unsigned char *p = playpal + 255*3;
1097-
1098-
do {
1099-
register long t, d;
1100-
1101-
pal_w1[0][i] = (pal[0][i] = t = p[0]) * w1;
1102-
d = t*t;
1103-
1104-
pal_w1[1][i] = (pal[1][i] = t = p[1]) * w1;
1105-
d += t*t;
1106-
1107-
pal_w1[2][i] = (pal[2][i] = t = p[2]) * w1;
1108-
d += t*t;
1109-
p -= 3;
1110-
1111-
tot[i] = d << (TSC - 1);
1112-
} while (--i >= 0);
1113-
}
1114-
1115-
byte *tp = *tmap;
1116-
1117-
for (int i = 0; i < 256; i++)
1118-
{
1119-
long r1 = pal[0][i] * w2;
1120-
long g1 = pal[1][i] * w2;
1121-
long b1 = pal[2][i] * w2;
1122-
1123-
for (int j = 0; j < 256; j++, tp++)
1124-
{
1125-
register int color = 255;
1126-
register long err;
1127-
1128-
long r = pal_w1[0][j] + r1,
1129-
g = pal_w1[1][j] + g1,
1130-
b = pal_w1[2][j] + b1;
1131-
1132-
long best = LONG_MAX;
1133-
1134-
do {
1135-
if ((err = tot[color] - pal[0][color]*r - pal[1][color]*g - pal[2][color]*b) < best)
1136-
{
1137-
best = err;
1138-
*tp = color;
1139-
}
1140-
} while (--color >= 0);
1141-
}
1142-
}
1143-
1144-
Z_ChangeTag(playpal, PU_CACHE);
1145-
}
1146-
11471167
//
11481168
// R_InitData
11491169
// Locates all the lumps
@@ -1164,11 +1184,25 @@ void R_InitData(void)
11641184
R_InitTranMap(1); // killough 2/21/98, 3/6/98
11651185
R_InitColormaps(); // killough 3/20/98
11661186

1167-
// [Nugget]
1168-
R_InitTranMapEx(&shadow_tranmap, hud_menu_shadows_filter_pct); // HUD/menu shadows
1169-
R_InitTranMapEx(& pspr_tranmap, pspr_translucency_pct); // Translucent flashes
1170-
R_InitTranMapEx(& xhair_tranmap, hud_crosshair_tran_pct); // Translucent crosshair
1171-
R_InitTranMapEx(& trail_tranmap, 25);
1187+
// [Nugget] ----------------------------------------------------------------
1188+
1189+
// These could be initialized just in time, upon being requested,
1190+
// but if we can already guess that they'll be used,
1191+
// we initialize them in advance to prevent stutters later
1192+
1193+
// HUD/menu shadows
1194+
if (hud_menu_shadows && hud_menu_shadows_filter_pct != 100)
1195+
{ R_GetGenericTranMap(hud_menu_shadows_filter_pct); }
1196+
1197+
// Translucent flashes
1198+
if (pspr_translucency_pct != 100)
1199+
{ R_GetGenericTranMap(pspr_translucency_pct); }
1200+
1201+
// Translucent crosshair
1202+
if (hud_crosshair_tran_pct != 100)
1203+
{ R_GetGenericTranMap(hud_crosshair_tran_pct); }
1204+
1205+
R_GetGenericTranMap(25); // Hitscan trails
11721206
}
11731207

11741208
//

src/r_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef enum
6666

6767
extern invul_mode_t invul_mode;
6868

69-
void R_InitTranMapEx(byte **const tmap, const int filter_pct); // [Nugget]
69+
byte *R_GetGenericTranMap(const int filter_pct); // [Nugget]
7070

7171
#endif
7272

src/r_things.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,8 @@ void R_DrawPSprite (pspdef_t *psp, boolean translucent) // [Nugget] Translucent
940940
}
941941
vis->brightmap = R_BrightmapForState(psp->state - states);
942942

943-
vis->tranmap = translucent ? pspr_tranmap : NULL; // [Nugget] Translucent flashes
943+
// [Nugget] Translucent flashes
944+
vis->tranmap = translucent ? R_GetGenericTranMap(pspr_translucency_pct) : NULL;
944945

945946
// interpolation for weapon bobbing
946947
if (uncapped)

src/v_video.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ int menu_backdrop_darkening;
162162

163163
byte cr_allblack[256],
164164
cr_gray_vc[256], // `V_Colorize()` only
165-
nightvision[256], // Night-vision visor
166-
*shadow_tranmap, // HUD/menu shadows
167-
*pspr_tranmap, // Translucent flashes
168-
*xhair_tranmap, // Translucent crosshair
169-
*trail_tranmap;
165+
nightvision[256]; // Night-vision visor
170166

171167
// [Nugget] -----------------------------------------------------------------/
172168

@@ -669,7 +665,12 @@ void V_DrawPatchShadowed(int x, int y, struct patch_s *patch, boolean flipped,
669665
if (hud_menu_shadows && drawshadows)
670666
{
671667
drawingshadow = true;
672-
V_DrawPatchTranslucent2(x + 1, y + 1, patch, flipped, cr_allblack, NULL, shadow_tranmap);
668+
669+
V_DrawPatchTranslucent2(
670+
x + 1, y + 1, patch, flipped, cr_allblack, NULL,
671+
R_GetGenericTranMap(hud_menu_shadows_filter_pct)
672+
);
673+
673674
drawingshadow = false;
674675
}
675676

@@ -869,7 +870,7 @@ void V_ShadowRect(int x, int y, int width, int height)
869870
{
870871
byte *const d = &dest[x];
871872

872-
*d = shadow_tranmap[*d << 8];
873+
*d = R_GetGenericTranMap(hud_menu_shadows_filter_pct)[*d << 8];
873874
}
874875

875876
dest += linesize;

0 commit comments

Comments
 (0)