diff --git a/source/build/include/build.h b/source/build/include/build.h index 2b4d70e75..37c0bfb14 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -119,7 +119,7 @@ enum { PALETTE_TRANSLUC = 1<<2, }; -EXTERN int32_t g_visibility; +inline int32_t g_visibility = 512, g_relvisibility = 0; EXTERN vec2_t windowxy1, windowxy2; @@ -189,8 +189,7 @@ enum { EXTERN int32_t enginecompatibility_mode; -int32_t engineInit(void); -void engineUnInit(void); +void engineInit(void); void videoSetCorrectedAspect(); void videoSetViewableArea(int32_t x1, int32_t y1, int32_t x2, int32_t y2); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 38907ae54..65143d2a5 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -146,30 +146,21 @@ int32_t animateoffs(int const tilenum, int fakevar) return offs; } -static int32_t engineLoadTables(void) +void engineInit(void) { - static char tablesloaded = 0; + int32_t i; - if (tablesloaded == 0) - { - 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]; - 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]; - - for (i=0; i<640; i++) - radarang[i] = atan((639.5 - i) / 160.) * (-64. / BAngRadian); - for (i=0; i<640; i++) - radarang[1279-i] = -radarang[i]; - - tablesloaded = 1; - } - - return 0; + for (i=0; i<640; i++) + radarang[i] = atan((639.5 - i) / 160.) * (-64. / BAngRadian); + for (i=0; i<640; i++) + radarang[1279-i] = -radarang[i]; } // @@ -342,18 +333,6 @@ const int16_t* getpsky(int32_t picnum, int32_t* dapyscale, int32_t* dapskybits, return psky->tileofs; } - -// -// initengine -// -int32_t engineInit(void) -{ - engineLoadTables(); - g_visibility = 512; - return 0; -} - - // // inside // diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index b5f8b9a0d..4fa7c1d93 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -337,7 +337,7 @@ static void polymost_updaterotmat(void) multiplyMatrix4f(matrix, tiltmatrix); renderSetViewMatrix(matrix); float fxdimen = FixedToFloat(xdimenscale); - renderSetVisibility(g_visibility * fxdimen * (1.f / (65536.f)) / r_ambientlight); + renderSetVisibility((g_visibility + g_relvisibility) * fxdimen * (1.f / (65536.f)) / r_ambientlight); } const vec2_16_t tileSize(int index) diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index f3a8c5ed2..88f220703 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -139,7 +139,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint& parentvp, HWViewpointUniforms* uni VPUniforms.mViewMatrix.loadIdentity(); VPUniforms.mNormalViewMatrix.loadIdentity(); //VPUniforms.mViewHeight = viewheight; - VPUniforms.mGlobVis = (2 / 65536.f) * g_visibility / r_ambientlight; + VPUniforms.mGlobVis = (2 / 65536.f) * (isBuildSoftwareLighting()? g_visibility + g_relvisibility : g_visibility) / r_ambientlight; VPUniforms.mPalLightLevels = numshades | (static_cast(gl_fogmode) << 8) | (5 << 16); VPUniforms.mClipLine.X = -10000000.0f; diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 9f13a3df7..9afb7e6b3 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -695,6 +695,7 @@ void SerializeMap(FSerializer& arc) ("randomseed", randomseed) ("numshades", numshades) // is this really needed? ("visibility", g_visibility) + ("relvisibility", g_relvisibility) ("parallaxtype", parallaxtype) ("parallaxyo", parallaxyoffs_override) ("parallaxys", parallaxyscale_override) diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index f1463f2aa..f38b6deec 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -739,7 +739,7 @@ void viewDrawScreen(bool sceneonly) break; } } - g_visibility = (int32_t)(ClipLow(gVisibility - 32 * gView->visibility - brightness, 0)); + g_relvisibility = (int32_t)(ClipLow(gVisibility - 32 * gView->visibility - brightness, 0)) - g_visibility; cA += interpolatedangle(buildang(deliriumTurnO), buildang(deliriumTurn), gInterpolate); int ceilingZ, floorZ; diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index bc2782e89..a1be35e38 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -563,6 +563,7 @@ void thunder(void) { if (testgotpic(RRTILE2577, true)) { + g_relvisibility = 0; if (krand() > 65000) { thunderflash = 1; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index e50840e72..6851fd43e 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -271,7 +271,8 @@ void displayrooms(int snum, double smoothratio, bool sceneonly) p->visibility = ud.const_visibility; } - g_visibility = p->visibility; + g_visibility = ud.const_visibility; + g_relvisibility = p->visibility - ud.const_visibility; videoSetCorrectedAspect(); diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index bb227a46d..d4d981ef7 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1450,7 +1450,9 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly) pp->siang = tang.asbuild(); QuakeViewChange(camerapp, &quake_z, &quake_x, &quake_y, &quake_ang); - VisViewChange(camerapp, &g_visibility); + int vis = g_visibility; + VisViewChange(camerapp, &vis); + g_relvisibility = vis - g_visibility; tz = tz + quake_z; tx = tx + quake_x; ty = ty + quake_y;