diff --git a/src/b_func.cpp b/src/b_func.cpp index efc3f7f57..d79e5df11 100644 --- a/src/b_func.cpp +++ b/src/b_func.cpp @@ -15,7 +15,6 @@ #include "g_game.h" #include "m_random.h" #include "r_sky.h" -#include "r_main.h" #include "st_stuff.h" #include "stats.h" #include "i_system.h" diff --git a/src/b_move.cpp b/src/b_move.cpp index 332160f1a..b456c0c84 100644 --- a/src/b_move.cpp +++ b/src/b_move.cpp @@ -12,7 +12,6 @@ #include "g_game.h" #include "d_ticcmd.h" #include "m_random.h" -#include "r_main.h" #include "i_system.h" #include "p_lnspec.h" #include "gi.h" diff --git a/src/b_think.cpp b/src/b_think.cpp index 742c33a8a..cc7f087e6 100644 --- a/src/b_think.cpp +++ b/src/b_think.cpp @@ -14,7 +14,6 @@ #include "b_bot.h" #include "g_game.h" #include "m_random.h" -#include "r_main.h" #include "stats.h" #include "a_pickups.h" #include "statnums.h" diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 6dc75dca9..993b4677f 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -61,7 +61,6 @@ #include "gi.h" #include "r_defs.h" #include "d_player.h" -#include "r_main.h" #include "templates.h" #include "p_local.h" #include "r_sky.h" @@ -663,32 +662,6 @@ CCMD (fov) Net_WriteByte (clamp (atoi (argv[1]), 5, 179)); } -//========================================================================== -// -// CCMD r_visibility -// -// Controls how quickly light ramps across a 1/z range. Set this, and it -// sets all the r_*Visibility variables (except r_SkyVisibilily, which is -// currently unused). -// -//========================================================================== - -CCMD (r_visibility) -{ - if (argv.argc() < 2) - { - Printf ("Visibility is %g\n", R_GetVisibility()); - } - else if (!netgame) - { - R_SetVisibility ((float)atof (argv[1])); - } - else - { - Printf ("Visibility cannot be changed in net games.\n"); - } -} - //========================================================================== // // CCMD warp diff --git a/src/c_console.cpp b/src/c_console.cpp index c8cac63bb..039125d56 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -53,7 +53,6 @@ #include "v_video.h" #include "v_text.h" #include "w_wad.h" -#include "r_main.h" #include "sbar.h" #include "s_sound.h" #include "s_sndseq.h" @@ -64,6 +63,7 @@ #include "d_net.h" #include "g_level.h" #include "d_event.h" +#include "d_player.h" #include "gi.h" diff --git a/src/g_game.cpp b/src/g_game.cpp index dda2e9753..1acab7a14 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -77,6 +77,7 @@ #include "d_event.h" #include "p_acs.h" #include "m_joy.h" +#include "farchive.h" #include "r_data/colormaps.h" #include diff --git a/src/g_shared/a_camera.cpp b/src/g_shared/a_camera.cpp index 77ba0e8de..24363851e 100644 --- a/src/g_shared/a_camera.cpp +++ b/src/g_shared/a_camera.cpp @@ -35,7 +35,6 @@ #include "actor.h" #include "info.h" #include "a_sharedglobal.h" -#include "r_main.h" #include "p_local.h" #include "farchive.h" diff --git a/src/g_shared/sbar_mugshot.cpp b/src/g_shared/sbar_mugshot.cpp index 02b72167a..7d4819413 100644 --- a/src/g_shared/sbar_mugshot.cpp +++ b/src/g_shared/sbar_mugshot.cpp @@ -34,13 +34,13 @@ */ #include "r_defs.h" -#include "r_main.h" #include "m_random.h" #include "d_player.h" #include "d_event.h" #include "sbar.h" #include "sbarinfo.h" #include "templates.h" +#include "r_utility.h" #define ST_RAMPAGEDELAY (2*TICRATE) #define ST_MUCHPAIN 20 diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index 6583881b7..60956a80b 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -51,7 +51,6 @@ #include "sbarinfo.h" #include "gi.h" #include "r_data/r_translate.h" -#include "r_main.h" #include "a_weaponpiece.h" #include "a_strifeglobal.h" #include "g_level.h" diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 3161b68a5..971110b56 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -48,10 +48,11 @@ #include "v_video.h" #include "hu_stuff.h" #include "gi.h" +#include "v_palette.h" #include "i_input.h" #include "gameconfigfile.h" #include "gstrings.h" -#include "r_main.h" +#include "r_utility.h" #include "menu/menu.h" #include "textures/textures.h" diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index 47643e4cd..9fa95d9cf 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -50,7 +50,7 @@ #include "tarray.h" #include "m_bbox.h" #include "c_console.h" -#include "r_main.h" +#include "r_state.h" const int MaxSegs = 64; const int SplitCost = 8; diff --git a/src/nodebuild_extract.cpp b/src/nodebuild_extract.cpp index b502fa8bc..6260ac2f0 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -43,7 +43,6 @@ #include "nodebuild.h" #include "templates.h" -#include "r_main.h" #if 0 #define D(x) x diff --git a/src/nodebuild_gl.cpp b/src/nodebuild_gl.cpp index d990d17c3..add4f7123 100644 --- a/src/nodebuild_gl.cpp +++ b/src/nodebuild_gl.cpp @@ -39,7 +39,6 @@ #include "doomtype.h" #include "nodebuild.h" -#include "r_main.h" static inline void STACK_ARGS Warn (const char *format, ...) { diff --git a/src/nodebuild_utility.cpp b/src/nodebuild_utility.cpp index 35842f76a..ac4671075 100644 --- a/src/nodebuild_utility.cpp +++ b/src/nodebuild_utility.cpp @@ -47,9 +47,9 @@ #include "nodebuild.h" #include "templates.h" #include "m_bbox.h" -#include "r_main.h" #include "i_system.h" #include "po_man.h" +#include "r_state.h" static const int PO_LINE_START = 1; static const int PO_LINE_EXPLICIT = 5; diff --git a/src/p_buildmap.cpp b/src/p_buildmap.cpp index 69287f298..af0819764 100644 --- a/src/p_buildmap.cpp +++ b/src/p_buildmap.cpp @@ -12,7 +12,6 @@ #include "w_wad.h" #include "templates.h" #include "r_sky.h" -#include "r_main.h" #include "r_defs.h" #include "p_setup.h" #include "g_level.h" diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 9ed876226..4e4d8fd5e 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -35,7 +35,6 @@ #include #include "actor.h" -#include "r_main.h" #include "p_conversation.h" #include "w_wad.h" #include "cmdlib.h" @@ -60,6 +59,7 @@ #include "sbar.h" #include "farchive.h" #include "p_lnspec.h" +#include "r_utility.h" #include "menu/menu.h" // The conversations as they exist inside a SCRIPTxx lump. diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 12453abb2..5e6532001 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -36,8 +36,10 @@ #include "doomtype.h" #include "doomstat.h" +#include "i_system.h" #include "c_cvars.h" #include "actor.h" +#include "m_argv.h" #include "p_effect.h" #include "p_local.h" #include "g_level.h" @@ -54,9 +56,17 @@ CVAR (Int, cl_rockettrails, 1, CVAR_ARCHIVE); CVAR (Bool, r_rail_smartspiral, 0, CVAR_ARCHIVE); CVAR (Int, r_rail_spiralsparsity, 1, CVAR_ARCHIVE); CVAR (Int, r_rail_trailsparsity, 1, CVAR_ARCHIVE); +CVAR (Bool, r_particles, true, 0); #define FADEFROMTTL(a) (255/(a)) +// [RH] particle globals +WORD NumParticles; +WORD ActiveParticles; +WORD InactiveParticles; +particle_t *Particles; +TArray ParticlesInSubsec; + static int grey1, grey2, grey3, grey4, red, green, blue, yellow, black, red1, green1, blue1, yellow1, purple, purple1, white, rblue1, rblue2, rblue3, rblue4, orange, yorange, dred, grey5, @@ -95,10 +105,114 @@ static const struct ColorList { {NULL, 0, 0, 0 } }; +inline particle_t *NewParticle (void) +{ + particle_t *result = NULL; + if (InactiveParticles != NO_PARTICLE) + { + result = Particles + InactiveParticles; + InactiveParticles = result->tnext; + result->tnext = ActiveParticles; + ActiveParticles = WORD(result - Particles); + } + return result; +} + +// +// [RH] Particle functions +// +void P_InitParticles (); +void P_DeinitParticles (); + +// [BC] Allow the maximum number of particles to be specified by a cvar (so people +// with lots of nice hardware can have lots of particles!). +CUSTOM_CVAR( Int, r_maxparticles, 4000, CVAR_ARCHIVE ) +{ + if ( self == 0 ) + self = 4000; + else if ( self < 100 ) + self = 100; + + if ( gamestate != GS_STARTUP ) + { + P_DeinitParticles( ); + P_InitParticles( ); + } +} + +void P_InitParticles () +{ + const char *i; + + if ((i = Args->CheckValue ("-numparticles"))) + NumParticles = atoi (i); + // [BC] Use r_maxparticles now. + else + NumParticles = r_maxparticles; + + // This should be good, but eh... + if ( NumParticles < 100 ) + NumParticles = 100; + + P_DeinitParticles(); + Particles = new particle_t[NumParticles]; + P_ClearParticles (); + atterm (P_DeinitParticles); +} + +void P_DeinitParticles() +{ + if (Particles != NULL) + { + delete[] Particles; + Particles = NULL; + } +} + +void P_ClearParticles () +{ + int i; + + memset (Particles, 0, NumParticles * sizeof(particle_t)); + ActiveParticles = NO_PARTICLE; + InactiveParticles = 0; + for (i = 0; i < NumParticles-1; i++) + Particles[i].tnext = i + 1; + Particles[i].tnext = NO_PARTICLE; +} + +// Group particles by subsectors. Because particles are always +// in motion, there is little benefit to caching this information +// from one frame to the next. + +void P_FindParticleSubsectors () +{ + if (ParticlesInSubsec.Size() < (size_t)numsubsectors) + { + ParticlesInSubsec.Reserve (numsubsectors - ParticlesInSubsec.Size()); + } + + clearbufshort (&ParticlesInSubsec[0], numsubsectors, NO_PARTICLE); + + if (!r_particles) + { + return; + } + for (WORD i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext) + { + subsector_t *ssec = R_PointInSubsector (Particles[i].x, Particles[i].y); + int ssnum = int(ssec-subsectors); + Particles[i].subsector = ssec; + Particles[i].snext = ParticlesInSubsec[ssnum]; + ParticlesInSubsec[ssnum] = i; + } +} + void P_InitEffects () { const struct ColorList *color = Colors; + P_InitParticles(); while (color->color) { *(color->color) = ColorMatcher.Pick (color->r, color->g, color->b); diff --git a/src/p_effect.h b/src/p_effect.h index 1ca18e340..5e41929c6 100644 --- a/src/p_effect.h +++ b/src/p_effect.h @@ -49,7 +49,31 @@ #define FX_BLACKFOUNTAIN 0x00060000 #define FX_WHITEFOUNTAIN 0x00070000 -struct particle_t; +// [RH] Particle details +struct particle_t +{ + fixed_t x,y,z; + fixed_t velx,vely,velz; + fixed_t accx,accy,accz; + BYTE ttl; + BYTE trans; + BYTE size; + BYTE fade; + int color; + WORD tnext; + WORD snext; + subsector_t * subsector; +}; + +extern particle_t *Particles; +extern TArray ParticlesInSubsec; + +const WORD NO_PARTICLE = 0xffff; + +void P_ClearParticles (); +void P_FindParticleSubsectors (); + + class AActor; particle_t *JitterParticle (int ttl); diff --git a/src/p_local.h b/src/p_local.h index 1742f69b7..4249442d0 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -23,8 +23,14 @@ #ifndef __P_LOCAL__ #define __P_LOCAL__ +#include "doomtype.h" +#include "doomdef.h" +#include "tables.h" +#include "r_state.h" +#include "r_utility.h" +#include "d_player.h" #ifndef __R_LOCAL__ -#include "r_local.h" +//#include "r_local.h" #endif #include "a_morph.h" diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 963c7ca08..9f59f2a80 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -25,10 +25,10 @@ #include "c_cvars.h" #include "doomstat.h" #include "g_level.h" -#include "r_main.h" #include "nodebuild.h" #include "po_man.h" #include "farchive.h" +#include "r_utility.h" #include "r_data/colormaps.h" diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 279d700bd..c75093b2e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -3930,7 +3930,7 @@ void P_SetupLevel (char *lumpname, int position) R_OldBlend = 0xffffffff; // [RH] Remove all particles - R_ClearParticles (); + P_ClearParticles (); times[17].Clock(); // preload graphics and sounds diff --git a/src/po_man.cpp b/src/po_man.cpp index 59928ed1d..da1e12757 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -22,7 +22,6 @@ #include "tables.h" #include "s_sndseq.h" #include "a_sharedglobal.h" -#include "r_main.h" #include "p_lnspec.h" #include "r_data/r_interpolate.h" #include "g_level.h" diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 4758ae7d2..689977911 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -45,6 +45,7 @@ #include "r_3dfloors.h" #include "a_sharedglobal.h" #include "g_level.h" +#include "p_effect.h" // State. #include "doomstat.h" diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 8cdbac7e9..06350e0b1 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -35,7 +35,6 @@ #include #include "templates.h" -#include "r_main.h" #include "r_data/r_translate.h" #include "v_video.h" #include "g_game.h" @@ -48,6 +47,7 @@ #include "w_wad.h" #include "r_data/colormaps.h" #include "farchive.h" +#include "d_player.h" #include "gi.h" #include "stats.h" diff --git a/src/r_data/sprites.h b/src/r_data/sprites.h index 475b5ea0e..43deab133 100644 --- a/src/r_data/sprites.h +++ b/src/r_data/sprites.h @@ -64,6 +64,7 @@ extern FPlayerSkin * skins; // [RH] extern BYTE OtherGameSkinRemap[256]; extern PalEntry OtherGameSkinPalette[256]; - +void R_InitSprites (); +void R_DeinitSprites (); #endif diff --git a/src/r_main.cpp b/src/r_main.cpp index 1ed4ab5e9..3a9fce10a 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -39,6 +39,7 @@ #include "r_sky.h" #include "st_stuff.h" #include "c_cvars.h" +#include "c_dispatch.h" #include "v_video.h" #include "stats.h" #include "i_video.h" @@ -52,6 +53,7 @@ #include "r_3dfloors.h" #include "v_palette.h" #include "po_man.h" +#include "p_effect.h" #include "st_start.h" #include "v_font.h" #include "r_data/colormaps.h" @@ -96,7 +98,6 @@ extern bool DrawFSHUD; // [RH] Defined in d_main.cpp extern short *openings; extern bool r_fakingunderwater; extern "C" int fuzzviewheight; -EXTERN_CVAR (Bool, r_particles) EXTERN_CVAR (Bool, cl_capfps) // PRIVATE DATA DECLARATIONS ----------------------------------------------- @@ -625,6 +626,32 @@ float R_GetVisibility () return CurrentVisibility; } +//========================================================================== +// +// CCMD r_visibility +// +// Controls how quickly light ramps across a 1/z range. Set this, and it +// sets all the r_*Visibility variables (except r_SkyVisibilily, which is +// currently unused). +// +//========================================================================== + +CCMD (r_visibility) +{ + if (argv.argc() < 2) + { + Printf ("Visibility is %g\n", R_GetVisibility()); + } + else if (!netgame) + { + R_SetVisibility ((float)atof (argv[1])); + } + else + { + Printf ("Visibility cannot be changed in net games.\n"); + } +} + //========================================================================== // // R_SetViewSize @@ -829,7 +856,6 @@ void R_Init () R_InitPlanes (); R_InitTranslationTables (); R_InitShadeMaps(); - R_InitParticles (); // [RH] Setup particle engine R_InitColumnDrawers (); colfunc = basecolfunc = R_DrawColumn; @@ -853,7 +879,6 @@ void R_Init () static void R_Shutdown () { - R_DeinitParticles(); R_DeinitTranslationTables(); R_DeinitPlanes(); R_DeinitColormaps (); @@ -1592,7 +1617,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines) r_fakingunderwater = false; // [RH] Setup particles for this frame - R_FindParticleSubsectors (); + P_FindParticleSubsectors (); WallCycles.Clock(); DWORD savedflags = camera->renderflags; diff --git a/src/r_main.h b/src/r_main.h index 89e82fbbe..4230b3311 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -23,12 +23,8 @@ #ifndef __R_MAIN_H__ #define __R_MAIN_H__ -// Number of diminishing brightness levels. -// There a 0-31, i.e. 32 LUT in the COLORMAP lump. -#define NUMCOLORMAPS 32 - +#include "r_utility.h" #include "d_player.h" -#include "r_state.h" #include "v_palette.h" #include "r_data/colormaps.h" @@ -49,11 +45,6 @@ extern fixed_t viewingrangerecip; extern fixed_t FocalLengthX, FocalLengthY; extern float FocalLengthXfloat; extern fixed_t InvZtoScale; -extern int WidescreenRatio; - -extern angle_t LocalViewAngle; // [RH] Added to consoleplayer's angle -extern int LocalViewPitch; // [RH] Used directly instead of consoleplayer's pitch -extern bool LocalKeyboardTurner; // [RH] The local player used the keyboard to turn, so interpolate extern float WallTMapScale; extern float WallTMapScale2; @@ -75,8 +66,6 @@ extern float iyaspectmulfloat; extern FDynamicColormap*basecolormap; // [RH] Colormap for sector currently being drawn -extern int validcount; - extern int linecount; extern int loopcount; @@ -120,10 +109,6 @@ extern float r_TiltVisibility; extern fixed_t r_SpriteVisibility; extern fixed_t r_SkyVisibility; -extern fixed_t r_TicFrac; -extern DWORD r_FrameTime; -extern bool r_NoInterpolate; - extern int extralight, r_actualextralight; extern bool foggy; extern int fixedlightlev; @@ -149,33 +134,6 @@ extern void (*hcolfunc_post2) (int hx, int sx, int yl, int yh); extern void (STACK_ARGS *hcolfunc_post4) (int sx, int yl, int yh); -// -// Utility functions. - -//========================================================================== -// -// R_PointOnSide -// -// Traverse BSP (sub) tree, check point against partition plane. -// Returns side 0 (front/on) or 1 (back). -// -// [RH] inlined, stripped down, and made more precise -// -//========================================================================== - -inline int R_PointOnSide (fixed_t x, fixed_t y, const node_t *node) -{ - return DMulScale32 (y-node->y, node->dx, node->x-x, node->dy) > 0; -} - -extern fixed_t viewx; -extern fixed_t viewy; - -angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); -inline angle_t R_PointToAngle (fixed_t x, fixed_t y) { return R_PointToAngle2 (viewx, viewy, x, y); } -subsector_t *R_PointInSubsector (fixed_t x, fixed_t y); -fixed_t R_PointToDist2 (fixed_t dx, fixed_t dy); - void R_SetFOV (float fov); float R_GetFOV (); void R_InitTextureMapping (); @@ -192,7 +150,6 @@ void R_SetupBuffer (); void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines = false); -void R_ResetViewInterpolation (); // Called by startup code. void R_Init (void); @@ -205,9 +162,6 @@ void R_SetViewSize (int blocks); void R_MultiresInit (void); -extern void R_FreePastViewers (); -extern void R_ClearPastViewer (AActor *actor); - extern int stacked_extralight; extern float stacked_visibility; extern fixed_t stacked_viewx, stacked_viewy, stacked_viewz; @@ -215,24 +169,5 @@ extern angle_t stacked_angle; extern void R_CopyStackedViewParameters(); -// This list keeps track of the cameras that draw into canvas textures. -struct FCanvasTextureInfo -{ - FCanvasTextureInfo *Next; - TObjPtr Viewpoint; - FCanvasTexture *Texture; - FTextureID PicNum; - int FOV; - - static void Add (AActor *viewpoint, FTextureID picnum, int fov); - static void UpdateAll (); - static void EmptyList (); - static void Serialize (FArchive &arc); - static void Mark(); - -private: - static FCanvasTextureInfo *List; -}; - #endif // __R_MAIN_H__ diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 4275f553c..9e754853f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -68,8 +68,6 @@ static void R_DrawSkyStriped (visplane_t *pl); -EXTERN_CVAR (Bool, r_particles); - planefunction_t floorfunc; planefunction_t ceilingfunc; diff --git a/src/r_things.cpp b/src/r_things.cpp index 2a769a1f0..89abed2cc 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -34,7 +34,6 @@ #include "templates.h" #include "doomdef.h" #include "m_swap.h" -#include "m_argv.h" #include "i_system.h" #include "w_wad.h" #include "r_local.h" @@ -53,6 +52,7 @@ #include "d_net.h" #include "colormatcher.h" #include "d_netinf.h" +#include "p_effect.h" #include "r_bsp.h" #include "r_plane.h" #include "r_segs.h" @@ -115,8 +115,6 @@ FDynamicColormap *VisPSpritesBaseColormap[NUMPSPRITES]; static int spriteshade; -TArray ParticlesInSubsec; - // constant arrays // used for psprite clipping and initializing clipping short zeroarray[MAXWIDTH]; @@ -134,14 +132,6 @@ int OffscreenBufferWidth, OffscreenBufferHeight; BYTE *OffscreenColorBuffer; FCoverageBuffer *OffscreenCoverageBuffer; -// [RH] particle globals -WORD NumParticles; -WORD ActiveParticles; -WORD InactiveParticles; -particle_t *Particles; - -CVAR (Bool, r_particles, true, 0); - // // GAME FUNCTIONS // @@ -2000,94 +1990,6 @@ void R_DrawMasked (void) } -// -// [RH] Particle functions -// - -// [BC] Allow the maximum number of particles to be specified by a cvar (so people -// with lots of nice hardware can have lots of particles!). -CUSTOM_CVAR( Int, r_maxparticles, 4000, CVAR_ARCHIVE ) -{ - if ( self == 0 ) - self = 4000; - else if ( self < 100 ) - self = 100; - - if ( gamestate != GS_STARTUP ) - { - R_DeinitParticles( ); - R_InitParticles( ); - } -} - -void R_InitParticles () -{ - const char *i; - - if ((i = Args->CheckValue ("-numparticles"))) - NumParticles = atoi (i); - // [BC] Use r_maxparticles now. - else - NumParticles = r_maxparticles; - - // This should be good, but eh... - if ( NumParticles < 100 ) - NumParticles = 100; - - R_DeinitParticles(); - Particles = new particle_t[NumParticles]; - R_ClearParticles (); - atterm (R_DeinitParticles); -} - -void R_DeinitParticles() -{ - if (Particles != NULL) - { - delete[] Particles; - Particles = NULL; - } -} - -void R_ClearParticles () -{ - int i; - - memset (Particles, 0, NumParticles * sizeof(particle_t)); - ActiveParticles = NO_PARTICLE; - InactiveParticles = 0; - for (i = 0; i < NumParticles-1; i++) - Particles[i].tnext = i + 1; - Particles[i].tnext = NO_PARTICLE; -} - -// Group particles by subsectors. Because particles are always -// in motion, there is little benefit to caching this information -// from one frame to the next. - -void R_FindParticleSubsectors () -{ - if (ParticlesInSubsec.Size() < (size_t)numsubsectors) - { - ParticlesInSubsec.Reserve (numsubsectors - ParticlesInSubsec.Size()); - } - - clearbufshort (&ParticlesInSubsec[0], numsubsectors, NO_PARTICLE); - - if (!r_particles) - { - return; - } - for (WORD i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext) - { - subsector_t *ssec = R_PointInSubsector (Particles[i].x, Particles[i].y); - int ssnum = int(ssec-subsectors); - Particles[i].subsector = ssec; - Particles[i].snext = ParticlesInSubsec[ssnum]; - ParticlesInSubsec[ssnum] = i; - } -} - void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, int fakeside) { fixed_t tr_x; diff --git a/src/r_things.h b/src/r_things.h index a751d1445..b031eea7e 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -60,50 +60,10 @@ struct vissprite_t visstyle_t Style; }; -// [RH] Particle details -struct particle_t -{ - fixed_t x,y,z; - fixed_t velx,vely,velz; - fixed_t accx,accy,accz; - BYTE ttl; - BYTE trans; - BYTE size; - BYTE fade; - int color; - WORD tnext; - WORD snext; - subsector_t * subsector; -}; +struct particle_t; -extern WORD NumParticles; -extern WORD ActiveParticles; -extern WORD InactiveParticles; -extern particle_t *Particles; - -const WORD NO_PARTICLE = 0xffff; - -inline particle_t *NewParticle (void) -{ - particle_t *result = NULL; - if (InactiveParticles != NO_PARTICLE) - { - result = Particles + InactiveParticles; - InactiveParticles = result->tnext; - result->tnext = ActiveParticles; - ActiveParticles = WORD(result - Particles); - } - return result; -} - -void R_InitParticles (); -void R_DeinitParticles (); -void R_ClearParticles (); void R_DrawParticle (vissprite_t *); void R_ProjectParticle (particle_t *, const sector_t *sector, int shade, int fakeside); -void R_FindParticleSubsectors (); - -extern TArray ParticlesInSubsec; extern int MaxVisSprites; @@ -135,8 +95,6 @@ void R_SortVisSprites (int (STACK_ARGS *compare)(const void *, const void *), si void R_AddSprites (sector_t *sec, int lightlevel, int fakeside); void R_AddPSprites (); void R_DrawSprites (); -void R_InitSprites (); -void R_DeinitSprites (); void R_ClearSprites (); void R_DrawMasked (); void R_DrawRemainingPlayerSprites (); diff --git a/src/r_utility.h b/src/r_utility.h new file mode 100644 index 000000000..e885a9ef9 --- /dev/null +++ b/src/r_utility.h @@ -0,0 +1,72 @@ +#ifndef __R_UTIL_H +#define __R_UTIL_H + +#include "r_state.h" +// +// Stuff from r_main.h that's needed outside the rendering code. + +// Number of diminishing brightness levels. +// There a 0-31, i.e. 32 LUT in the COLORMAP lump. +#define NUMCOLORMAPS 32 + +extern fixed_t viewx; +extern fixed_t viewy; + +extern bool r_NoInterpolate; +extern int validcount; + +extern angle_t LocalViewAngle; // [RH] Added to consoleplayer's angle +extern int LocalViewPitch; // [RH] Used directly instead of consoleplayer's pitch +extern bool LocalKeyboardTurner; // [RH] The local player used the keyboard to turn, so interpolate +extern int WidescreenRatio; + +extern fixed_t r_TicFrac; +extern DWORD r_FrameTime; + +//========================================================================== +// +// R_PointOnSide +// +// Traverse BSP (sub) tree, check point against partition plane. +// Returns side 0 (front/on) or 1 (back). +// +// [RH] inlined, stripped down, and made more precise +// +//========================================================================== + +inline int R_PointOnSide (fixed_t x, fixed_t y, const node_t *node) +{ + return DMulScale32 (y-node->y, node->dx, node->x-x, node->dy) > 0; +} + +angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); +inline angle_t R_PointToAngle (fixed_t x, fixed_t y) { return R_PointToAngle2 (viewx, viewy, x, y); } +subsector_t *R_PointInSubsector (fixed_t x, fixed_t y); +fixed_t R_PointToDist2 (fixed_t dx, fixed_t dy); +void R_ResetViewInterpolation (); +void R_SetViewSize (int blocks); + +extern void R_FreePastViewers (); +extern void R_ClearPastViewer (AActor *actor); + +// This list keeps track of the cameras that draw into canvas textures. +struct FCanvasTextureInfo +{ + FCanvasTextureInfo *Next; + TObjPtr Viewpoint; + FCanvasTexture *Texture; + FTextureID PicNum; + int FOV; + + static void Add (AActor *viewpoint, FTextureID picnum, int fov); + static void UpdateAll (); + static void EmptyList (); + static void Serialize (FArchive &arc); + static void Mark(); + +private: + static FCanvasTextureInfo *List; +}; + + +#endif diff --git a/src/sdl/i_main.cpp b/src/sdl/i_main.cpp index dc5b82e0c..d80d8a430 100644 --- a/src/sdl/i_main.cpp +++ b/src/sdl/i_main.cpp @@ -61,7 +61,7 @@ #include "g_level.h" #include "r_state.h" #include "cmdlib.h" -#include "r_main.h" +#include "r_utility.h" #include "doomstat.h" // MACROS ------------------------------------------------------------------ diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index 0e6ff925c..f047f4dde 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -35,8 +35,8 @@ #include "doomtype.h" #include "files.h" -#include "r_main.h" #include "templates.h" +#include "r_utility.h" #include "textures/textures.h" diff --git a/src/v_palette.cpp b/src/v_palette.cpp index a745d3c53..80ea75a6f 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -47,7 +47,6 @@ #include "templates.h" #include "v_video.h" #include "i_system.h" -#include "r_main.h" // For lighting constants #include "w_wad.h" #include "i_video.h" #include "c_dispatch.h" diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 87c50da99..eeab8226a 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -79,7 +79,7 @@ #include "cmdlib.h" #include "g_level.h" #include "doomstat.h" -#include "r_main.h" +#include "r_utility.h" #include "stats.h" #include "st_start.h" diff --git a/zdoom.vcproj b/zdoom.vcproj index 9500d7573..832fdf305 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -2407,6 +2407,10 @@ RelativePath=".\src\r_things.h" > + +