diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index bae286b844..debb2a73d2 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -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; } diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 2ac631e5d1..904b66820a 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -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); diff --git a/src/common/console/c_commandline.cpp b/src/common/console/c_commandline.cpp index 4516af4ed5..4f500ffe66 100644 --- a/src/common/console/c_commandline.cpp +++ b/src/common/console/c_commandline.cpp @@ -57,17 +57,19 @@ // \c becomes just TEXTCOLOR_ESCAPE // $ is replaced by the contents of -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) diff --git a/src/common/console/c_commandline.h b/src/common/console/c_commandline.h index 88b19cc93b..dc5466df1c 100644 --- a/src/common/console/c_commandline.h +++ b/src/common/console/c_commandline.h @@ -50,9 +50,9 @@ public: private: const char *cmd; + bool noescapes; int _argc; char **_argv; - long argsize; - bool noescapes; + size_t argsize; }; diff --git a/src/common/models/model.cpp b/src/common/models/model.cpp index 1829ccebbd..21f5c9f41c 100644 --- a/src/common/models/model.cpp +++ b/src/common/models/model.cpp @@ -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; } } diff --git a/src/common/models/model.h b/src/common/models/model.h index 300661d250..edbcc48419 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -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; diff --git a/src/common/models/model_kvx.h b/src/common/models/model_kvx.h index 4c107db5c6..1491b03b48 100644 --- a/src/common/models/model_kvx.h +++ b/src/common/models/model_kvx.h @@ -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; } diff --git a/src/common/models/model_md2.h b/src/common/models/model_md2.h index 966a38975c..b1feef645a 100644 --- a/src/common/models/model_md2.h +++ b/src/common/models/model_md2.h @@ -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; diff --git a/src/common/models/model_md3.h b/src/common/models/model_md3.h index e79a4c98b9..3d81cb1c39 100644 --- a/src/common/models/model_md3.h +++ b/src/common/models/model_md3.h @@ -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); diff --git a/src/common/models/model_obj.h b/src/common/models/model_obj.h index a07090900d..55a47363cb 100644 --- a/src/common/models/model_obj.h +++ b/src/common/models/model_obj.h @@ -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; diff --git a/src/common/models/model_ue1.h b/src/common/models/model_ue1.h index 2d29c2eff9..f2ed1952c4 100644 --- a/src/common/models/model_ue1.h +++ b/src/common/models/model_ue1.h @@ -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; diff --git a/src/common/models/models_md2.cpp b/src/common/models/models_md2.cpp index f384723016..81d1c36668 100644 --- a/src/common/models/models_md2.cpp +++ b/src/common/models/models_md2.cpp @@ -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= numFrames) return FErr_NotFound; + return index; } void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) diff --git a/src/common/models/models_voxel.cpp b/src/common/models/models_voxel.cpp index 6db0c9e5f9..41f5e854af 100644 --- a/src/common/models/models_voxel.cpp +++ b/src/common/models/models_voxel.cpp @@ -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. } //=========================================================================== diff --git a/src/common/objects/dobjgc.h b/src/common/objects/dobjgc.h index a1695b8efa..7997145b7e 100644 --- a/src/common/objects/dobjgc.h +++ b/src/common/objects/dobjgc.h @@ -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 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; } diff --git a/src/common/scripting/core/types.cpp b/src/common/scripting/core/types.cpp index fb844c62a6..5dd7cd6b3b 100644 --- a/src/common/scripting/core/types.cpp +++ b/src/common/scripting/core/types.cpp @@ -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)); } //========================================================================== diff --git a/src/common/thirdparty/math/cmath.h b/src/common/thirdparty/math/cmath.h index 26102e3f09..4da0afcb6d 100644 --- a/src/common/thirdparty/math/cmath.h +++ b/src/common/thirdparty/math/cmath.h @@ -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) diff --git a/src/common/utility/cmdlib.h b/src/common/utility/cmdlib.h index b998cf99d6..f0eef9b403 100644 --- a/src/common/utility/cmdlib.h +++ b/src/common/utility/cmdlib.h @@ -100,7 +100,7 @@ inline void fillshort(void* buff, size_t count, uint16_t clear) } } -template inline constexpr T Sgn(const T& val) { return (val > 0) - (val < 0); } +template inline constexpr int Sgn(const T& val) { return (val > 0) - (val < 0); } inline int sizeToBits(int w) diff --git a/src/common/utility/intrect.h b/src/common/utility/intrect.h index 97e9bd90a0..1de15df29c 100644 --- a/src/common/utility/intrect.h +++ b/src/common/utility/intrect.h @@ -46,6 +46,16 @@ struct IntRect return top + height; } + int Width() const + { + return width; + } + + int Height() const + { + return height; + } + }; diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index cb927b4c2d..126f3f51c4 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -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) {