From 6dd7fac902fda1775bb0b545417b8884bb882831 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Sep 2022 12:26:37 +0200 Subject: [PATCH] - eliminated the sine table and moved tilehasmodelorvoxel to a different file to delete engine.cpp. --- source/CMakeLists.txt | 3 +- source/build/include/build.h | 48 ++++----------- source/build/include/mdsprite.h | 8 +-- source/build/src/clip.cpp | 4 +- source/build/src/engine.cpp | 68 --------------------- source/build/src/mdsprite.cpp | 2 + source/core/gamecontrol.cpp | 1 - source/core/gamefuncs.cpp | 13 ++++ source/core/gamefuncs.h | 28 ++++++--- source/core/maploader.cpp | 1 - source/core/rendering/scene/hw_setcolor.cpp | 3 +- source/core/rendering/scene/hw_walls.cpp | 3 +- source/games/blood/src/misc.h | 10 --- 13 files changed, 55 insertions(+), 137 deletions(-) delete mode 100644 source/build/src/engine.cpp diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6dff8b033..7c61382cb 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -883,7 +883,7 @@ set( VM_JIT_SOURCES common/scripting/jit/jit_store.cpp ) -# Enable fast math for some sources where performance matters (or where the PCH must not be used.) (This would be good for rendering code, but unfortunately that is hopelessly intermingled with the playsim code in engine.cpp.) +# Enable fast math for some sources where performance matters (or where the PCH must not be used.) set( FASTMATH_SOURCES common/rendering/gl_load/gl_load.c @@ -958,7 +958,6 @@ set (PCH_SOURCES # Todo: Split out the license-safe code from this. build/src/clip.cpp - build/src/engine.cpp build/src/mdsprite.cpp core/actorinfo.cpp diff --git a/source/build/include/build.h b/source/build/include/build.h index ea8b143fc..ee15f9b42 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -17,17 +17,6 @@ static_assert('\xff' == 255, "Char must be unsigned!"); #include "printf.h" #include "palette.h" - - //Make all variables in BUILD.H defined in the ENGINE, - //and externed in GAME -#ifdef engine_c_ -# define EXTERN -#else -# define EXTERN extern -#endif - -EXTERN int sintable[2048]; - #include "buildtiles.h" #include "c_cvars.h" #include "cmdlib.h" @@ -86,8 +75,6 @@ enum { int32_t getwalldist(vec2_t const in, int const wallnum, vec2_t * const out); -EXTERN int32_t guniqhudid; - struct usermaphack_t { FString mhkfile; @@ -95,25 +82,12 @@ struct usermaphack_t uint8_t md4[16]{}; }; -EXTERN int leveltimer; - -EXTERN int32_t Numsprites; -EXTERN int32_t display_mirror; - -EXTERN int32_t randomseed; - -EXTERN uint8_t paletteloaded; - enum { PALETTE_MAIN = 1<<0, PALETTE_SHADE = 1<<1, PALETTE_TRANSLUC = 1<<2, }; -inline int32_t g_visibility = 512, g_relvisibility = 0; - -extern uint8_t globalr, globalg, globalb; - enum { ENGINECOMPATIBILITY_NONE = 0, ENGINECOMPATIBILITY_19950829, // Powerslave/Exhumed @@ -121,11 +95,17 @@ enum { ENGINECOMPATIBILITY_19961112, // Duke 3d v1.5, Redneck Rampage }; -EXTERN int32_t enginecompatibility_mode; +inline int leveltimer; +inline int32_t Numsprites; +inline int32_t display_mirror; +inline int32_t randomseed; +inline uint8_t paletteloaded; +inline int32_t g_visibility = 512, g_relvisibility = 0; +inline int32_t enginecompatibility_mode; +inline int32_t nextvoxid; +inline FixedBitArrayvoxreserve; -void engineInit(void); - void setVideoMode(); class F2DDrawer; @@ -173,9 +153,6 @@ inline int hitscan(const DVector3& start, const sectortype* startsect, const vec return hitscan(istart, startsect, direction, hitinfo, cliptype); } - -extern const int16_t *chsecptr_onextwall; - inline int32_t krand(void) { randomseed = (randomseed * 27584621) + 1; @@ -206,7 +183,6 @@ EXTERN_CVAR(Bool, hw_useindexedcolortextures) EXTERN_CVAR(Bool, r_voxels) extern int32_t mdtims, omdtims; - extern int32_t r_rorphase; // flags bitset: 1 = don't compress @@ -215,8 +191,6 @@ int32_t md_loadmodel(const char *fn); int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags); // int32_t md_tilehasmodel(int32_t tilenume, int32_t pal); -EXTERN int32_t nextvoxid; -EXTERN FixedBitArrayvoxreserve; #ifdef USE_OPENGL // TODO: dynamically allocate this @@ -237,8 +211,8 @@ typedef struct # define EXTRATILES (MAXTILES/8) -EXTERN int32_t mdinited; -EXTERN tile2model_t tile2model[MAXTILES+EXTRATILES]; +inline int32_t mdinited; +inline tile2model_t tile2model[MAXTILES+EXTRATILES]; inline int32_t md_tilehasmodel(int32_t const tilenume, int32_t const pal) { diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index cdda97b71..9d6de6182 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -177,16 +177,16 @@ struct md3model_t : public idmodel_t */ }; -EXTERN mdmodel_t **models; +inline mdmodel_t **models; FGameTexture* mdloadskin(idmodel_t* m, int32_t number, int32_t pal, int32_t surf, bool* exact); void mdinit(void); void freeallmodels(void); int32_t polymost_mddraw(tspritetype* tspr); -EXTERN void md3_vox_calcmat_common(tspritetype* tspr, const FVector3 *a0, float f, float mat[16]); +void md3_vox_calcmat_common(tspritetype* tspr, const FVector3 *a0, float f, float mat[16]); -EXTERN int32_t mdpause; -EXTERN int32_t nextmodelid; +inline int32_t mdpause; +inline int32_t nextmodelid; #endif // defined USE_OPENGL diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index aeff8a280..7022f1c29 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -1327,8 +1327,8 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire { int32_t x3, y3, x4, y4; int32_t const heinum = spriteGetSlope(actor); - int32_t const dax = (heinum * sintable[(actor->int_ang() + 1024) & 2047]) << 1; - int32_t const day = (heinum * sintable[(actor->int_ang() + 512) & 2047]) << 1; + int32_t const dax = (heinum * -bsin(actor->int_ang())) << 1; + int32_t const day = (heinum * bcos(actor->int_ang())) << 1; int32_t const j = (vz << 8) - DMulScale(dax, vy, -day, vx, 15); if (j == 0) continue; if ((cstat & 64) != 0) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp deleted file mode 100644 index 89b492791..000000000 --- a/source/build/src/engine.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jf@jonof.id.au) -// by the EDuke32 team (development@voidpoint.com) - -#define engine_c_ - -#include "gl_load.h" -#include "build.h" -#include "automap.h" - -#include "imagehelpers.h" -#include "palette.h" -#include "gamecvars.h" -#include "c_console.h" -#include "v_2ddrawer.h" -#include "v_draw.h" -#include "stats.h" -#include "razemenu.h" -#include "version.h" -#include "earcut.hpp" -#include "gamestate.h" -#include "inputstate.h" -#include "printf.h" -#include "gamecontrol.h" -#include "render.h" -#include "gamefuncs.h" -#include "hw_voxels.h" -#include "coreactor.h" - -#ifdef USE_OPENGL -# include "mdsprite.h" -#include "v_video.h" -#include "gl_renderer.h" -#endif - -int32_t mdtims, omdtims; - -uint8_t globalr = 255, globalg = 255, globalb = 255; - -// -// Internal Engine Functions -// - -void engineInit(void) -{ - int32_t i; - - for (i=0; i<=512; i++) - sintable[i] = int(sin(i * BAngRadian) * +SINTABLEUNIT); - for (i=513; i<1024; i++) - sintable[i] = sintable[1024-i]; - for (i=1024; i<2048; i++) - sintable[i] = -sintable[i-1024]; - -} - - -int tilehasmodelorvoxel(int const tilenume, int pal) -{ - return - (mdinited && hw_models && tile2model[Ptile2tile(tilenume, pal)].modelid != -1) || - (r_voxels && tiletovox[tilenume] != -1); -} diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index d5f4be105..5b7e27529 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -16,6 +16,8 @@ #include "printf.h" #include "hw_voxels.h" +int32_t mdtims, omdtims; + #ifdef _MSC_VER // just make it shut up. Most of this file will go down the drain anyway soon. #pragma warning(disable:4244) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index d55965cf4..c2a31f97e 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1111,7 +1111,6 @@ int RunGame() gameinfo.mBackButton = "engine/graphics/m_back.png"; StartWindow->Progress(); - engineInit(); GC::AddMarkerFunc(MarkMap); gi->app_init(); StartWindow->Progress(); diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 3449deb81..e83f78dc4 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "intvec.h" #include "coreactor.h" #include "interpolate.h" +#include "hw_voxels.h" IntRect viewport3d; @@ -785,6 +786,18 @@ tspritetype* renderAddTsprite(tspriteArray& tsprites, DCoreActor* actor) return tspr; } +//========================================================================== +// +// +// +//========================================================================== + +int tilehasmodelorvoxel(int const tilenume, int pal) +{ + return + (mdinited && hw_models && tile2model[Ptile2tile(tilenume, pal)].modelid != -1) || + (r_voxels && tiletovox[tilenume] != -1); +} //========================================================================== // diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 0ea187288..02b7d0b82 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -174,8 +174,6 @@ constexpr double BAngRadian = pi::pi() * (1. / 1024.); constexpr double BAngToDegree = 360. / 2048.; constexpr DAngle DAngleBuildToDeg = DAngle::fromDeg(BAngToDegree); -extern int sintable[2048]; - inline constexpr double sinscale(const int shift) { return shift >= -BUILDSINBITS ? uint64_t(1) << (BUILDSINBITS + shift) : 1. / (uint64_t(1) << abs(BUILDSINBITS + shift)); @@ -188,15 +186,20 @@ inline constexpr double sinscale(const int shift) // //--------------------------------------------------------------------------- -inline int bsin(const int ang, int shift = 0) -{ - return (shift -= BUILDSINSHIFT) < 0 ? sintable[ang & 2047] >> abs(shift) : sintable[ang & 2047] << shift; -} inline double bsinf(const double ang, const int shift = 0) { return g_sinbam(ang * BAMUNIT) * sinscale(shift); } +inline int bsin(const int ang, int shift = 0) +{ + return (int)bsinf(ang, shift); +} + +inline int Sin(int ang) +{ + return (int)bsinf(ang, 16); +} //--------------------------------------------------------------------------- // @@ -211,15 +214,20 @@ inline double bsinf(const double ang, const int shift = 0) // //--------------------------------------------------------------------------- -inline int bcos(const int ang, int shift = 0) -{ - return (shift -= BUILDSINSHIFT) < 0 ? sintable[(ang + 512) & 2047] >> abs(shift) : sintable[(ang + 512) & 2047] << shift; -} inline double bcosf(const double ang, const int shift = 0) { return g_cosbam(ang * BAMUNIT) * sinscale(shift); } +inline int bcos(const int ang, int shift = 0) +{ + return (int)bcosf(ang, shift); +} + +inline int Cos(int ang) +{ + return (int)bcosf(ang, 16); +} //--------------------------------------------------------------------------- // diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index c391ff58c..b7df223b1 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -536,7 +536,6 @@ void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, secto fixSectors(); *cursect = validSectorIndex(cursectnum) ? §or[cursectnum] : nullptr; updatesector(*pos, cursect); - guniqhudid = 0; fr.Seek(0, FileReader::SeekSet); auto buffer = fr.Read(); uint8_t md4[16]; diff --git a/source/core/rendering/scene/hw_setcolor.cpp b/source/core/rendering/scene/hw_setcolor.cpp index ee5d5b84b..0464b5982 100644 --- a/source/core/rendering/scene/hw_setcolor.cpp +++ b/source/core/rendering/scene/hw_setcolor.cpp @@ -193,6 +193,7 @@ void SetLightAndFog(HWDrawInfo* di, FRenderState& state, PalEntry fade, int pale } // The shade rgb from the tint is ignored here. - state.SetColor(globalr * (1 / 255.f), globalg * (1 / 255.f), globalb * (1 / 255.f), alpha); + //state.SetColor(globalr * (1 / 255.f), globalg * (1 / 255.f), globalb * (1 / 255.f), alpha); + state.SetColor(1., 1., 1., alpha); } diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index f0112dd3b..ce30f8b88 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -158,7 +158,8 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) // Use sphere mapping for this state.SetEffect(EFF_SPHEREMAP); SetLightAndFog(di, state, fade, palette, min(shade, numshades), visibility, alpha); - state.SetColor(PalEntry(25, globalr >> 1, globalg >> 1, globalb >> 1)); + //state.SetColor(PalEntry(25, globalr >> 1, globalg >> 1, globalb >> 1)); + state.SetColor(PalEntry(25, 128, 128, 128)); state.SetRenderStyle(STYLE_Add); state.AlphaFunc(Alpha_Greater, 0); diff --git a/source/games/blood/src/misc.h b/source/games/blood/src/misc.h index 1f491b05c..9853ee115 100644 --- a/source/games/blood/src/misc.h +++ b/source/games/blood/src/misc.h @@ -72,16 +72,6 @@ void RotateVector(int* dx, int* dy, int nAngle); #include "m_fixed.h" -inline int Sin(int ang) -{ - return sintable[ang & 2047]; -} - -inline int Cos(int ang) -{ - return sintable[(ang + 512) & 2047]; -} - enum SurfaceType { kSurfNone = 0, kSurfStone,