From f133b4caa4532e4a35bcedf10fb45f391021a076 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 30 Dec 2016 07:15:10 +0100 Subject: [PATCH] Move vissprite to its own file --- src/CMakeLists.txt | 1 + src/swrenderer/scene/r_things.cpp | 47 +------------ src/swrenderer/scene/r_things.h | 76 +-------------------- src/swrenderer/scene/r_visible_sprite.cpp | 64 +++++++++++++++++ src/swrenderer/scene/r_visible_sprite.h | 83 +++++++++++++++++++++++ 5 files changed, 151 insertions(+), 120 deletions(-) create mode 100644 src/swrenderer/scene/r_visible_sprite.cpp create mode 100644 src/swrenderer/scene/r_visible_sprite.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46dc1b118c..e1ec4293a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -826,6 +826,7 @@ set( FASTMATH_PCH_SOURCES swrenderer/scene/r_portal_segment.cpp swrenderer/scene/r_portal.cpp swrenderer/scene/r_visible_plane.cpp + swrenderer/scene/r_visible_sprite.cpp polyrenderer/poly_renderer.cpp polyrenderer/scene/poly_scene.cpp polyrenderer/scene/poly_portal.cpp diff --git a/src/swrenderer/scene/r_things.cpp b/src/swrenderer/scene/r_things.cpp index 246fbb4154..f2193e1398 100644 --- a/src/swrenderer/scene/r_things.cpp +++ b/src/swrenderer/scene/r_things.cpp @@ -161,12 +161,6 @@ FCoverageBuffer *OffscreenCoverageBuffer; // GAME FUNCTIONS // -int MaxVisSprites; -vissprite_t **vissprites; -vissprite_t **firstvissprite; -vissprite_t **vissprite_p; -vissprite_t **lastvissprite; -int newvissprite; bool DrewAVoxel; static vissprite_t **spritesorter; @@ -179,15 +173,7 @@ static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID p void R_DeinitSprites() { - // Free vissprites - for (int i = 0; i < MaxVisSprites; ++i) - { - delete vissprites[i]; - } - free (vissprites); - vissprites = NULL; - vissprite_p = lastvissprite = NULL; - MaxVisSprites = 0; + R_DeinitVisSprites(); // Free vissprites sorter if (spritesorter != NULL) @@ -217,39 +203,10 @@ void R_DeinitSprites() // void R_ClearSprites (void) { - vissprite_p = firstvissprite; + R_ClearVisSprites(); DrewAVoxel = false; } - -// -// R_NewVisSprite -// -vissprite_t *R_NewVisSprite (void) -{ - if (vissprite_p == lastvissprite) - { - ptrdiff_t firstvisspritenum = firstvissprite - vissprites; - ptrdiff_t prevvisspritenum = vissprite_p - vissprites; - - MaxVisSprites = MaxVisSprites ? MaxVisSprites * 2 : 128; - vissprites = (vissprite_t **)M_Realloc (vissprites, MaxVisSprites * sizeof(vissprite_t)); - lastvissprite = &vissprites[MaxVisSprites]; - firstvissprite = &vissprites[firstvisspritenum]; - vissprite_p = &vissprites[prevvisspritenum]; - DPrintf (DMSG_NOTIFY, "MaxVisSprites increased to %d\n", MaxVisSprites); - - // Allocate sprites from the new pile - for (vissprite_t **p = vissprite_p; p < lastvissprite; ++p) - { - *p = new vissprite_t; - } - } - - vissprite_p++; - return *(vissprite_p-1); -} - // // R_DrawMaskedColumn // Used for sprites and masked mid textures. diff --git a/src/swrenderer/scene/r_things.h b/src/swrenderer/scene/r_things.h index 7f00ce1775..c5553899a4 100644 --- a/src/swrenderer/scene/r_things.h +++ b/src/swrenderer/scene/r_things.h @@ -23,7 +23,7 @@ #ifndef __R_THINGS__ #define __R_THINGS__ -#include "r_bsp.h" +#include "r_visible_sprite.h" struct particle_t; struct FVoxel; @@ -31,84 +31,10 @@ struct FVoxel; namespace swrenderer { -// A vissprite_t is a thing -// that will be drawn during a refresh. -// I.e. a sprite object that is partly visible. - -struct vissprite_t -{ - struct posang - { - FVector3 vpos; // view origin - FAngle vang; // view angle - }; - - short x1, x2; - FVector3 gpos; // origin in world coordinates - union - { - struct - { - float gzb, gzt; // global bottom / top for silhouette clipping - }; - struct - { - int y1, y2; // top / bottom of particle on screen - }; - }; - DAngle Angle; - fixed_t xscale; - float yscale; - float depth; - float idepth; // 1/z - float deltax, deltay; - DWORD FillColor; - double floorclip; - union - { - FTexture *pic; - struct FVoxel *voxel; - }; - union - { - // Used by face sprites - struct - { - double texturemid; - fixed_t startfrac; // horizontal position of x1 - fixed_t xiscale; // negative if flipped - }; - // Used by wall sprites - FWallCoords wallc; - // Used by voxels - posang pa; - }; - sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling - sector_t *sector; // [RH] sector this sprite is in - F3DFloor *fakefloor; - F3DFloor *fakeceiling; - BYTE bIsVoxel:1; // [RH] Use voxel instead of pic - BYTE bWallSprite:1; // [RH] This is a wall sprite - BYTE bSplitSprite:1; // [RH] Sprite was split by a drawseg - BYTE bInMirror:1; // [RH] Sprite is "inside" a mirror - BYTE FakeFlatStat; // [RH] which side of fake/floor ceiling sprite is on - short renderflags; - DWORD Translation; // [RH] for color translation - visstyle_t Style; - int CurrentPortalUniq; // [ZZ] to identify the portal that this thing is in. used for clipping. - - vissprite_t() {} -}; - void R_DrawParticle (vissprite_t *); void R_ProjectParticle (particle_t *, const sector_t *sector, int shade, int fakeside); -extern int MaxVisSprites; - -extern vissprite_t **vissprites, **firstvissprite; -extern vissprite_t **vissprite_p; - // Constant arrays used for psprite clipping // and initializing clipping. extern short zeroarray[MAXWIDTH]; diff --git a/src/swrenderer/scene/r_visible_sprite.cpp b/src/swrenderer/scene/r_visible_sprite.cpp new file mode 100644 index 0000000000..f3cd357913 --- /dev/null +++ b/src/swrenderer/scene/r_visible_sprite.cpp @@ -0,0 +1,64 @@ + +#include +#include +#include +#include "p_lnspec.h" +#include "templates.h" +#include "doomdef.h" +#include "m_swap.h" +#include "i_system.h" +#include "w_wad.h" +#include "swrenderer/r_main.h" +#include "swrenderer/scene/r_visible_sprite.h" + +namespace swrenderer +{ + int MaxVisSprites; + vissprite_t **vissprites; + vissprite_t **firstvissprite; + vissprite_t **vissprite_p; + vissprite_t **lastvissprite; + + void R_DeinitVisSprites() + { + // Free vissprites + for (int i = 0; i < MaxVisSprites; ++i) + { + delete vissprites[i]; + } + free(vissprites); + vissprites = nullptr; + vissprite_p = lastvissprite = nullptr; + MaxVisSprites = 0; + } + + void R_ClearVisSprites() + { + vissprite_p = firstvissprite; + } + + vissprite_t *R_NewVisSprite() + { + if (vissprite_p == lastvissprite) + { + ptrdiff_t firstvisspritenum = firstvissprite - vissprites; + ptrdiff_t prevvisspritenum = vissprite_p - vissprites; + + MaxVisSprites = MaxVisSprites ? MaxVisSprites * 2 : 128; + vissprites = (vissprite_t **)M_Realloc(vissprites, MaxVisSprites * sizeof(vissprite_t)); + lastvissprite = &vissprites[MaxVisSprites]; + firstvissprite = &vissprites[firstvisspritenum]; + vissprite_p = &vissprites[prevvisspritenum]; + DPrintf(DMSG_NOTIFY, "MaxVisSprites increased to %d\n", MaxVisSprites); + + // Allocate sprites from the new pile + for (vissprite_t **p = vissprite_p; p < lastvissprite; ++p) + { + *p = new vissprite_t; + } + } + + vissprite_p++; + return *(vissprite_p - 1); + } +} diff --git a/src/swrenderer/scene/r_visible_sprite.h b/src/swrenderer/scene/r_visible_sprite.h new file mode 100644 index 0000000000..426840fc35 --- /dev/null +++ b/src/swrenderer/scene/r_visible_sprite.h @@ -0,0 +1,83 @@ + +#pragma once + +#include "r_bsp.h" + +struct particle_t; +struct FVoxel; + +namespace swrenderer +{ + struct vissprite_t + { + struct posang + { + FVector3 vpos; // view origin + FAngle vang; // view angle + }; + + short x1, x2; + FVector3 gpos; // origin in world coordinates + union + { + struct + { + float gzb, gzt; // global bottom / top for silhouette clipping + }; + struct + { + int y1, y2; // top / bottom of particle on screen + }; + }; + DAngle Angle; + fixed_t xscale; + float yscale; + float depth; + float idepth; // 1/z + float deltax, deltay; + uint32_t FillColor; + double floorclip; + union + { + FTexture *pic; + struct FVoxel *voxel; + }; + union + { + // Used by face sprites + struct + { + double texturemid; + fixed_t startfrac; // horizontal position of x1 + fixed_t xiscale; // negative if flipped + }; + // Used by wall sprites + FWallCoords wallc; + // Used by voxels + posang pa; + }; + sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling + sector_t *sector; // [RH] sector this sprite is in + F3DFloor *fakefloor; + F3DFloor *fakeceiling; + uint8_t bIsVoxel : 1; // [RH] Use voxel instead of pic + uint8_t bWallSprite : 1; // [RH] This is a wall sprite + uint8_t bSplitSprite : 1; // [RH] Sprite was split by a drawseg + uint8_t bInMirror : 1; // [RH] Sprite is "inside" a mirror + uint8_t FakeFlatStat; // [RH] which side of fake/floor ceiling sprite is on + short renderflags; + uint32_t Translation; // [RH] for color translation + visstyle_t Style; + int CurrentPortalUniq; // [ZZ] to identify the portal that this thing is in. used for clipping. + + vissprite_t() {} + }; + + extern int MaxVisSprites; + extern vissprite_t **vissprites, **firstvissprite; + extern vissprite_t **vissprite_p; + + void R_DeinitVisSprites(); + void R_ClearVisSprites(); + vissprite_t *R_NewVisSprite(); +}