From e5e7205c95e40aa6b34c612aec4cc2f286f8d57d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 11 Jan 2025 07:25:12 +0100 Subject: [PATCH] change how randomized light works so it doesent kill actual soc set randomlight if you toggle it --- src/d_main.c | 8 ++++---- src/dehacked.c | 3 +++ src/doomstat.h | 1 + src/p_setup.c | 15 +++++---------- src/p_spec.c | 27 +++++++++++++++++++++++---- src/r_main.c | 24 +----------------------- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 209e7fb76..b03fa3da4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -183,13 +183,13 @@ static void D_GamePadMenuScrollTicker(void) int key = 0; // butt-on output // wish i had a switch ono - if (DPADUPSCROLL) + if (DPADUPSCROLL) key = KEY_UPARROW; - else if (DPADDOWNSCROLL) + else if (DPADDOWNSCROLL) key = KEY_DOWNARROW; - else if (DPADLEFTSCROLL) + else if (DPADLEFTSCROLL) key = KEY_LEFTARROW; - else if (DPADRIGHTSCROLL) + else if (DPADRIGHTSCROLL) key = KEY_RIGHTARROW; if (key) diff --git a/src/dehacked.c b/src/dehacked.c index 57feee732..1413ad314 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -986,10 +986,12 @@ static void readlevelheader(MYFILE *f, INT32 num, INT32 wadnum) else if (fastcmp(word, "LIGHTCONTRAST")) { mapheaderinfo[num-1]->light_contrast = (UINT8)i; + mapheaderinfo[num-1]->use_custom_light = true; } else if (fastcmp(word, "SPRITEBACKLIGHT")) { mapheaderinfo[num-1]->sprite_backlight = (SINT8)i; + mapheaderinfo[num-1]->use_custom_light = true; } else if (fastcmp(word, "LIGHTANGLE")) { @@ -1003,6 +1005,7 @@ static void readlevelheader(MYFILE *f, INT32 num, INT32 wadnum) mapheaderinfo[num-1]->use_light_angle = true; mapheaderinfo[num-1]->light_angle = FixedAngle(FloatToFixed(atof(word2))); } + mapheaderinfo[num-1]->use_custom_light = true; } // Individual triggers for level flags, for ease of use (and 2.0 compatibility) diff --git a/src/doomstat.h b/src/doomstat.h index 03c295f65..cb8f83f8d 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -259,6 +259,7 @@ typedef struct //boolean automap; ///< Displays a level's white map outline in modified games fixed_t mobj_scale; ///< Replacement for TOL_ERZ3 + boolean use_custom_light; UINT8 light_contrast; ///< Range of wall lighting. 0 is no lighting. SINT8 sprite_backlight; ///< Subtract from wall lighting for sprites only. boolean use_light_angle; ///< When false, wall lighting is evenly distributed. When true, wall lighting is directional. diff --git a/src/p_setup.c b/src/p_setup.c index ca41f9f7a..fcc5ae5fa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -324,17 +324,13 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) // SRB2Kart //mapheaderinfo[num]->automap = false; mapheaderinfo[num]->mobj_scale = FRACUNIT; - // an even further impossibility, delfile custom opts support + mapheaderinfo[num]->customopts = NULL; mapheaderinfo[num]->numCustomOptions = 0; -} - -void P_ClearDirectionalLightMapHeaderInfo(INT16 i) // lol dont always reset this on every map load -{ - mapheaderinfo[i]->light_contrast = cv_randomdirlight.value ? M_RandomRange(0, 58) : 8; - mapheaderinfo[i]->sprite_backlight = 0; - mapheaderinfo[i]->use_light_angle = cv_randomdirlight.value ? true : false; - mapheaderinfo[i]->light_angle = cv_randomdirlight.value ? M_RandomRange(-382, 382) : 0; + mapheaderinfo[num]->light_contrast = 8; + mapheaderinfo[num]->sprite_backlight = 0; + mapheaderinfo[num]->use_light_angle = false; + mapheaderinfo[num]->light_angle = 0; } /** Allocates a new map-header structure. @@ -347,7 +343,6 @@ void P_AllocMapHeader(INT16 i) { mapheaderinfo[i] = Z_Malloc(sizeof(mapheader_t), PU_STATIC, NULL); mapheaderinfo[i]->grades = NULL; - P_ClearDirectionalLightMapHeaderInfo(i); } P_ClearSingleMapHeaderInfo(i + 1); } diff --git a/src/p_spec.c b/src/p_spec.c index 045e9db58..cbb5b0d5c 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5225,6 +5225,28 @@ static void P_RunLevelLoadExecutors(void) } } +static void P_SetupDirectionalLight(void) +{ + if (cv_randomdirlight.value && mapheaderinfo[gamemap-1]->use_custom_light == false) + { + static INT16 oldmap = 0; // dont reset stuff when you restart a map + if (gamemap != oldmap) + { + maplighting.contrast = M_RandomRange(0, 58); + maplighting.backlight = 0; + maplighting.directional = M_RandomRange(0, 1); // either on or off + maplighting.angle = M_RandomRange(-382, 382); + } + oldmap = gamemap; + return; + } + + maplighting.contrast = mapheaderinfo[gamemap-1]->light_contrast; + maplighting.backlight = mapheaderinfo[gamemap-1]->sprite_backlight; + maplighting.directional = mapheaderinfo[gamemap-1]->use_light_angle; + maplighting.angle = mapheaderinfo[gamemap-1]->light_angle; +} + /** After the map has loaded, scans for specials that spawn 3Dfloors and * thinkers. * @@ -5251,10 +5273,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) gravity = (FRACUNIT*8)/10; // Set map lighting settings. - maplighting.contrast = mapheaderinfo[gamemap-1]->light_contrast; - maplighting.backlight = mapheaderinfo[gamemap-1]->sprite_backlight; - maplighting.directional = mapheaderinfo[gamemap-1]->use_light_angle; - maplighting.angle = mapheaderinfo[gamemap-1]->light_angle; + P_SetupDirectionalLight(); // Defaults in case levels don't have them set. sstimer = 90*TICRATE + 6; diff --git a/src/r_main.c b/src/r_main.c index 76ee85428..f4054fbfd 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -159,8 +159,6 @@ void SendWeaponPref2(void); void SendWeaponPref3(void); void SendWeaponPref4(void); -static void DirLight_OnChange(void); - static void Precipstuff_OnChange(void); consvar_t cv_tailspickup = {"tailspickup", "On", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -209,27 +207,7 @@ consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // randomized directional lightning -consvar_t cv_randomdirlight = {"randomdirectionallight", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, DirLight_OnChange, 0, NULL, NULL, 0, 0, NULL}; - -static void DirLight_OnChange(void) -{ - for (int i = 0; i < NUMMAPS; i++) - { - if (!mapheaderinfo[i]) - continue; - - P_ClearDirectionalLightMapHeaderInfo(i); - } - - //current map - if (mapheaderinfo[gamemap-1]) - { - maplighting.contrast = mapheaderinfo[gamemap-1]->light_contrast; - maplighting.backlight = mapheaderinfo[gamemap-1]->sprite_backlight; - maplighting.directional = mapheaderinfo[gamemap-1]->use_light_angle; - maplighting.angle = mapheaderinfo[gamemap-1]->light_angle; - } -} +consvar_t cv_randomdirlight = {"randomdirectionallight", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; void SplitScreen_OnChange(void) {