Skip to content

Commit

Permalink
- sprite lightlevel cleanup and fixes.
Browse files Browse the repository at this point in the history
* consolidated the getter functions on the game data side
* better handling of per-sprite lighting with fog
* allow negative values for additive per-sprite lighting.
* also fixed return type of UpdateWaterDepth.
  • Loading branch information
coelckers committed Jun 1, 2022
1 parent da30b6f commit 344c634
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 46 deletions.
28 changes: 28 additions & 0 deletions l
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Mainly a bugfix release addressing the following issues:
- Fixed: SBar_DrawTextureRotated was missing the angle parameter
- Compat patch for misplaced items in Hexen MAP08.
- fixed some imprecisions in font luminosity calculation. This was still going through the palette which could result in off-by-one errors.
- fixed palette initialization for single lump fonts (FON2 and BMF)
- push sprite shadows a little back for distance sorting
- avoid multiple Dehacked mappings to the same function to fix MBF21 lookup issues.
- disallow changing the line spacing for option menus.
- be a bit more aggressive with the GC when not running the game loop.
- fixed memory leak in DShape2DBufferInfo.
- allow "INDEXFON" as an alias for "INDEXFONT".
- fixed A_Punch having a short attack range (take 2).
- GLES: Fix texture MapBuffer and AllocateBuffer create client side memory.
- Fix "out of memory" errors when the vulkan backend is asked to create zero byte sized buffers
- resolved a VM abort upon morphing while the tome of power is active
- fixed particle processing in the main thinker loop. This may not be guarded by the dynamic light flags, only the light ticking may.
- fixed handling of states with the 'light' keyword.
- Fixed broken V_BreakLines.
- treat "materials" as a known folder name for eliminating root folders in Zips.

New Features:
- widescreen assets for all officially supported games. This version adds Hacx, Harmony and Chex Quest.
- Allow WorldUnloaded events to know the next map name (if any).
- Allow map markers to scale relative to automap zoom.
- Add cvars to control automap line alpha and thickness
- PreTravelled virtual for player and inventory.
- Allow customization of pause screen.
- ReadThisMenu / MenuDelegate overriding.
34 changes: 34 additions & 0 deletions options.checklist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
N/A weapon_recoil Firing a weapon pushes the player back
---N/A (todo, lastenemy?) monsters_remember 1 Friendly monsters return to old target when losing current one
!LEVEL2_NOINFIGHTING monster_infighting 1 Monsters infight
LEVEL3_AVOIDMELEE monster_backing Ranged monsters will back away from close melee targets
COMPATF2_AVOID_HAZARDS monster_avoid_hazards 1 Monsters avoid hazards such as crushing ceilings
N/A monkeys Monsters can climb steep stairs
COMPATF_MBFMONSTERMOVE monster_friction 1 Monsters are affected by friction modifiers
help_friends Friendly monsters prefer targets of friends
player_helpers Number of dogs to spawn
friend_distance 128 Friendly monsters try to keep at least this distance apart
!LEVEL3_NOJUMPDOWN dog_jumping 1 Dogs can jump down from high ledges
N/A comp_telefrag Spawners only telefrag on Map 30
COMPATF_DROPOFF comp_dropoff 01 Discourage / prevent enemies from walking off ledges (?)
COMPATF_CORPSEGIBS,BCOMPATF_VILEGHOSTS comp_vile Archviles can create ghosts
COMPATF_LIMITPAIN comp_pain Pain elementals don't spawn lost souls if there are over 20
--- N/A (todo) comp_skull Lost souls can spawn past impassable lines
N/A comp_blazing Blazing doors have double sounds
COMPATF_NODOORLIGHT comp_doorlight Door lighting changes are abrupt
COMPATF_LIGHT,COMPATF_SHORTTEX (partial) comp_model Assorted physics quirks and bugs
N/A comp_god God mode is removed in sector 11 & ignored at 1000+ damage
N/A comp_falloff Don't pull monsters off ledges they are hanging off of
COMPATF2_FLOORMOVE comp_floors Assorted floor bugs
N/A comp_skymap Don't apply invulnerability palette to skies
---todo comp_pursuit 1 Monsters can infight immediately when alerted
N/A comp_doorstuck Monsters get stuck in door tracks
COMPATF2_STAYONLIFT comp_staylift Monsters don't prefer staying on lifts their target is on
N/A comp_zombie Dead players can activate things
COMPATF_STAIRINDEX comp_stairs Assorted stair bugs
N/A comp_infcheat ?
N/A comp_zerotags Allow tag zero actions
N/A comp_respawn Monsters not spawned at level start respawn at the origin
N/A comp_soul Buggy lost soul bouncing
COMPATF_CROSSDROPOFF comp_ledgeblock 10 Monsters are blocked by ledges (except when scrolling)
---todo comp_friendlyspawn 1 Spawned things inherit the friend attribute from the source
205 changes: 205 additions & 0 deletions src/gamedata/options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
//
// Copyright(C) 2020 by Ryan Krafnick
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// DSDA Options Lump
//

#include "filesystem.h"
#include "g_mapinfo.h"
#include "doomdef.h"
#include "templates.h"


struct dsda_options
{
int monsters_remember = -1;
int monster_infighting = -1;
int monster_backing = -1;
int monster_avoid_hazards = -1;
int monster_friction = -1;
int help_friends = 0;
int player_helpers = 0;
int friend_distance = 128;
int dog_jumping = -1;
int comp_dropoff = -1;
int comp_vile = -1;
int comp_pain = -1;
int comp_doorlight = -1;
int comp_model = -1;
int comp_floors = -1;
int comp_pursuit = -1; // 1 for 'latest'
int comp_staylift = -1;
int comp_stairs = -1;
int comp_ledgeblock = -1;
int comp_friendlyspawn = -1;
};

struct dsda_option_t
{
const char* key;
int dsda_options::* value;
int min;
int max;
};

static dsda_option_t option_list[] = {
{ "monsters_remember", &dsda_options::monsters_remember, 0, 1 },
{ "monster_infighting", &dsda_options::monster_infighting, 0, 1 },
{ "monster_backing", &dsda_options::monster_backing, 0, 1 },
{ "monster_avoid_hazards", &dsda_options::monster_avoid_hazards, 0, 1 },
{ "monster_friction", &dsda_options::monster_friction, 0, 1 },
{ "help_friends", &dsda_options::help_friends, 0, 1 },
{ "player_helpers", &dsda_options::player_helpers, 0, 3 },
{ "friend_distance", &dsda_options::friend_distance, 0, 999 },
{ "dog_jumping", &dsda_options::dog_jumping, 0, 1 },
{ "comp_dropoff", &dsda_options::comp_dropoff, 0, 1 },
{ "comp_vile", &dsda_options::comp_vile, 0, 1 },
{ "comp_pain", &dsda_options::comp_pain, 0, 1 },
{ "comp_doorlight", &dsda_options::comp_doorlight, 0, 1 },
{ "comp_model", &dsda_options::comp_model, 0, 1 },
{ "comp_floors", &dsda_options::comp_floors, 0, 1 },
{ "comp_pursuit", &dsda_options::comp_pursuit, 0, 1 },
{ "comp_staylift", &dsda_options::comp_staylift, 0, 1 },
{ "comp_stairs", &dsda_options::comp_stairs, 0, 1 },
{ "comp_ledgeblock", &dsda_options::comp_ledgeblock, 0, 1 },
{ "comp_friendlyspawn", &dsda_options::comp_friendlyspawn, 0, 1 },
{ 0 }
};

enum { OPTIONS_LINE_LENGTH = 80 };

struct options_lump_t
{
const char* data;
int length;
};

static const char* dsda_ReadOption(char* buf, size_t size, options_lump_t* lump)
{
if (lump->length <= 0)
return nullptr;

while (size > 1 && *lump->data && lump->length)
{
size--;
lump->length--;
if ((*buf++ = *lump->data++) == '\n')
break;
}

*buf = '\0';

return lump->data;
}

static struct dsda_options dsda_LumpOptions(int lumpnum)
{
struct dsda_options mbf_options;

options_lump_t lump;
char buf[OPTIONS_LINE_LENGTH];
char key[OPTIONS_LINE_LENGTH];
char* scan;
int value, count;
dsda_option_t* option;

lump.length = fileSystem.FileLength(lumpnum);
auto data = fileSystem.ReadFile(lumpnum);
lump.data = (char*)data.GetMem();

while (dsda_ReadOption(buf, OPTIONS_LINE_LENGTH, &lump))
{
if (buf[0] == '#')
continue;

scan = buf;
count = sscanf(scan, "%79s %d", key, &value);

if (count != 2)
continue;

for (option = option_list; option->value; option++)
{
if (!strncmp(key, option->key, OPTIONS_LINE_LENGTH))
{
mbf_options.*option->value = clamp(option->min, option->max, value);

//lprintf(LO_INFO, "dsda_LumpOptions: %s = %d\n", key, value);

break;
}
}
}
return mbf_options;
}


void parseOptions()
{
int lumpnum = fileSystem.FindFile("OPTIONS");

if (lumpnum == -1)
return;

auto opt = dsda_LumpOptions(lumpnum);

auto setflag = [](auto& flag, auto mask, bool set)
{
if (set) flag |= mask;
else flag &= ~mask;
};

for (auto& lev : wadlevelinfos)
{
setflag(lev.flags2, LEVEL2_NOINFIGHTING, opt.monster_infighting);
setflag(lev.flags3, LEVEL3_AVOIDMELEE, opt.monster_backing);
setflag(lev.compatflags2, COMPATF2_AVOID_HAZARDS, opt.monster_avoid_hazards);
setflag(lev.compatmask2, COMPATF2_AVOID_HAZARDS, opt.monster_avoid_hazards);
setflag(lev.compatflags, COMPATF_MBFMONSTERMOVE, opt.monster_friction);
setflag(lev.compatmask, COMPATF_MBFMONSTERMOVE, opt.monster_friction);
setflag(lev.compatflags, COMPATF_DROPOFF, opt.comp_dropoff);
setflag(lev.compatmask, COMPATF_DROPOFF, opt.comp_dropoff);
setflag(lev.compatflags, COMPATF_DROPOFF, opt.comp_dropoff);
setflag(lev.compatmask, COMPATF_DROPOFF, opt.comp_dropoff);
setflag(lev.compatflags, COMPATF_CORPSEGIBS, opt.comp_vile);
setflag(lev.compatmask, COMPATF_CORPSEGIBS, opt.comp_vile);
setflag(lev.flags3, LEVEL3_VILEOPTION, opt.comp_vile);
setflag(lev.flags3, LEVEL3_NOJUMPDOWN, !opt.dog_jumping); // this one's rather pointless, but well...
setflag(lev.compatflags, COMPATF_LIMITPAIN, opt.comp_pain);
setflag(lev.compatmask, COMPATF_LIMITPAIN, opt.comp_pain);
setflag(lev.compatflags, COMPATF_NODOORLIGHT, opt.comp_doorlight);
setflag(lev.compatmask, COMPATF_NODOORLIGHT, opt.comp_doorlight);
setflag(lev.compatflags, COMPATF_LIGHT | COMPATF_SHORTTEX, opt.comp_model); // only the relevant parts of this catch-all option.
setflag(lev.compatmask, COMPATF_LIGHT | COMPATF_SHORTTEX, opt.comp_model);
setflag(lev.compatflags2, COMPATF2_FLOORMOVE, opt.comp_floors);
setflag(lev.compatmask2, COMPATF2_FLOORMOVE, opt.comp_floors);
setflag(lev.compatflags2, COMPATF2_STAYONLIFT, opt.comp_staylift);
setflag(lev.compatmask2, COMPATF2_STAYONLIFT, opt.comp_staylift);
setflag(lev.compatflags, COMPATF_STAIRINDEX, opt.comp_stairs);
setflag(lev.compatmask, COMPATF_STAIRINDEX, opt.comp_stairs);
setflag(lev.compatflags, COMPATF_CROSSDROPOFF, opt.comp_ledgeblock);
setflag(lev.compatmask, COMPATF_CROSSDROPOFF, opt.comp_ledgeblock);

/* later. these should be supported but are not implemented yet.
if (opt.monsters_remember == 0)
if (opt.comp_pursuit)
if (opt.comp_friendlyspawn == 0)
int help_friends = 0;
int player_helpers = 0;
int friend_distance = 128;
*/

}
}

6 changes: 6 additions & 0 deletions src/gamedata/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "r_data/r_translate.h"
#include "texmanip.h"
#include "fcolormap.h"
#include "r_sky.h"
#include "p_terrain.h"

#include "hwrenderer/data/buffers.h"
Expand Down Expand Up @@ -797,6 +798,7 @@ struct sector_t

int GetFloorLight() const;
int GetCeilingLight() const;
int GetSpriteLight() const;

sector_t *GetHeightSec() const
{
Expand Down Expand Up @@ -1795,6 +1797,10 @@ inline void sector_t::SetColor(PalEntry pe, int desat) { ::SetColor(this, pe, de
inline void sector_t::SetFade(PalEntry pe) { ::SetFade(this, pe); }
inline int sector_t::GetFloorLight() const { return ::GetFloorLight(this); }
inline int sector_t::GetCeilingLight() const { return ::GetCeilingLight(this); }
inline int sector_t::GetSpriteLight() const
{
return GetTexture(ceiling) == skyflatnum ? GetCeilingLight() : GetFloorLight();
}
inline double sector_t::GetFriction(int plane, double *movefac) const { return ::GetFriction(this, plane, movefac); }

inline void sector_t::CheckExColorFlag()
Expand Down
3 changes: 2 additions & 1 deletion src/playsim/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ class AActor : public DThinker
bool IsMapActor();
int GetTics(FState * newstate);
bool SetState (FState *newstate, bool nofunction=false);
int UpdateWaterDepth(bool splash);
double UpdateWaterDepth(bool splash);
virtual void SplashCheck();
virtual bool UpdateWaterLevel (bool splash=true);
bool isFast();
Expand Down Expand Up @@ -1509,6 +1509,7 @@ class AActor : public DThinker
return max(1., Distance2D(dest) / speed);
}

int GetLightLevel(sector_t* rendersector);
int ApplyDamageFactor(FName damagetype, int damage) const;
int GetModifiedDamage(FName damagetype, int damage, bool passive, AActor *inflictor, AActor *source, int flags = 0);
void DeleteAttachedLights();
Expand Down
16 changes: 16 additions & 0 deletions src/playsim/actorinlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ inline bool AActor::isFrozen() const
return false;
}

inline int AActor::GetLightLevel(sector_t* rendersector)
{
int lightlevel = rendersector->GetSpriteLight();

if (flags8 & MF8_ADDLIGHTLEVEL)
{
lightlevel += LightLevel;
}
else if (LightLevel > -1)
{
lightlevel = LightLevel;
}
return lightlevel;
}


// Consolidated from all (incomplete) variants that check if a line should block.
inline bool P_IsBlockedByLine(AActor* actor, line_t* line)
{
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4272,7 +4272,7 @@ void AActor::CheckSectorTransition(sector_t *oldsec)
//
//==========================================================================

int AActor::UpdateWaterDepth(bool splash)
double AActor::UpdateWaterDepth(bool splash)
{
double fh = -FLT_MAX;
bool reset = false;
Expand Down
1 change: 1 addition & 0 deletions src/r_data/colormaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "filesystem.h"
#include "r_sky.h"
#include "textures.h"
#include "colormaps.h"

#include "c_cvars.h"
Expand Down
22 changes: 3 additions & 19 deletions src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,31 +997,16 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
// light calculation

bool enhancedvision = false;
const bool UseActorLight = (thing->LightLevel > -1);

// allow disabling of the fullbright flag by a brightmap definition
// (e.g. to do the gun flashes of Doom's zombies correctly.
fullbright = (thing->flags5 & MF5_BRIGHT) ||
((thing->renderflags & RF_FULLBRIGHT) && (!texture || !texture->isFullbrightDisabled()));

if (fullbright) lightlevel = 255;
else if (UseActorLight)
{
int newlevel = thing->LightLevel;
if (thing->flags8 & MF8_ADDLIGHTLEVEL)
{
newlevel += hw_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ?
rendersector->GetCeilingLight() : rendersector->GetFloorLight());

newlevel = clamp(newlevel, 0, 255);
}
lightlevel = newlevel;
}
else
lightlevel = hw_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ?
rendersector->GetCeilingLight() : rendersector->GetFloorLight());
else lightlevel = hw_ClampLight(thing->GetLightLevel(rendersector));

foglevel = (uint8_t)clamp<short>((UseActorLight) ? lightlevel : rendersector->lightlevel, 0, 255);
foglevel = (uint8_t)clamp<short>(rendersector->lightlevel, 0, 255); // this *must* use the sector's light level or the fog will just look bad.

lightlevel = rendersector->CheckSpriteGlow(lightlevel, thingpos);

Expand Down Expand Up @@ -1234,8 +1219,7 @@ void HWSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t *
{
if (particle->alpha==0) return;

lightlevel = hw_ClampLight(sector->GetTexture(sector_t::ceiling) == skyflatnum ?
sector->GetCeilingLight() : sector->GetFloorLight());
lightlevel = hw_ClampLight(sector->GetSpriteLight());
foglevel = (uint8_t)clamp<short>(sector->lightlevel, 0, 255);

if (di->isFullbrightScene())
Expand Down
Loading

0 comments on commit 344c634

Please sign in to comment.