- reviewed and sorted out the remaining parts of g_shared

This commit is contained in:
Christoph Oelckers 2019-01-31 02:27:54 +01:00
commit 25d5b788f5
6 changed files with 333 additions and 68 deletions

View file

@ -45,6 +45,16 @@
#include "g_levellocals.h"
#include "vm.h"
EXTERN_CVAR (Bool, cl_spreaddecals)
EXTERN_CVAR (Int, cl_maxdecals)
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
struct SpreadInfo
{
double DecalWidth, DecalLeft, DecalRight;
@ -54,7 +64,12 @@ struct SpreadInfo
TArray<side_t *> SpreadStack;
};
CVAR (Bool, cl_spreaddecals, true, CVAR_ARCHIVE)
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
IMPLEMENT_CLASS(DBaseDecal, false, true)
@ -65,6 +80,12 @@ IMPLEMENT_POINTERS_END
IMPLEMENT_CLASS(DImpactDecal, false, false)
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Construct(double z)
{
Z = z;
@ -72,6 +93,12 @@ void DBaseDecal::Construct(double z)
PicNum.SetInvalid();
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Construct(const AActor *basis)
{
Z = basis->Z();
@ -85,6 +112,12 @@ void DBaseDecal::Construct(const AActor *basis)
RenderStyle = basis->RenderStyle;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Construct(const DBaseDecal *basis)
{
LeftDistance = basis->LeftDistance;
@ -100,12 +133,24 @@ void DBaseDecal::Construct(const DBaseDecal *basis)
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::OnDestroy ()
{
Remove ();
Super::OnDestroy();
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Remove ()
{
if (WallPrev == nullptr)
@ -120,6 +165,12 @@ void DBaseDecal::Remove ()
WallNext = nullptr;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Serialize(FSerializer &arc)
{
Super::Serialize (arc);
@ -139,6 +190,12 @@ void DBaseDecal::Serialize(FSerializer &arc)
("sector", Sector);
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::GetXY (side_t *wall, double &ox, double &oy) const
{
line_t *line = wall->linedef;
@ -162,18 +219,35 @@ void DBaseDecal::GetXY (side_t *wall, double &ox, double &oy) const
oy = v1->fY() + LeftDistance * dy;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::SetShade (uint32_t rgb)
{
PalEntry *entry = (PalEntry *)&rgb;
AlphaColor = rgb | (ColorMatcher.Pick (entry->r, entry->g, entry->b) << 24);
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::SetShade (int r, int g, int b)
{
AlphaColor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b);
}
//----------------------------------------------------------------------------
//
// Returns the texture the decal stuck to.
//
//----------------------------------------------------------------------------
FTextureID DBaseDecal::StickToWall (side_t *wall, double x, double y, F3DFloor *ffloor)
{
Side = wall;
@ -265,6 +339,12 @@ FTextureID DBaseDecal::StickToWall (side_t *wall, double x, double y, F3DFloor *
return tex;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
double DBaseDecal::GetRealZ (const side_t *wall) const
{
const line_t *line = wall->linedef;
@ -319,6 +399,12 @@ double DBaseDecal::GetRealZ (const side_t *wall) const
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::CalcFracPos (side_t *wall, double x, double y)
{
line_t *line = wall->linedef;
@ -352,6 +438,12 @@ void DBaseDecal::CalcFracPos (side_t *wall, double x, double y)
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
static void GetWallStuff (side_t *wall, vertex_t *&v1, double &ldx, double &ldy)
{
line_t *line = wall->linedef;
@ -369,11 +461,23 @@ static void GetWallStuff (side_t *wall, vertex_t *&v1, double &ldx, double &ldy)
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
static double Length (double dx, double dy)
{
return DVector2(dx, dy).Length();
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
static side_t *NextWall (const side_t *wall)
{
line_t *line = wall->linedef;
@ -392,6 +496,12 @@ static side_t *NextWall (const side_t *wall)
return NULL;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor, SpreadInfo *spread)
{
double ldx, ldy;
@ -436,6 +546,12 @@ void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFloor *ffloor, SpreadInfo *spread)
{
vertex_t *v1;
@ -476,6 +592,12 @@ void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFl
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor)
{
SpreadInfo spread;
@ -509,6 +631,12 @@ void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, double x, doub
Length (wall->linedef->Delta().X, wall->linedef->Delta().Y), ffloor, &spread);
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DBaseDecal *DBaseDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const
{
DBaseDecal *decal = Level->CreateThinker<DBaseDecal>(iz);
@ -530,24 +658,11 @@ DBaseDecal *DBaseDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double
return decal;
}
CUSTOM_CVAR (Int, cl_maxdecals, 1024, CVAR_ARCHIVE)
{
if (self < 0)
{
self = 0;
}
else for (auto Level : AllLevels())
{
while (Level->ImpactDecalCount > self)
{
DThinker *thinker = Level->FirstThinker(STAT_AUTODECAL);
if (thinker != NULL)
{
thinker->Destroy();
}
}
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void DImpactDecal::CheckMax ()
{
@ -562,6 +677,12 @@ void DImpactDecal::CheckMax ()
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color)
{
if (cl_maxdecals > 0)
@ -576,6 +697,12 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name,
return NULL;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color)
{
DImpactDecal *decal = NULL;
@ -621,6 +748,12 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTempl
return decal;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const
{
if (wall->Flags & WALLF_NOAUTODECALS)
@ -648,31 +781,11 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl
return decal;
}
CCMD (countdecals)
{
for (auto Level : AllLevels())
{
auto iterator = Level->GetThinkerIterator<DImpactDecal>(NAME_None, STAT_AUTODECAL);
int count = 0;
while (iterator.Next())
count++;
Printf("%s: Counted %d impact decals\n", Level->MapName.GetChars(), count);
}
}
CCMD (spray)
{
if (who == NULL || argv.argc() < 2)
{
Printf ("Usage: spray <decal>\n");
return;
}
Net_WriteByte (DEM_SPRAY);
Net_WriteString (argv[1]);
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void SprayDecal(AActor *shooter, const char *name, double distance)
{
@ -692,6 +805,12 @@ void SprayDecal(AActor *shooter, const char *name, double distance)
}
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent)
{
if (tpl == NULL || (tpl = tpl->GetDecal()) == NULL)
@ -728,12 +847,16 @@ DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t
return NULL;
}
DEFINE_ACTION_FUNCTION(ADecal, SpawnDecal)
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
static void SpawnDecal(AActor *self)
{
PARAM_SELF_PROLOGUE(AActor);
const FDecalTemplate *tpl = nullptr;
if (self->args[0] < 0)
{
FName name = ENamedName(-self->args[0]);
@ -744,7 +867,7 @@ DEFINE_ACTION_FUNCTION(ADecal, SpawnDecal)
int decalid = self->args[0] + (self->args[1] << 8); // [KS] High byte for decals.
tpl = DecalLibrary.GetDecalByNum(decalid);
}
// If no decal is specified, don't try to create one.
if (tpl != nullptr)
{
@ -767,5 +890,11 @@ DEFINE_ACTION_FUNCTION(ADecal, SpawnDecal)
{
DPrintf (DMSG_ERROR, "Decal actor at (%f,%f) does not have a good template\n", self->X(), self->Y());
}
}
DEFINE_ACTION_FUNCTION_NATIVE(ADecal, SpawnDecal, SpawnDecal)
{
PARAM_SELF_PROLOGUE(AActor);
SpawnDecal(self);
return 0;
}