- final cleanup of picanm code.

This commit is contained in:
Christoph Oelckers 2020-05-24 13:53:27 +02:00
parent 266364fc2e
commit d6786cf0eb
6 changed files with 131 additions and 63 deletions

View File

@ -177,7 +177,7 @@ void FGLRenderer::BindToFrameBuffer(FTexture *mat)
if (BaseLayer == nullptr) if (BaseLayer == nullptr)
{ {
// must create the hardware texture first // must create the hardware texture first
BaseLayer = new FHardwareTexture(); BaseLayer = new ::FHardwareTexture();
BaseLayer->CreateTexture(mat->GetTexelWidth()*4, mat->GetTexelHeight()*4, ::FHardwareTexture::TrueColor, false); BaseLayer->CreateTexture(mat->GetTexelWidth()*4, mat->GetTexelHeight()*4, ::FHardwareTexture::TrueColor, false);
mat->SetHardwareTexture(0, BaseLayer); mat->SetHardwareTexture(0, BaseLayer);
} }

View File

@ -470,10 +470,7 @@ void SaveEngineState()
{ {
fw->Write(&picanm[i], sizeof(picanm[i])); fw->Write(&picanm[i], sizeof(picanm[i]));
} }
for (int i = 0; i < MAXTILES; i++) WriteMagic(fw);
{
MREAD(&picanm[i], sizeof(picanm[i]), 1, fil);
}
fw->Write(&tailspritefree, sizeof(tailspritefree)); fw->Write(&tailspritefree, sizeof(tailspritefree));
@ -538,6 +535,11 @@ void LoadEngineState()
fr.Read(prevspritestat, sizeof(prevspritestat)); fr.Read(prevspritestat, sizeof(prevspritestat));
fr.Read(nextspritestat, sizeof(nextspritestat)); fr.Read(nextspritestat, sizeof(nextspritestat));
CheckMagic(fr); CheckMagic(fr);
for (int i = 0; i < MAXTILES; i++)
{
fr.Read(&picanm[i], sizeof(picanm[i]));
}
CheckMagic(fr);
fr.Read(&tailspritefree, sizeof(tailspritefree)); fr.Read(&tailspritefree, sizeof(tailspritefree));
fr.Read(&myconnectindex, sizeof(myconnectindex)); fr.Read(&myconnectindex, sizeof(myconnectindex));

View File

@ -115,6 +115,7 @@ void FTileTexture::Create8BitPixels(uint8_t* buffer)
FArtTile* GetTileTexture(const char* name, const TArray<uint8_t>& backingstore, uint32_t offset, int width, int height, int picanm) FArtTile* GetTileTexture(const char* name, const TArray<uint8_t>& backingstore, uint32_t offset, int width, int height, int picanm)
{ {
auto tex = new FArtTile(backingstore, offset, width, height, picanm); auto tex = new FArtTile(backingstore, offset, width, height, picanm);
if (tex) if (tex)
{ {
tex->SetName(name); tex->SetName(name);
@ -176,6 +177,10 @@ void BuildTiles::AddTiles (int firsttile, TArray<uint8_t>& RawData, bool permap)
auto tex = GetTileTexture("", RawData, uint32_t(tiledata - tiles), width, height, anm); auto tex = GetTileTexture("", RawData, uint32_t(tiledata - tiles), width, height, anm);
AddTile(i, tex); AddTile(i, tex);
int leftoffset, topoffset;
auto PicAnim = tileConvertAnimFormat(anm, &leftoffset, &topoffset);
tex->SetOffsets(leftoffset, topoffset);
tiledata += size; tiledata += size;
} }
} }
@ -597,7 +602,7 @@ void tileCopy(int tile, int source, int pal, int xoffset, int yoffset, int flags
// Only modify the picanm info. // Only modify the picanm info.
tex = TileFiles.tiles[tile]; tex = TileFiles.tiles[tile];
if (!tex) return; if (!tex) return;
picanm = &tex->PicAnim; picanm = &TileFiles.tiledata[tile].picanm;
sourceanm = picanm; sourceanm = picanm;
srcxo = tex->GetLeftOffset(); srcxo = tex->GetLeftOffset();
srcyo = tex->GetTopOffset(); srcyo = tex->GetTopOffset();
@ -607,7 +612,7 @@ void tileCopy(int tile, int source, int pal, int xoffset, int yoffset, int flags
if (source == -1) source = tile; if (source == -1) source = tile;
tex = TileFiles.tiles[source]; tex = TileFiles.tiles[source];
if (!tex) return; if (!tex) return;
sourceanm = &tex->PicAnim; sourceanm = &TileFiles.tiledata[source].picanm;
srcxo = tex->GetLeftOffset(); srcxo = tex->GetLeftOffset();
srcyo = tex->GetTopOffset(); srcyo = tex->GetTopOffset();
@ -623,7 +628,7 @@ void tileCopy(int tile, int source, int pal, int xoffset, int yoffset, int flags
} }
} }
tex = new FLooseTile(buffer, tex->GetWidth(), tex->GetHeight()); tex = new FLooseTile(buffer, tex->GetWidth(), tex->GetHeight());
picanm = &tex->PicAnim; picanm = &TileFiles.tiledata[tile].picanm;
TileFiles.AddTile(tile, tex); TileFiles.AddTile(tile, tex);
} }

View File

@ -2,6 +2,32 @@
#include "textures.h" #include "textures.h"
// picanm[].sf:
// |bit(1<<7)
// |animtype|animtype|texhitscan|nofullbright|speed|speed|speed|speed|
enum AnimFlags
{
PICANM_ANIMTYPE_NONE = 0,
PICANM_ANIMTYPE_OSC = (1 << 6),
PICANM_ANIMTYPE_FWD = (2 << 6),
PICANM_ANIMTYPE_BACK = (3 << 6),
PICANM_ANIMTYPE_SHIFT = 6,
PICANM_ANIMTYPE_MASK = (3 << 6), // must be 192
PICANM_MISC_MASK = (3 << 4),
PICANM_TEXHITSCAN_BIT = (2 << 4),
PICANM_NOFULLBRIGHT_BIT = (1 << 4),
PICANM_ANIMSPEED_MASK = 15, // must be 15
};
enum
{
MAXTILES = 30720,
MAXUSERTILES = (MAXTILES-16) // reserve 16 tiles at the end
};
enum class ReplacementType : int enum class ReplacementType : int
{ {
Art, Art,
@ -10,6 +36,28 @@ enum class ReplacementType : int
Canvas Canvas
}; };
// NOTE: If the layout of this struct is changed, loadpics() must be modified
// accordingly.
struct picanm_t
{
uint8_t num; // animate number
uint8_t sf; // anim. speed and flags
uint8_t extra;
void Clear()
{
extra = sf = num = 0;
}
};
picanm_t tileConvertAnimFormat(int32_t const picanmdisk, int* lo, int* to);
struct rottile_t
{
int16_t newtile;
int16_t owner;
};
struct HightileReplacement struct HightileReplacement
{ {
FTexture* faces[6]; // only one gets used by a texture, the other 5 are for skyboxes only FTexture* faces[6]; // only one gets used by a texture, the other 5 are for skyboxes only
@ -45,7 +93,6 @@ public:
: RawPixels(backingstore), Offset(offset) : RawPixels(backingstore), Offset(offset)
{ {
SetSize(width, height); SetSize(width, height);
PicAnim = tileConvertAnimFormat(picanm, &leftoffset, &topoffset);
} }
const uint8_t* Get8BitPixels() override const uint8_t* Get8BitPixels() override
@ -358,7 +405,7 @@ struct PicAnm
picanm_t& operator[](size_t index) picanm_t& operator[](size_t index)
{ {
assert(index < MAXTILES); assert(index < MAXTILES);
return TileFiles.tiles[index]->GetAnim(); return TileFiles.tiledata[index].picanm;
} }
}; };
extern PicAnm picanm; extern PicAnm picanm;
@ -411,7 +458,7 @@ inline int heightBits(int num)
inline rottile_t& RotTile(int tile) inline rottile_t& RotTile(int tile)
{ {
assert(tile < MAXTILES); assert(tile < MAXTILES);
return TileFiles.tiles[tile]->GetRotTile(); return TileFiles.tiledata[tile].RotTile;
} }

View File

@ -41,63 +41,71 @@
#include "tarray.h" #include "tarray.h"
#include "palentry.h" #include "palentry.h"
class FImageSource;
class FTexture;
class FHardwareTexture; class FHardwareTexture;
class FImageSource;
// picanm[].sf: enum MaterialShaderIndex
// |bit(1<<7)
// |animtype|animtype|texhitscan|nofullbright|speed|speed|speed|speed|
enum AnimFlags
{ {
PICANM_ANIMTYPE_NONE = 0, SHADER_Default,
PICANM_ANIMTYPE_OSC = (1 << 6), SHADER_Warp1,
PICANM_ANIMTYPE_FWD = (2 << 6), SHADER_Warp2,
PICANM_ANIMTYPE_BACK = (3 << 6), SHADER_Brightmap,
SHADER_Specular,
PICANM_ANIMTYPE_SHIFT = 6, SHADER_SpecularBrightmap,
PICANM_ANIMTYPE_MASK = (3 << 6), // must be 192 SHADER_PBR,
PICANM_MISC_MASK = (3 << 4), SHADER_PBRBrightmap,
PICANM_TEXHITSCAN_BIT = (2 << 4), SHADER_Paletted,
PICANM_NOFULLBRIGHT_BIT = (1 << 4), SHADER_NoTexture,
PICANM_ANIMSPEED_MASK = 15, // must be 15 SHADER_BasicFuzz,
SHADER_SmoothFuzz,
SHADER_SwirlyFuzz,
SHADER_TranslucentFuzz,
SHADER_JaggedFuzz,
SHADER_NoiseFuzz,
SHADER_SmoothNoiseFuzz,
SHADER_SoftwareFuzz,
FIRST_USER_SHADER
}; };
struct UserShaderDesc
{
FString shader;
MaterialShaderIndex shaderType;
FString defines;
bool disablealphatest = false;
};
extern TArray<UserShaderDesc> usershaders;
struct FloatRect
{
float left,top;
float width,height;
void Offset(float xofs,float yofs)
{
left+=xofs;
top+=yofs;
}
void Scale(float xfac,float yfac)
{
left*=xfac;
width*=xfac;
top*=yfac;
height*=yfac;
}
};
enum ECreateTexBufferFlags enum ECreateTexBufferFlags
{ {
CTF_CheckHires = 1, // use external hires replacement if found
CTF_Expand = 2, // create buffer with a one-pixel wide border CTF_Expand = 2, // create buffer with a one-pixel wide border
CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture. CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures. CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures.
}; };
enum
{
MAXTILES = 30720,
MAXUSERTILES = (MAXTILES-16) // reserve 16 tiles at the end
};
// NOTE: If the layout of this struct is changed, loadpics() must be modified
// accordingly.
struct picanm_t
{
uint8_t num; // animate number
uint8_t sf; // anim. speed and flags
uint8_t extra;
void Clear()
{
extra = sf = num = 0;
}
};
struct rottile_t
{
int16_t newtile;
int16_t owner;
};
class FBitmap; class FBitmap;
struct FRemapTable; struct FRemapTable;
@ -113,23 +121,30 @@ class FMultipatchTextureBuilder;
extern int r_spriteadjustSW, r_spriteadjustHW; extern int r_spriteadjustSW, r_spriteadjustHW;
picanm_t tileConvertAnimFormat(int32_t const picanmdisk, int *lo, int *to);
class FNullTextureID : public FTextureID class FNullTextureID : public FTextureID
{ {
public: public:
FNullTextureID() : FTextureID(0) {} FNullTextureID() : FTextureID(0) {}
}; };
enum FTextureFormat : uint32_t
{
TEX_Pal,
TEX_Gray,
TEX_RGB, // Actually ARGB
TEX_Count
};
class FSoftwareTexture;
class FGLRenderState; class FGLRenderState;
struct spriteframewithrotate;
class FSerializer; class FSerializer;
namespace OpenGLRenderer namespace OpenGLRenderer
{ {
class FGLRenderState; class FGLRenderState;
class FHardwareTexture;
} }
union FContentIdBuilder union FContentIdBuilder
@ -150,6 +165,7 @@ struct FTextureBuffer
uint8_t *mBuffer = nullptr; uint8_t *mBuffer = nullptr;
int mWidth = 0; int mWidth = 0;
int mHeight = 0; int mHeight = 0;
uint64_t mContentId = 0; // unique content identifier. (Two images created from the same image source with the same settings will return the same value.)
FTextureBuffer() = default; FTextureBuffer() = default;
@ -164,6 +180,7 @@ struct FTextureBuffer
mBuffer = other.mBuffer; mBuffer = other.mBuffer;
mWidth = other.mWidth; mWidth = other.mWidth;
mHeight = other.mHeight; mHeight = other.mHeight;
mContentId = other.mContentId;
other.mBuffer = nullptr; other.mBuffer = nullptr;
} }
@ -172,6 +189,7 @@ struct FTextureBuffer
mBuffer = other.mBuffer; mBuffer = other.mBuffer;
mWidth = other.mWidth; mWidth = other.mWidth;
mHeight = other.mHeight; mHeight = other.mHeight;
mContentId = other.mContentId;
other.mBuffer = nullptr; other.mBuffer = nullptr;
return *this; return *this;
} }
@ -227,8 +245,6 @@ public:
int GetDisplayLeftOffset() const { return leftoffset; } int GetDisplayLeftOffset() const { return leftoffset; }
int GetDisplayTopOffset() const { return topoffset; } int GetDisplayTopOffset() const { return topoffset; }
void SetOffsets(int x, int y) { leftoffset = x; topoffset = y; } void SetOffsets(int x, int y) { leftoffset = x; topoffset = y; }
picanm_t& GetAnim() { return PicAnim; } // This must be modifiable. There's quite a bit of code messing around with the flags in here.
rottile_t& GetRotTile() { return RotTile; }
FTextureBuffer CreateTexBuffer(const PalEntry *palette, int flags = 0); FTextureBuffer CreateTexBuffer(const PalEntry *palette, int flags = 0);
bool GetTranslucency(); bool GetTranslucency();
void CheckTrans(unsigned char * buffer, int size, int trans); void CheckTrans(unsigned char * buffer, int size, int trans);
@ -247,7 +263,6 @@ public:
} }
int alphaThreshold = 128; int alphaThreshold = 128;
picanm_t PicAnim = {};
FixedBitArray<256> NoBrightmapFlag{ 0 }; FixedBitArray<256> NoBrightmapFlag{ 0 };
protected: protected:
@ -272,7 +287,6 @@ protected:
struct { uint16_t Width, Height; }; struct { uint16_t Width, Height; };
}; };
int leftoffset = 0, topoffset = 0; int leftoffset = 0, topoffset = 0;
rottile_t RotTile = { -1,-1 };
uint8_t bMasked = true; // Texture (might) have holes uint8_t bMasked = true; // Texture (might) have holes
int8_t bTranslucent = -1; // Does this texture have an active alpha channel? int8_t bTranslucent = -1; // Does this texture have an active alpha channel?
bool skyColorDone = false; bool skyColorDone = false;

View File

@ -345,7 +345,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
} }
} }
#if 1 #if 1
if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap] && picnum > -1) if (picnum > -1 && !(TileFiles.tiledata[picnum].picanm.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap])
{ {
if (TextureType == TT_HICREPLACE) if (TextureType == TT_HICREPLACE)
{ {
@ -359,7 +359,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
} }
else else
{ {
tex->PicAnim.sf |= PICANM_NOFULLBRIGHT_BIT; TileFiles.tiledata[picnum].picanm.sf |= PICANM_NOFULLBRIGHT_BIT;
} }
} }
else if (TextureType == TT_TRUECOLOR) else if (TextureType == TT_TRUECOLOR)