2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** a_decals.cpp
|
|
|
|
** Implements the actor that represents decals in the level
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "actor.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "r_defs.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_trace.h"
|
|
|
|
#include "decallib.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "d_net.h"
|
2020-04-11 17:27:11 +00:00
|
|
|
#include "serializer_doom.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "doomdata.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2018-11-19 16:54:38 +00:00
|
|
|
#include "vm.h"
|
2020-04-11 17:00:07 +00:00
|
|
|
#include "texturemanager.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
EXTERN_CVAR (Bool, cl_spreaddecals)
|
|
|
|
EXTERN_CVAR (Int, cl_maxdecals)
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
struct SpreadInfo
|
|
|
|
{
|
|
|
|
double DecalWidth, DecalLeft, DecalRight;
|
|
|
|
double SpreadZ;
|
|
|
|
const DBaseDecal *SpreadSource;
|
|
|
|
const FDecalTemplate *SpreadTemplate;
|
|
|
|
TArray<side_t *> SpreadStack;
|
|
|
|
};
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DBaseDecal, false, true)
|
2016-11-05 16:08:54 +00:00
|
|
|
|
|
|
|
IMPLEMENT_POINTERS_START(DBaseDecal)
|
|
|
|
IMPLEMENT_POINTER(WallPrev)
|
|
|
|
IMPLEMENT_POINTER(WallNext)
|
|
|
|
IMPLEMENT_POINTERS_END
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DImpactDecal, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-01-27 12:08:54 +00:00
|
|
|
void DBaseDecal::Construct(double z)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-27 12:08:54 +00:00
|
|
|
Z = z;
|
2016-03-01 15:47:10 +00:00
|
|
|
RenderStyle = STYLE_None;
|
|
|
|
PicNum.SetInvalid();
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-01-27 12:08:54 +00:00
|
|
|
void DBaseDecal::Construct(const AActor *basis)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-27 12:08:54 +00:00
|
|
|
Z = basis->Z();
|
|
|
|
ScaleX = basis->Scale.X;
|
|
|
|
ScaleY = basis->Scale.Y;
|
|
|
|
Alpha = basis->Alpha;
|
|
|
|
AlphaColor = basis->fillcolor;
|
|
|
|
Translation = basis->Translation;
|
|
|
|
PicNum = basis->picnum;
|
|
|
|
RenderFlags = basis->renderflags;
|
|
|
|
RenderStyle = basis->RenderStyle;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-01-27 12:08:54 +00:00
|
|
|
void DBaseDecal::Construct(const DBaseDecal *basis)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-27 12:08:54 +00:00
|
|
|
LeftDistance = basis->LeftDistance;
|
|
|
|
Z = basis->Z;
|
|
|
|
ScaleX = basis->ScaleX;
|
|
|
|
ScaleY = basis->ScaleY;
|
|
|
|
Alpha = basis->Alpha;
|
|
|
|
AlphaColor = basis->AlphaColor;
|
|
|
|
Translation = basis->Translation;
|
|
|
|
PicNum = basis->PicNum;
|
|
|
|
RenderFlags = basis->RenderFlags;
|
|
|
|
RenderStyle = basis->RenderStyle;
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2017-01-12 21:49:18 +00:00
|
|
|
void DBaseDecal::OnDestroy ()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Remove ();
|
2017-01-12 21:49:18 +00:00
|
|
|
Super::OnDestroy();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
void DBaseDecal::Remove ()
|
|
|
|
{
|
2016-09-23 06:49:30 +00:00
|
|
|
if (WallPrev == nullptr)
|
|
|
|
{
|
|
|
|
if (Side != nullptr) Side->AttachedDecals = WallNext;
|
|
|
|
}
|
2016-09-19 22:41:22 +00:00
|
|
|
else WallPrev->WallNext = WallNext;
|
|
|
|
|
|
|
|
if (WallNext != nullptr) WallNext->WallPrev = WallPrev;
|
|
|
|
|
2016-09-23 06:49:30 +00:00
|
|
|
WallPrev = nullptr;
|
|
|
|
WallNext = nullptr;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-09-19 22:41:22 +00:00
|
|
|
void DBaseDecal::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 22:41:22 +00:00
|
|
|
arc("wallprev", WallPrev)
|
|
|
|
("wallnext", WallNext)
|
|
|
|
("leftdistance", LeftDistance)
|
|
|
|
("z", Z)
|
|
|
|
("scalex", ScaleX)
|
|
|
|
("scaley", ScaleY)
|
|
|
|
("alpha", Alpha)
|
|
|
|
("alphacolor", AlphaColor)
|
|
|
|
("translation", Translation)
|
|
|
|
("picnum", PicNum)
|
|
|
|
("renderflags", RenderFlags)
|
|
|
|
("renderstyle", RenderStyle)
|
|
|
|
("side", Side)
|
2016-09-23 07:20:58 +00:00
|
|
|
("sector", Sector);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
void DBaseDecal::GetXY (side_t *wall, double &ox, double &oy) const
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
line_t *line = wall->linedef;
|
|
|
|
vertex_t *v1, *v2;
|
|
|
|
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
v1 = line->v1;
|
|
|
|
v2 = line->v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v1 = line->v2;
|
|
|
|
v2 = line->v1;
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
double dx = v2->fX() - v1->fX();
|
|
|
|
double dy = v2->fY() - v1->fY();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
ox = v1->fX() + LeftDistance * dx;
|
|
|
|
oy = v1->fY() + LeftDistance * dy;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2017-03-08 17:44:37 +00:00
|
|
|
void DBaseDecal::SetShade (uint32_t rgb)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
PalEntry *entry = (PalEntry *)&rgb;
|
|
|
|
AlphaColor = rgb | (ColorMatcher.Pick (entry->r, entry->g, entry->b) << 24);
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
void DBaseDecal::SetShade (int r, int g, int b)
|
|
|
|
{
|
|
|
|
AlphaColor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b);
|
|
|
|
}
|
|
|
|
|
2020-03-15 23:00:10 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DBaseDecal::SetTranslation(uint32_t trans)
|
|
|
|
{
|
|
|
|
Translation = trans;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
2016-03-01 15:47:10 +00:00
|
|
|
// Returns the texture the decal stuck to.
|
2019-01-31 01:27:54 +00:00
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
FTextureID DBaseDecal::StickToWall (side_t *wall, double x, double y, F3DFloor *ffloor)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 22:41:22 +00:00
|
|
|
Side = wall;
|
|
|
|
WallPrev = wall->AttachedDecals;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 22:41:22 +00:00
|
|
|
while (WallPrev != nullptr && WallPrev->WallNext != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 22:41:22 +00:00
|
|
|
WallPrev = WallPrev->WallNext;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-09-19 22:41:22 +00:00
|
|
|
if (WallPrev != nullptr) WallPrev->WallNext = this;
|
|
|
|
else wall->AttachedDecals = this;
|
|
|
|
WallNext = nullptr;
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
sector_t *front, *back;
|
|
|
|
line_t *line;
|
|
|
|
FTextureID tex;
|
|
|
|
|
|
|
|
line = wall->linedef;
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
front = line->frontsector;
|
|
|
|
back = line->backsector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
front = line->backsector;
|
|
|
|
back = line->frontsector;
|
|
|
|
}
|
|
|
|
if (back == NULL)
|
|
|
|
{
|
|
|
|
RenderFlags |= RF_RELMID;
|
|
|
|
if (line->flags & ML_DONTPEGBOTTOM)
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= front->GetPlaneTexZ(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
else
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
tex = wall->GetTexture(side_t::mid);
|
|
|
|
}
|
|
|
|
else if (back->floorplane.ZatPoint (x, y) >= Z)
|
|
|
|
{
|
|
|
|
RenderFlags |= RF_RELLOWER|RF_CLIPLOWER;
|
|
|
|
if (line->flags & ML_DONTPEGBOTTOM)
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
else
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= back->GetPlaneTexZ(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
tex = wall->GetTexture(side_t::bottom);
|
|
|
|
}
|
|
|
|
else if (back->ceilingplane.ZatPoint (x, y) <= Z)
|
|
|
|
{
|
|
|
|
RenderFlags |= RF_RELUPPER|RF_CLIPUPPER;
|
|
|
|
if (line->flags & ML_DONTPEGTOP)
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
else
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= back->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
tex = wall->GetTexture(side_t::top);
|
|
|
|
}
|
|
|
|
else if (ffloor) // this is a 3d-floor segment - do this only if we know which one!
|
|
|
|
{
|
|
|
|
Sector=ffloor->model;
|
|
|
|
RenderFlags |= RF_RELMID|RF_CLIPMID;
|
|
|
|
if (line->flags & ML_DONTPEGBOTTOM)
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= Sector->GetPlaneTexZ(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
else
|
2016-04-24 10:15:09 +00:00
|
|
|
Z -= Sector->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (ffloor->flags & FF_UPPERTEXTURE)
|
|
|
|
{
|
|
|
|
tex = wall->GetTexture(side_t::top);
|
|
|
|
}
|
|
|
|
else if (ffloor->flags & FF_LOWERTEXTURE)
|
|
|
|
{
|
|
|
|
tex = wall->GetTexture(side_t::bottom);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tex = ffloor->master->sidedef[0]->GetTexture(side_t::mid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else return FNullTextureID();
|
|
|
|
CalcFracPos (wall, x, y);
|
|
|
|
|
2020-04-14 16:01:51 +00:00
|
|
|
auto texture = TexMan.GetGameTexture(tex);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-12-06 00:11:04 +00:00
|
|
|
if (texture == NULL || texture->allowNoDecals())
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return FNullTextureID();
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
double DBaseDecal::GetRealZ (const side_t *wall) const
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
const line_t *line = wall->linedef;
|
|
|
|
const sector_t *front, *back;
|
|
|
|
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
front = line->frontsector;
|
|
|
|
back = line->backsector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
front = line->backsector;
|
|
|
|
back = line->frontsector;
|
|
|
|
}
|
|
|
|
if (back == NULL)
|
|
|
|
{
|
|
|
|
back = front;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (RenderFlags & RF_RELMASK)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return Z;
|
|
|
|
case RF_RELUPPER:
|
|
|
|
if (line->flags & ML_DONTPEGTOP)
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + back->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
case RF_RELLOWER:
|
|
|
|
if (line->flags & ML_DONTPEGBOTTOM)
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + back->GetPlaneTexZ(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
case RF_RELMID:
|
|
|
|
if (line->flags & ML_DONTPEGBOTTOM)
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + front->GetPlaneTexZ(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-24 10:15:09 +00:00
|
|
|
return Z + front->GetPlaneTexZ(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
void DBaseDecal::CalcFracPos (side_t *wall, double x, double y)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
line_t *line = wall->linedef;
|
|
|
|
vertex_t *v1, *v2;
|
|
|
|
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
v1 = line->v1;
|
|
|
|
v2 = line->v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v1 = line->v2;
|
|
|
|
v2 = line->v1;
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
double dx = v2->fX() - v1->fX();
|
|
|
|
double dy = v2->fY() - v1->fY();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
if (fabs(dx) > fabs(dy))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-22 21:07:38 +00:00
|
|
|
LeftDistance = (x - v1->fX()) / dx;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else if (dy != 0)
|
|
|
|
{
|
2016-03-22 21:07:38 +00:00
|
|
|
LeftDistance = (y - v1->fY()) / dy;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LeftDistance = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
static void GetWallStuff (side_t *wall, vertex_t *&v1, double &ldx, double &ldy)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
line_t *line = wall->linedef;
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
v1 = line->v1;
|
2016-03-22 21:07:38 +00:00
|
|
|
ldx = line->Delta().X;
|
|
|
|
ldy = line->Delta().Y;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v1 = line->v2;
|
2016-03-22 21:07:38 +00:00
|
|
|
ldx = -line->Delta().X;
|
|
|
|
ldy = -line->Delta().Y;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
static double Length (double dx, double dy)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-22 21:07:38 +00:00
|
|
|
return DVector2(dx, dy).Length();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
static side_t *NextWall (const side_t *wall)
|
|
|
|
{
|
|
|
|
line_t *line = wall->linedef;
|
|
|
|
|
|
|
|
if (line->sidedef[0] == wall)
|
|
|
|
{
|
|
|
|
if (line->sidedef[1] != NULL)
|
|
|
|
{
|
|
|
|
return line->sidedef[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line->sidedef[1] == wall)
|
|
|
|
{
|
|
|
|
return line->sidedef[0];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor, SpreadInfo *spread)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-22 21:07:38 +00:00
|
|
|
double ldx, ldy;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
spread->SpreadStack.Push (feelwall);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
while (r < 0 && feelwall->LeftSide != NO_SIDE)
|
|
|
|
{
|
2016-03-22 21:07:38 +00:00
|
|
|
double startr = r;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
double x = v1->fX();
|
|
|
|
double y = v1->fY();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-27 23:55:21 +00:00
|
|
|
feelwall = &feelwall->GetLevel()->sides[feelwall->LeftSide];
|
2016-03-01 15:47:10 +00:00
|
|
|
GetWallStuff (feelwall, v1, ldx, ldy);
|
2016-03-22 21:07:38 +00:00
|
|
|
double wallsize = Length (ldx, ldy);
|
2018-12-29 10:48:28 +00:00
|
|
|
r += spread->DecalLeft;
|
2016-03-22 21:07:38 +00:00
|
|
|
x += r*ldx / wallsize;
|
|
|
|
y += r*ldy / wallsize;
|
2016-03-01 15:47:10 +00:00
|
|
|
r = wallsize + startr;
|
2018-12-29 10:48:28 +00:00
|
|
|
spread->SpreadSource->CloneSelf (spread->SpreadTemplate, x, y, spread->SpreadZ, feelwall, ffloor);
|
|
|
|
spread->SpreadStack.Push (feelwall);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
side_t *nextwall = NextWall (feelwall);
|
|
|
|
if (nextwall != NULL && nextwall->LeftSide != NO_SIDE)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
for (i = spread->SpreadStack.Size(); i-- > 0; )
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-12-29 10:48:28 +00:00
|
|
|
if (spread->SpreadStack[i] == nextwall)
|
2016-03-01 15:47:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == -1)
|
|
|
|
{
|
|
|
|
vertex_t *v2;
|
|
|
|
|
|
|
|
GetWallStuff (nextwall, v2, ldx, ldy);
|
2018-12-29 10:48:28 +00:00
|
|
|
SpreadLeft (startr, v2, nextwall, ffloor, spread);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFloor *ffloor, SpreadInfo *spread)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
vertex_t *v1;
|
2016-03-22 21:07:38 +00:00
|
|
|
double x, y, ldx, ldy;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
spread->SpreadStack.Push (feelwall);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
while (r > wallsize && feelwall->RightSide != NO_SIDE)
|
|
|
|
{
|
2019-01-27 23:55:21 +00:00
|
|
|
feelwall = &feelwall->GetLevel()->sides[feelwall->RightSide];
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
side_t *nextwall = NextWall (feelwall);
|
|
|
|
if (nextwall != NULL && nextwall->LeftSide != NO_SIDE)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
for (i = spread->SpreadStack.Size(); i-- > 0; )
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-12-29 10:48:28 +00:00
|
|
|
if (spread->SpreadStack[i] == nextwall)
|
2016-03-01 15:47:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == -1)
|
|
|
|
{
|
2018-12-29 10:48:28 +00:00
|
|
|
SpreadRight (r, nextwall, wallsize, ffloor, spread);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
r = spread->DecalWidth - r + wallsize - spread->DecalLeft;
|
2016-03-01 15:47:10 +00:00
|
|
|
GetWallStuff (feelwall, v1, ldx, ldy);
|
2016-03-22 21:07:38 +00:00
|
|
|
x = v1->fX();
|
|
|
|
y = v1->fY();
|
2016-03-01 15:47:10 +00:00
|
|
|
wallsize = Length (ldx, ldy);
|
2016-03-22 21:07:38 +00:00
|
|
|
x -= r*ldx / wallsize;
|
|
|
|
y -= r*ldy / wallsize;
|
2018-12-29 10:48:28 +00:00
|
|
|
r = spread->DecalRight - r;
|
|
|
|
spread->SpreadSource->CloneSelf (spread->SpreadTemplate, x, y, spread->SpreadZ, feelwall, ffloor);
|
|
|
|
spread->SpreadStack.Push (feelwall);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-12-29 10:48:28 +00:00
|
|
|
SpreadInfo spread;
|
2020-04-14 16:01:51 +00:00
|
|
|
FGameTexture *tex;
|
2016-03-01 15:47:10 +00:00
|
|
|
vertex_t *v1;
|
2016-03-22 21:07:38 +00:00
|
|
|
double rorg, ldx, ldy;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
GetWallStuff (wall, v1, ldx, ldy);
|
2016-03-22 21:07:38 +00:00
|
|
|
rorg = Length (x - v1->fX(), y - v1->fY());
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2020-04-14 16:01:51 +00:00
|
|
|
if ((tex = TexMan.GetGameTexture(PicNum)) == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-14 16:01:51 +00:00
|
|
|
double dwidth = tex->GetDisplayWidth ();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-12-29 10:48:28 +00:00
|
|
|
spread.DecalWidth = dwidth * ScaleX;
|
|
|
|
spread.DecalLeft = tex->GetDisplayLeftOffset() * ScaleX;
|
|
|
|
spread.DecalRight = spread.DecalWidth - spread.DecalLeft;
|
|
|
|
spread.SpreadSource = this;
|
|
|
|
spread.SpreadTemplate = tpl;
|
|
|
|
spread.SpreadZ = z;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Try spreading left first
|
2018-12-29 10:48:28 +00:00
|
|
|
SpreadLeft (rorg - spread.DecalLeft, v1, wall, ffloor, &spread);
|
|
|
|
spread.SpreadStack.Clear ();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Then try spreading right
|
2018-12-29 10:48:28 +00:00
|
|
|
SpreadRight (rorg + spread.DecalRight, wall,
|
|
|
|
Length (wall->linedef->Delta().X, wall->linedef->Delta().Y), ffloor, &spread);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
DBaseDecal *DBaseDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-27 00:49:20 +00:00
|
|
|
DBaseDecal *decal = Level->CreateThinker<DBaseDecal>(iz);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (decal != NULL)
|
|
|
|
{
|
|
|
|
if (decal->StickToWall (wall, ix, iy, ffloor).isValid())
|
|
|
|
{
|
|
|
|
tpl->ApplyToDecal (decal, wall);
|
|
|
|
decal->AlphaColor = AlphaColor;
|
|
|
|
decal->RenderFlags = (decal->RenderFlags & RF_DECALMASK) |
|
|
|
|
(this->RenderFlags & ~RF_DECALMASK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
decal->Destroy();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decal;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
void DImpactDecal::CheckMax ()
|
|
|
|
{
|
2019-02-07 08:36:39 +00:00
|
|
|
static int SpawnCounter;
|
|
|
|
|
2019-01-28 01:41:29 +00:00
|
|
|
if (++Level->ImpactDecalCount >= cl_maxdecals)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-28 13:06:19 +00:00
|
|
|
DThinker *thinker = Level->FirstThinker (STAT_AUTODECAL);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (thinker != NULL)
|
|
|
|
{
|
|
|
|
thinker->Destroy();
|
2019-01-28 01:41:29 +00:00
|
|
|
Level->ImpactDecalCount--;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-02-07 08:36:39 +00:00
|
|
|
void DImpactDecal::Expired()
|
|
|
|
{
|
|
|
|
Level->ImpactDecalCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2020-03-15 23:00:10 +00:00
|
|
|
DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (cl_maxdecals > 0)
|
|
|
|
{
|
|
|
|
const FDecalTemplate *tpl = DecalLibrary.GetDecalByName (name);
|
|
|
|
|
|
|
|
if (tpl != NULL && (tpl = tpl->GetDecal()) != NULL)
|
|
|
|
{
|
2020-03-15 23:00:10 +00:00
|
|
|
return StaticCreate (Level, tpl, pos, wall, ffloor, color, bloodTranslation);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2020-03-15 23:00:10 +00:00
|
|
|
DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
DImpactDecal *decal = NULL;
|
|
|
|
if (tpl != NULL && cl_maxdecals > 0 && !(wall->Flags & WALLF_NOAUTODECALS))
|
|
|
|
{
|
|
|
|
if (tpl->LowerDecal)
|
|
|
|
{
|
|
|
|
int lowercolor;
|
|
|
|
const FDecalTemplate * tpl_low = tpl->LowerDecal->GetDecal();
|
|
|
|
|
|
|
|
// If the default color of the lower decal is the same as the main decal's
|
|
|
|
// apply the custom color as well.
|
|
|
|
if (tpl->ShadeColor != tpl_low->ShadeColor) lowercolor=0;
|
|
|
|
else lowercolor = color;
|
2020-03-15 23:00:10 +00:00
|
|
|
|
|
|
|
uint32_t lowerTrans = (bloodTranslation != 0 ? bloodTranslation : 0);
|
|
|
|
|
|
|
|
StaticCreate (Level, tpl_low, pos, wall, ffloor, lowercolor, lowerTrans);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2019-01-27 00:49:20 +00:00
|
|
|
decal = Level->CreateThinker<DImpactDecal>(pos.Z);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (decal == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
if (!decal->StickToWall (wall, pos.X, pos.Y, ffloor).isValid())
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-01-08 23:04:28 +00:00
|
|
|
decal->CheckMax();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
tpl->ApplyToDecal (decal, wall);
|
|
|
|
if (color != 0)
|
|
|
|
{
|
|
|
|
decal->SetShade (color.r, color.g, color.b);
|
|
|
|
}
|
|
|
|
|
2020-03-16 14:31:58 +00:00
|
|
|
// [Nash] opaque blood
|
|
|
|
if (bloodTranslation != 0 && tpl->ShadeColor == 0 && tpl->opaqueBlood)
|
2020-03-15 23:00:10 +00:00
|
|
|
{
|
|
|
|
decal->SetTranslation(bloodTranslation);
|
2020-03-16 14:31:58 +00:00
|
|
|
decal->RenderStyle = STYLE_Normal;
|
2020-03-15 23:00:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!cl_spreaddecals || !decal->PicNum.isValid())
|
|
|
|
{
|
|
|
|
return decal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spread decal to nearby walls if it does not all fit on this one
|
2016-03-22 21:07:38 +00:00
|
|
|
decal->Spread (tpl, wall, pos.X, pos.Y, pos.Z, ffloor);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return decal;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-03-22 21:07:38 +00:00
|
|
|
DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (wall->Flags & WALLF_NOAUTODECALS)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-27 00:49:20 +00:00
|
|
|
DImpactDecal *decal = Level->CreateThinker<DImpactDecal>(iz);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (decal != NULL)
|
|
|
|
{
|
|
|
|
if (decal->StickToWall (wall, ix, iy, ffloor).isValid())
|
|
|
|
{
|
2019-01-08 23:04:28 +00:00
|
|
|
decal->CheckMax();
|
2016-03-01 15:47:10 +00:00
|
|
|
tpl->ApplyToDecal (decal, wall);
|
|
|
|
decal->AlphaColor = AlphaColor;
|
2020-03-15 23:00:10 +00:00
|
|
|
|
2020-03-16 14:31:58 +00:00
|
|
|
// [Nash] opaque blood
|
|
|
|
if (tpl->ShadeColor == 0 && tpl->opaqueBlood)
|
|
|
|
{
|
|
|
|
decal->SetTranslation(Translation);
|
|
|
|
decal->RenderStyle = STYLE_Normal;
|
|
|
|
}
|
2020-03-15 23:00:10 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
decal->RenderFlags = (decal->RenderFlags & RF_DECALMASK) |
|
|
|
|
(this->RenderFlags & ~RF_DECALMASK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
decal->Destroy();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decal;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2020-04-07 20:11:49 +00:00
|
|
|
void SprayDecal(AActor *shooter, const char *name, double distance, DVector3 offset, DVector3 direction)
|
2017-02-26 17:37:12 +00:00
|
|
|
{
|
2020-04-07 20:11:49 +00:00
|
|
|
//just in case
|
|
|
|
if (!shooter)
|
|
|
|
return;
|
|
|
|
|
2017-02-26 17:37:12 +00:00
|
|
|
FTraceResults trace;
|
2020-04-07 20:11:49 +00:00
|
|
|
DVector3 off(0, 0, 0), dir(0, 0, 0);
|
|
|
|
|
|
|
|
//use vanilla offset only if "custom" equal to zero
|
|
|
|
if (offset.isZero() )
|
|
|
|
off = shooter->PosPlusZ(shooter->Height / 2);
|
|
|
|
|
2020-03-30 11:27:36 +00:00
|
|
|
else
|
2020-04-07 20:11:49 +00:00
|
|
|
off = shooter->Pos() + offset;
|
|
|
|
|
|
|
|
//same for direction
|
|
|
|
if (direction.isZero() )
|
2020-03-30 11:27:36 +00:00
|
|
|
{
|
|
|
|
DAngle ang = shooter->Angles.Yaw;
|
|
|
|
DAngle pitch = shooter->Angles.Pitch;
|
|
|
|
double c = pitch.Cos();
|
2020-04-07 20:11:49 +00:00
|
|
|
dir = DVector3(c * ang.Cos(), c * ang.Sin(), -pitch.Sin());
|
2020-03-30 11:27:36 +00:00
|
|
|
}
|
2020-04-07 20:11:49 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
dir = direction;
|
2017-02-26 17:37:12 +00:00
|
|
|
|
|
|
|
|
2020-04-07 20:11:49 +00:00
|
|
|
if (Trace(off, shooter->Sector, dir, distance, 0, ML_BLOCKEVERYTHING, shooter, trace, TRACE_NoSky))
|
2017-02-26 17:37:12 +00:00
|
|
|
{
|
|
|
|
if (trace.HitType == TRACE_HitWall)
|
|
|
|
{
|
2019-01-27 00:49:20 +00:00
|
|
|
DImpactDecal::StaticCreate(shooter->Level, name, trace.HitPos, trace.Line->sidedef[trace.Side], NULL);
|
2017-02-26 17:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-01-27 00:49:20 +00:00
|
|
|
DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (tpl == NULL || (tpl = tpl->GetDecal()) == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FTraceResults trace;
|
|
|
|
DBaseDecal *decal;
|
|
|
|
side_t *wall;
|
|
|
|
|
2016-03-24 00:46:11 +00:00
|
|
|
Trace(DVector3(x,y,z), sec, DVector3(angle.ToVector(), 0), tracedist, 0, 0, NULL, trace, TRACE_NoSky);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (trace.HitType == TRACE_HitWall)
|
|
|
|
{
|
|
|
|
if (permanent)
|
|
|
|
{
|
2019-01-27 00:49:20 +00:00
|
|
|
decal = Level->CreateThinker<DBaseDecal>(trace.HitPos.Z);
|
2016-03-01 15:47:10 +00:00
|
|
|
wall = trace.Line->sidedef[trace.Side];
|
2016-03-23 17:07:04 +00:00
|
|
|
decal->StickToWall(wall, trace.HitPos.X, trace.HitPos.Y, trace.ffloor);
|
2016-03-01 15:47:10 +00:00
|
|
|
tpl->ApplyToDecal(decal, wall);
|
|
|
|
// Spread decal to nearby walls if it does not all fit on this one
|
|
|
|
if (cl_spreaddecals)
|
|
|
|
{
|
2016-03-23 17:07:04 +00:00
|
|
|
decal->Spread(tpl, wall, trace.HitPos.X, trace.HitPos.Y, trace.HitPos.Z, trace.ffloor);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return decal;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-27 00:49:20 +00:00
|
|
|
return DImpactDecal::StaticCreate(Level, tpl, trace.HitPos, trace.Line->sidedef[trace.Side], NULL);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-31 01:27:54 +00:00
|
|
|
static void SpawnDecal(AActor *self)
|
|
|
|
{
|
2017-02-26 16:05:04 +00:00
|
|
|
const FDecalTemplate *tpl = nullptr;
|
2019-01-31 01:27:54 +00:00
|
|
|
|
2018-11-19 16:54:38 +00:00
|
|
|
if (self->args[0] < 0)
|
2017-02-26 16:05:04 +00:00
|
|
|
{
|
2018-11-19 16:54:38 +00:00
|
|
|
FName name = ENamedName(-self->args[0]);
|
2017-02-26 16:05:04 +00:00
|
|
|
tpl = DecalLibrary.GetDecalByName(name.GetChars());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-19 16:54:38 +00:00
|
|
|
int decalid = self->args[0] + (self->args[1] << 8); // [KS] High byte for decals.
|
2017-02-26 16:05:04 +00:00
|
|
|
tpl = DecalLibrary.GetDecalByNum(decalid);
|
|
|
|
}
|
2019-01-31 01:27:54 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
// If no decal is specified, don't try to create one.
|
2017-02-26 16:05:04 +00:00
|
|
|
if (tpl != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (!tpl->PicNum.Exists())
|
|
|
|
{
|
2018-11-19 16:54:38 +00:00
|
|
|
Printf("Decal actor at (%f,%f) does not have a valid texture\n", self->X(), self->Y());
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Look for a wall within 64 units behind the actor. If none can be
|
|
|
|
// found, then no decal is created, and this actor is destroyed
|
|
|
|
// without effectively doing anything.
|
2019-01-27 00:49:20 +00:00
|
|
|
if (!ShootDecal(self->Level, tpl, self->Sector, self->X(), self->Y(), self->Z(), self->Angles.Yaw + 180, 64., true))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-11-19 16:54:38 +00:00
|
|
|
DPrintf (DMSG_WARNING, "Could not find a wall to stick decal to at (%f,%f)\n", self->X(), self->Y());
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-19 16:54:38 +00:00
|
|
|
DPrintf (DMSG_ERROR, "Decal actor at (%f,%f) does not have a good template\n", self->X(), self->Y());
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2019-01-31 01:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_NATIVE(ADecal, SpawnDecal, SpawnDecal)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
SpawnDecal(self);
|
2018-11-19 16:54:38 +00:00
|
|
|
return 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|