- floatified most of r_data (The interpolations cannot be done yet.)

This commit is contained in:
Christoph Oelckers 2016-03-24 14:10:06 +01:00
parent 09d8b4af80
commit 86d1b2955a
7 changed files with 71 additions and 75 deletions

View file

@ -310,7 +310,7 @@ FNativePalette *FRemapTable::GetNative()
void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2)
{
fixed_t palcol, palstep;
double palcol, palstep;
if (start > end)
{
@ -326,11 +326,11 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2)
Palette[start].a = start == 0 ? 0 : 255;
return;
}
palcol = pal1 << FRACBITS;
palstep = ((pal2 << FRACBITS) - palcol) / (end - start);
palcol = pal1;
palstep = (pal2 - palcol) / (end - start);
for (int i = start; i <= end; palcol += palstep, ++i)
{
int j = GPalette.Remap[i], k = GPalette.Remap[palcol >> FRACBITS];
int j = GPalette.Remap[i], k = GPalette.Remap[int(palcol)];
Remap[j] = k;
Palette[j] = GPalette.BaseColors[k];
Palette[j].a = j == 0 ? 0 : 255;
@ -345,14 +345,14 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2)
void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, int _r2, int _g2, int _b2)
{
fixed_t r1 = _r1 << FRACBITS;
fixed_t g1 = _g1 << FRACBITS;
fixed_t b1 = _b1 << FRACBITS;
fixed_t r2 = _r2 << FRACBITS;
fixed_t g2 = _g2 << FRACBITS;
fixed_t b2 = _b2 << FRACBITS;
fixed_t r, g, b;
fixed_t rs, gs, bs;
double r1 = _r1;
double g1 = _g1;
double b1 = _b1;
double r2 = _r2;
double g2 = _g2;
double b2 = _b2;
double r, g, b;
double rs, gs, bs;
if (start > end)
{
@ -376,9 +376,8 @@ void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, in
if (start == end)
{
start = GPalette.Remap[start];
Remap[start] = ColorMatcher.Pick(r >> FRACBITS, g >> FRACBITS, b >> FRACBITS);
Palette[start] = PalEntry(r >> FRACBITS, g >> FRACBITS, b >> FRACBITS);
Palette[start].a = start == 0 ? 0 : 255;
Palette[start] = PalEntry(start == 0 ? 0 : 255, int(r), int(g), int(b));
Remap[start] = ColorMatcher.Pick(Palette[start]);
}
else
{
@ -388,8 +387,8 @@ void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, in
for (int i = start; i <= end; ++i)
{
int j = GPalette.Remap[i];
Remap[j] = ColorMatcher.Pick(r >> FRACBITS, g >> FRACBITS, b >> FRACBITS);
Palette[j] = PalEntry(j == 0 ? 0 : 255, r >> FRACBITS, g >> FRACBITS, b >> FRACBITS);
Palette[j] = PalEntry(j == 0 ? 0 : 255, int(r), int(g), int(b));
Remap[j] = ColorMatcher.Pick(Palette[j]);
r += rs;
g += gs;
b += bs;

View file

@ -105,6 +105,18 @@ FArchive &operator<< (FArchive &arc, FRenderStyle &style)
return arc;
}
double GetAlpha(int type, double alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return alpha;
case STYLEALPHA_InvSrc: return 1. - alpha;
default: return 0;
}
}
//==========================================================================
//
// FRenderStyle :: IsVisible
@ -130,7 +142,7 @@ bool FRenderStyle::IsVisible(double alpha) const throw()
{
alpha = clamp(alpha, 0., 1.);
}
return GetAlpha(SrcAlpha, alpha) != 0 || GetAlpha(DestAlpha, alpha) != OPAQUE;
return GetAlpha(SrcAlpha, alpha) != 0 || GetAlpha(DestAlpha, alpha) != 1;
}
// Treat anything else as visible.
return true;
@ -186,29 +198,3 @@ void FRenderStyle::CheckFuzz()
BlendOp = STYLEOP_Fuzz;
}
}
fixed_t GetAlpha(int type, fixed_t alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return alpha;
case STYLEALPHA_InvSrc: return OPAQUE - alpha;
default: return 0;
}
}
fixed_t GetAlpha(int type, double alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return FLOAT2FIXED(alpha);
case STYLEALPHA_InvSrc: return FLOAT2FIXED(1. - alpha);
default: return 0;
}
}

View file

@ -165,7 +165,5 @@ inline FRenderStyle &FRenderStyle::operator= (ERenderStyle legacy)
class FArchive;
FArchive &operator<< (FArchive &arc, FRenderStyle &style);
fixed_t GetAlpha(int type, fixed_t alpha);
fixed_t GetAlpha(int type, double alpha);
#endif

View file

@ -71,13 +71,13 @@ TDeletingArray<FVoxelDef *> VoxelDefs;
struct VoxelOptions
{
VoxelOptions()
: DroppedSpin(0), PlacedSpin(0), Scale(FRACUNIT), AngleOffset(ANGLE_90), OverridePalette(false)
: DroppedSpin(0), PlacedSpin(0), Scale(1.), AngleOffset(90.), OverridePalette(false)
{}
int DroppedSpin;
int PlacedSpin;
fixed_t Scale;
angle_t AngleOffset;
double Scale;
DAngle AngleOffset;
bool OverridePalette;
};
@ -213,9 +213,9 @@ FVoxel *R_LoadKVX(int lumpnum)
mipl->SizeX = GetInt(rawmip + 0);
mipl->SizeY = GetInt(rawmip + 4);
mipl->SizeZ = GetInt(rawmip + 8);
mipl->PivotX = GetInt(rawmip + 12);
mipl->PivotY = GetInt(rawmip + 16);
mipl->PivotZ = GetInt(rawmip + 20);
mipl->Pivot.X = GetInt(rawmip + 12) / 256.;
mipl->Pivot.Y = GetInt(rawmip + 16) / 256.;
mipl->Pivot.Z = GetInt(rawmip + 20) / 256.;
// How much space do we have for voxdata?
int offsetsize = (mipl->SizeX + 1) * 4 + mipl->SizeX * (mipl->SizeY + 1) * 2;
@ -300,9 +300,7 @@ FVoxel *R_LoadKVX(int lumpnum)
// Fix pivot data for submips, since some tools seem to like to just center these.
for (i = 1; i < mip; ++i)
{
voxel->Mips[i].PivotX = voxel->Mips[0].PivotX >> i;
voxel->Mips[i].PivotY = voxel->Mips[0].PivotY >> i;
voxel->Mips[i].PivotZ = voxel->Mips[0].PivotZ >> i;
voxel->Mips[i].Pivot = voxel->Mips[i - 1].Pivot / 2;
}
for (i = 0; i < mip; ++i)
@ -339,9 +337,9 @@ FVoxelDef *R_LoadVoxelDef(int lumpnum, int spin)
{
FVoxelDef *voxdef = new FVoxelDef;
voxdef->Voxel = vox;
voxdef->Scale = FRACUNIT;
voxdef->Scale = 1.;
voxdef->DroppedSpin = voxdef->PlacedSpin = spin;
voxdef->AngleOffset = ANGLE_90;
voxdef->AngleOffset = 90.;
Voxels.Push(vox);
VoxelDefs.Push(voxdef);
@ -358,7 +356,7 @@ FVoxelDef *R_LoadVoxelDef(int lumpnum, int spin)
FVoxelMipLevel::FVoxelMipLevel()
{
SizeZ = SizeY = SizeX = 0;
PivotZ = PivotY = PivotX = 0;
Pivot.Zero();
OffsetX = NULL;
OffsetXY = NULL;
SlabData = NULL;
@ -499,7 +497,7 @@ static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts)
{
sc.MustGetToken('=');
sc.MustGetToken(TK_FloatConst);
opts.Scale = FLOAT2FIXED(sc.Float);
opts.Scale = sc.Float;
}
else if (sc.Compare("spin"))
{
@ -531,7 +529,7 @@ static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts)
{
sc.TokenMustBe(TK_FloatConst);
}
opts.AngleOffset = ANGLE_90 + FLOAT2ANGLE(sc.Float);
opts.AngleOffset = sc.Float + 90.;
}
else if (sc.Compare("overridepalette"))
{

View file

@ -23,9 +23,7 @@ struct FVoxelMipLevel
int SizeX;
int SizeY;
int SizeZ;
fixed_t PivotX; // 24.8 fixed point
fixed_t PivotY; // ""
fixed_t PivotZ; // ""
DVector3 Pivot;
int *OffsetX;
short *OffsetXY;
BYTE *SlabData;
@ -51,8 +49,8 @@ struct FVoxelDef
int PlacedSpin; // degrees/sec to spin actors without MF_DROPPED set
int DroppedSpin; // degrees/sec to spin actors with MF_DROPPED set
int VoxeldefIndex; // Needed by GZDoom
fixed_t Scale;
angle_t AngleOffset; // added to actor's angle to compensate for wrong-facing voxels
double Scale;
DAngle AngleOffset;// added to actor's angle to compensate for wrong-facing voxels
};
extern TDeletingArray<FVoxel *> Voxels; // used only to auto-delete voxels on exit.

View file

@ -2350,6 +2350,18 @@ static bool R_SetBlendFunc (int op, fixed_t fglevel, fixed_t bglevel, int flags)
}
}
static fixed_t GetAlpha(int type, fixed_t alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return alpha;
case STYLEALPHA_InvSrc: return OPAQUE - alpha;
default: return 0;
}
}
ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color)
{
fixed_t fglevel, bglevel;

View file

@ -918,10 +918,11 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
}
else
{
xscale = FixedMul(spritescaleX, voxel->Scale);
yscale = FixedMul(spritescaleY, voxel->Scale);
gzt = fz + MulScale8(yscale, voxel->Voxel->Mips[0].PivotZ) - FLOAT2FIXED(thing->Floorclip);
gzb = fz + MulScale8(yscale, voxel->Voxel->Mips[0].PivotZ - (voxel->Voxel->Mips[0].SizeZ << 8));
xscale = fixed_t(spritescaleX * voxel->Scale);
yscale = fixed_t(spritescaleY * voxel->Scale);
fixed_t piv = fixed_t(voxel->Voxel->Mips[0].Pivot.Z*256.);
gzt = fz + MulScale8(yscale, piv) - FLOAT2FIXED(thing->Floorclip);
gzb = fz + MulScale8(yscale, piv - (voxel->Voxel->Mips[0].SizeZ << 8));
if (gzt <= gzb)
return;
}
@ -1030,7 +1031,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
fz -= FLOAT2FIXED(thing->Floorclip);
vis->angle = thing->_f_angle() + voxel->AngleOffset;
vis->angle = thing->Angles.Yaw.BAMs() + voxel->AngleOffset.BAMs();
int voxelspin = (thing->flags & MF_DROPPED) ? voxel->DroppedSpin : voxel->PlacedSpin;
if (voxelspin != 0)
@ -2728,18 +2729,22 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang
daxscalerecip = (1<<30) / daxscale;
dayscalerecip = (1<<30) / dayscale;
fixed_t piv_x = fixed_t(mip->Pivot.X*256.);
fixed_t piv_y = fixed_t(mip->Pivot.Y*256.);
fixed_t piv_z = fixed_t(mip->Pivot.Z*256.);
x = FixedMul(globalposx - dasprx, daxscalerecip);
y = FixedMul(globalposy - daspry, daxscalerecip);
backx = (DMulScale10(x, sprcosang, y, sprsinang) + mip->PivotX) >> 8;
backy = (DMulScale10(y, sprcosang, x, -sprsinang) + mip->PivotY) >> 8;
backx = (DMulScale10(x, sprcosang, y, sprsinang) + piv_x) >> 8;
backy = (DMulScale10(y, sprcosang, x, -sprsinang) + piv_y) >> 8;
cbackx = clamp(backx, 0, mip->SizeX - 1);
cbacky = clamp(backy, 0, mip->SizeY - 1);
sprcosang = MulScale14(daxscale, sprcosang);
sprsinang = MulScale14(daxscale, sprsinang);
x = (dasprx - globalposx) - DMulScale18(mip->PivotX, sprcosang, mip->PivotY, -sprsinang);
y = (daspry - globalposy) - DMulScale18(mip->PivotY, sprcosang, mip->PivotX, sprsinang);
x = (dasprx - globalposx) - DMulScale18(piv_x, sprcosang, piv_y, -sprsinang);
y = (daspry - globalposy) - DMulScale18(piv_y, sprcosang, piv_x, sprsinang);
cosang = FixedMul(cosang, dayscalerecip);
sinang = FixedMul(sinang, dayscalerecip);
@ -2759,7 +2764,7 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang
ggyinc[i] = y; y += gyinc;
}
syoff = DivScale21(globalposz - dasprz, FixedMul(dazscale, 0xE800)) + (mip->PivotZ << 7);
syoff = DivScale21(globalposz - dasprz, FixedMul(dazscale, 0xE800)) + (piv_z << 7);
yoff = (abs(gxinc) + abs(gyinc)) >> 1;
for (cnt = 0; cnt < 8; cnt++)