Skip to content

Commit

Permalink
Add config variable and support for Doom
Browse files Browse the repository at this point in the history
  • Loading branch information
JNechaevsky committed Oct 29, 2024
1 parent 7ba4db1 commit 6baa54e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/crispy.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static crispy_t crispy_s = {
#ifdef CRISPY_TRUECOLOR
.smoothlight = 1,
.truecolor = 1,
.blendquality = 1,
#endif
.vsync = 1,
.widescreen = 1, // match screen by default
Expand Down
1 change: 1 addition & 0 deletions src/crispy.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct
int translucency;
#ifdef CRISPY_TRUECOLOR
int truecolor;
int blendquality;
#endif
int uncapped;
int vsync;
Expand Down
1 change: 1 addition & 0 deletions src/doom/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ void D_BindVariables(void)
M_BindIntVariable("crispy_translucency", &crispy->translucency);
#ifdef CRISPY_TRUECOLOR
M_BindIntVariable("crispy_truecolor", &crispy->truecolor);
M_BindIntVariable("crispy_blendquality", &crispy->blendquality);
#endif
M_BindIntVariable("crispy_uncapped", &crispy->uncapped);
M_BindIntVariable("crispy_vsync", &crispy->vsync);
Expand Down
2 changes: 1 addition & 1 deletion src/doom/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ void R_ProjectSprite (mobj_t* thing)
// [crispy] translucent sprites
if (thing->flags & MF_TRANSLUCENT)
{
vis->blendfunc = (thing->frame & FF_FULLBRIGHT) ? I_BlendAdd : I_BlendOverTranmap;
vis->blendfunc = (thing->frame & FF_FULLBRIGHT) ? I_BlendAddFunc : I_BlendOverTranmap;
}
#endif
}
Expand Down
23 changes: 22 additions & 1 deletion src/i_truecolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ static uint32_t blendAddLUT[512][512]; // Additive blending
static uint32_t blendOverLUT[512][512]; // Overlay blending
static uint32_t blendOverAltLUT[512][512]; // Overlay "alt" blending

const uint32_t (*I_BlendAddFunc) (const uint32_t bg_i, const uint32_t fg_i);
const uint32_t (*I_BlendOverFunc) (const uint32_t bg_i, const uint32_t fg_i, const int amount);
//const uint32_t (*I_BlendOverAltFunc) (const uint32_t bg_i, const uint32_t fg_i);

// [JN] Different blending alpha values for different games
#define OVERLAY_ALPHA_TRANMAP 168 // Doom: TRANMAP, 66% opacity
#define OVERLAY_ALPHA_TINTTAB 96 // Raven: TINTTAB, 38% opacity
Expand Down Expand Up @@ -176,7 +180,7 @@ const uint32_t I_BlendOverLow (const uint32_t bg_i, const uint32_t fg_i, const i
// [crispy] TRANMAP blending emulation, used for Doom
const uint32_t I_BlendOverTranmap (const uint32_t bg, const uint32_t fg)
{
return I_BlendOver(bg, fg, 0xA8); // 168 (66% opacity)
return I_BlendOverFunc(bg, fg, 0xA8); // 168 (66% opacity)
}

// [crispy] TINTTAB blending emulation, used for Heretic and Hexen
Expand All @@ -203,4 +207,21 @@ const uint32_t I_BlendOverAltXlatab (const uint32_t bg, const uint32_t fg)
return I_BlendOver(bg, fg, 0x40); // 64 (25% opacity)
}

// [JN] Set pointers to blending functions.
void R_InitBlendQuality (void)
{
if (crispy->blendquality)
{
I_BlendAddFunc = I_BlendAdd;
I_BlendOverFunc = I_BlendOver;
// I_BlendOverAltFunc = I_BlendOverAlt;
}
else
{
I_BlendAddFunc = I_BlendAddLow;
I_BlendOverFunc = I_BlendOverLow;
// I_BlendOverAltFunc = I_BlendOverAltLow;
}
}

#endif
3 changes: 3 additions & 0 deletions src/i_truecolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
extern const uint32_t (*blendfunc) (const uint32_t fg, const uint32_t bg);

extern void R_InitBlendMaps (void);
extern void R_InitBlendQuality (void);
extern const uint32_t (*I_BlendAddFunc) (const uint32_t bg_i, const uint32_t fg_i);
extern const uint32_t (*I_BlendOverFunc) (const uint32_t bg_i, const uint32_t fg_i, const int amount);

const uint32_t I_BlendAdd (const uint32_t bg_i, const uint32_t fg_i);
const uint32_t I_BlendDark (const uint32_t bg_i, const int d);
Expand Down
8 changes: 8 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,14 @@ static default_t extra_defaults_list[] =
//

CONFIG_VARIABLE_INT(crispy_truecolor),

//!
// @game doom
//
// Quality of translucency blending.
//

CONFIG_VARIABLE_INT(crispy_blendquality),
#endif

//!
Expand Down
1 change: 1 addition & 0 deletions src/setup/compatibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void BindCompatibilityVariables(void)
M_BindIntVariable("crispy_translucency", &crispy->translucency);
#ifdef CRISPY_TRUECOLOR
M_BindIntVariable("crispy_truecolor", &crispy->truecolor);
M_BindIntVariable("crispy_blendquality", &crispy->blendquality);
#endif
M_BindIntVariable("crispy_uncapped", &crispy->uncapped);
M_BindIntVariable("crispy_vsync", &crispy->vsync);
Expand Down

1 comment on commit 6baa54e

@JNechaevsky
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiangreffrath 👋, at this point you may see translucency of 512 colors in action, it will be crispy_blendquality 0 in crispy-doom.cfg. Have to say, it was a really good choice comparing to 256 colors! It's not hot-swappable yet, and there is still a lot of things to to and discuss (variable and function names, menu item...) though, including tabs vs. spaces game.

Please sign in to comment.