- Backend update from Raze, mostly maintenance changes without new functionality.

This commit is contained in:
Christoph Oelckers 2022-08-11 22:51:19 +02:00
parent 283c5d688c
commit c89ae6358e
22 changed files with 90 additions and 43 deletions

View File

@ -796,19 +796,19 @@ void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
//
//==========================================================================
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2)
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip)
{
RenderCommand dg;
if (!img || !img->isValid()) return;
dg.mType = DrawTypeTriangles;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth() - 1 || clipy2 < GetHeight() - 1)
if (clip != nullptr)
{
dg.mScissor[0] = clipx1 + int(offset.X);
dg.mScissor[1] = clipy1 + int(offset.Y);
dg.mScissor[2] = clipx2 + 1 + int(offset.X);
dg.mScissor[3] = clipy2 + 1 + int(offset.Y);
dg.mScissor[0] = clip->Left() + int(offset.X);
dg.mScissor[1] = clip->Top() + int(offset.Y);
dg.mScissor[2] = clip->Right() + int(offset.X);
dg.mScissor[3] = clip->Bottom() + int(offset.Y);
dg.mFlags |= DTF_Scissor;
}

View File

@ -216,7 +216,7 @@ public:
void AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley,
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip);
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
int clipx1, int clipy1, int clipx2, int clipy2);
void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0, PalEntry color = 0xffffffff, ERenderStyle rs = STYLE_Normal);

View File

@ -57,17 +57,19 @@
// \c becomes just TEXTCOLOR_ESCAPE
// $<cvar> is replaced by the contents of <cvar>
static long ParseCommandLine(const char* args, int* argc, char** argv, bool no_escapes)
static size_t ParseCommandLine(const char* args, int* argc, char** argv, bool no_escapes)
{
int count;
char* buffstart;
char* buffplace;
count = 0;
buffplace = NULL;
buffstart = NULL;
if (argv != NULL)
{
buffplace = argv[0];
buffstart = argv[0];
}
buffplace = buffstart;
for (;;)
{
@ -154,7 +156,7 @@ static long ParseCommandLine(const char* args, int* argc, char** argv, bool no_e
{
*argc = count;
}
return (long)(buffplace - (char*)0);
return (buffplace - buffstart);
}
FCommandLine::FCommandLine (const char *commandline, bool no_escapes)

View File

@ -50,9 +50,9 @@ public:
private:
const char *cmd;
bool noescapes;
int _argc;
char **_argv;
long argsize;
bool noescapes;
size_t argsize;
};

View File

@ -155,12 +155,13 @@ unsigned FindModel(const char * path, const char * modelfile)
FModel * model = nullptr;
FString fullname;
fullname.Format("%s%s", path, modelfile);
if (path) fullname.Format("%s%s", path, modelfile);
else fullname = modelfile;
int lump = fileSystem.CheckNumForFullName(fullname);
if (lump<0)
{
Printf("FindModel: '%s' not found\n", fullname.GetChars());
Printf(PRINT_HIGH, "FindModel: '%s' not found\n", fullname.GetChars());
return -1;
}
@ -226,7 +227,7 @@ unsigned FindModel(const char * path, const char * modelfile)
}
else
{
Printf("LoadModel: Unknown model format in '%s'\n", fullname.GetChars());
Printf(PRINT_HIGH, "LoadModel: Unknown model format in '%s'\n", fullname.GetChars());
return -1;
}
}

View File

@ -53,6 +53,13 @@ enum ModelRendererType
NumModelRendererTypes
};
enum EFrameError
{
FErr_NotFound = -1,
FErr_Voxel = -2,
FErr_Singleframe = -3
};
class FModel
{
public:
@ -60,7 +67,7 @@ public:
virtual ~FModel();
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0;
virtual int FindFrame(const char * name) = 0;
virtual int FindFrame(const char * name, bool nodefault = false) = 0;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) = 0;
virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0;
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) = 0;

View File

@ -15,9 +15,9 @@ struct FVoxelVertexHash
// Returns the hash value for a key.
hash_t Hash(const FModelVertex &key)
{
int ix = xs_RoundToInt(key.x);
int iy = xs_RoundToInt(key.y);
int iz = xs_RoundToInt(key.z);
int ix = int(key.x);
int iy = int(key.y);
int iz = int(key.z);
return (hash_t)(ix + (iy<<9) + (iz<<18));
}
@ -58,7 +58,7 @@ public:
~FVoxelModel();
bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
void Initialize();
virtual int FindFrame(const char * name) override;
virtual int FindFrame(const char * name, bool nodefault) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
FTextureID GetPaletteTexture() const { return mPalette; }

View File

@ -112,7 +112,7 @@ public:
virtual ~FDMDModel();
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
virtual int FindFrame(const char * name) override;
virtual int FindFrame(const char * name, bool nodefault) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
virtual void LoadGeometry();
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;

View File

@ -66,7 +66,7 @@ public:
FMD3Model() = default;
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
virtual int FindFrame(const char * name) override;
virtual int FindFrame(const char * name, bool nodefault) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void LoadGeometry();
void BuildVertexBuffer(FModelRenderer *renderer);

View File

@ -97,7 +97,7 @@ public:
FOBJModel(): hasMissingNormals(false), hasSmoothGroups(false), vertFaces(nullptr) {}
~FOBJModel();
bool Load(const char* fn, int lumpnum, const char* buffer, int length) override;
int FindFrame(const char* name) override;
int FindFrame(const char* name, bool nodefault) override;
void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void BuildVertexBuffer(FModelRenderer* renderer) override;
void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override;

View File

@ -25,7 +25,7 @@ public:
};
bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
int FindFrame(const char * name) override;
int FindFrame(const char * name, bool nodefault) override;
void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void BuildVertexBuffer(FModelRenderer *renderer) override;
void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;

View File

@ -348,13 +348,13 @@ void FDMDModel::AddSkins(uint8_t *hitlist, const FTextureID*)
// FDMDModel::FindFrame
//
//===========================================================================
int FDMDModel::FindFrame(const char * name)
int FDMDModel::FindFrame(const char * name, bool nodefault)
{
for (int i=0;i<info.numFrames;i++)
{
if (!stricmp(name, frames[i].name)) return i;
}
return -1;
return FErr_NotFound;
}
//===========================================================================

View File

@ -328,13 +328,13 @@ void FMD3Model::AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids)
//
//===========================================================================
int FMD3Model::FindFrame(const char * name)
int FMD3Model::FindFrame(const char * name, bool nodefault)
{
for (unsigned i = 0; i < Frames.Size(); i++)
{
if (!stricmp(name, Frames[i].Name)) return i;
}
return -1;
return FErr_NotFound;
}
//===========================================================================

View File

@ -613,9 +613,9 @@ FVector3 FOBJModel::CalculateNormalSmooth(unsigned int vidx, unsigned int smooth
* @param name The name of the frame
* @return The index of the frame
*/
int FOBJModel::FindFrame(const char* name)
int FOBJModel::FindFrame(const char* name, bool nodefault)
{
return 0; // OBJs are not animated.
return nodefault? FErr_Singleframe : 0; // OBJs are not animated.
}
/**

View File

@ -221,10 +221,12 @@ void FUE1Model::UnloadGeometry()
groups.Reset();
}
int FUE1Model::FindFrame( const char *name )
int FUE1Model::FindFrame( const char *name, bool nodefault )
{
// unsupported, there are no named frames
return -1;
// there are no named frames, but we need something here to properly interface with it. So just treat the string as an index number.
auto index = strtol(name, nullptr, 0);
if (index < 0 || index >= numFrames) return FErr_NotFound;
return index;
}
void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids)

View File

@ -378,9 +378,9 @@ bool FVoxelModel::Load(const char * fn, int lumpnum, const char * buffer, int le
//
//===========================================================================
int FVoxelModel::FindFrame(const char * name)
int FVoxelModel::FindFrame(const char * name, bool nodefault)
{
return 0;
return nodefault? FErr_Voxel : 0; // -2, not -1 because voxels are special.
}
//===========================================================================

View File

@ -107,6 +107,16 @@ namespace GC
return obj = NULL;
}
// Handles a read barrier for a const pointer. This does not alter the source data, but only returns NULL if the object is destroyed.
template<class T> inline T* ReadBarrier(const T*& obj)
{
if (obj == NULL || !(obj->ObjectFlags & OF_EuthanizeMe))
{
return obj;
}
return NULL;
}
// Check if it's time to collect, and do a collection step if it is.
static inline void CheckGC()
{
@ -214,7 +224,13 @@ public:
return GC::ReadBarrier(pp);
}
constexpr T ForceGet() noexcept //for situations where the read barrier needs to be skipped.
constexpr T Get() const noexcept
{
auto ppp = pp;
return GC::ReadBarrier(ppp);
}
constexpr T ForceGet() const noexcept //for situations where the read barrier needs to be skipped.
{
return pp;
}

View File

@ -918,7 +918,7 @@ void PFloat::SetValue(void *addr, double val)
int PFloat::GetValueInt(void *addr) const
{
return xs_ToInt(GetValueFloat(addr));
return int(GetValueFloat(addr));
}
//==========================================================================

View File

@ -54,14 +54,14 @@ extern FFastTrig fasttrig;
#define RAD2BAM(f) ((unsigned)xs_CRoundToInt((f) * (0x80000000/3.14159265358979323846)))
inline double fastcosbam(double v)
inline double fastcosbam(unsigned int v)
{
return fasttrig.cos(xs_CRoundToUInt(v));
return fasttrig.cos(v);
}
inline double fastsinbam(double v)
inline double fastsinbam(unsigned int v)
{
return fasttrig.sin(xs_CRoundToUInt(v));
return fasttrig.sin(v);
}
inline double fastcosdeg(double v)

View File

@ -100,7 +100,7 @@ inline void fillshort(void* buff, size_t count, uint16_t clear)
}
}
template<typename T> inline constexpr T Sgn(const T& val) { return (val > 0) - (val < 0); }
template<typename T> inline constexpr int Sgn(const T& val) { return (val > 0) - (val < 0); }
inline int sizeToBits(int w)

View File

@ -46,6 +46,16 @@ struct IntRect
return top + height;
}
int Width() const
{
return width;
}
int Height() const
{
return height;
}
};

View File

@ -141,11 +141,13 @@ struct TVector2
}
// Scalar addition
#if 0
TVector2 &operator+= (double scalar)
{
X += scalar, Y += scalar;
return *this;
}
#endif
friend TVector2 operator+ (const TVector2 &v, vec_t scalar)
{
@ -341,6 +343,11 @@ struct TVector3
return X == 0 && Y == 0 && Z == 0;
}
TVector3 plusZ(double z)
{
return { X, Y, Z + z };
}
TVector3 &operator= (const TVector3 &other) = default;
// Access X and Y and Z as an array
@ -385,11 +392,13 @@ struct TVector3
}
// Scalar addition
#if 0
TVector3 &operator+= (vec_t scalar)
{
X += scalar, Y += scalar, Z += scalar;
return *this;
}
#endif
friend TVector3 operator+ (const TVector3 &v, vec_t scalar)
{