From 629737bd72deb86c10bbf576202fe24e5dbb204b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Oct 2020 17:20:52 +0100 Subject: [PATCH] - main 3D render function. --- source/build/include/build.h | 2 + source/build/src/engine.cpp | 2 +- source/build/src/engine_priv.h | 2 - source/games/whaven/CMakeLists.txt | 1 + source/games/whaven/src/main.cpp | 2 +- source/games/whaven/src/render.cpp | 101 +++++++++++++++++++++++++++++ source/games/whaven/src/wh.h | 3 +- 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 source/games/whaven/src/render.cpp diff --git a/source/build/include/build.h b/source/build/include/build.h index 0989f3f14..83947a547 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -217,6 +217,8 @@ EXTERN tspriteptr_t tsprite; extern sectortype sectorbackup[MAXSECTORS]; extern walltype wallbackup[MAXWALLS]; +extern bool inpreparemirror; + static inline tspriteptr_t renderMakeTSpriteFromSprite(tspriteptr_t const tspr, uint16_t const spritenum) { diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 2b5f5de72..a714f249b 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -211,7 +211,7 @@ int16_t searchsector, searchwall, searchstat; //search output // When aiming at a 2-sided wall, 1 if aiming at the bottom part, 0 else int16_t searchbottomwall, searchisbottom; -char inpreparemirror = 0; +bool inpreparemirror = 0; static int32_t mirrorsx1, mirrorsy1, mirrorsx2, mirrorsy2; #define MAXSETVIEW 4 diff --git a/source/build/src/engine_priv.h b/source/build/src/engine_priv.h index ec9d814c4..6a9d5c5c1 100644 --- a/source/build/src/engine_priv.h +++ b/source/build/src/engine_priv.h @@ -106,8 +106,6 @@ extern int32_t searchx, searchy; extern int16_t searchsector, searchwall, searchstat; extern int16_t searchbottomwall, searchisbottom; -extern char inpreparemirror; - extern int16_t sectorborder[256]; extern int32_t hitallsprites; diff --git a/source/games/whaven/CMakeLists.txt b/source/games/whaven/CMakeLists.txt index 350f6548c..c48c69fbc 100644 --- a/source/games/whaven/CMakeLists.txt +++ b/source/games/whaven/CMakeLists.txt @@ -47,6 +47,7 @@ set( PCH_SOURCES src/fonts.cpp src/screenflash.cpp src/precache.cpp + src/render.cpp ) add_game_library2( whaven ) diff --git a/source/games/whaven/src/main.cpp b/source/games/whaven/src/main.cpp index 8c29fca5d..87e804434 100644 --- a/source/games/whaven/src/main.cpp +++ b/source/games/whaven/src/main.cpp @@ -281,7 +281,7 @@ void GameInterface::DrawBackground() } } -inline bool playrunning() +bool playrunning() { return (paused == 0 || multiplayer/* || demoplay/record*/); } diff --git a/source/games/whaven/src/render.cpp b/source/games/whaven/src/render.cpp new file mode 100644 index 000000000..0b30f860d --- /dev/null +++ b/source/games/whaven/src/render.cpp @@ -0,0 +1,101 @@ +#include "ns.h" +#include "wh.h" +#include "automap.h" +#include "mmulti.h" +#include "glbackend/glbackend.h" +#include "raze_music.h" + +BEGIN_WH_NS + + +void drawscreen(int num, int dasmoothratio) { + + PLAYER& plr = player[num]; + + int cposx = plr.x; + int cposy = plr.y; + int cposz = plr.z; + float cang = plr.ang; + float choriz = plr.horiz + plr.jumphoriz; + + if (!paused) + { + auto& prevloc = gPrevPlayerLoc[num]; + + int ix = prevloc.x; + int iy = prevloc.y; + int iz = prevloc.z; + float iHoriz = prevloc.horiz; + float inAngle = prevloc.ang; + + ix += mulscale(cposx - prevloc.x, dasmoothratio, 16); + iy += mulscale(cposy - prevloc.y, dasmoothratio, 16); + iz += mulscale(cposz - prevloc.z, dasmoothratio, 16); + iHoriz += ((choriz - prevloc.horiz) * dasmoothratio) / 65536.0f; + inAngle += ((BClampAngle(cang - prevloc.ang + 1024) - 1024) * dasmoothratio) / 65536.0f; + + cposx = ix; + cposy = iy; + cposz = iz; + + choriz = iHoriz; + cang = inAngle; + } + + // wango + if ((gotpic[FLOORMIRROR >> 3] & (1 << (FLOORMIRROR & 7))) != 0) { + int dist = 0x7fffffff; + int i = 0, j; + for (int k = floormirrorcnt - 1; k >= 0; k--) { + int sect = floormirrorsector[k]; + if((gotsector[sect >> 3] & (1 << (sect & 7))) == 0) continue; + j = klabs(wall[sector[sect].wallptr].x - plr.x); + j += klabs(wall[sector[sect].wallptr].y - plr.y); + if (j < dist) { + dist = j; i = k; + } + } + + // Todo: render this with 30% light only. + inpreparemirror = true; + renderSetRollAngle(1024); + renderDrawRoomsQ16(cposx, cposy, cposz, FloatToFixed(cang), FloatToFixed(201 - choriz), floormirrorsector[i]); + analyzesprites(plr, dasmoothratio); + renderDrawMasks(); + renderSetRollAngle(0); + inpreparemirror = false; + + gotpic[FLOORMIRROR >> 3] &= ~(1 << (FLOORMIRROR & 7)); + } + + int ceilz, floorz; + getzsofslope(plr.sector, cposx, cposy, &ceilz, &floorz); + int lz = 4 << 8; + if (cposz < ceilz + lz) + cposz = ceilz + lz; + if (cposz > floorz - lz) + cposz = floorz - lz; + + renderDrawRoomsQ16(cposx, cposy, cposz, FloatToFixed(cang), FloatToFixed(choriz), plr.sector); + analyzesprites(plr, dasmoothratio); + renderDrawMasks(); + + if (automapMode != am_off) + { + DrawOverheadMap(cposx, cposy, int(cang)); + } +} + +void GameInterface::Render() +{ + double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio; + + drawscreen(pyrn, FloatToFixed(smoothRatio)); + if (!paused && isWh2() && attacktheme && !Mus_IsPlaying()) + { + startsong(krand() % 2); + attacktheme = 0; + } +} + +END_WH_NS diff --git a/source/games/whaven/src/wh.h b/source/games/whaven/src/wh.h index 131491d3f..74b57cd80 100644 --- a/source/games/whaven/src/wh.h +++ b/source/games/whaven/src/wh.h @@ -510,6 +510,7 @@ void InitFonts(); void sfxInit(void); void IntroMovie(const CompletionFunc& completion); +bool playrunning(); #include "item.h" @@ -538,7 +539,7 @@ struct GameInterface : public ::GameInterface //void UpdateSounds() override; void Startup() override; void DrawBackground() override; - //void Render() override; + void Render() override; void Ticker() override; const char* GenericCheat(int player, int cheat) override; const char* CheckCheatMode() override;