From 89535b803a8234898d66b9420eebd1442e09f512 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 7 Oct 2023 18:42:24 +0200 Subject: [PATCH] Backend update from Raze. --- src/am_map.cpp | 2 +- src/common/audio/sound/s_sound.cpp | 10 +- src/common/filesystem/source/file_whres.cpp | 4 +- src/common/filesystem/source/file_zip.cpp | 2 +- src/common/filesystem/source/files.cpp | 6 +- .../filesystem/source/files_decompress.cpp | 10 +- src/common/filesystem/source/filesystem.cpp | 4 +- src/common/filesystem/source/resourcefile.cpp | 2 +- src/common/objects/dobjgc.cpp | 21 +- .../rendering/hwrenderer/data/hw_aabbtree.cpp | 8 +- src/common/scripting/frontend/zcc-parse.lemon | 10 + src/common/scripting/frontend/zcc_compile.cpp | 5 + src/common/scripting/frontend/zcc_compile.h | 1 + src/common/scripting/vm/vm.h | 5 + src/common/textures/animlib.cpp | 4 +- src/common/textures/formats/qoitexture.cpp | 4 +- src/common/textures/texturemanager.cpp | 4 +- src/common/thirdparty/math/asin.c | 6 +- src/common/thirdparty/math/atan.c | 8 +- src/common/thirdparty/math/cosh.c | 3 +- src/common/thirdparty/math/exp.c | 5 +- src/common/thirdparty/math/isnan.c | 9 +- src/common/thirdparty/math/log.c | 3 +- src/common/thirdparty/math/log10.c | 3 +- src/common/thirdparty/math/mtherr.c | 4 +- src/common/thirdparty/math/polevl.c | 10 +- src/common/thirdparty/math/pow.c | 6 +- src/common/thirdparty/math/powi.c | 4 +- src/common/thirdparty/math/sin.c | 9 +- src/common/thirdparty/math/sinh.c | 3 +- src/common/thirdparty/math/sqrt.c | 3 +- src/common/thirdparty/math/tan.c | 10 +- src/common/thirdparty/math/tanh.c | 3 +- src/common/utility/cmdlib.cpp | 40 +- src/common/utility/cmdlib.h | 7 +- src/common/utility/filereadermusicinterface.h | 6 +- src/common/utility/tarray.h | 4 +- src/common/utility/vectors.h | 437 ++++++++++-------- src/common/utility/zstring.cpp | 4 +- src/g_game.cpp | 2 +- src/g_levellocals.h | 12 +- src/gamedata/r_defs.h | 10 + src/maploader/polyobjects.cpp | 4 +- src/maploader/slopes.cpp | 2 +- src/maploader/specials.cpp | 2 +- src/playsim/actor.h | 10 +- src/playsim/bots/b_func.cpp | 2 +- src/playsim/bots/b_think.cpp | 2 +- src/playsim/fragglescript/t_func.cpp | 2 +- src/playsim/p_actionfunctions.cpp | 4 +- src/playsim/p_destructible.cpp | 2 +- src/playsim/p_effect.cpp | 2 +- src/playsim/p_enemy.cpp | 6 +- src/playsim/p_lnspec.cpp | 4 +- src/playsim/p_map.cpp | 70 +-- src/playsim/p_maputl.h | 5 + src/playsim/p_mobj.cpp | 26 +- src/playsim/p_secnodes.cpp | 4 +- src/playsim/p_sight.cpp | 2 +- src/playsim/p_teleport.cpp | 6 +- src/playsim/p_things.cpp | 6 +- src/playsim/p_trace.cpp | 2 +- src/playsim/po_man.cpp | 4 +- src/rendering/hwrenderer/scene/hw_bsp.cpp | 2 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 4 +- src/rendering/r_utility.cpp | 2 +- .../swrenderer/line/r_farclip_line.cpp | 2 +- src/rendering/swrenderer/line/r_line.cpp | 2 +- .../swrenderer/plane/r_slopeplane.cpp | 2 +- .../swrenderer/scene/r_opaque_pass.cpp | 2 +- .../swrenderer/things/r_particle.cpp | 2 +- .../swrenderer/things/r_visiblesprite.cpp | 4 +- src/sound/s_doomsound.cpp | 4 +- 74 files changed, 506 insertions(+), 402 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index efd33ae70..bf0c61b7d 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2808,7 +2808,7 @@ void DAutomap::drawPlayers () int numarrowlines; double vh = players[consoleplayer].viewheight; - DVector2 pos = players[consoleplayer].camera->InterpolatedPosition(r_viewpoint.TicFrac); + DVector2 pos = players[consoleplayer].camera->InterpolatedPosition(r_viewpoint.TicFrac).XY(); pt.x = pos.X; pt.y = pos.Y; if (am_rotate == 1 || (am_rotate == 2 && viewactive)) diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 58e4a981f..6f53e663e 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -1856,12 +1856,18 @@ CCMD(snd_listdrivers) GSnd->PrintDriversList(); } +//========================================================================== +// +// CCMD listsounds +// +//========================================================================== + CCMD(listsounds) { for (unsigned i = 1; i < soundEngine->GetNumSounds(); i++) { - auto S_sfx = soundEngine->GetSfx(FSoundID::fromInt(i)); - Printf("%04d: %s\n", i, S_sfx->name.GetChars()); + auto sfx = soundEngine->GetSfx(FSoundID::fromInt(i)); + Printf("%4d: name = %s, resId = %d, lumpnum = %d\n", i, sfx->name.GetChars(), sfx->ResourceId, sfx->lumpnum); } } diff --git a/src/common/filesystem/source/file_whres.cpp b/src/common/filesystem/source/file_whres.cpp index efdfd5d39..cef800a0f 100644 --- a/src/common/filesystem/source/file_whres.cpp +++ b/src/common/filesystem/source/file_whres.cpp @@ -91,8 +91,8 @@ bool FWHResFile::Open(LumpFilterInfo*) uint32_t offset = LittleLong(directory[k*3]) * 4096; uint32_t length = LittleLong(directory[k*3+1]); if (length == 0) break; - char num[5]; - snprintf(num, 5, "/%04d", k); + char num[6]; + snprintf(num, 6, "/%04d", k); std::string synthname = BaseName; synthname += num; Lumps[i].LumpNameSetup(synthname.c_str(), stringpool); diff --git a/src/common/filesystem/source/file_zip.cpp b/src/common/filesystem/source/file_zip.cpp index 9aa34095a..155cbf45a 100644 --- a/src/common/filesystem/source/file_zip.cpp +++ b/src/common/filesystem/source/file_zip.cpp @@ -298,7 +298,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) // at least one of the more common definition lumps must be present. for (auto &p : filter->requiredPrefixes) { - if (name.find(name0 + p) == 0 || name.rfind(p) == ptrdiff_t(name.length() - p.length())) + if (name.find(name0 + p) == 0 || name.rfind(p) == size_t(name.length() - p.length())) { foundspeciallump = true; break; diff --git a/src/common/filesystem/source/files.cpp b/src/common/filesystem/source/files.cpp index a17f7c1b8..271831e36 100644 --- a/src/common/filesystem/source/files.cpp +++ b/src/common/filesystem/source/files.cpp @@ -142,10 +142,10 @@ public: char *Gets(char *strbuf, ptrdiff_t len) override { if (len <= 0 || len > 0x7fffffff || FilePos >= StartPos + Length) return nullptr; - char *p = fgets(strbuf, len, File); + char *p = fgets(strbuf, (int)len, File); if (p != nullptr) { - int old = FilePos; + ptrdiff_t old = FilePos; FilePos = ftell(File); if (FilePos - StartPos > Length) { @@ -240,7 +240,7 @@ public: char *p = mReader->Gets(strbuf, len); if (p != nullptr) { - int old = FilePos; + ptrdiff_t old = FilePos; FilePos = mReader->Tell(); if (FilePos - StartPos > Length) { diff --git a/src/common/filesystem/source/files_decompress.cpp b/src/common/filesystem/source/files_decompress.cpp index 28046ad41..6b32bf660 100644 --- a/src/common/filesystem/source/files_decompress.cpp +++ b/src/common/filesystem/source/files_decompress.cpp @@ -176,7 +176,7 @@ public: ptrdiff_t Read (void *buffer, ptrdiff_t len) override { - int err; + int err = 0; if (File == nullptr) { @@ -188,7 +188,7 @@ public: while (len > 0) { Stream.next_out = (Bytef*)buffer; - auto rlen = std::min(len, 0x40000000); + unsigned rlen = (unsigned)std::min(len, 0x40000000); Stream.avail_out = rlen; buffer = Stream.next_out + rlen; len -= rlen; @@ -304,7 +304,7 @@ public: while (len > 0) { Stream.next_out = (char*)buffer; - auto rlen = std::min(len, 0x40000000); + unsigned rlen = (unsigned)std::min(len, 0x40000000); Stream.avail_out = rlen; buffer = Stream.next_out + rlen; len -= rlen; @@ -798,7 +798,7 @@ public: if (len > 0xffffffff) len = 0xffffffff; // this format cannot be larger than 4GB. uint8_t *Out = (uint8_t*)buffer; - unsigned AvailOut = len; + ptrdiff_t AvailOut = len; do { @@ -812,7 +812,7 @@ public: break; } - unsigned int copy = std::min(Stream.InternalOut, AvailOut); + unsigned int copy = (unsigned)std::min(Stream.InternalOut, AvailOut); if(copy > 0) { memcpy(Out, Stream.WindowData, copy); diff --git a/src/common/filesystem/source/filesystem.cpp b/src/common/filesystem/source/filesystem.cpp index 1cdb6692b..0841ea68e 100644 --- a/src/common/filesystem/source/filesystem.cpp +++ b/src/common/filesystem/source/filesystem.cpp @@ -147,7 +147,7 @@ struct FileSystem::LumpRecord { std::string longName = LongName; ptrdiff_t encodedResID = longName.find_last_of(".{"); - if (resourceId == -1 && encodedResID != std::string::npos) + if (resourceId == -1 && (size_t)encodedResID != std::string::npos) { const char* p = LongName + encodedResID; char* q; @@ -978,7 +978,7 @@ void FileSystem::MoveLumpsInFolder(const char *path) int FileSystem::FindLump (const char *name, int *lastlump, bool anyns) { - if (*lastlump >= FileInfo.size()) return -1; + if ((size_t)*lastlump >= FileInfo.size()) return -1; union { char name8[8]; diff --git a/src/common/filesystem/source/resourcefile.cpp b/src/common/filesystem/source/resourcefile.cpp index 1da4aa04d..64c620c3b 100644 --- a/src/common/filesystem/source/resourcefile.cpp +++ b/src/common/filesystem/source/resourcefile.cpp @@ -415,7 +415,7 @@ void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize, LumpFilterI ptrdiff_t lastpos = -1; std::string file; std::string& LumpFilter = filter->dotFilter; - while ((len = LumpFilter.find_first_of('.', lastpos+1)) != LumpFilter.npos) + while (size_t(len = LumpFilter.find_first_of('.', lastpos+1)) != LumpFilter.npos) { max -= FilterLumps(std::string(LumpFilter, 0, len), lumps, lumpsize, max); lastpos = len; diff --git a/src/common/objects/dobjgc.cpp b/src/common/objects/dobjgc.cpp index 64f36a129..d388e4836 100644 --- a/src/common/objects/dobjgc.cpp +++ b/src/common/objects/dobjgc.cpp @@ -287,11 +287,22 @@ static size_t DestroyObjects(size_t count) while ((curr = ToDestroy) != nullptr && count-- > 0) { - assert(!(curr->ObjectFlags & OF_EuthanizeMe)); - bytes_destroyed += curr->GetClass()->Size + GCDESTROYCOST; - ToDestroy = curr->GCNext; - curr->GCNext = nullptr; - curr->Destroy(); + // Note that we cannot assume here that the object has not yet been destroyed. + // If destruction happens as the result of another object's destruction we may + // get entries here that have been destroyed already if that owning object was + // first in the list. + if (!(curr->ObjectFlags & OF_EuthanizeMe)) + { + bytes_destroyed += curr->GetClass()->Size + GCDESTROYCOST; + ToDestroy = curr->GCNext; + curr->GCNext = nullptr; + curr->Destroy(); + } + else + { + ToDestroy = curr->GCNext; + curr->GCNext = nullptr; + } } return bytes_destroyed; } diff --git a/src/common/rendering/hwrenderer/data/hw_aabbtree.cpp b/src/common/rendering/hwrenderer/data/hw_aabbtree.cpp index 20a1d39a1..d7d221fe3 100644 --- a/src/common/rendering/hwrenderer/data/hw_aabbtree.cpp +++ b/src/common/rendering/hwrenderer/data/hw_aabbtree.cpp @@ -56,10 +56,10 @@ TArray LevelAABBTree::FindNodePath(unsigned int line, unsigned int node) double LevelAABBTree::RayTest(const DVector3 &ray_start, const DVector3 &ray_end) { // Precalculate some of the variables used by the ray/line intersection test - DVector2 raydelta = ray_end - ray_start; + DVector2 raydelta = (ray_end - ray_start).XY(); double raydist2 = raydelta | raydelta; DVector2 raynormal = DVector2(raydelta.Y, -raydelta.X); - double rayd = raynormal | ray_start; + double rayd = raynormal | ray_start.XY(); if (raydist2 < 1.0) return 1.0f; @@ -73,7 +73,7 @@ double LevelAABBTree::RayTest(const DVector3 &ray_start, const DVector3 &ray_end { int node_index = stack[stack_pos - 1]; - if (!OverlapRayAABB(ray_start, ray_end, nodes[node_index])) + if (!OverlapRayAABB(ray_start.XY(), ray_end.XY(), nodes[node_index])) { // If the ray doesn't overlap this node's AABB we're done for this subtree stack_pos--; @@ -81,7 +81,7 @@ double LevelAABBTree::RayTest(const DVector3 &ray_start, const DVector3 &ray_end else if (nodes[node_index].line_index != -1) // isLeaf(node_index) { // We reached a leaf node. Do a ray/line intersection test to see if we hit the line. - hit_fraction = std::min(IntersectRayLine(ray_start, ray_end, nodes[node_index].line_index, raydelta, rayd, raydist2), hit_fraction); + hit_fraction = std::min(IntersectRayLine(ray_start.XY(), ray_end.XY(), nodes[node_index].line_index, raydelta, rayd, raydist2), hit_fraction); stack_pos--; } else if (stack_pos == 32) diff --git a/src/common/scripting/frontend/zcc-parse.lemon b/src/common/scripting/frontend/zcc-parse.lemon index d25820dda..295c58dd9 100644 --- a/src/common/scripting/frontend/zcc-parse.lemon +++ b/src/common/scripting/frontend/zcc-parse.lemon @@ -378,6 +378,15 @@ flag_def(X) ::= FLAGDEF(T) IDENTIFIER(A) COLON IDENTIFIER(B) COMMA INTCONST(C) S X = def; } +flag_def(X) ::= FLAGDEF(T) INTERNAL IDENTIFIER(A) COLON IDENTIFIER(B) COMMA INTCONST(C) SEMICOLON. +{ + NEW_AST_NODE(FlagDef,def,T); + def->NodeName = A.Name(); + def->RefName = B.Name(); + def->BitValue = C.Int | 0x10000; + X = def; +} + identifier_list(X) ::= IDENTIFIER(A). { @@ -437,6 +446,7 @@ struct_member(X) ::= declarator(A). { X = A; /*X-overwrites-A*/ } struct_member(X) ::= enum_def(A). { X = A; /*X-overwrites-A*/ } struct_member(X) ::= const_def(A). { X = A; /*X-overwrites-A*/ } struct_member(X) ::= staticarray_statement(A). { X = A; /*X-overwrites-A*/ } +struct_member(X) ::= flag_def(A). { X = A; /*X-overwrites-A*/ } /*----- Constant Definition ------*/ /* Like UnrealScript, a constant's type is implied by its value's type. */ diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index b43e9622f..fbe3d80dd 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -452,6 +452,11 @@ void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *treenode, ZC } break; + case AST_FlagDef: + cls->FlagDefs.Push(static_cast(node)); + break; + + default: assert(0 && "Unhandled AST node type"); break; diff --git a/src/common/scripting/frontend/zcc_compile.h b/src/common/scripting/frontend/zcc_compile.h index b6f32018d..82c6342ff 100644 --- a/src/common/scripting/frontend/zcc_compile.h +++ b/src/common/scripting/frontend/zcc_compile.h @@ -23,6 +23,7 @@ struct ZCC_StructWork TArray Fields; TArray Functions; TArray Arrays; + TArray FlagDefs; ZCC_StructWork() { diff --git a/src/common/scripting/vm/vm.h b/src/common/scripting/vm/vm.h index 73c4b48bb..6442034c1 100644 --- a/src/common/scripting/vm/vm.h +++ b/src/common/scripting/vm/vm.h @@ -724,6 +724,11 @@ struct AFuncDesc extern FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr; \ MSVC_FSEG FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr GCC_FSEG = &VMField_##cls##_##scriptname; +#define DEFINE_FIELD_NAMED_UNSIZED(cls, name, scriptname) \ + static const FieldDesc VMField_##cls##_##scriptname = { #cls, #scriptname, (unsigned)myoffsetof(cls, name), ~0u, 0 }; \ + extern FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr; \ + MSVC_FSEG FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr GCC_FSEG = &VMField_##cls##_##scriptname; + #define DEFINE_FIELD_BIT(cls, name, scriptname, bitval) \ static const FieldDesc VMField_##cls##_##scriptname = { #cls, #scriptname, (unsigned)myoffsetof(cls, name), (unsigned)sizeof(cls::name), bitval }; \ extern FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr; \ diff --git a/src/common/textures/animlib.cpp b/src/common/textures/animlib.cpp index cc83f87ba..4791a1313 100644 --- a/src/common/textures/animlib.cpp +++ b/src/common/textures/animlib.cpp @@ -222,7 +222,7 @@ int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length) if (memcmp(buffer, "LPF ", 4)) return -1; length -= sizeof(lpfileheader)+128+768; - if (length < 0) + if ((signed)length < 0) return -1; anim->curlpnum = 0xffff; @@ -244,7 +244,7 @@ int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length) lpheader.framesPerSecond = LittleShort(lpheader.framesPerSecond); length -= lpheader.nLps * sizeof(lp_descriptor); - if (length < 0) + if ((signed)length < 0) return -2; buffer += sizeof(lpfileheader)+128; diff --git a/src/common/textures/formats/qoitexture.cpp b/src/common/textures/formats/qoitexture.cpp index 663472f20..2df651756 100644 --- a/src/common/textures/formats/qoitexture.cpp +++ b/src/common/textures/formats/qoitexture.cpp @@ -59,7 +59,7 @@ FImageSource *QOIImage_TryCreate(FileReader &file, int lumpnum) { QOIHeader header; - if (file.GetLength() < (sizeof(header) + 8)) + if ((size_t)file.GetLength() < (sizeof(header) + 8)) { return nullptr; } @@ -86,7 +86,7 @@ FQOITexture::FQOITexture(int lumpnum, QOIHeader& header) LeftOffset = TopOffset = 0; Width = header.width; Height = header.height; - if (header.channels == 3) bMasked = bTranslucent = false; + if (header.channels == 3) bMasked = (bTranslucent = false); } PalettedPixels FQOITexture::CreatePalettedPixels(int conversion, int frame) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index c2ebe6249..b742ca787 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1632,7 +1632,7 @@ void FTextureManager::Listaliases() void FTextureManager::SetLinkedTexture(int lump, FGameTexture* tex) { - if ((size_t)lump < fileSystem.GetNumEntries()) + if (lump < fileSystem.GetNumEntries()) { linkedMap.Insert(lump, tex); } @@ -1646,7 +1646,7 @@ void FTextureManager::SetLinkedTexture(int lump, FGameTexture* tex) FGameTexture* FTextureManager::GetLinkedTexture(int lump) { - if ((size_t)lump < fileSystem.GetNumEntries()) + if (lump < fileSystem.GetNumEntries()) { auto check = linkedMap.CheckKey(lump); if (check) return *check; diff --git a/src/common/thirdparty/math/asin.c b/src/common/thirdparty/math/asin.c index 8bc342dd1..72dc9b3e9 100644 --- a/src/common/thirdparty/math/asin.c +++ b/src/common/thirdparty/math/asin.c @@ -276,8 +276,7 @@ double c_asin(); #endif extern double PIO2, PIO4, NAN; -double c_asin(x) -double x; +double c_asin(double x) { double a, p, z, zz; short sign; @@ -327,8 +326,7 @@ return(z); -double c_acos(x) -double x; +double c_acos(double x) { if( (x < -1.0) || (x > 1.0) ) { diff --git a/src/common/thirdparty/math/atan.c b/src/common/thirdparty/math/atan.c index d73ed1ee4..68e10310a 100644 --- a/src/common/thirdparty/math/atan.c +++ b/src/common/thirdparty/math/atan.c @@ -212,8 +212,7 @@ extern double PI, PIO2, PIO4, INFINITY, NEGZERO, MAXNUM; #endif -double c_atan(x) -double x; +double c_atan(double x) { double y, z; short sign, flag; @@ -269,11 +268,10 @@ return(y); /* atan2 */ #ifdef ANSIC -double c_atan2( y, x ) +double c_atan2(double y, double x) #else -double c_atan2( x, y ) +double c_atan2(double x, double y) #endif -double x, y; { double z, w; short code; diff --git a/src/common/thirdparty/math/cosh.c b/src/common/thirdparty/math/cosh.c index 778ccd951..bd4df2f39 100644 --- a/src/common/thirdparty/math/cosh.c +++ b/src/common/thirdparty/math/cosh.c @@ -79,8 +79,7 @@ int isnan(), isfinite(); #endif extern double MAXLOG, INFINITY, LOGE2; -double c_cosh(x) -double x; +double c_cosh(double x) { double y; diff --git a/src/common/thirdparty/math/exp.c b/src/common/thirdparty/math/exp.c index 29ec8d5da..46cd0f559 100644 --- a/src/common/thirdparty/math/exp.c +++ b/src/common/thirdparty/math/exp.c @@ -164,12 +164,11 @@ static short sc2[] = {0x3eb7,0xf7d1,0xcf79,0xabca}; extern double LOGE2, LOG2E, MAXLOG, MINLOG, MAXNUM; -double c_exp(x) -double x; +double c_exp(double x) { double px, xx; int n; -double polevl(), floor(), ldexp(); +double polevl(double, void *, int), floor(double), ldexp(double, int); if( x > MAXLOG) { diff --git a/src/common/thirdparty/math/isnan.c b/src/common/thirdparty/math/isnan.c index 6c421441f..b09ce01a3 100644 --- a/src/common/thirdparty/math/isnan.c +++ b/src/common/thirdparty/math/isnan.c @@ -99,8 +99,7 @@ POSSIBILITY OF SUCH DAMAGE. /* Return 1 if the sign bit of x is 1, else 0. */ -int signbit(x) -double x; +int signbit(double x) { union { @@ -140,8 +139,7 @@ else /* Return 1 if x is a number that is Not a Number, else return 0. */ -int isnan(x) -double x; +int isnan(double x) { #ifdef NANS union @@ -209,8 +207,7 @@ return(0); /* Return 1 if x is not infinite and is not a NaN. */ -int isfinite(x) -double x; +int isfinite(double x) { #ifdef INFINITIES union diff --git a/src/common/thirdparty/math/log.c b/src/common/thirdparty/math/log.c index 81595120c..8ad060c7e 100644 --- a/src/common/thirdparty/math/log.c +++ b/src/common/thirdparty/math/log.c @@ -230,8 +230,7 @@ int isnan(), isfinite(); #define SQRTH 0.70710678118654752440 extern double INFINITY, NAN; -double c_log(x) -double x; +double c_log(double x) { int e; #ifdef DEC diff --git a/src/common/thirdparty/math/log10.c b/src/common/thirdparty/math/log10.c index 037741c60..b7662dc0e 100644 --- a/src/common/thirdparty/math/log10.c +++ b/src/common/thirdparty/math/log10.c @@ -178,8 +178,7 @@ int isnan(), isfinite(); #endif extern double LOGE2, SQRT2, INFINITY, NAN; -double c_log10(x) -double x; +double c_log10(double x) { VOLATILE double z; double y; diff --git a/src/common/thirdparty/math/mtherr.c b/src/common/thirdparty/math/mtherr.c index 5650e07ed..3f24da2b7 100644 --- a/src/common/thirdparty/math/mtherr.c +++ b/src/common/thirdparty/math/mtherr.c @@ -99,9 +99,7 @@ static char *ermsg[7] = { }; -int mtherr( name, code ) -char *name; -int code; +int mtherr(char* name, int code) { /* Display string passed by calling program, diff --git a/src/common/thirdparty/math/polevl.c b/src/common/thirdparty/math/polevl.c index bc17a1210..dde27daff 100644 --- a/src/common/thirdparty/math/polevl.c +++ b/src/common/thirdparty/math/polevl.c @@ -75,10 +75,7 @@ Direct inquiries to 30 Frost Street, Cambridge, MA 02140 */ -double polevl( x, coef, N ) -double x; -double coef[]; -int N; +double polevl(double x, double coef[], int N) { double ans; int i; @@ -101,10 +98,7 @@ return( ans ); * Otherwise same as polevl. */ -double p1evl( x, coef, N ) -double x; -double coef[]; -int N; +double p1evl(double x, double coef[], int N) { double ans; double *p; diff --git a/src/common/thirdparty/math/pow.c b/src/common/thirdparty/math/pow.c index 49d091445..3631c4c78 100644 --- a/src/common/thirdparty/math/pow.c +++ b/src/common/thirdparty/math/pow.c @@ -387,8 +387,7 @@ extern double NAN; extern double NEGZERO; #endif -double c_pow( x, y ) -double x, y; +double c_pow(double x, double y) { double w, z, W, Wa, Wb, ya, yb, u; /* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */ @@ -768,8 +767,7 @@ return( z ); /* Find a multiple of 1/16 that is within 1/16 of x. */ -static double reduc(x) -double x; +static double reduc(double x) { double t; diff --git a/src/common/thirdparty/math/powi.c b/src/common/thirdparty/math/powi.c index d4d5a07f6..75a22f8f1 100644 --- a/src/common/thirdparty/math/powi.c +++ b/src/common/thirdparty/math/powi.c @@ -78,9 +78,7 @@ int signbit(); #endif extern double NEGZERO, INFINITY, MAXNUM, MAXLOG, MINLOG, LOGE2; -double c_powi( x, nn ) -double x; -int nn; +double c_powi(double x, int nn) { int n, e, sign, asign, lx; double w, y, s; diff --git a/src/common/thirdparty/math/sin.c b/src/common/thirdparty/math/sin.c index 76c6a1938..4b4275f2e 100644 --- a/src/common/thirdparty/math/sin.c +++ b/src/common/thirdparty/math/sin.c @@ -238,8 +238,7 @@ extern double INFINITY; #endif -double c_sin(x) -double x; +double c_sin(double x) { double y, z, zz; int j, sign; @@ -318,8 +317,7 @@ return(y); -double c_cos(x) -double x; +double c_cos(double x) { double y, z, zz; int i; @@ -403,8 +401,7 @@ static unsigned short P648[] = {034513,054170,0176773,0116043,}; static double P64800 = 4.8481368110953599358991410e-5; #endif -double radian(d,m,s) -double d,m,s; +double radian(double d, double m, double s) { return( ((d*60.0 + m)*60.0 + s)*P64800 ); diff --git a/src/common/thirdparty/math/sinh.c b/src/common/thirdparty/math/sinh.c index eb868b765..3b54760c4 100644 --- a/src/common/thirdparty/math/sinh.c +++ b/src/common/thirdparty/math/sinh.c @@ -132,8 +132,7 @@ double fabs(), c_exp(), polevl(), p1evl(); #endif extern double INFINITY, MINLOG, MAXLOG, LOGE2; -double c_sinh(x) -double x; +double c_sinh(double x) { double a; diff --git a/src/common/thirdparty/math/sqrt.c b/src/common/thirdparty/math/sqrt.c index de214aff0..67f7376f1 100644 --- a/src/common/thirdparty/math/sqrt.c +++ b/src/common/thirdparty/math/sqrt.c @@ -78,8 +78,7 @@ double frexp(), ldexp(); #endif extern double SQRT2; /* _sqrt2 = 1.41421356237309504880 */ -double c_sqrt(x) -double x; +double c_sqrt(double x) { int e; #ifndef UNK diff --git a/src/common/thirdparty/math/tan.c b/src/common/thirdparty/math/tan.c index 0b5fecc9c..adeade460 100644 --- a/src/common/thirdparty/math/tan.c +++ b/src/common/thirdparty/math/tan.c @@ -220,8 +220,7 @@ extern double PIO4; extern double INFINITY; extern double NAN; -double c_tan(x) -double x; +double c_tan(double x) { #ifdef MINUSZERO if( x == 0.0 ) @@ -240,8 +239,7 @@ return( tancot(x,0) ); } -double c_cot(x) -double x; +double c_cot(double x) { if( x == 0.0 ) @@ -253,9 +251,7 @@ return( tancot(x,1) ); } -static double tancot( xx, cotflg ) -double xx; -int cotflg; +static double tancot(double xx, int cotflg) { double x, y, z, zz; int j, sign; diff --git a/src/common/thirdparty/math/tanh.c b/src/common/thirdparty/math/tanh.c index 1836d35cc..92452c10f 100644 --- a/src/common/thirdparty/math/tanh.c +++ b/src/common/thirdparty/math/tanh.c @@ -128,8 +128,7 @@ double fabs(), c_exp(), polevl(), p1evl(); #endif extern double MAXLOG; -double c_tanh(x) -double x; +double c_tanh(double x) { double s, z; diff --git a/src/common/utility/cmdlib.cpp b/src/common/utility/cmdlib.cpp index b5fd87224..88a37f362 100644 --- a/src/common/utility/cmdlib.cpp +++ b/src/common/utility/cmdlib.cpp @@ -69,13 +69,16 @@ FString progdir; // //========================================================================== -static inline bool IsSeperator (int c) +static inline bool IsSeperator (int c, bool forcebackslash = false) { if (c == '/') return true; #ifdef _WIN32 if (c == '\\') return true; +#else + if (forcebackslash && c == '\\') + return true; #endif return false; } @@ -243,11 +246,11 @@ bool GetFileInfo(const char* pathname, size_t *size, time_t *time) // //========================================================================== -void DefaultExtension (FString &path, const char *extension) +void DefaultExtension (FString &path, const char *extension, bool forcebackslash) { const char *src = &path[int(path.Len())-1]; - while (src != &path[0] && !IsSeperator(*src)) + while (src != &path[0] && !IsSeperator(*src, forcebackslash)) { if (*src == '.') return; // it has an extension @@ -269,7 +272,7 @@ void DefaultExtension (FString &path, const char *extension) // //========================================================================== -FString ExtractFilePath (const char *path) +FString ExtractFilePath (const char *path, bool forcebackslash) { const char *src; @@ -278,7 +281,7 @@ FString ExtractFilePath (const char *path) // // back up until a \ or the start // - while (src != path && !IsSeperator(*(src-1))) + while (src != path && !IsSeperator(*(src-1), forcebackslash)) src--; return FString(path, src - path); @@ -292,7 +295,7 @@ FString ExtractFilePath (const char *path) // //========================================================================== -FString ExtractFileBase (const char *path, bool include_extension) +FString ExtractFileBase (const char *path, bool include_extension, bool forcebackslash) { const char *src, *dot; @@ -301,7 +304,7 @@ FString ExtractFileBase (const char *path, bool include_extension) if (src >= path) { // back up until a / or the start - while (src != path && !IsSeperator(*(src-1))) + while (src != path && !IsSeperator(*(src-1), forcebackslash)) src--; // Check for files with drive specification but no path @@ -325,6 +328,29 @@ FString ExtractFileBase (const char *path, bool include_extension) return FString(); } +//========================================================================== +// +// SplitPath +// +// splits a path into directory, base name and extension +// +//========================================================================== + + void SplitPath(const char* path, FString& directory, FString& base, FString& ext, bool forcebackslash) +{ + directory = ExtractFilePath(path, forcebackslash); + base = ExtractFileBase(path, forcebackslash); + auto dot = base.LastIndexOf('.'); + if (dot > -1) + { + ext = base.Mid(dot + 1); + base.Truncate(dot); + } + else + ext = ""; +} + + //========================================================================== // // StripExtension diff --git a/src/common/utility/cmdlib.h b/src/common/utility/cmdlib.h index 6f5c6b584..df779a975 100644 --- a/src/common/utility/cmdlib.h +++ b/src/common/utility/cmdlib.h @@ -48,12 +48,13 @@ extern FString progdir; void FixPathSeperator (char *path); static void inline FixPathSeperator (FString &path) { path.ReplaceChars('\\', '/'); } -void DefaultExtension (FString &path, const char *extension); +void DefaultExtension (FString &path, const char *extension, bool forcebackslash = false); void NormalizeFileName(FString &str); -FString ExtractFilePath (const char *path); -FString ExtractFileBase (const char *path, bool keep_extension=false); +FString ExtractFilePath (const char *path, bool forcebackslash = false); +FString ExtractFileBase (const char *path, bool keep_extension=false, bool forcebackslash = false); FString StripExtension(const char* path); +void SplitPath(const char* path, FString& directory, FString& base, FString& ext, bool forcebackslash = false); struct FScriptPosition; bool IsNum (const char *str); // [RH] added diff --git a/src/common/utility/filereadermusicinterface.h b/src/common/utility/filereadermusicinterface.h index 042804b53..c30ac6c55 100644 --- a/src/common/utility/filereadermusicinterface.h +++ b/src/common/utility/filereadermusicinterface.h @@ -11,9 +11,9 @@ inline ZMusicCustomReader *GetMusicReader(FileReader& fr) zcr->handle = fr.GetInterface(); zcr->gets = [](ZMusicCustomReader* zr, char* buff, int n) { return reinterpret_cast(zr->handle)->Gets(buff, n); }; - zcr->read = [](ZMusicCustomReader* zr, void* buff, int32_t size) -> long { return reinterpret_cast(zr->handle)->Read(buff, size); }; - zcr->seek = [](ZMusicCustomReader* zr, long offset, int whence) -> long { return reinterpret_cast(zr->handle)->Seek(offset, whence); }; - zcr->tell = [](ZMusicCustomReader* zr) -> long { return reinterpret_cast(zr->handle)->Tell(); }; + zcr->read = [](ZMusicCustomReader* zr, void* buff, int32_t size) -> long { return (long)reinterpret_cast(zr->handle)->Read(buff, size); }; + zcr->seek = [](ZMusicCustomReader* zr, long offset, int whence) -> long { return (long)reinterpret_cast(zr->handle)->Seek(offset, whence); }; + zcr->tell = [](ZMusicCustomReader* zr) -> long { return (long)reinterpret_cast(zr->handle)->Tell(); }; zcr->close = [](ZMusicCustomReader* zr) { delete reinterpret_cast(zr->handle); diff --git a/src/common/utility/tarray.h b/src/common/utility/tarray.h index c377f330b..760dd6092 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -1142,12 +1142,12 @@ public: Node *n = FindKey(key); if (n != NULL) { - n->Pair.Value = std::move(value); + n->Pair.Value = value; } else { n = NewKey(key); - ::new(&n->Pair.Value) VT(std::move(value)); + ::new(&n->Pair.Value) VT(value); } return n->Pair.Value; } diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index a7bc2b2f3..c861ffdfa 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -44,6 +44,7 @@ #include #include #include +#include // this is needed to properly normalize angles. We cannot do that with compiler provided conversions because they differ too much #include "xs_Float.h" @@ -79,61 +80,56 @@ struct TVector2 { vec_t X, Y; - TVector2() = default; + constexpr TVector2() = default; - TVector2 (vec_t a, vec_t b) + constexpr TVector2 (vec_t a, vec_t b) : X(a), Y(b) { } - TVector2(const TVector2 &other) = default; + constexpr TVector2(const TVector2 &other) = default; - TVector2 (const TVector3 &other) // Copy the X and Y from the 3D vector and discard the Z - : X(other.X), Y(other.Y) - { - } - - TVector2(vec_t *o) + constexpr TVector2(vec_t *o) : X(o[0]), Y(o[1]) { } template - explicit operator TVector2 () const noexcept { + constexpr explicit operator TVector2 () const noexcept { return TVector2(static_cast(X), static_cast(Y)); } - void Zero() + constexpr void Zero() { Y = X = 0; } - bool isZero() const + constexpr bool isZero() const { return X == 0 && Y == 0; } - TVector2 &operator= (const TVector2 &other) = default; + constexpr TVector2 &operator= (const TVector2 &other) = default; // Access X and Y as an array - vec_t &operator[] (int index) + constexpr vec_t &operator[] (int index) { return index == 0 ? X : Y; } - const vec_t &operator[] (int index) const + constexpr const vec_t &operator[] (int index) const { return index == 0 ? X : Y; } // Test for equality - bool operator== (const TVector2 &other) const + constexpr bool operator== (const TVector2 &other) const { return X == other.X && Y == other.Y; } // Test for inequality - bool operator!= (const TVector2 &other) const + constexpr bool operator!= (const TVector2 &other) const { return X != other.X || Y != other.Y; } @@ -151,92 +147,92 @@ struct TVector2 } // Unary negation - TVector2 operator- () const + constexpr TVector2 operator- () const { return TVector2(-X, -Y); } // Scalar addition #if 0 - TVector2 &operator+= (double scalar) + constexpr TVector2 &operator+= (double scalar) { X += scalar, Y += scalar; return *this; } #endif - friend TVector2 operator+ (const TVector2 &v, vec_t scalar) + constexpr friend TVector2 operator+ (const TVector2 &v, vec_t scalar) { return TVector2(v.X + scalar, v.Y + scalar); } - friend TVector2 operator+ (vec_t scalar, const TVector2 &v) + constexpr friend TVector2 operator+ (vec_t scalar, const TVector2 &v) { return TVector2(v.X + scalar, v.Y + scalar); } // Scalar subtraction - TVector2 &operator-= (vec_t scalar) + constexpr TVector2 &operator-= (vec_t scalar) { X -= scalar, Y -= scalar; return *this; } - TVector2 operator- (vec_t scalar) const + constexpr TVector2 operator- (vec_t scalar) const { return TVector2(X - scalar, Y - scalar); } // Scalar multiplication - TVector2 &operator*= (vec_t scalar) + constexpr TVector2 &operator*= (vec_t scalar) { X *= scalar, Y *= scalar; return *this; } - friend TVector2 operator* (const TVector2 &v, vec_t scalar) + constexpr friend TVector2 operator* (const TVector2 &v, vec_t scalar) { return TVector2(v.X * scalar, v.Y * scalar); } - friend TVector2 operator* (vec_t scalar, const TVector2 &v) + constexpr friend TVector2 operator* (vec_t scalar, const TVector2 &v) { return TVector2(v.X * scalar, v.Y * scalar); } // Scalar division - TVector2 &operator/= (vec_t scalar) + constexpr TVector2 &operator/= (vec_t scalar) { scalar = 1 / scalar, X *= scalar, Y *= scalar; return *this; } - TVector2 operator/ (vec_t scalar) const + constexpr TVector2 operator/ (vec_t scalar) const { scalar = 1 / scalar; return TVector2(X * scalar, Y * scalar); } // Vector addition - TVector2 &operator+= (const TVector2 &other) + constexpr TVector2 &operator+= (const TVector2 &other) { X += other.X, Y += other.Y; return *this; } - TVector2 operator+ (const TVector2 &other) const + constexpr TVector2 operator+ (const TVector2 &other) const { return TVector2(X + other.X, Y + other.Y); } // Vector subtraction - TVector2 &operator-= (const TVector2 &other) + constexpr TVector2 &operator-= (const TVector2 &other) { X -= other.X, Y -= other.Y; return *this; } - TVector2 operator- (const TVector2 &other) const + constexpr TVector2 operator- (const TVector2 &other) const { return TVector2(X - other.X, Y - other.Y); } @@ -247,7 +243,7 @@ struct TVector2 return (vec_t)g_sqrt (LengthSquared()); } - vec_t LengthSquared() const + constexpr vec_t LengthSquared() const { return X*X + Y*Y; } @@ -300,12 +296,12 @@ struct TVector2 } // Dot product - vec_t operator | (const TVector2 &other) const + constexpr vec_t operator | (const TVector2 &other) const { return X*other.X + Y*other.Y; } - vec_t dot(const TVector2 &other) const + constexpr vec_t dot(const TVector2 &other) const { return X*other.X + Y*other.Y; } @@ -331,19 +327,19 @@ struct TVector2 } // Returns a rotated vector. angle is in degrees. - TVector2 Rotated(const double cosval, const double sinval) const + constexpr TVector2 Rotated(const double cosval, const double sinval) const { return TVector2(X*cosval - Y*sinval, Y*cosval + X*sinval); } // Returns a vector rotated 90 degrees clockwise. - TVector2 Rotated90CW() const + constexpr TVector2 Rotated90CW() const { return TVector2(Y, -X); } // Returns a vector rotated 90 degrees counterclockwise. - TVector2 Rotated90CCW() const + constexpr TVector2 Rotated90CCW() const { return TVector2(-Y, X); } @@ -358,23 +354,23 @@ struct TVector3 vec_t X, Y, Z; - TVector3() = default; + constexpr TVector3() = default; - TVector3 (vec_t a, vec_t b, vec_t c) + constexpr TVector3 (vec_t a, vec_t b, vec_t c) : X(a), Y(b), Z(c) { } - TVector3(vec_t *o) + constexpr TVector3(vec_t *o) : X(o[0]), Y(o[1]), Z(o[2]) { } - TVector3(std::nullptr_t nul) = delete; + constexpr TVector3(std::nullptr_t nul) = delete; - TVector3(const TVector3 &other) = default; + constexpr TVector3(const TVector3 &other) = default; - TVector3 (const Vector2 &xy, vec_t z) + constexpr TVector3 (const Vector2 &xy, vec_t z) : X(xy.X), Y(xy.Y), Z(z) { } @@ -382,46 +378,46 @@ struct TVector3 TVector3 (const TRotator &rot); template - explicit operator TVector3 () const noexcept { + constexpr explicit operator TVector3 () const noexcept { return TVector3(static_cast(X), static_cast(Y), static_cast(Z)); } - void Zero() + constexpr void Zero() { Z = Y = X = 0; } - bool isZero() const + constexpr bool isZero() const { return X == 0 && Y == 0 && Z == 0; } - TVector3 plusZ(double z) const + constexpr TVector3 plusZ(double z) const { return { X, Y, Z + z }; } - TVector3 &operator= (const TVector3 &other) = default; + constexpr TVector3 &operator= (const TVector3 &other) = default; // Access X and Y and Z as an array - vec_t &operator[] (int index) + constexpr vec_t &operator[] (int index) { return index == 0 ? X : index == 1 ? Y : Z; } - const vec_t &operator[] (int index) const + constexpr const vec_t &operator[] (int index) const { return index == 0 ? X : index == 1 ? Y : Z; } // Test for equality - bool operator== (const TVector3 &other) const + constexpr bool operator== (const TVector3 &other) const { return X == other.X && Y == other.Y && Z == other.Z; } // Test for inequality - bool operator!= (const TVector3 &other) const + constexpr bool operator!= (const TVector3 &other) const { return X != other.X || Y != other.Y || Z != other.Z; } @@ -439,140 +435,140 @@ struct TVector3 } // Unary negation - TVector3 operator- () const + constexpr TVector3 operator- () const { return TVector3(-X, -Y, -Z); } // Scalar addition #if 0 - TVector3 &operator+= (vec_t scalar) + constexpr TVector3 &operator+= (vec_t scalar) { X += scalar, Y += scalar, Z += scalar; return *this; } #endif - friend TVector3 operator+ (const TVector3 &v, vec_t scalar) + constexpr friend TVector3 operator+ (const TVector3 &v, vec_t scalar) { return TVector3(v.X + scalar, v.Y + scalar, v.Z + scalar); } - friend TVector3 operator+ (vec_t scalar, const TVector3 &v) + constexpr friend TVector3 operator+ (vec_t scalar, const TVector3 &v) { return TVector3(v.X + scalar, v.Y + scalar, v.Z + scalar); } // Scalar subtraction - TVector3 &operator-= (vec_t scalar) + constexpr TVector3 &operator-= (vec_t scalar) { X -= scalar, Y -= scalar, Z -= scalar; return *this; } - TVector3 operator- (vec_t scalar) const + constexpr TVector3 operator- (vec_t scalar) const { return TVector3(X - scalar, Y - scalar, Z - scalar); } // Scalar multiplication - TVector3 &operator*= (vec_t scalar) + constexpr TVector3 &operator*= (vec_t scalar) { X = vec_t(X *scalar), Y = vec_t(Y * scalar), Z = vec_t(Z * scalar); return *this; } - friend TVector3 operator* (const TVector3 &v, vec_t scalar) + constexpr friend TVector3 operator* (const TVector3 &v, vec_t scalar) { return TVector3(v.X * scalar, v.Y * scalar, v.Z * scalar); } - friend TVector3 operator* (vec_t scalar, const TVector3 &v) + constexpr friend TVector3 operator* (vec_t scalar, const TVector3 &v) { return TVector3(v.X * scalar, v.Y * scalar, v.Z * scalar); } // Scalar division - TVector3 &operator/= (vec_t scalar) + constexpr TVector3 &operator/= (vec_t scalar) { scalar = 1 / scalar, X = vec_t(X * scalar), Y = vec_t(Y * scalar), Z = vec_t(Z * scalar); return *this; } - TVector3 operator/ (vec_t scalar) const + constexpr TVector3 operator/ (vec_t scalar) const { scalar = 1 / scalar; return TVector3(X * scalar, Y * scalar, Z * scalar); } // Vector addition - TVector3 &operator+= (const TVector3 &other) + constexpr TVector3 &operator+= (const TVector3 &other) { X += other.X, Y += other.Y, Z += other.Z; return *this; } - TVector3 operator+ (const TVector3 &other) const + constexpr TVector3 operator+ (const TVector3 &other) const { return TVector3(X + other.X, Y + other.Y, Z + other.Z); } // Vector subtraction - TVector3 &operator-= (const TVector3 &other) + constexpr TVector3 &operator-= (const TVector3 &other) { X -= other.X, Y -= other.Y, Z -= other.Z; return *this; } - TVector3 operator- (const TVector3 &other) const + constexpr TVector3 operator- (const TVector3 &other) const { return TVector3(X - other.X, Y - other.Y, Z - other.Z); } // Add a 2D vector to this 3D vector, leaving Z unchanged. - TVector3 &operator+= (const Vector2 &other) + constexpr TVector3 &operator+= (const Vector2 &other) { X += other.X, Y += other.Y; return *this; } // Subtract a 2D vector from this 3D vector, leaving Z unchanged. - TVector3 &operator-= (const Vector2 &other) + constexpr TVector3 &operator-= (const Vector2 &other) { X -= other.X, Y -= other.Y; return *this; } // returns the XY fields as a 2D-vector. - const Vector2& XY() const + constexpr const Vector2& XY() const { return *reinterpret_cast(this); } - Vector2& XY() + constexpr Vector2& XY() { return *reinterpret_cast(this); } // Add a 3D vector and a 2D vector. - friend TVector3 operator+ (const TVector3 &v3, const Vector2 &v2) + constexpr friend TVector3 operator+ (const TVector3 &v3, const Vector2 &v2) { return TVector3(v3.X + v2.X, v3.Y + v2.Y, v3.Z); } - friend TVector3 operator- (const TVector3 &v3, const Vector2 &v2) + constexpr friend TVector3 operator- (const TVector3 &v3, const Vector2 &v2) { return TVector3(v3.X - v2.X, v3.Y - v2.Y, v3.Z); } - friend Vector2 operator+ (const Vector2 &v2, const TVector3 &v3) + constexpr friend Vector2 operator+ (const Vector2 &v2, const TVector3 &v3) { return Vector2(v2.X + v3.X, v2.Y + v3.Y); } // Subtract a 3D vector and a 2D vector. // Discards the Z component of the 3D vector and returns a 2D vector. - friend Vector2 operator- (const TVector2 &v2, const TVector3 &v3) + constexpr friend Vector2 operator- (const TVector2 &v2, const TVector3 &v3) { return Vector2(v2.X - v3.X, v2.Y - v3.Y); } @@ -635,7 +631,7 @@ struct TVector3 return g_sqrt (LengthSquared()); } - double LengthSquared() const + constexpr double LengthSquared() const { return X*X + Y*Y + Z*Z; } @@ -691,25 +687,25 @@ struct TVector3 } // Dot product - vec_t operator | (const TVector3 &other) const + constexpr vec_t operator | (const TVector3 &other) const { return X*other.X + Y*other.Y + Z*other.Z; } - vec_t dot (const TVector3& other) const + constexpr vec_t dot (const TVector3& other) const { return X * other.X + Y * other.Y + Z * other.Z; } // Cross product - TVector3 operator ^ (const TVector3 &other) const + constexpr TVector3 operator ^ (const TVector3 &other) const { return TVector3(Y*other.Z - Z*other.Y, Z*other.X - X*other.Z, X*other.Y - Y*other.X); } - TVector3 &operator ^= (const TVector3 &other) + constexpr TVector3 &operator ^= (const TVector3 &other) { *this = *this ^ other; return *this; @@ -724,88 +720,88 @@ struct TVector4 vec_t X, Y, Z, W; - TVector4() = default; + constexpr TVector4() = default; - TVector4(vec_t a, vec_t b, vec_t c, vec_t d) + constexpr TVector4(vec_t a, vec_t b, vec_t c, vec_t d) : X(a), Y(b), Z(c), W(d) { } - TVector4(vec_t *o) + constexpr TVector4(vec_t *o) : X(o[0]), Y(o[1]), Z(o[2]), W(o[3]) { } - TVector4(const TVector4 &other) = default; + constexpr TVector4(const TVector4 &other) = default; - TVector4(const Vector3 &xyz, vec_t w) + constexpr TVector4(const Vector3 &xyz, vec_t w) : X(xyz.X), Y(xyz.Y), Z(xyz.Z), W(w) { } - TVector4(const vec_t v[4]) + constexpr TVector4(const vec_t v[4]) : TVector4(v[0], v[1], v[2], v[3]) { } template - explicit operator TVector4 () const noexcept { + constexpr explicit operator TVector4 () const noexcept { return TVector4(static_cast(X), static_cast(Y), static_cast(Z), static_cast(W)); } - void Zero() + constexpr void Zero() { Z = Y = X = W = 0; } - bool isZero() const + constexpr bool isZero() const { return X == 0 && Y == 0 && Z == 0 && W == 0; } - TVector4 &operator= (const TVector4 &other) = default; + constexpr TVector4 &operator= (const TVector4 &other) = default; // Access X and Y and Z as an array - vec_t &operator[] (int index) + constexpr vec_t &operator[] (int index) { return (&X)[index]; } - const vec_t &operator[] (int index) const + constexpr const vec_t &operator[] (int index) const { return (&X)[index]; } // Test for equality - bool operator== (const TVector4 &other) const + constexpr bool operator== (const TVector4 &other) const { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } // Test for inequality - bool operator!= (const TVector4 &other) const + constexpr bool operator!= (const TVector4 &other) const { return X != other.X || Y != other.Y || Z != other.Z || W != other.W; } // returns the XY fields as a 2D-vector. - const Vector2& XY() const + constexpr const Vector2& XY() const { return *reinterpret_cast(this); } - Vector2& XY() + constexpr Vector2& XY() { return *reinterpret_cast(this); } // returns the XY fields as a 2D-vector. - const Vector3& XYZ() const + constexpr const Vector3& XYZ() const { return *reinterpret_cast(this); } - Vector3& XYZ() + constexpr Vector3& XYZ() { return *reinterpret_cast(this); } @@ -824,127 +820,127 @@ struct TVector4 } // Unary negation - TVector4 operator- () const + constexpr TVector4 operator- () const { return TVector4(-X, -Y, -Z, -W); } // Scalar addition - TVector4 &operator+= (vec_t scalar) + constexpr TVector4 &operator+= (vec_t scalar) { X += scalar, Y += scalar, Z += scalar; W += scalar; return *this; } - friend TVector4 operator+ (const TVector4 &v, vec_t scalar) + constexpr friend TVector4 operator+ (const TVector4 &v, vec_t scalar) { return TVector4(v.X + scalar, v.Y + scalar, v.Z + scalar, v.W + scalar); } - friend TVector4 operator+ (vec_t scalar, const TVector4 &v) + constexpr friend TVector4 operator+ (vec_t scalar, const TVector4 &v) { return TVector4(v.X + scalar, v.Y + scalar, v.Z + scalar, v.W + scalar); } // Scalar subtraction - TVector4 &operator-= (vec_t scalar) + constexpr TVector4 &operator-= (vec_t scalar) { X -= scalar, Y -= scalar, Z -= scalar, W -= scalar; return *this; } - TVector4 operator- (vec_t scalar) const + constexpr TVector4 operator- (vec_t scalar) const { return TVector4(X - scalar, Y - scalar, Z - scalar, W - scalar); } // Scalar multiplication - TVector4 &operator*= (vec_t scalar) + constexpr TVector4 &operator*= (vec_t scalar) { X = vec_t(X *scalar), Y = vec_t(Y * scalar), Z = vec_t(Z * scalar), W = vec_t(W * scalar); return *this; } - friend TVector4 operator* (const TVector4 &v, vec_t scalar) + constexpr friend TVector4 operator* (const TVector4 &v, vec_t scalar) { return TVector4(v.X * scalar, v.Y * scalar, v.Z * scalar, v.W * scalar); } - friend TVector4 operator* (vec_t scalar, const TVector4 &v) + constexpr friend TVector4 operator* (vec_t scalar, const TVector4 &v) { return TVector4(v.X * scalar, v.Y * scalar, v.Z * scalar, v.W * scalar); } // Scalar division - TVector4 &operator/= (vec_t scalar) + constexpr TVector4 &operator/= (vec_t scalar) { scalar = 1 / scalar, X = vec_t(X * scalar), Y = vec_t(Y * scalar), Z = vec_t(Z * scalar), W = vec_t(W * scalar); return *this; } - TVector4 operator/ (vec_t scalar) const + constexpr TVector4 operator/ (vec_t scalar) const { scalar = 1 / scalar; return TVector4(X * scalar, Y * scalar, Z * scalar, W * scalar); } // Vector addition - TVector4 &operator+= (const TVector4 &other) + constexpr TVector4 &operator+= (const TVector4 &other) { X += other.X, Y += other.Y, Z += other.Z, W += other.W; return *this; } - TVector4 operator+ (const TVector4 &other) const + constexpr TVector4 operator+ (const TVector4 &other) const { return TVector4(X + other.X, Y + other.Y, Z + other.Z, W + other.W); } // Vector subtraction - TVector4 &operator-= (const TVector4 &other) + constexpr TVector4 &operator-= (const TVector4 &other) { X -= other.X, Y -= other.Y, Z -= other.Z, W -= other.W; return *this; } - TVector4 operator- (const TVector4 &other) const + constexpr TVector4 operator- (const TVector4 &other) const { return TVector4(X - other.X, Y - other.Y, Z - other.Z, W - other.W); } // Add a 3D vector to this 4D vector, leaving W unchanged. - TVector4 &operator+= (const Vector3 &other) + constexpr TVector4 &operator+= (const Vector3 &other) { X += other.X, Y += other.Y, Z += other.Z; return *this; } // Subtract a 3D vector from this 4D vector, leaving W unchanged. - TVector4 &operator-= (const Vector3 &other) + constexpr TVector4 &operator-= (const Vector3 &other) { X -= other.X, Y -= other.Y, Z -= other.Z; return *this; } // Add a 4D vector and a 3D vector. - friend TVector4 operator+ (const TVector4 &v4, const Vector3 &v3) + constexpr friend TVector4 operator+ (const TVector4 &v4, const Vector3 &v3) { return TVector4(v4.X + v3.X, v4.Y + v3.Y, v4.Z + v3.Z, v4.W); } - friend TVector4 operator- (const TVector4 &v4, const Vector3 &v3) + constexpr friend TVector4 operator- (const TVector4 &v4, const Vector3 &v3) { return TVector4(v4.X - v3.X, v4.Y - v3.Y, v4.Z - v3.Z, v4.W); } - friend Vector3 operator+ (const Vector3 &v3, const TVector4 &v4) + constexpr friend Vector3 operator+ (const Vector3 &v3, const TVector4 &v4) { return Vector3(v3.X + v4.X, v3.Y + v4.Y, v3.Z + v4.Z); } // Subtract a 4D vector and a 3D vector. // Discards the W component of the 4D vector and returns a 3D vector. - friend Vector3 operator- (const TVector3 &v3, const TVector4 &v4) + constexpr friend Vector3 operator- (const TVector3 &v3, const TVector4 &v4) { return Vector3(v3.X - v4.X, v3.Y - v4.Y, v3.Z - v4.Z); } @@ -955,7 +951,7 @@ struct TVector4 return g_sqrt(LengthSquared()); } - double LengthSquared() const + constexpr double LengthSquared() const { return X*X + Y*Y + Z*Z + W*W; } @@ -1012,12 +1008,12 @@ struct TVector4 } // Dot product - vec_t operator | (const TVector4 &other) const + constexpr vec_t operator | (const TVector4 &other) const { return X*other.X + Y*other.Y + Z*other.Z + W*other.W; } - vec_t dot(const TVector4 &other) const + constexpr vec_t dot(const TVector4 &other) const { return X*other.X + Y*other.Y + Z*other.Z + W*other.W; } @@ -1030,11 +1026,11 @@ struct TMatrix3x3 vec_t Cells[3][3]; - TMatrix3x3() = default; - TMatrix3x3(const TMatrix3x3 &other) = default; - TMatrix3x3& operator=(const TMatrix3x3& other) = default; + constexpr TMatrix3x3() = default; + constexpr TMatrix3x3(const TMatrix3x3 &other) = default; + constexpr TMatrix3x3& operator=(const TMatrix3x3& other) = default; - TMatrix3x3(const Vector3 &row1, const Vector3 &row2, const Vector3 &row3) + constexpr TMatrix3x3(const Vector3 &row1, const Vector3 &row2, const Vector3 &row3) { (*this)[0] = row1; (*this)[1] = row2; @@ -1043,16 +1039,16 @@ struct TMatrix3x3 // Construct a rotation matrix about an arbitrary axis. // (The axis vector must be normalized.) - TMatrix3x3(const Vector3 &axis, double degrees) + constexpr TMatrix3x3(const Vector3 &axis, double degrees) : TMatrix3x3(axis, g_sindeg(degrees), g_cosdeg(degrees)) { } - TMatrix3x3(const Vector3 &axis, double c/*cosine*/, double s/*sine*/) + constexpr TMatrix3x3(const Vector3 &axis, double c/*cosine*/, double s/*sine*/) { double t = 1 - c; double sx = s*axis.X, sy = s*axis.Y, sz = s*axis.Z; - double tx, ty, txx, tyy, u, v; + double tx = 0, ty = 0, txx = 0, tyy = 0, u = 0, v = 0; tx = t*axis.X; Cells[0][0] = vec_t( (txx=tx*axis.X) + c ); @@ -1082,7 +1078,7 @@ struct TMatrix3x3 return ret; } - static TMatrix3x3 Scale2D(TVector2 scaleVec) + constexpr static TMatrix3x3 Scale2D(TVector2 scaleVec) { TMatrix3x3 ret; ret.Cells[0][0] = scaleVec.X; ret.Cells[0][1] = 0; ret.Cells[0][2] = 0; @@ -1091,7 +1087,7 @@ struct TMatrix3x3 return ret; } - static TMatrix3x3 Translate2D(TVector2 translateVec) + constexpr static TMatrix3x3 Translate2D(TVector2 translateVec) { TMatrix3x3 ret; ret.Cells[0][0] = 1; ret.Cells[0][1] = 0; ret.Cells[0][2] = translateVec.X; @@ -1100,30 +1096,30 @@ struct TMatrix3x3 return ret; } - void Zero() + constexpr void Zero() { memset (this, 0, sizeof *this); } - void Identity() + constexpr void Identity() { Cells[0][0] = 1; Cells[0][1] = 0; Cells[0][2] = 0; Cells[1][0] = 0; Cells[1][1] = 1; Cells[1][2] = 0; Cells[2][0] = 0; Cells[2][1] = 0; Cells[2][2] = 1; } - Vector3 &operator[] (int index) + constexpr Vector3 &operator[] (int index) { return *((Vector3 *)&Cells[index]); } - const Vector3 &operator[] (int index) const + constexpr const Vector3 &operator[] (int index) const { return *((Vector3 *)&Cells[index]); } // Multiply a scalar - TMatrix3x3 &operator*= (double scalar) + constexpr TMatrix3x3 &operator*= (double scalar) { (*this)[0] *= scalar; (*this)[1] *= scalar; @@ -1131,29 +1127,29 @@ struct TMatrix3x3 return *this; } - friend TMatrix3x3 operator* (double s, const TMatrix3x3 &m) + constexpr friend TMatrix3x3 operator* (double s, const TMatrix3x3 &m) { return TMatrix3x3(m[0]*s, m[1]*s, m[2]*s); } - TMatrix3x3 operator* (double s) const + constexpr TMatrix3x3 operator* (double s) const { return TMatrix3x3((*this)[0]*s, (*this)[1]*s, (*this)[2]*s); } // Divide a scalar - TMatrix3x3 &operator/= (double scalar) + constexpr TMatrix3x3 &operator/= (double scalar) { return *this *= 1 / scalar; } - TMatrix3x3 operator/ (double s) const + constexpr TMatrix3x3 operator/ (double s) const { return *this * (1 / s); } // Add two 3x3 matrices together - TMatrix3x3 &operator+= (const TMatrix3x3 &o) + constexpr TMatrix3x3 &operator+= (const TMatrix3x3 &o) { (*this)[0] += o[0]; (*this)[1] += o[1]; @@ -1161,13 +1157,13 @@ struct TMatrix3x3 return *this; } - TMatrix3x3 operator+ (const TMatrix3x3 &o) const + constexpr TMatrix3x3 operator+ (const TMatrix3x3 &o) const { return TMatrix3x3((*this)[0] + o[0], (*this)[1] + o[1], (*this)[2] + o[2]); } // Subtract two 3x3 matrices - TMatrix3x3 &operator-= (const TMatrix3x3 &o) + constexpr TMatrix3x3 &operator-= (const TMatrix3x3 &o) { (*this)[0] -= o[0]; (*this)[1] -= o[1]; @@ -1175,18 +1171,18 @@ struct TMatrix3x3 return *this; } - TMatrix3x3 operator- (const TMatrix3x3 &o) const + constexpr TMatrix3x3 operator- (const TMatrix3x3 &o) const { return TMatrix3x3((*this)[0] - o[0], (*this)[1] - o[1], (*this)[2] - o[2]); } // Concatenate two 3x3 matrices - TMatrix3x3 &operator*= (const TMatrix3x3 &o) + constexpr TMatrix3x3 &operator*= (const TMatrix3x3 &o) { return *this = *this * o; } - TMatrix3x3 operator* (const TMatrix3x3 &o) const + constexpr TMatrix3x3 operator* (const TMatrix3x3 &o) const { return TMatrix3x3( Vector3(Cells[0][0]*o[0][0] + Cells[0][1]*o[1][0] + Cells[0][2]*o[2][0], @@ -1201,12 +1197,12 @@ struct TMatrix3x3 } // Multiply a 3D vector by a rotation matrix - friend Vector3 operator* (const Vector3 &v, const TMatrix3x3 &m) + constexpr friend Vector3 operator* (const Vector3 &v, const TMatrix3x3 &m) { return Vector3(m[0] | v, m[1] | v, m[2] | v); } - friend Vector3 operator* (const TMatrix3x3 &m, const Vector3 &v) + constexpr friend Vector3 operator* (const TMatrix3x3 &m, const Vector3 &v) { return Vector3(m[0] | v, m[1] | v, m[2] | v); } @@ -1243,7 +1239,7 @@ private: } public: - vec_t& Degrees__() { return Degrees_; } + constexpr vec_t& Degrees__() { return Degrees_; } static constexpr TAngle fromDeg(float deg) { @@ -1290,8 +1286,8 @@ public: return TAngle(bang * (90. / 16384)); } - TAngle(const TAngle &other) = default; - TAngle &operator= (const TAngle &other) = default; + constexpr TAngle(const TAngle &other) = default; + constexpr TAngle &operator= (const TAngle &other) = default; constexpr TAngle operator- () const { @@ -1462,6 +1458,24 @@ public: } }; +typedef TAngle FAngle; +typedef TAngle DAngle; + +constexpr DAngle nullAngle = DAngle::fromDeg(0.); +constexpr FAngle nullFAngle = FAngle::fromDeg(0.); +constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); +constexpr FAngle minFAngle = FAngle::fromDeg(1. / 65536.); + +constexpr DAngle DAngle1 = DAngle::fromDeg(1); +constexpr DAngle DAngle15 = DAngle::fromDeg(15); +constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); +constexpr DAngle DAngle45 = DAngle::fromDeg(45); +constexpr DAngle DAngle60 = DAngle::fromDeg(60); +constexpr DAngle DAngle90 = DAngle::fromDeg(90); +constexpr DAngle DAngle180 = DAngle::fromDeg(180); +constexpr DAngle DAngle270 = DAngle::fromDeg(270); +constexpr DAngle DAngle360 = DAngle::fromDeg(360); + template inline TAngle fabs (const TAngle °) { @@ -1522,11 +1536,23 @@ TAngle TVector3::Pitch() const } template -inline TVector2 clamp(const TVector2 &vec, const TVector2 &min, const TVector2 &max) +constexpr inline TVector2 clamp(const TVector2 &vec, const TVector2 &min, const TVector2 &max) { return TVector2(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y)); } +template +constexpr inline TVector3 clamp(const TVector3 &vec, const TVector3 &min, const TVector3 &max) +{ + return TVector3(std::clamp(vec.X, min.X, max.X), std::clamp(vec.Y, min.Y, max.Y), std::clamp(vec.Z, min.Z, max.Z)); +} + +template +constexpr inline TRotator clamp(const TRotator &rot, const TRotator &min, const TRotator &max) +{ + return TRotator(clamp(rot.Pitch, min.Pitch, max.Pitch), clamp(rot.Yaw, min.Yaw, max.Yaw), clamp(rot.Roll, min.Roll, max.Roll)); +} + template inline TAngle interpolatedvalue(const TAngle &oang, const TAngle &ang, const double interpfrac) { @@ -1544,7 +1570,7 @@ inline TRotator interpolatedvalue(const TRotator &oang, const TRotator } template -inline T interpolatedvalue(const T& oval, const T& val, const double interpfrac) +constexpr inline T interpolatedvalue(const T& oval, const T& val, const double interpfrac) { return T(oval + (val - oval) * interpfrac); } @@ -1559,125 +1585,162 @@ struct TRotator Angle Yaw; // left/right Angle Roll; // rotation about the forward axis. - TRotator() = default; + constexpr TRotator() = default; - TRotator (const Angle &p, const Angle &y, const Angle &r) + constexpr TRotator (const Angle &p, const Angle &y, const Angle &r) : Pitch(p), Yaw(y), Roll(r) { } - TRotator(const TRotator &other) = default; - TRotator &operator= (const TRotator &other) = default; + constexpr TRotator(const TRotator &other) = default; + constexpr TRotator &operator= (const TRotator &other) = default; + + constexpr void Zero() + { + Roll = Yaw = Pitch = nullAngle; + } + + constexpr bool isZero() const + { + return Pitch == nullAngle && Yaw == nullAngle && Roll == nullAngle; + } // Access angles as an array - Angle &operator[] (int index) + constexpr Angle &operator[] (int index) { return *(&Pitch + index); } - const Angle &operator[] (int index) const + constexpr const Angle &operator[] (int index) const { return *(&Pitch + index); } // Test for equality - bool operator== (const TRotator &other) const + constexpr bool operator== (const TRotator &other) const { - return fabs(Pitch - other.Pitch) < Angle(EQUAL_EPSILON) && fabs(Yaw - other.Yaw) < Angle(EQUAL_EPSILON) && fabs(Roll - other.Roll) < Angle(EQUAL_EPSILON); + return Pitch == other.Pitch && Yaw == other.Yaw && Roll == other.Roll; } // Test for inequality - bool operator!= (const TRotator &other) const + constexpr bool operator!= (const TRotator &other) const { - return fabs(Pitch - other.Pitch) >= Angle(EQUAL_EPSILON) && fabs(Yaw - other.Yaw) >= Angle(EQUAL_EPSILON) && fabs(Roll - other.Roll) >= Angle(EQUAL_EPSILON); + return Pitch != other.Pitch || Yaw != other.Yaw || Roll != other.Roll; + } + + // Test for approximate equality + bool ApproximatelyEquals (const TRotator &other) const + { + constexpr auto epsilon = Angle(EQUAL_EPSILON); + return fabs(Pitch - other.Pitch) < epsilon && fabs(Yaw - other.Yaw) < epsilon && fabs(Roll - other.Roll) < epsilon; + } + + // Test for approximate inequality + bool DoesNotApproximatelyEqual (const TRotator &other) const + { + constexpr auto epsilon = Angle(EQUAL_EPSILON); + return fabs(Pitch - other.Pitch) >= epsilon && fabs(Yaw - other.Yaw) >= epsilon && fabs(Roll - other.Roll) >= epsilon; } // Unary negation - TRotator operator- () const + constexpr TRotator operator- () const { return TRotator(-Pitch, -Yaw, -Roll); } // Scalar addition - TRotator &operator+= (const Angle &scalar) + constexpr TRotator &operator+= (const Angle &scalar) { Pitch += scalar, Yaw += scalar, Roll += scalar; return *this; } - friend TRotator operator+ (const TRotator &v, const Angle &scalar) + constexpr friend TRotator operator+ (const TRotator &v, const Angle &scalar) { return TRotator(v.Pitch + scalar, v.Yaw + scalar, v.Roll + scalar); } - friend TRotator operator+ (const Angle &scalar, const TRotator &v) + constexpr friend TRotator operator+ (const Angle &scalar, const TRotator &v) { return TRotator(v.Pitch + scalar, v.Yaw + scalar, v.Roll + scalar); } // Scalar subtraction - TRotator &operator-= (const Angle &scalar) + constexpr TRotator &operator-= (const Angle &scalar) { Pitch -= scalar, Yaw -= scalar, Roll -= scalar; return *this; } - TRotator operator- (const Angle &scalar) const + constexpr TRotator operator- (const Angle &scalar) const { return TRotator(Pitch - scalar, Yaw - scalar, Roll - scalar); } // Scalar multiplication - TRotator &operator*= (const Angle &scalar) + constexpr TRotator &operator*= (const Angle &scalar) { Pitch *= scalar, Yaw *= scalar, Roll *= scalar; return *this; } - friend TRotator operator* (const TRotator &v, const Angle &scalar) + constexpr friend TRotator operator* (const TRotator &v, const Angle &scalar) { return TRotator(v.Pitch * scalar, v.Yaw * scalar, v.Roll * scalar); } - friend TRotator operator* (const Angle &scalar, const TRotator &v) + constexpr friend TRotator operator* (const Angle &scalar, const TRotator &v) { return TRotator(v.Pitch * scalar, v.Yaw * scalar, v.Roll * scalar); } // Scalar division - TRotator &operator/= (const Angle &scalar) + constexpr TRotator &operator/= (const Angle &scalar) { Angle mul(1 / scalar.Degrees_); Pitch *= mul, Yaw *= mul, Roll *= mul; return *this; } - TRotator operator/ (const Angle &scalar) const + constexpr TRotator &operator/= (const vec_t &scalar) + { + const auto mul = 1. / scalar; + Pitch *= mul, Yaw *= mul, Roll *= mul; + return *this; + } + + constexpr TRotator operator/ (const Angle &scalar) const { Angle mul(1 / scalar.Degrees_); return TRotator(Pitch * mul, Yaw * mul, Roll * mul); } + constexpr TRotator operator/ (const vec_t &scalar) const + { + const auto mul = 1. / scalar; + return TRotator(Pitch * mul, Yaw * mul, Roll * mul); + } + // Vector addition - TRotator &operator+= (const TRotator &other) + constexpr TRotator &operator+= (const TRotator &other) { Pitch += other.Pitch, Yaw += other.Yaw, Roll += other.Roll; return *this; } - TRotator operator+ (const TRotator &other) const + constexpr TRotator operator+ (const TRotator &other) const { return TRotator(Pitch + other.Pitch, Yaw + other.Yaw, Roll + other.Roll); } // Vector subtraction - TRotator &operator-= (const TRotator &other) + constexpr TRotator &operator-= (const TRotator &other) { Pitch -= other.Pitch, Yaw -= other.Yaw, Roll -= other.Roll; return *this; } - TRotator operator- (const TRotator &other) const + constexpr TRotator operator- (const TRotator &other) const { return TRotator(Pitch - other.Pitch, Yaw - other.Yaw, Roll - other.Roll); } @@ -1718,28 +1781,12 @@ typedef TVector3 FVector3; typedef TVector4 FVector4; typedef TRotator FRotator; typedef TMatrix3x3 FMatrix3x3; -typedef TAngle FAngle; typedef TVector2 DVector2; typedef TVector3 DVector3; typedef TVector4 DVector4; typedef TRotator DRotator; typedef TMatrix3x3 DMatrix3x3; -typedef TAngle DAngle; - -constexpr DAngle nullAngle = DAngle::fromDeg(0.); -constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); -constexpr FAngle nullFAngle = FAngle::fromDeg(0.); - -constexpr DAngle DAngle1 = DAngle::fromDeg(1); -constexpr DAngle DAngle15 = DAngle::fromDeg(15); -constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); -constexpr DAngle DAngle45 = DAngle::fromDeg(45); -constexpr DAngle DAngle60 = DAngle::fromDeg(60); -constexpr DAngle DAngle90 = DAngle::fromDeg(90); -constexpr DAngle DAngle180 = DAngle::fromDeg(180); -constexpr DAngle DAngle270 = DAngle::fromDeg(270); -constexpr DAngle DAngle360 = DAngle::fromDeg(360); class Plane { diff --git a/src/common/utility/zstring.cpp b/src/common/utility/zstring.cpp index c8d8e7b5b..160647b7b 100644 --- a/src/common/utility/zstring.cpp +++ b/src/common/utility/zstring.cpp @@ -842,12 +842,12 @@ void FString::StripLeftRight () if (max == 0) return; for (i = 0; i < max; ++i) { - if (Chars[i] < 0 || !isspace((unsigned char)Chars[i])) + if ((signed char)Chars[i] < 0 || !isspace((unsigned char)Chars[i])) break; } for (j = max - 1; j >= i; --j) { - if (Chars[j] < 0 || !isspace((unsigned char)Chars[j])) + if ((signed char)Chars[j] < 0 || !isspace((unsigned char)Chars[j])) break; } if (i == 0 && j == max - 1) diff --git a/src/g_game.cpp b/src/g_game.cpp index 2d69009e8..ba3b8ea4b 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1471,7 +1471,7 @@ bool FLevelLocals::CheckSpot (int playernum, FPlayerStart *mthing) // return false; players[playernum].mo->flags |= MF_SOLID; - i = P_CheckPosition(players[playernum].mo, spot); + i = P_CheckPosition(players[playernum].mo, spot.XY()); players[playernum].mo->flags &= ~MF_SOLID; players[playernum].mo->SetZ(oldz); // [RH] Restore corpse's height if (!i) diff --git a/src/g_levellocals.h b/src/g_levellocals.h index b50b19fe4..504eea607 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -379,6 +379,11 @@ public: return PointInSubsector(pos.X, pos.Y)->sector; } + sector_t* PointInSector(const DVector3& pos) + { + return PointInSubsector(pos.X, pos.Y)->sector; + } + sector_t *PointInSector(double x, double y) { return PointInSubsector(x, y)->sector; @@ -389,6 +394,11 @@ public: return PointInRenderSubsector(FloatToFixed(pos.X), FloatToFixed(pos.Y)); } + subsector_t* PointInRenderSubsector(const DVector3& pos) + { + return PointInRenderSubsector(FloatToFixed(pos.X), FloatToFixed(pos.Y)); + } + FPolyObj *GetPolyobj (int polyNum) { auto index = Polyobjects.FindEx([=](const auto &poly) { return poly.tag == polyNum; }); @@ -873,7 +883,7 @@ inline bool line_t::hitSkyWall(AActor* mo) const { return backsector && backsector->GetTexture(sector_t::ceiling) == skyflatnum && - mo->Z() >= backsector->ceilingplane.ZatPoint(mo->PosRelative(this)); + mo->Z() >= backsector->ceilingplane.ZatPoint(mo->PosRelative(this).XY()); } // This must later be extended to return an array with all levels. diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index c6284b2f1..4af030b28 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -364,11 +364,21 @@ public: return (D + normal.X*pos.X + normal.Y*pos.Y) * negiC; } + double ZatPoint(const DVector3& pos) const + { + return (D + normal.X * pos.X + normal.Y * pos.Y) * negiC; + } + double ZatPoint(const FVector2 &pos) const { return (D + normal.X*pos.X + normal.Y*pos.Y) * negiC; } + double ZatPoint(const FVector3& pos) const + { + return (D + normal.X * pos.X + normal.Y * pos.Y) * negiC; + } + double ZatPoint(const vertex_t *v) const { return (D + normal.X*v->fX() + normal.Y*v->fY()) * negiC; diff --git a/src/maploader/polyobjects.cpp b/src/maploader/polyobjects.cpp index 00b7ccca4..b16942429 100644 --- a/src/maploader/polyobjects.cpp +++ b/src/maploader/polyobjects.cpp @@ -364,7 +364,7 @@ void MapLoader::PO_Init (void) if (type >= SMT_PolySpawn && type <= SMT_PolySpawnHurt) { // Polyobj StartSpot Pt. - Level->Polyobjects[polyIndex].StartSpot.pos = polythings[i]->pos; + Level->Polyobjects[polyIndex].StartSpot.pos = polythings[i]->pos.XY(); SpawnPolyobj(polyIndex, polythings[i]->angle, type); polyIndex++; } @@ -375,7 +375,7 @@ void MapLoader::PO_Init (void) if (type == SMT_PolyAnchor) { // Polyobj Anchor Pt. - TranslateToStartSpot (polythings[i]->angle, polythings[i]->pos); + TranslateToStartSpot (polythings[i]->angle, polythings[i]->pos.XY()); } } diff --git a/src/maploader/slopes.cpp b/src/maploader/slopes.cpp index 9567c6ef4..77c33cd74 100644 --- a/src/maploader/slopes.cpp +++ b/src/maploader/slopes.cpp @@ -424,7 +424,7 @@ void MapLoader::SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const i if (mt->info != NULL && mt->info->Type == NULL && (mt->info->Special == SMT_CopyFloorPlane || mt->info->Special == SMT_CopyCeilingPlane)) { - CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane); + CopyPlane (mt->args[0], mt->pos.XY(), mt->info->Special == SMT_CopyCeilingPlane); mt->EdNum = 0; } } diff --git a/src/maploader/specials.cpp b/src/maploader/specials.cpp index 117e266c9..6becec6e9 100644 --- a/src/maploader/specials.cpp +++ b/src/maploader/specials.cpp @@ -281,7 +281,7 @@ void MapLoader::SetupPortals() { if (s.mType == PORTS_STACKEDSECTORTHING && s.mSkybox) { - s.mDisplacement = s.mSkybox->Pos() - s.mSkybox->target->Pos(); + s.mDisplacement = s.mSkybox->Pos().XY() - s.mSkybox->target->Pos().XY(); s.mSkybox = nullptr; } } diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 6ebb7f1cd..5a58dfb44 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -960,13 +960,13 @@ public: double Distance2DSquared(AActor *other, bool absolute = false) { - DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + DVector2 otherpos = absolute ? other->Pos().XY() : other->PosRelative(this).XY(); return (Pos().XY() - otherpos).LengthSquared(); } double Distance2D(AActor *other, bool absolute = false) const { - DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + DVector2 otherpos = absolute ? other->Pos().XY() : other->PosRelative(this).XY(); return (Pos().XY() - otherpos).Length(); } @@ -997,19 +997,19 @@ public: DAngle AngleTo(AActor *other, bool absolute = false) { - DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + DVector2 otherpos = absolute ? other->Pos().XY() : other->PosRelative(this).XY(); return VecToAngle(otherpos - Pos().XY()); } DAngle AngleTo(AActor *other, double oxofs, double oyofs, bool absolute = false) const { - DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); + DVector2 otherpos = absolute ? other->Pos().XY() : other->PosRelative(this).XY(); return VecToAngle(otherpos - Pos() + DVector2(oxofs, oyofs)); } DVector2 Vec2To(AActor *other) const { - return other->PosRelative(this) - Pos(); + return other->PosRelative(this).XY() - Pos().XY(); } DVector3 Vec3To(AActor *other) const diff --git a/src/playsim/bots/b_func.cpp b/src/playsim/bots/b_func.cpp index 07cdd08d0..e537bf9f7 100644 --- a/src/playsim/bots/b_func.cpp +++ b/src/playsim/bots/b_func.cpp @@ -541,7 +541,7 @@ DAngle DBot::FireRox (AActor *enemy, ticcmd_t *cmd) //Predict. m = ((dist+1) / GetDefaultByName("Rocket")->Speed); - Level->BotInfo.SetBodyAt(Level, DVector3((enemy->Pos() + enemy->Vel * (m + 2)), ONFLOORZ), 1); + Level->BotInfo.SetBodyAt(Level, DVector3((enemy->Pos().XY() + enemy->Vel * (m + 2)), ONFLOORZ), 1); //try the predicted location if (P_CheckSight (actor, Level->BotInfo.body1, SF_IGNOREVISIBILITY)) //See the predicted location, so give a test missile diff --git a/src/playsim/bots/b_think.cpp b/src/playsim/bots/b_think.cpp index 12c7d4113..9fba192d5 100644 --- a/src/playsim/bots/b_think.cpp +++ b/src/playsim/bots/b_think.cpp @@ -339,7 +339,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd) if (t_fight<(AFTERTICS/2)) player->mo->flags |= MF_DROPOFF; - old = player->mo->Pos(); + old = player->mo->Pos().XY(); } int P_GetRealMaxHealth(AActor *actor, int max); diff --git a/src/playsim/fragglescript/t_func.cpp b/src/playsim/fragglescript/t_func.cpp index 28ff091c6..f9fff1b9e 100644 --- a/src/playsim/fragglescript/t_func.cpp +++ b/src/playsim/fragglescript/t_func.cpp @@ -2714,7 +2714,7 @@ void FParser::SF_MoveCamera(void) double targetheight = floatvalue(t_argv[2]); double movespeed = floatvalue(t_argv[3]); DVector3 campos = cam->Pos(); - DVector3 targpos = DVector3(target->Pos(), targetheight); + DVector3 targpos = DVector3(target->Pos().XY(), targetheight); DVector3 movement = targpos - campos; double movelen = movement.Length(); diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index de0abf053..681983f4f 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -2055,7 +2055,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Respawn) } else { - oktorespawn = P_CheckPosition(self, self->Pos(), true); + oktorespawn = P_CheckPosition(self, self->Pos().XY(), true); } if (oktorespawn) @@ -4752,7 +4752,7 @@ DEFINE_ACTION_FUNCTION(AActor, CheckBlock) if (flags & CBF_NOACTORS) fpass |= PCM_NOACTORS; if (flags & CBF_NOLINES) fpass |= PCM_NOLINES; mobj->SetZ(pos.Z); - checker = P_CheckMove(mobj, pos, fpass); + checker = P_CheckMove(mobj, pos.XY(), fpass); mobj->SetZ(oldpos.Z); } else diff --git a/src/playsim/p_destructible.cpp b/src/playsim/p_destructible.cpp index 126ddbd42..a40970c76 100644 --- a/src/playsim/p_destructible.cpp +++ b/src/playsim/p_destructible.cpp @@ -716,7 +716,7 @@ bool P_ProjectileHitLinedef(AActor* mo, line_t* line) } } - int wside = P_PointOnLineSide(mo->Pos(), line); + int wside = P_PointOnLineSide(mo->Pos().XY(), line); int oside = !wside; side_t* otherside = line->sidedef[oside]; // check if hit upper or lower part diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index a7588d1ba..6f9275257 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -703,7 +703,7 @@ void P_DrawRailTrail(AActor *source, TArray &portalhits, int color1, AActor *mo = player->camera; double r = ((seg.start.Y - mo->Y()) * (-seg.dir.Y) - (seg.start.X - mo->X()) * (seg.dir.X)) / (seg.length * seg.length); r = clamp(r, 0., 1.); - seg.soundpos = seg.start + r * seg.dir; + seg.soundpos = seg.start.XY() + r * seg.dir.XY(); seg.sounddist = (seg.soundpos - mo->Pos()).LengthSquared(); } else diff --git a/src/playsim/p_enemy.cpp b/src/playsim/p_enemy.cpp index b93f528a4..ab40fea65 100644 --- a/src/playsim/p_enemy.cpp +++ b/src/playsim/p_enemy.cpp @@ -604,7 +604,7 @@ static int P_Move (AActor *actor) move = move.Rotated(anglediff); oldangle = actor->Angles.Yaw; } - start = actor->Pos() - move * i / steps; + start = actor->Pos().XY() - move * i / steps; } } @@ -2640,7 +2640,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi if ((!fastchase || !actor->FastChaseStrafeCount) && !dontmove) { // CANTLEAVEFLOORPIC handling was completely missing in the non-serpent functions. - DVector2 old = actor->Pos(); + DVector2 old = actor->Pos().XY(); int oldgroup = actor->PrevPortalGroup; FTextureID oldFloor = actor->floorpic; @@ -2802,7 +2802,7 @@ bool P_CheckForResurrection(AActor* self, bool usevilestates, FState* state = nu corpsehit->flags |= MF_SOLID; corpsehit->Height = corpsehit->GetDefault()->Height; - bool check = P_CheckPosition(corpsehit, corpsehit->Pos()); + bool check = P_CheckPosition(corpsehit, corpsehit->Pos().XY()); corpsehit->flags = oldflags; corpsehit->radius = oldradius; corpsehit->Height = oldheight; diff --git a/src/playsim/p_lnspec.cpp b/src/playsim/p_lnspec.cpp index 0ac2c977e..407cc23e4 100644 --- a/src/playsim/p_lnspec.cpp +++ b/src/playsim/p_lnspec.cpp @@ -175,7 +175,7 @@ FUNC(LS_Polyobj_MoveToSpot) auto iterator = Level->GetActorIterator(arg2); AActor *spot = iterator.Next(); if (spot == NULL) return false; - return EV_MovePolyTo (Level, ln, arg0, SPEED(arg1), spot->Pos(), false); + return EV_MovePolyTo (Level, ln, arg0, SPEED(arg1), spot->Pos().XY(), false); } FUNC(LS_Polyobj_DoorSwing) @@ -226,7 +226,7 @@ FUNC(LS_Polyobj_OR_MoveToSpot) auto iterator = Level->GetActorIterator(arg2); AActor *spot = iterator.Next(); if (spot == NULL) return false; - return EV_MovePolyTo (Level, ln, arg0, SPEED(arg1), spot->Pos(), true); + return EV_MovePolyTo (Level, ln, arg0, SPEED(arg1), spot->Pos().XY(), true); } FUNC(LS_Polyobj_Stop) diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index edb865b16..015d40b11 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -267,7 +267,7 @@ static bool PIT_FindFloorCeiling(FMultiBlockLinesIterator &mit, FMultiBlockLines return true; } - DVector2 refpoint = FindRefPoint(ld, cres.Position); + DVector2 refpoint = FindRefPoint(ld, cres.Position.XY()); FLineOpening open; P_LineOpening(open, tmf.thing, ld, refpoint, &cres.Position, flags); @@ -851,8 +851,8 @@ bool PIT_CheckLine(FMultiBlockLinesIterator &mit, FMultiBlockLinesIterator::Chec { spechit_t spec; spec.line = ld; - spec.Refpos = cres.Position; - spec.Oldrefpos = tm.thing->PosRelative(ld); + spec.Refpos = cres.Position.XY(); + spec.Oldrefpos = tm.thing->PosRelative(ld).XY(); portalhit.Push(spec); return true; } @@ -963,12 +963,12 @@ bool PIT_CheckLine(FMultiBlockLinesIterator &mit, FMultiBlockLinesIterator::Chec tm.thing->BlockingLine = ld; } // Calculate line side based on the actor's original position, not the new one. - CheckForPushSpecial(ld, P_PointOnLineSide(cres.Position, ld), tm.thing); + CheckForPushSpecial(ld, P_PointOnLineSide(cres.Position.XY(), ld), tm.thing); return false; } } } - DVector2 ref = FindRefPoint(ld, cres.Position); + DVector2 ref = FindRefPoint(ld, cres.Position.XY()); FLineOpening open; P_LineOpening(open, tm.thing, ld, ref, &cres.Position, cres.portalflags); @@ -1089,15 +1089,15 @@ bool PIT_CheckLine(FMultiBlockLinesIterator &mit, FMultiBlockLinesIterator::Chec if (ld->special) { spec.line = ld; - spec.Refpos = cres.Position; - spec.Oldrefpos = tm.thing->PosRelative(ld); + spec.Refpos = cres.Position.XY(); + spec.Oldrefpos = tm.thing->PosRelative(ld).XY(); spechit.Push(spec); } if (ld->isLinePortal()) { spec.line = ld; - spec.Refpos = cres.Position; - spec.Oldrefpos = tm.thing->PosRelative(ld); + spec.Refpos = cres.Position.XY(); + spec.Oldrefpos = tm.thing->PosRelative(ld).XY(); portalhit.Push(spec); } @@ -1153,7 +1153,7 @@ static bool PIT_CheckPortal(FMultiBlockLinesIterator &mit, FMultiBlockLinesItera if (ld->backsector == NULL) continue; - DVector2 ref = FindRefPoint(ld, cres.Position); + DVector2 ref = FindRefPoint(ld, cres.Position.XY()); FLineOpening open; P_LineOpening(open, tm.thing, ld, ref, &cres.Position, 0); @@ -2017,7 +2017,7 @@ int P_TestMobjLocation(AActor *mobj) flags = mobj->flags; mobj->flags &= ~MF_PICKUP; - if (P_CheckPosition(mobj, mobj->Pos())) + if (P_CheckPosition(mobj, mobj->Pos().XY())) { // XY is ok, now check Z mobj->flags = flags; if ((mobj->Z() < mobj->floorz) || (mobj->Top() > mobj->ceilingz)) @@ -2547,7 +2547,7 @@ bool P_TryMove(AActor *thing, const DVector2 &pos, { FLinkContext ctx; thing->UnlinkFromWorld(&ctx); - thing->SetXY(tm.pos + port->mDisplacement); + thing->SetXY(tm.pos.XY() + port->mDisplacement); thing->Prev += port->mDisplacement; thing->LinkToWorld(&ctx); P_FindFloorCeiling(thing); @@ -2557,15 +2557,15 @@ bool P_TryMove(AActor *thing, const DVector2 &pos, } else if (!portalcrossed) { - DVector3 pos(tm.pos, thing->Z()); + DVector3 pos(tm.pos.XY(), thing->Z()); DVector3 oldthingpos = thing->Pos(); - DVector2 thingpos = oldthingpos; + DVector2 thingpos = oldthingpos.XY(); P_TranslatePortalXY(ld, pos.X, pos.Y); P_TranslatePortalXY(ld, thingpos.X, thingpos.Y); P_TranslatePortalZ(ld, pos.Z); thing->SetXYZ(thingpos.X, thingpos.Y, pos.Z); - if (!P_CheckPosition(thing, pos, true)) // check if some actor blocks us on the other side. (No line checks, because of the mess that'd create.) + if (!P_CheckPosition(thing, pos.XY(), true)) // check if some actor blocks us on the other side. (No line checks, because of the mess that'd create.) { thing->SetXYZ(oldthingpos); thing->flags6 &= ~MF6_INTRYMOVE; @@ -2644,7 +2644,7 @@ bool P_TryMove(AActor *thing, const DVector2 &pos, if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP))) { spechit_t spec; - DVector2 lastpos = thing->Pos(); + DVector2 lastpos = thing->Pos().XY(); while (spechit.Pop(spec)) { line_t *ld = spec.line; @@ -2988,7 +2988,7 @@ void FSlide::HitSlideLine(line_t* ld) // less than 45 degrees. // phares DVector3 pos = slidemo->PosRelative(ld); - side = P_PointOnLineSide(pos, ld); + side = P_PointOnLineSide(pos.XY(), ld); lineangle = ld->Delta().Angle(); @@ -3081,7 +3081,7 @@ void FSlide::SlideTraverse(const DVector2 &start, const DVector2 &end) if (!(li->flags & ML_TWOSIDED) || !li->backsector) { DVector3 pos = slidemo->PosRelative(li); - if (P_PointOnLineSide(pos, li)) + if (P_PointOnLineSide(pos.XY(), li)) { // don't hit the back side continue; @@ -3203,11 +3203,11 @@ retry: // killough 3/15/98: Allow objects to drop off ledges move = { 0, tryp.Y }; walkplane = P_CheckSlopeWalk(mo, move); - if (!P_TryMove(mo, mo->Pos() + move, true, walkplane)) + if (!P_TryMove(mo, mo->Pos().XY() + move, true, walkplane)) { move = { tryp.X, 0 }; walkplane = P_CheckSlopeWalk(mo, move); - P_TryMove(mo, mo->Pos() + move, true, walkplane); + P_TryMove(mo, mo->Pos().XY() + move, true, walkplane); } return; } @@ -3222,7 +3222,7 @@ retry: const DVector2 startvel = mo->Vel.XY(); // killough 3/15/98: Allow objects to drop off ledges - if (!P_TryMove(mo, mo->Pos() + newpos, true)) + if (!P_TryMove(mo, mo->Pos().XY() + newpos, true)) goto stairstep; if (mo->Vel.XY() != startvel) @@ -3255,7 +3255,7 @@ retry: walkplane = P_CheckSlopeWalk(mo, tmmove); // killough 3/15/98: Allow objects to drop off ledges - if (!P_TryMove(mo, mo->Pos() + tmmove, true, walkplane)) + if (!P_TryMove(mo, mo->Pos().XY() + tmmove, true, walkplane)) { goto retry; } @@ -3335,7 +3335,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move) DVector2 dest; double t; - dest = actor->Pos() + move; + dest = actor->Pos().XY() + move; t = (plane->Normal() | DVector3(dest, actor->Z())) + plane->fD(); if (t < 0) { // Desired location is behind (below) the plane @@ -3370,7 +3370,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move) } if (dopush) { - move = plane->Normal() * 2; + move = plane->Normal().XY() * 2; actor->Vel.X = move.X; actor->Vel.Y = move.Y; } @@ -3379,7 +3379,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move) } // Slide the desired location along the plane's normal // so that it lies on the plane's surface - dest -= plane->Normal() * t; + dest -= plane->Normal().XY() * t; move = dest - actor->Pos().XY(); return (actor->floorsector == actor->Sector) ? plane : NULL; } @@ -3389,7 +3389,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move) { // Actor's current spot is on/in the plane, so walk down it // Same principle as walking up, except reversed - dest += plane->Normal() * t; + dest += plane->Normal().XY() * t; move = dest - actor->Pos().XY(); return (actor->floorsector == actor->Sector) ? plane : NULL; } @@ -3428,7 +3428,7 @@ bool FSlide::BounceTraverse(const DVector2 &start, const DVector2 &end) } if (!(li->flags&ML_TWOSIDED) || !li->backsector) { - if (P_PointOnLineSide(slidemo->Pos(), li)) + if (P_PointOnLineSide(slidemo->Pos().XY(), li)) continue; // don't hit the back side goto bounceblocking; } @@ -3557,7 +3557,7 @@ bool FSlide::BounceWall(AActor *mo) return true; } - side = P_PointOnLineSide(mo->Pos(), line); + side = P_PointOnLineSide(mo->Pos().XY(), line); lineangle = line->Delta().Angle(); if (side == 1) { @@ -4047,7 +4047,7 @@ struct aim_t newtrace.startfrac = frac + 1 / attackrange; // this is to skip the transition line to the portal which would produce a bogus opening - DVector2 pos = newtrace.startpos + newtrace.aimtrace * newtrace.startfrac; + DVector2 pos = newtrace.startpos.XY() + newtrace.aimtrace * newtrace.startfrac; newtrace.lastsector = li->GetLevel()->PointInSector(pos); P_TranslatePortalZ(li, limitz); @@ -5694,7 +5694,7 @@ bool P_UseTraverse(AActor *usething, const DVector2 &start, const DVector2 &end, return true; } - sec = P_PointOnLineSide(xpos, in->d.line) == 0 ? + sec = P_PointOnLineSide(xpos.XY(), in->d.line) == 0 ? in->d.line->frontsector : in->d.line->backsector; if (sec != NULL && sec->SecActTarget && @@ -5713,7 +5713,7 @@ bool P_UseTraverse(AActor *usething, const DVector2 &start, const DVector2 &end, continue; // not a special line, but keep checking } - if (P_PointOnLineSide(xpos, in->d.line) == 1) + if (P_PointOnLineSide(xpos.XY(), in->d.line) == 1) { if (!(in->d.line->activation & SPAC_UseBack)) { @@ -5807,7 +5807,7 @@ void P_UseLines(player_t *player) bool foundline = false; // If the player is transitioning a portal, use the group that is at its vertical center. - DVector2 start = player->mo->GetPortalTransition(player->mo->Height / 2); + DVector2 start = player->mo->GetPortalTransition(player->mo->Height / 2).XY(); // [NS] Now queries the Player's UseRange. DVector2 end = start + player->mo->Angles.Yaw.ToVector(player->mo->FloatVar(NAME_UseRange)); @@ -5847,7 +5847,7 @@ int P_UsePuzzleItem(AActor *PuzzleItemUser, int PuzzleItemType) else usedist = USERANGE; - start = PuzzleItemUser->GetPortalTransition(PuzzleItemUser->Height / 2); + start = PuzzleItemUser->GetPortalTransition(PuzzleItemUser->Height / 2).XY(); end = PuzzleItemUser->Angles.Yaw.ToVector(usedist); FPathTraverse it(PuzzleItemUser->Level, start.X, start.Y, end.X, end.Y, PT_DELTA | PT_ADDLINES | PT_ADDTHINGS); @@ -5869,7 +5869,7 @@ int P_UsePuzzleItem(AActor *PuzzleItemUser, int PuzzleItemType) } continue; } - if (P_PointOnLineSide(PuzzleItemUser->Pos(), in->d.line) == 1) + if (P_PointOnLineSide(PuzzleItemUser->Pos().XY(), in->d.line) == 1) { // Don't use back sides return false; } @@ -6311,7 +6311,7 @@ bool P_AdjustFloorCeil(AActor *thing, FChangePosition *cpos) thing->flags2 |= MF2_PASSMOBJ; } - bool isgood = P_CheckPosition(thing, thing->Pos(), tm); + bool isgood = P_CheckPosition(thing, thing->Pos().XY(), tm); if (!(thing->flags4 & MF4_ACTLIKEBRIDGE)) { thing->floorz = tm.floorz; diff --git a/src/playsim/p_maputl.h b/src/playsim/p_maputl.h index 53984f1d3..7c89bab06 100644 --- a/src/playsim/p_maputl.h +++ b/src/playsim/p_maputl.h @@ -49,6 +49,11 @@ inline int P_PointOnLineSidePrecise(const DVector2 &pt, const linebase_t *line) return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON; } +inline int P_PointOnLineSidePrecise(const DVector3& pt, const linebase_t* line) +{ + return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON; +} + inline int P_PointOnLineSide (double x, double y, const line_t *line) { extern int P_VanillaPointOnLineSide(double x, double y, const line_t* line); diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index bc0b85961..1dcf511da 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -1879,7 +1879,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) { mo->Vel.MakeResize(VELOCITY_THRESHOLD); } - move = mo->Vel; + move = mo->Vel.XY(); // [RH] Carrying sectors didn't work with low speeds in BOOM. This is // because BOOM relied on the speed being fast enough to accumulate // despite friction. If the speed is too low, then its movement will get @@ -1965,7 +1965,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) // because it also calls P_CheckSlopeWalk on its clipped steps. DVector2 onestep = startmove / steps; - start = mo->Pos(); + start = mo->Pos().XY(); step = 1; totalsteps = steps; @@ -1990,7 +1990,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) ptry = start + move * step / steps; - DVector2 startvel = mo->Vel; + DVector2 startvel = mo->Vel.XY(); // killough 3/15/98: Allow objects to drop off // [RH] If walking on a slope, stay on the slope @@ -2044,7 +2044,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) // If the move is done a second time (because it was too fast for one move), it // is still clipped against the wall at its full speed, so you effectively // execute two moves in one tic. - P_SlideMove (mo, mo->Vel, 1); + P_SlideMove (mo, mo->Vel.XY(), 1); } else { @@ -2058,7 +2058,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) { if (!player || !(mo->Level->i_compatflags & COMPATF_WALLRUN)) { - move = mo->Vel; + move = mo->Vel.XY(); onestep = move / steps; P_CheckSlopeWalk (mo, move); } @@ -2075,7 +2075,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) DVector2 t; t.X = 0, t.Y = onestep.Y; walkplane = P_CheckSlopeWalk (mo, t); - if (P_TryMove (mo, mo->Pos() + t, true, walkplane, tm)) + if (P_TryMove (mo, mo->Pos().XY() + t, true, walkplane, tm)) { mo->Vel.X = 0; } @@ -2083,7 +2083,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) { t.X = onestep.X, t.Y = 0; walkplane = P_CheckSlopeWalk (mo, t); - if (P_TryMove (mo, mo->Pos() + t, true, walkplane, tm)) + if (P_TryMove (mo, mo->Pos().XY() + t, true, walkplane, tm)) { mo->Vel.Y = 0; } @@ -2194,7 +2194,7 @@ static double P_XYMovement (AActor *mo, DVector2 scroll) move = move.Rotated(anglediff); oldangle = mo->Angles.Yaw; } - start = mo->Pos() - move * step / steps; + start = mo->Pos().XY() - move * step / steps; } } } @@ -2877,7 +2877,7 @@ void P_NightmareRespawn (AActor *mobj) } // something is occupying its position? - if (!P_CheckPosition(mo, mo->Pos(), true)) + if (!P_CheckPosition(mo, mo->Pos().XY(), true)) { //[GrafZahl] MF_COUNTKILL still needs to be checked here. mo->ClearCounters(); @@ -2906,7 +2906,7 @@ void P_NightmareRespawn (AActor *mobj) P_SpawnTeleportFog(mobj, mobj->Pos(), true, true); // spawn a teleport fog at the new spot - P_SpawnTeleportFog(mobj, DVector3(mobj->SpawnPoint, z), false, true); + P_SpawnTeleportFog(mobj, DVector3(mobj->SpawnPoint.XY(), z), false, true); // remove the old monster mobj->Destroy (); @@ -5728,7 +5728,7 @@ AActor *FLevelLocals::SpawnMapThing (FMapThing *mthing, int position) else sz = ONFLOORZ; - mobj = AActor::StaticSpawn (this, i, DVector3(mthing->pos, sz), NO_REPLACE, true); + mobj = AActor::StaticSpawn (this, i, DVector3(mthing->pos.XY(), sz), NO_REPLACE, true); if (sz == ONFLOORZ) { @@ -6538,7 +6538,7 @@ bool P_CheckMissileSpawn (AActor* th, double maxdist) // killough 3/15/98: no dropoff (really = don't care for missiles) auto oldf2 = th->flags2; th->flags2 &= ~(MF2_MCROSS|MF2_PCROSS); // The following check is not supposed to activate missile triggers. - if (!(P_TryMove (th, newpos, false, NULL, tm, true))) + if (!(P_TryMove (th, newpos.XY(), false, NULL, tm, true))) { // [RH] Don't explode ripping missiles that spawn inside something if (th->BlockingMobj == NULL || !(th->flags2 & MF2_RIP) || (th->BlockingMobj->flags5 & MF5_DONTRIP)) @@ -7576,7 +7576,7 @@ static FRandom pr_restore("RestorePos"); void AActor::RestoreSpecialPosition() { // Move item back to its original location - DVector2 sp = SpawnPoint; + DVector2 sp = SpawnPoint.XY(); FLinkContext ctx; UnlinkFromWorld(&ctx); diff --git a/src/playsim/p_secnodes.cpp b/src/playsim/p_secnodes.cpp index f43b0e30e..e19846c75 100644 --- a/src/playsim/p_secnodes.cpp +++ b/src/playsim/p_secnodes.cpp @@ -414,7 +414,7 @@ void AActor::UpdateRenderSectorList() if (planeh <= lasth) break; // broken setup. if (Top() + SPRITE_SPACE < planeh) break; lasth = planeh; - DVector2 newpos = Pos() + sec->GetPortalDisplacement(sector_t::ceiling); + DVector2 newpos = Pos().XY() + sec->GetPortalDisplacement(sector_t::ceiling); sec = sec->Level->PointInSector(newpos); touching_sectorportallist = P_AddSecnode(sec, this, touching_sectorportallist, sec->sectorportal_thinglist); } @@ -426,7 +426,7 @@ void AActor::UpdateRenderSectorList() if (planeh >= lasth) break; // broken setup. if (Z() - SPRITE_SPACE > planeh) break; lasth = planeh; - DVector2 newpos = Pos() + sec->GetPortalDisplacement(sector_t::floor); + DVector2 newpos = Pos().XY() + sec->GetPortalDisplacement(sector_t::floor); sec = sec->Level->PointInSector(newpos); touching_sectorportallist = P_AddSecnode(sec, this, touching_sectorportallist, sec->sectorportal_thinglist); } diff --git a/src/playsim/p_sight.cpp b/src/playsim/p_sight.cpp index b5564346a..2cf957c8c 100644 --- a/src/playsim/p_sight.cpp +++ b/src/playsim/p_sight.cpp @@ -127,7 +127,7 @@ public: void init(AActor * t1, AActor * t2, sector_t *startsector, SightTask *task, int flags) { sightstart = t1->PosRelative(task->portalgroup); - sightend = t2->PosRelative(task->portalgroup); + sightend = t2->PosRelative(task->portalgroup).XY(); sightstart.Z += t1->Height * 0.75; portalgroup = task->portalgroup; diff --git a/src/playsim/p_teleport.cpp b/src/playsim/p_teleport.cpp index fb2217ef0..1643b1b76 100644 --- a/src/playsim/p_teleport.cpp +++ b/src/playsim/p_teleport.cpp @@ -60,7 +60,7 @@ void P_SpawnTeleportFog(AActor *mobj, const DVector3 &pos, bool beforeTele, bool else { double fogDelta = mobj->flags & MF_MISSILE ? 0 : TELEFOGHEIGHT; - mo = Spawn(mobj->Level, (beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType), DVector3(pos, pos.Z + fogDelta), ALLOW_REPLACE); + mo = Spawn(mobj->Level, (beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType), pos.plusZ(fogDelta), ALLOW_REPLACE); } if (mo != NULL && setTarget) @@ -414,7 +414,7 @@ bool FLevelLocals::EV_Teleport (int tid, int tag, line_t *line, int side, AActor { badangle = DAngle::fromDeg(0.01); } - if (P_Teleport (thing, DVector3(searcher->Pos(), z), searcher->Angles.Yaw + badangle, flags)) + if (P_Teleport (thing, DVector3(searcher->Pos().XY(), z), searcher->Angles.Yaw + badangle, flags)) { // [RH] Lee Killough's changes for silent teleporters from BOOM if (line) @@ -658,7 +658,7 @@ bool FLevelLocals::EV_TeleportOther (int other_tid, int dest_tid, bool fog) bool DoGroupForOne (AActor *victim, AActor *source, AActor *dest, bool floorz, bool fog) { DAngle an = dest->Angles.Yaw - source->Angles.Yaw; - DVector2 off = victim->Pos() - source->Pos(); + DVector2 off = victim->Pos().XY() - source->Pos().XY(); DAngle offAngle = victim->Angles.Yaw - source->Angles.Yaw; DVector2 newp = { off.X * an.Cos() - off.Y * an.Sin(), off.X * an.Sin() + off.Y * an.Cos() }; double z = floorz ? ONFLOORZ : dest->Z() + victim->Z() - source->Z(); diff --git a/src/playsim/p_things.cpp b/src/playsim/p_things.cpp index 0089a29c2..3391030aa 100644 --- a/src/playsim/p_things.cpp +++ b/src/playsim/p_things.cpp @@ -468,7 +468,7 @@ bool P_Thing_Raise(AActor *thing, AActor *raiser, int flags) thing->flags |= MF_SOLID; thing->Height = info->Height; // [RH] Use real height thing->radius = info->radius; // [RH] Use real radius - if (!(flags & RF_NOCHECKPOSITION) && !P_CheckPosition (thing, thing->Pos())) + if (!(flags & RF_NOCHECKPOSITION) && !P_CheckPosition (thing, thing->Pos().XY())) { thing->flags = oldflags; thing->radius = oldradius; @@ -512,7 +512,7 @@ bool P_Thing_CanRaise(AActor *thing) thing->Height = info->Height; thing->radius = info->radius; - bool check = P_CheckPosition (thing, thing->Pos()); + bool check = P_CheckPosition (thing, thing->Pos().XY()); // Restore checked properties thing->flags = oldflags; @@ -813,7 +813,7 @@ int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, do { caller->AddZ(reference->GetBobOffset()); } - P_TryMove(caller, caller->Pos(), false); + P_TryMove(caller, caller->Pos().XY(), false); } return true; } diff --git a/src/playsim/p_trace.cpp b/src/playsim/p_trace.cpp index d8b362ca7..7e47a7323 100644 --- a/src/playsim/p_trace.cpp +++ b/src/playsim/p_trace.cpp @@ -406,7 +406,7 @@ bool FTraceInfo::LineCheck(intercept_t *in, double dist, DVector3 hit, bool spec } else { - lineside = P_PointOnLineSide(Start, in->d.line); + lineside = P_PointOnLineSide(Start.XY(), in->d.line); CurSector = lineside ? in->d.line->backsector : in->d.line->frontsector; } } diff --git a/src/playsim/po_man.cpp b/src/playsim/po_man.cpp index f29001b9f..a547d619a 100644 --- a/src/playsim/po_man.cpp +++ b/src/playsim/po_man.cpp @@ -1097,7 +1097,7 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd) performBlockingThrust = true; } - DVector2 pos = mobj->PosRelative(ld); + DVector2 pos = mobj->PosRelative(ld).XY(); FBoundingBox box(pos.X, pos.Y, mobj->radius); if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) @@ -1108,7 +1108,7 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd) if (ld->isLinePortal()) { // Fixme: this still needs to figure out if the polyobject move made the player cross the portal line. - if (P_TryMove(mobj, mobj->Pos(), false)) + if (P_TryMove(mobj, mobj->Pos().XY(), false)) { continue; } diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 822f7c2ca..4110063e8 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -598,7 +598,7 @@ void HWDrawInfo::RenderParticles(subsector_t *sub, sector_t *front) { if (mClipPortal) { - int clipres = mClipPortal->ClipPoint(Level->Particles[i].Pos); + int clipres = mClipPortal->ClipPoint(Level->Particles[i].Pos.XY()); if (clipres == PClip_InFront) continue; } diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 18de9babf..e8e887567 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -447,7 +447,7 @@ int HWLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos) { return PClip_Inside; // should be handled properly. } - return P_ClipLineToPortal(linedef, this, viewpos) ? PClip_InFront : PClip_Inside; + return P_ClipLineToPortal(linedef, this, viewpos.XY()) ? PClip_InFront : PClip_Inside; } int HWLinePortal::ClipSubsector(subsector_t *sub) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 80b2170db..ec9a8d2b9 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -806,7 +806,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (thruportal != 2 && di->mClipPortal != nullptr) { - int clipres = di->mClipPortal->ClipPoint(thingpos); + int clipres = di->mClipPortal->ClipPoint(thingpos.XY()); if (clipres == PClip_InFront) return; } // disabled because almost none of the actual game code is even remotely prepared for this. If desired, use the INTERPOLATE flag. @@ -961,7 +961,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // Tests show that this doesn't look good for many decorations and corpses if (spriteheight > 0 && gl_spriteclip > 0 && (thing->renderflags & RF_SPRITETYPEMASK) == RF_FACESPRITE) { - PerformSpriteClipAdjustment(thing, thingpos, spriteheight); + PerformSpriteClipAdjustment(thing, thingpos.XY(), spriteheight); } switch (spritetype) diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index 694223688..70a70ad51 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -528,7 +528,7 @@ void R_InterpolateView (FRenderViewpoint &viewpoint, player_t *player, double Fr nviewz -= totalzdiff - zdiff; oviewangle += adiff; nviewangle -= totaladiff - adiff; - DVector2 viewpos = start.pos + (fragfrac * (end.pos - start.pos)); + DVector2 viewpos = start.pos.XY() + (fragfrac * (end.pos - start.pos).XY()); viewpoint.Pos = { viewpos, oviewz + Frac * (nviewz - oviewz) }; break; } diff --git a/src/rendering/swrenderer/line/r_farclip_line.cpp b/src/rendering/swrenderer/line/r_farclip_line.cpp index 8b2cd07f2..fd662952e 100644 --- a/src/rendering/swrenderer/line/r_farclip_line.cpp +++ b/src/rendering/swrenderer/line/r_farclip_line.cpp @@ -93,7 +93,7 @@ namespace swrenderer // reject lines that aren't seen from the portal (if any) // [ZZ] 10.01.2016: lines inside a skybox shouldn't be clipped, although this imposes some limitations on portals in skyboxes. - if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos)) + if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos.XY())) return; mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1); diff --git a/src/rendering/swrenderer/line/r_line.cpp b/src/rendering/swrenderer/line/r_line.cpp index 1a6717450..c09801d5a 100644 --- a/src/rendering/swrenderer/line/r_line.cpp +++ b/src/rendering/swrenderer/line/r_line.cpp @@ -106,7 +106,7 @@ namespace swrenderer // reject lines that aren't seen from the portal (if any) // [ZZ] 10.01.2016: lines inside a skybox shouldn't be clipped, although this imposes some limitations on portals in skyboxes. - if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos)) + if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos.XY())) return; mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1); diff --git a/src/rendering/swrenderer/plane/r_slopeplane.cpp b/src/rendering/swrenderer/plane/r_slopeplane.cpp index 808a1a0b7..0a13c11eb 100644 --- a/src/rendering/swrenderer/plane/r_slopeplane.cpp +++ b/src/rendering/swrenderer/plane/r_slopeplane.cpp @@ -89,7 +89,7 @@ namespace swrenderer auto viewport = Thread->Viewport.get(); // Stupid way of doing it, but at least it works - DVector3 worldP0(viewport->viewpoint.Pos, pl->height.ZatPoint(viewport->viewpoint.Pos)); + DVector3 worldP0(viewport->viewpoint.Pos.XY(), pl->height.ZatPoint(viewport->viewpoint.Pos)); DVector3 worldP1 = worldP0 + pl->height.Normal(); DVector3 viewP0 = viewport->PointWorldToView(worldP0); DVector3 viewP1 = viewport->PointWorldToView(worldP1); diff --git a/src/rendering/swrenderer/scene/r_opaque_pass.cpp b/src/rendering/swrenderer/scene/r_opaque_pass.cpp index bcd864d05..b688ef636 100644 --- a/src/rendering/swrenderer/scene/r_opaque_pass.cpp +++ b/src/rendering/swrenderer/scene/r_opaque_pass.cpp @@ -853,7 +853,7 @@ namespace swrenderer node_t *bsp = (node_t *)node; // Decide which side the view point is on. - int side = R_PointOnSide(Thread->Viewport->viewpoint.Pos, bsp); + int side = R_PointOnSide(Thread->Viewport->viewpoint.Pos.XY(), bsp); // Recursively divide front space (toward the viewer). RenderBSPNode(bsp->children[side]); diff --git a/src/rendering/swrenderer/things/r_particle.cpp b/src/rendering/swrenderer/things/r_particle.cpp index 23a859c0e..058a2609a 100644 --- a/src/rendering/swrenderer/things/r_particle.cpp +++ b/src/rendering/swrenderer/things/r_particle.cpp @@ -90,7 +90,7 @@ namespace swrenderer RenderPortal *renderportal = thread->Portal.get(); // [ZZ] Particle not visible through the portal plane - if (renderportal->CurrentPortal && !!P_PointOnLineSide(particle->Pos, renderportal->CurrentPortal->dst)) + if (renderportal->CurrentPortal && !!P_PointOnLineSide(particle->Pos.XY(), renderportal->CurrentPortal->dst)) return; // transform the origin point diff --git a/src/rendering/swrenderer/things/r_visiblesprite.cpp b/src/rendering/swrenderer/things/r_visiblesprite.cpp index 1878008cd..a91b851a4 100644 --- a/src/rendering/swrenderer/things/r_visiblesprite.cpp +++ b/src/rendering/swrenderer/things/r_visiblesprite.cpp @@ -193,7 +193,7 @@ namespace swrenderer { // only things in specially marked sectors if (spr->FakeFlatStat != WaterFakeSide::AboveCeiling) { - double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos); + double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos.XY()); int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::BelowFloor) @@ -215,7 +215,7 @@ namespace swrenderer } if (spr->FakeFlatStat != WaterFakeSide::BelowFloor && !(spr->heightsec->MoreFlags & SECMF_FAKEFLOORONLY)) { - double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos); + double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos.XY()); int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::AboveCeiling) diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 31a46ca2d..c46e1dfa9 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -946,7 +946,7 @@ static void CalcSectorSoundOrg(const DVector3& listenpos, const sector_t* sec, i // Find the closest point on the sector's boundary lines and use // that as the perceived origin of the sound. DVector2 xy; - sec->ClosestPoint(listenpos, xy); + sec->ClosestPoint(listenpos.XY(), xy); pos.X = (float)xy.X; pos.Z = (float)xy.Y; } @@ -989,7 +989,7 @@ static void CalcPolyobjSoundOrg(const DVector3& listenpos, const FPolyObj* poly, sector_t* sec; DVector2 ppos; - poly->ClosestPoint(listenpos, ppos, &side); + poly->ClosestPoint(listenpos.XY(), ppos, &side); pos.X = (float)ppos.X; pos.Z = (float)ppos.Y; sec = side->sector;