// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. // Copyright (C) 1999-2018 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- /// \file r_main.h /// \brief Rendering variables, consvars, defines #ifndef __R_MAIN__ #define __R_MAIN__ #ifdef __cplusplus extern "C" { #endif #include "d_player.h" #include "r_data.h" #include "m_perfstats.h" // // POV related. // extern fixed_t viewcos, viewsin; extern INT32 viewheight; extern INT32 centerx, centery; extern fixed_t centerxfrac, centeryfrac; extern fixed_t projection, projectiony; extern fixed_t fovtan; // field of view #define MINFOV 5 #define MAXFOV 179 extern size_t validcount, linecount, loopcount, framecount; // Evaluated delta tics for this frame (how many tics since the last frame) extern fixed_t renderdeltatics; // The current render is a new logical tic extern boolean renderisnewtic; extern mobj_t *viewmobj; // // Lighting LUT. // Used for z-depth cuing per column/row, // and other lighting effects (sector ambient, flash). // // Lighting constants. // Now with 32 levels. #define LIGHTLEVELS 32 #define LIGHTSEGSHIFT 3 #define MAXLIGHTSCALE 48 #define LIGHTSCALESHIFT 12 #define MAXLIGHTZ 128 #define LIGHTZSHIFT 20 #define LIGHTRESOLUTIONFIX (640*fovtan/vid.width) extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // Number of diminishing brightness levels. // There a 0-31, i.e. 32 LUT in the COLORMAP lump. #define NUMCOLORMAPS 32 #define COLORMAP_SIZE (256*LIGHTLEVELS) #define COLORMAP_REMAPOFFSET COLORMAP_SIZE // Utility functions. // // R_PointOnSide // Traverse BSP (sub) tree, // check point against partition plane. // Returns side 0 (front) or 1 (back). // // killough 5/2/98: reformatted // FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t* restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; if (!node->dy) return y <= node->y ? node->dx < 0 : node->dx > 0; x -= node->x; y -= node->y; // Try to quickly decide by looking at sign bits. // also use a mask to avoid branch prediction INT32 mask = (((node->dy ^ node->dx ^ x ^ y) < 0) ? -1 : 0); return (mask & ((node->dy ^ x) < 0)) | // (left is negative) (~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x))); } // This is not as accurate // SHOULD NOT BE USED FOR ANYTHING GAMEPLAY RELATED!! FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSideFast(fixed_t x, fixed_t y, const node_t* restrict node) { // use cross product to determine side quickly INT64 v = ((INT64)y - node->y) * node->dx - ((INT64)x - node->x) * node->dy; return v > 0; } FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) { fixed_t lx = line->v1->x; fixed_t ly = line->v1->y; fixed_t ldx = line->v2->x - lx; fixed_t ldy = line->v2->y - ly; // use cross product to determine side quickly INT64 v = ((INT64)y - ly) * ldx - ((INT64)x - lx) * ldy; return v > 0; } angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); // // R_PointInSubsector // #define R_POINTINSUBSECTOR(FUNCNAME, SIDEFUNC)\ FUNCINLINE static ATTRINLINE subsector_t *FUNCNAME(fixed_t x, fixed_t y)\ {\ size_t nodenum = numnodes-1;\ while (!(nodenum & NF_SUBSECTOR))\ nodenum = nodes[nodenum].children[SIDEFUNC(x, y, nodes+nodenum)];\ return &subsectors[nodenum & ~NF_SUBSECTOR];\ } R_POINTINSUBSECTOR(R_PointInSubsector, R_PointOnSide) R_POINTINSUBSECTOR(R_PointInSubsectorFast, R_PointOnSideFast) subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); #define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) #define R_PointToDist2(px2, py2, px1, py1) FixedHypot((px1) - (px2), (py1) - (py2)) FUNCMATH FUNCINLINE static ATTRINLINE fixed_t R_QuickDist(fixed_t x1, fixed_t y1, fixed_t x, fixed_t y) { const fixed_t absx = abs(x - x1); const fixed_t absy = abs(y - y1); #ifdef __cplusplus return std::max(absx, absy); #else return max(absx, absy); #endif } // Takes 2 fixed-point coordinates, returns "distance" between them and camera, // as an fixed-point integer. // It is very rough, tho it is used only for optimizing out unnecessary // interpolation, so it is kinda ok on big distances. FUNCINLINE static ATTRINLINE PUREFUNC fixed_t R_QuickCamDist(fixed_t x, fixed_t y) { return R_QuickDist(viewx, viewy, x, y); } line_t *R_GetFFloorLine(const line_t *line, const ffloor_t *pfloor, const sector_t *sector); side_t *R_GetFFloorSide(const line_t *line, const ffloor_t *pfloor, const sector_t *sector); boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh); // Performance stats extern precise_t ps_prevframetime;// time when previous frame was rendered extern ps_metric_t ps_rendercalltime; extern ps_metric_t ps_otherrendertime; extern ps_metric_t ps_uitime; extern ps_metric_t ps_swaptime; extern ps_metric_t ps_skyboxtime; extern ps_metric_t ps_bsptime; extern ps_metric_t ps_sw_spritecliptime; extern ps_metric_t ps_sw_portaltime; extern ps_metric_t ps_sw_planetime; extern ps_metric_t ps_sw_maskedtime; extern ps_metric_t ps_numbspcalls; extern ps_metric_t ps_numsprites; extern ps_metric_t ps_numdrawnodes; extern ps_metric_t ps_numpolyobjects; // // REFRESH - the actual rendering functions. // extern consvar_t cv_precachetextures; extern consvar_t cv_showhud, cv_translucenthud, cv_uncappedhud; extern consvar_t cv_homremoval; extern consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcammode; extern consvar_t cv_shadow, cv_shadowoffs; extern consvar_t cv_ffloorclip, cv_spriteclip; extern consvar_t cv_softcyancut; extern consvar_t cv_translucency; extern consvar_t cv_drawdist, cv_drawdist_precip, cv_lessprecip; extern consvar_t cv_fov, cv_fovchange; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; extern consvar_t cv_maxinterpdist; extern consvar_t cv_playerfade; extern consvar_t cv_ripplewater; extern consvar_t cv_secbright; extern consvar_t cv_randomdirlight; FUNCINLINE static ATTRINLINE INT32 R_GetSoftLightlevel(INT32 llevel) { return CLAMP(llevel, cv_secbright.value, 255) >> LIGHTSEGSHIFT; } // Called by startup code. void R_Init(void); void R_CheckViewMorph(void); void R_ApplyViewMorph(void); angle_t R_ViewRollAngle(const player_t *player); // just sets setsizeneeded true extern boolean setsizeneeded; void R_SetViewSize(void); // do it (sometimes explicitly called) void R_ExecuteSetViewSize(void); fixed_t R_GetPlayerFov(player_t *player); void R_SkyboxFrame(UINT8 pnum); void R_SetupFrame(UINT8 pnum, boolean skybox); // Called by G_Drawer. void R_RenderPlayerView(player_t *player); // add commands related to engine, at game startup void R_RegisterEngineStuff(void); #ifdef __cplusplus } // extern "C" #endif #endif