mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-30 21:20:54 +00:00
Merge branch 'lightfade-ticbased' into le-fadefof
This commit is contained in:
commit
4ca38dc8a1
5 changed files with 132 additions and 46 deletions
|
@ -1809,9 +1809,11 @@ static int lib_pFadeLight(lua_State *L)
|
|||
INT16 tag = (INT16)luaL_checkinteger(L, 1);
|
||||
INT32 destvalue = (INT32)luaL_checkinteger(L, 2);
|
||||
INT32 speed = (INT32)luaL_checkinteger(L, 3);
|
||||
boolean ticbased = lua_optboolean(L, 4);
|
||||
boolean exactlightlevel = lua_optboolean(L, 5);
|
||||
NOHUD
|
||||
INLEVEL
|
||||
P_FadeLight(tag, destvalue, speed);
|
||||
P_FadeLight(tag, destvalue, speed, ticbased, exactlightlevel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
146
src/p_lights.c
146
src/p_lights.c
|
@ -13,7 +13,9 @@
|
|||
/// Fire flicker, light flash, strobe flash, lightning flash, glow, and fade.
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "doomstat.h" // gametic
|
||||
#include "p_local.h"
|
||||
#include "r_main.h" // LIGHTSEGSHIFT
|
||||
#include "r_state.h"
|
||||
#include "z_zone.h"
|
||||
#include "m_random.h"
|
||||
|
@ -322,40 +324,62 @@ glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector,
|
|||
return g;
|
||||
}
|
||||
|
||||
/** Fades all the lights in sectors with a particular tag to a new
|
||||
/** Fades all the lights in specified sector to a new
|
||||
* value.
|
||||
*
|
||||
* \param tag Tag to look for sectors by.
|
||||
* \param sector Target sector
|
||||
* \param destvalue The final light value in these sectors.
|
||||
* \param speed Speed of the fade; the change to the ligh
|
||||
* level in each sector per tic.
|
||||
* \todo Calculate speed better so that it is possible to specify
|
||||
* the time for completion of the fade, and all lights fade
|
||||
* in this time regardless of initial values.
|
||||
* \param ticbased Use a specific duration for the fade, defined by speed
|
||||
* \param exactlightlevel Do not snap to software values (for OpenGL)
|
||||
* \sa T_LightFade
|
||||
*/
|
||||
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed)
|
||||
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel)
|
||||
{
|
||||
lightlevel_t *ll;
|
||||
|
||||
P_RemoveLighting(sector); // remove the old lighting effect first
|
||||
|
||||
if ((ticbased && !speed) || sector->lightlevel == destvalue) // set immediately
|
||||
{
|
||||
sector->lightlevel = destvalue;
|
||||
return;
|
||||
}
|
||||
|
||||
ll = Z_Calloc(sizeof (*ll), PU_LEVSPEC, NULL);
|
||||
ll->thinker.function.acp1 = (actionf_p1)T_LightFade;
|
||||
sector->lightingdata = ll; // set it to the lightlevel_t
|
||||
|
||||
P_AddThinker(&ll->thinker); // add thinker
|
||||
|
||||
ll->sector = sector;
|
||||
ll->destlevel = destvalue;
|
||||
ll->exactlightlevel = exactlightlevel;
|
||||
ll->lightlevel = sector->lightlevel;
|
||||
|
||||
if (ticbased)
|
||||
{
|
||||
ll->duration = abs(speed);
|
||||
ll->speed = FixedFloor(FixedDiv(destvalue - sector->lightlevel, ll->duration))/FRACUNIT;
|
||||
if (!ll->speed)
|
||||
ll->speed = (destvalue < sector->lightlevel) ? -1 : 1;
|
||||
ll->interval = max(FixedFloor(FixedDiv(ll->duration, abs(destvalue - sector->lightlevel)))/FRACUNIT, 1);
|
||||
ll->firsttic = gametic;
|
||||
}
|
||||
else
|
||||
{
|
||||
ll->duration = -1;
|
||||
ll->speed = abs(speed);
|
||||
}
|
||||
}
|
||||
|
||||
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel)
|
||||
{
|
||||
INT32 i;
|
||||
lightlevel_t *ll;
|
||||
sector_t *sector;
|
||||
|
||||
// search all sectors for ones with tag
|
||||
for (i = -1; (i = P_FindSectorFromTag(tag, i)) >= 0 ;)
|
||||
{
|
||||
sector = §ors[i];
|
||||
|
||||
P_RemoveLighting(sector); // remove the old lighting effect first
|
||||
ll = Z_Calloc(sizeof (*ll), PU_LEVSPEC, NULL);
|
||||
ll->thinker.function.acp1 = (actionf_p1)T_LightFade;
|
||||
sector->lightingdata = ll; // set it to the lightlevel_t
|
||||
|
||||
P_AddThinker(&ll->thinker); // add thinker
|
||||
|
||||
ll->sector = sector;
|
||||
ll->destlevel = destvalue;
|
||||
ll->speed = speed;
|
||||
}
|
||||
P_FadeLightBySector(§ors[i], destvalue, speed, ticbased, exactlightlevel);
|
||||
}
|
||||
|
||||
/** Fades the light level in a sector to a new value.
|
||||
|
@ -365,30 +389,66 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed)
|
|||
*/
|
||||
void T_LightFade(lightlevel_t *ll)
|
||||
{
|
||||
if (ll->sector->lightlevel < ll->destlevel)
|
||||
{
|
||||
// increase the lightlevel
|
||||
if (ll->sector->lightlevel + ll->speed >= ll->destlevel)
|
||||
{
|
||||
// stop changing light level
|
||||
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
|
||||
boolean stillfading = false;
|
||||
INT16 lightlevel = ll->lightlevel;
|
||||
|
||||
if (ll->duration >= 0) // tic-based
|
||||
{
|
||||
stillfading = !(gametic - ll->firsttic >= ll->duration);
|
||||
if (gametic - ll->firsttic >= ll->duration)
|
||||
{
|
||||
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
|
||||
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
|
||||
}
|
||||
else
|
||||
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel + (INT16)ll->speed); // move lightlevel
|
||||
else if (!((gametic - ll->firsttic) % ll->interval))
|
||||
{
|
||||
if (ll->speed < 0)
|
||||
lightlevel = max(lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
|
||||
else
|
||||
lightlevel = min(lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
|
||||
}
|
||||
}
|
||||
else // x/tic speed-based
|
||||
{
|
||||
if (lightlevel < ll->destlevel)
|
||||
{
|
||||
// increase the lightlevel
|
||||
if (lightlevel + ll->speed >= ll->destlevel)
|
||||
{
|
||||
// stop changing light level
|
||||
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
|
||||
|
||||
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
|
||||
}
|
||||
else
|
||||
{
|
||||
stillfading = true;
|
||||
lightlevel = (INT16)(lightlevel + (INT16)ll->speed); // move lightlevel
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// decrease lightlevel
|
||||
if (lightlevel - ll->speed <= ll->destlevel)
|
||||
{
|
||||
// stop changing light level
|
||||
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
|
||||
|
||||
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
|
||||
}
|
||||
else
|
||||
{
|
||||
stillfading = true;
|
||||
lightlevel = (INT16)(lightlevel - (INT16)ll->speed); // move lightlevel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Snap light level to software values
|
||||
if (!stillfading || ll->exactlightlevel)
|
||||
ll->sector->lightlevel = lightlevel;
|
||||
else
|
||||
{
|
||||
// decrease lightlevel
|
||||
if (ll->sector->lightlevel - ll->speed <= ll->destlevel)
|
||||
{
|
||||
// stop changing light level
|
||||
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
|
||||
ll->sector->lightlevel = (lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT;
|
||||
|
||||
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
|
||||
}
|
||||
else
|
||||
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel - (INT16)ll->speed); // move lightlevel
|
||||
}
|
||||
ll->lightlevel = lightlevel;
|
||||
}
|
||||
|
|
|
@ -1540,6 +1540,11 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type)
|
|||
WRITEUINT32(save_p, SaveSector(ht->sector));
|
||||
WRITEINT32(save_p, ht->destlevel);
|
||||
WRITEINT32(save_p, ht->speed);
|
||||
WRITEINT32(save_p, ht->duration);
|
||||
WRITEUINT32(save_p, ht->interval);
|
||||
WRITEUINT32(save_p, (UINT32)ht->firsttic);
|
||||
WRITEUINT8(save_p, (UINT8)ht->exactlightlevel);
|
||||
WRITEINT16(save_p, ht->lightlevel);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -2540,6 +2545,11 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker)
|
|||
ht->sector = LoadSector(READUINT32(save_p));
|
||||
ht->destlevel = READINT32(save_p);
|
||||
ht->speed = READINT32(save_p);
|
||||
ht->duration = READINT32(save_p);
|
||||
ht->interval = READUINT32(save_p);
|
||||
ht->firsttic = (tic_t)READUINT32(save_p);
|
||||
ht->exactlightlevel = (boolean)READUINT8(save_p);
|
||||
ht->lightlevel = READINT16(save_p);
|
||||
if (ht->sector)
|
||||
ht->sector->lightingdata = ht;
|
||||
P_AddThinker(&ht->thinker);
|
||||
|
|
|
@ -2785,7 +2785,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
|
|||
break;
|
||||
|
||||
case 420: // Fade light levels in tagged sectors to new value
|
||||
P_FadeLight(line->tag, line->frontsector->lightlevel, P_AproxDistance(line->dx, line->dy)>>FRACBITS);
|
||||
P_FadeLight(line->tag,
|
||||
(line->flags & ML_BLOCKMONSTERS) ? max(min(sides[line->sidenum[0]].textureoffset>>FRACBITS, 255), 0) : line->frontsector->lightlevel,
|
||||
(line->flags & ML_BLOCKMONSTERS) ? max(sides[line->sidenum[0]].rowoffset>>FRACBITS, 0) : P_AproxDistance(line->dx, line->dy)>>FRACBITS,
|
||||
(line->flags & ML_NOCLIMB),
|
||||
(line->flags & ML_TFERLINE));
|
||||
break;
|
||||
|
||||
case 421: // Stop lighting effect in tagged sectors
|
||||
|
|
12
src/p_spec.h
12
src/p_spec.h
|
@ -138,6 +138,15 @@ typedef struct
|
|||
sector_t *sector; ///< Sector where action is taking place.
|
||||
INT32 destlevel; ///< Light level we're fading to.
|
||||
INT32 speed; ///< Speed at which to change light level.
|
||||
|
||||
// Tic-based behavior
|
||||
INT32 duration; ///< If <0, do not use tic-based behavior. If 0, set instantly. If >0, fade lasts this duration.
|
||||
UINT32 interval; ///< Interval to deduct light level
|
||||
tic_t firsttic; ///< First gametic to count from
|
||||
|
||||
// Snap to software values
|
||||
boolean exactlightlevel; ///< Use exact values for OpenGL
|
||||
INT16 lightlevel; ///< Internal counter for fading
|
||||
} lightlevel_t;
|
||||
|
||||
#define GLOWSPEED 8
|
||||
|
@ -156,7 +165,8 @@ strobe_t * P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector
|
|||
void T_Glow(glow_t *g);
|
||||
glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, INT32 length);
|
||||
|
||||
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed);
|
||||
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel);
|
||||
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel);
|
||||
void T_LightFade(lightlevel_t *ll);
|
||||
|
||||
typedef enum
|
||||
|
|
Loading…
Reference in a new issue