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

View file

@ -105,6 +105,18 @@ FArchive &operator<< (FArchive &arc, FRenderStyle &style)
return arc; 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 // FRenderStyle :: IsVisible
@ -130,7 +142,7 @@ bool FRenderStyle::IsVisible(double alpha) const throw()
{ {
alpha = clamp(alpha, 0., 1.); 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. // Treat anything else as visible.
return true; return true;
@ -186,29 +198,3 @@ void FRenderStyle::CheckFuzz()
BlendOp = STYLEOP_Fuzz; 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; class FArchive;
FArchive &operator<< (FArchive &arc, FRenderStyle &style); FArchive &operator<< (FArchive &arc, FRenderStyle &style);
fixed_t GetAlpha(int type, fixed_t alpha);
fixed_t GetAlpha(int type, double alpha);
#endif #endif

View file

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

View file

@ -23,9 +23,7 @@ struct FVoxelMipLevel
int SizeX; int SizeX;
int SizeY; int SizeY;
int SizeZ; int SizeZ;
fixed_t PivotX; // 24.8 fixed point DVector3 Pivot;
fixed_t PivotY; // ""
fixed_t PivotZ; // ""
int *OffsetX; int *OffsetX;
short *OffsetXY; short *OffsetXY;
BYTE *SlabData; BYTE *SlabData;
@ -51,8 +49,8 @@ struct FVoxelDef
int PlacedSpin; // degrees/sec to spin actors without MF_DROPPED set int PlacedSpin; // degrees/sec to spin actors without MF_DROPPED set
int DroppedSpin; // degrees/sec to spin actors with MF_DROPPED set int DroppedSpin; // degrees/sec to spin actors with MF_DROPPED set
int VoxeldefIndex; // Needed by GZDoom int VoxeldefIndex; // Needed by GZDoom
fixed_t Scale; double Scale;
angle_t AngleOffset; // added to actor's angle to compensate for wrong-facing voxels 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. 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) ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color)
{ {
fixed_t fglevel, bglevel; fixed_t fglevel, bglevel;

View file

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