From 01f8fb323320856b2de029ddd614f363a93804af Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 15 Dec 2022 05:16:19 -0800 Subject: [PATCH 1/8] Use sinusoidial interpolation for Broly ki --- src/k_objects.h | 1 + src/objects/broly.c | 43 +++++++++++++++++++++++++++++++++++++------ src/p_mobj.c | 3 +++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/k_objects.h b/src/k_objects.h index fc15a2153..4cc4ed1c3 100644 --- a/src/k_objects.h +++ b/src/k_objects.h @@ -56,5 +56,6 @@ void Obj_DuelBombInit(mobj_t *bomb); /* Broly Ki */ mobj_t *Obj_SpawnBrolyKi(mobj_t *source, tic_t duration); +void Obj_BrolyKiThink(mobj_t *ki); #endif/*k_objects_H*/ diff --git a/src/objects/broly.c b/src/objects/broly.c index 8c743a64a..d041c23b7 100644 --- a/src/objects/broly.c +++ b/src/objects/broly.c @@ -2,9 +2,33 @@ #include "../info.h" #include "../k_kart.h" #include "../k_objects.h" +#include "../m_easing.h" #include "../p_local.h" #include "../s_sound.h" +// TODO: generic function +static void P_InstaScale(mobj_t *thing, fixed_t scale) +{ + P_SetScale(thing, scale); + thing->destscale = scale; +} + +/* An object may not be visible on the same tic: + 1) that it spawned + 2) that it cycles to the next state */ +#define BUFFER_TICS (2) + +#define broly_duration(o) ((o)->extravalue1) +#define broly_maxscale(o) ((o)->extravalue2) + +static inline fixed_t +get_unit_linear (const mobj_t *x) +{ + const tic_t t = (x->tics - BUFFER_TICS); + + return t * FRACUNIT / broly_duration(x); +} + mobj_t * Obj_SpawnBrolyKi ( mobj_t * source, @@ -25,13 +49,10 @@ Obj_SpawnBrolyKi x->color = source->color; x->hitlag = 0; // do not copy source hitlag - P_SetScale(x, 64 * mapobjectscale); - x->scalespeed = x->scale / duration; + broly_maxscale(x) = 64 * mapobjectscale; + broly_duration(x) = duration; - // The last tic doesn't actually get rendered so in order - // to show scale = destscale, add one buffer tic. - x->tics = (duration + 1); - x->destscale = 1; // 0 also doesn't work + x->tics = (duration + BUFFER_TICS); K_ReduceVFX(x, NULL); @@ -39,3 +60,13 @@ Obj_SpawnBrolyKi return x; } + +void +Obj_BrolyKiThink (mobj_t *x) +{ + const fixed_t + t = get_unit_linear(x), + n = Easing_OutSine(t, 0, broly_maxscale(x)); + + P_InstaScale(x, n); +} diff --git a/src/p_mobj.c b/src/p_mobj.c index ce526659d..19041e3e4 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6508,6 +6508,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_DRIFTELECTRICSPARK: mobj->renderflags ^= RF_DONTDRAW; break; + case MT_BROLY: + Obj_BrolyKiThink(mobj); + break; case MT_VWREF: case MT_VWREB: { From 4feba883276502f5603c158c541bb7fabc6a01aa Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 15 Dec 2022 22:08:29 -0500 Subject: [PATCH 2/8] Slightly improve colorize's luminance method Before I was using coefficents from another formula I forget the source of, but over time I've stopped liking how it looked -- just considers greens far too bright. Here I'm trying out BT.601 coefficents instead (https://en.wikipedia.org/wiki/Rec._601). These are also the coefficients Doom itself used for invulnerability's invert effect (if you ignore the typo Carmack made :p), so this checks out. --- src/k_color.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/k_color.c b/src/k_color.c index ac1a2e6c8..5f58441e0 100644 --- a/src/k_color.c +++ b/src/k_color.c @@ -24,11 +24,12 @@ --------------------------------------------------*/ UINT8 K_ColorRelativeLuminance(UINT8 r, UINT8 g, UINT8 b) { - UINT32 redweight = 1063 * r; - UINT32 greenweight = 3576 * g; - UINT32 blueweight = 361 * b; - UINT32 brightness = (redweight + greenweight + blueweight) / 5000; - return min(brightness, UINT8_MAX); + // These are the BT.601 coefficents + // See also: https://en.wikipedia.org/wiki/Rec._601 + UINT32 redweight = 299 * r; + UINT32 greenweight = 587 * g; + UINT32 blueweight = 114 * b; + return min((redweight + greenweight + blueweight) / 1000, UINT8_MAX); } /*-------------------------------------------------- From 107ec2784631a556f6033d64162504d3cbd37657 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 15 Dec 2022 22:29:38 -0500 Subject: [PATCH 3/8] Go back to the old one, but gamma correct it Did more research into the subject, the formula I used before was fine and was just expecting gamma correction. --- src/k_color.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/k_color.c b/src/k_color.c index 5f58441e0..d73a938e7 100644 --- a/src/k_color.c +++ b/src/k_color.c @@ -24,12 +24,18 @@ --------------------------------------------------*/ UINT8 K_ColorRelativeLuminance(UINT8 r, UINT8 g, UINT8 b) { - // These are the BT.601 coefficents - // See also: https://en.wikipedia.org/wiki/Rec._601 - UINT32 redweight = 299 * r; - UINT32 greenweight = 587 * g; - UINT32 blueweight = 114 * b; - return min((redweight + greenweight + blueweight) / 1000, UINT8_MAX); + double redWeight = ((r * 1.0) / UINT8_MAX); + double greenWeight = ((g * 1.0) / UINT8_MAX); + double blueWeight = ((b * 1.0) / UINT8_MAX); + double brightness = 0.5; + + redWeight = pow(redWeight, 2.2) * 0.2126; + greenWeight = pow(greenWeight, 2.2) * 0.7152; + blueWeight = pow(greenWeight, 2.2) * 0.0722; + + brightness = pow(redWeight + greenWeight + blueWeight, 1.0 / 2.2); + + return (UINT8)(brightness * UINT8_MAX); } /*-------------------------------------------------- From 81fec17bb4d13c6d942215fd3a95feff13350758 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 17 Dec 2022 16:39:10 +0000 Subject: [PATCH 4/8] First Musicdef changes in preparation for music test - Add `title` field, to permit seperation from `source` - Store current displayed string as zone memory, to prevent repeated recalculation --- src/hu_stuff.c | 18 ++++++++---------- src/p_setup.c | 1 + src/s_sound.c | 14 +++++++------- src/s_sound.h | 3 ++- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index e30a725e9..0f861f642 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -938,8 +938,7 @@ static void HU_TickSongCredits(void) if (cursongcredit.anim > 0) { - char *str = va("\x1F"" %s", cursongcredit.def->source); - INT32 len = V_ThinStringWidth(str, V_ALLOWLOWERCASE|V_6WIDTHSPACE); + INT32 len = V_ThinStringWidth(cursongcredit.text, V_ALLOWLOWERCASE|V_6WIDTHSPACE); fixed_t destx = (len+7) * FRACUNIT; if (cursongcredit.trans > 0) @@ -2045,29 +2044,28 @@ static void HU_DrawDemoInfo(void) // void HU_DrawSongCredits(void) { - char *str; fixed_t x; fixed_t y = (r_splitscreen ? (BASEVIDHEIGHT/2)-4 : 32) * FRACUNIT; INT32 bgt; - if (!cursongcredit.def) // No def + if (!cursongcredit.def || cursongcredit.trans >= NUMTRANSMAPS) // No def { return; } - str = va("\x1F"" %s", cursongcredit.def->source); bgt = (NUMTRANSMAPS/2) + (cursongcredit.trans / 2); x = R_InterpolateFixed(cursongcredit.old_x, cursongcredit.x); if (bgt < NUMTRANSMAPS) { - V_DrawFixedPatch(x, y - (2 * FRACUNIT), FRACUNIT, V_SNAPTOLEFT|(bgt<usage, textline); -#endif + if (!stricmp(stoken, "title")) { + STRBUFCPY(def->title, textline); } else if (!stricmp(stoken, "source")) { STRBUFCPY(def->source, textline); } else if (!stricmp(stoken, "volume")) { @@ -1609,13 +1607,15 @@ void S_ShowMusicCredit(void) if (!stricmp(def->name, music_name)) { cursongcredit.def = def; + Z_Free(cursongcredit.text); + cursongcredit.text = Z_StrDup(va("\x1F"" %s - %s", def->title, def->source)); cursongcredit.anim = 5*TICRATE; - cursongcredit.x = cursongcredit.old_x =0; + cursongcredit.x = cursongcredit.old_x = 0; cursongcredit.trans = NUMTRANSMAPS; return; } - else - def = def->next; + + def = def->next; } } diff --git a/src/s_sound.h b/src/s_sound.h index adbf92533..0b1148964 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -173,7 +173,7 @@ boolean S_SpeedMusic(float speed); struct musicdef_t { char name[7]; - //char usage[256]; + char title[256]; char source[256]; int volume; musicdef_t *next; @@ -182,6 +182,7 @@ struct musicdef_t extern struct cursongcredit { musicdef_t *def; + char *text; UINT16 anim; UINT8 trans; fixed_t x; From ac423b3461c03f7d1d7ff2fe422fa1714155560b Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 17 Dec 2022 17:36:44 +0000 Subject: [PATCH 5/8] Further changes to musicdef based on discussion with Gunla - Add "author" and "originalcomposers" fields - "author" is for remixes and original compositions, can be ommitted - "originalcomposers" will not be visible mid-game, but will be visible in music test. Stores original sound team info - Store all strings as Zone memory instead of static arrays, since not every field will be relevant for every track --- src/s_sound.c | 71 +++++++++++++++++++++++++++++++++++++++++++++------ src/s_sound.h | 6 +++-- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 29c3bb6d4..96211d653 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1476,14 +1476,32 @@ ReadMusicDefFields textline = value; - /* based ignored lumps */ - if (!stricmp(stoken, "title")) { - STRBUFCPY(def->title, textline); - } else if (!stricmp(stoken, "source")) { - STRBUFCPY(def->source, textline); - } else if (!stricmp(stoken, "volume")) { + if (!stricmp(stoken, "title")) + { + Z_Free(def->title); + def->title = Z_StrDup(textline); + } + else if (!stricmp(stoken, "author")) + { + Z_Free(def->author); + def->author = Z_StrDup(textline); + } + else if (!stricmp(stoken, "source")) + { + Z_Free(def->source); + def->source = Z_StrDup(textline); + } + else if (!stricmp(stoken, "originalcomposers")) + { + Z_Free(def->composers); + def->composers = Z_StrDup(textline); + } + else if (!stricmp(stoken, "volume")) + { def->volume = atoi(textline); - } else { + } + else + { MusicDefError(CONS_WARNING, "Unknown field '%s'.", stoken, lumpnum, line); @@ -1606,9 +1624,46 @@ void S_ShowMusicCredit(void) { if (!stricmp(def->name, music_name)) { + char credittext[128] = ""; + char *work = NULL; + size_t len = 128, worklen; + + if (!def->title) + { + return; + } + + work = va("\x1F %s", def->title); + worklen = strlen(work); + if (worklen <= len) + { + strncat(credittext, work, len); + len -= worklen; + +#define MUSICCREDITAPPEND(field)\ + if (field)\ + {\ + work = va(" - %s", field);\ + worklen = strlen(work);\ + if (worklen <= len)\ + {\ + strncat(credittext, work, len);\ + len -= worklen;\ + }\ + } + + MUSICCREDITAPPEND(def->author); + MUSICCREDITAPPEND(def->source); + +#undef MUSICCREDITAPPEND + } + + if (credittext[0] == '\0') + return; + cursongcredit.def = def; Z_Free(cursongcredit.text); - cursongcredit.text = Z_StrDup(va("\x1F"" %s - %s", def->title, def->source)); + cursongcredit.text = Z_StrDup(credittext); cursongcredit.anim = 5*TICRATE; cursongcredit.x = cursongcredit.old_x = 0; cursongcredit.trans = NUMTRANSMAPS; diff --git a/src/s_sound.h b/src/s_sound.h index 0b1148964..c9a86a2f5 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -173,8 +173,10 @@ boolean S_SpeedMusic(float speed); struct musicdef_t { char name[7]; - char title[256]; - char source[256]; + char *title; + char *author; + char *source; + char *composers; int volume; musicdef_t *next; }; From 3a40352679f15fd5e2a61ab9f09573ab3f0d0027 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 17 Dec 2022 18:38:40 -0800 Subject: [PATCH 6/8] opengl: fix bottom and right edge of clip rect --- src/hardware/hw_draw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index d8eac4a44..a336bd53c 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -249,7 +249,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p if ((cx + fwidth) > clip->right) { - const float n = (clip->right - clip->left); + const float n = (clip->right - cx); s_max = (s_min + ((n / fwidth) * s_max)); fwidth = n; @@ -257,7 +257,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p if ((cy + fheight) > clip->bottom) { - const float n = (clip->bottom - clip->top); + const float n = (clip->bottom - cy); t_max = (t_min + ((n / fheight) * t_max)); fheight = n; From 374342358d82a100299a1af265148a4921585a00 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 17 Dec 2022 18:55:36 -0800 Subject: [PATCH 7/8] Fix HUD item flicker crash Fixes item capsule award if a roulette was not rolled sometime before. --- src/k_hud.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_hud.c b/src/k_hud.c index 7c1d94e42..8d9167a4e 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -1023,7 +1023,7 @@ static void K_drawKartItem(void) // Why write V_DrawScaledPatch calls over and over when they're all the same? // Set to 'no item' just in case. const UINT8 offset = ((r_splitscreen > 1) ? 1 : 0); - patch_t *localpatch[3] = { kp_nodraw }; + patch_t *localpatch[3] = { kp_nodraw, kp_nodraw, kp_nodraw }; patch_t *localbg = ((offset) ? kp_itembg[2] : kp_itembg[0]); patch_t *localinv = ((offset) ? kp_invincibility[((leveltime % (6*3)) / 3) + 7] : kp_invincibility[(leveltime % (7*3)) / 3]); INT32 fx = 0, fy = 0, fflags = 0; // final coords for hud and flags... From ab42c473735c22305c49a15269a80d7f61af9e90 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 17 Dec 2022 21:23:07 -0800 Subject: [PATCH 8/8] .gitignore: add CMakeUserPresets.json --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3eca1c57a..6b2702a76 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ Win32_LIB_ASM_Release /make /bin /build +/CMakeUserPresets.json