diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 71c4ccd9..379849ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -744,14 +744,12 @@ add_executable( zdoom WIN32 r_bsp.cpp r_draw.cpp r_drawt.cpp - r_interpolate.cpp r_main.cpp r_plane.cpp r_polymost.cpp r_segs.cpp r_sky.cpp r_things.cpp - r_translate.cpp s_advsound.cpp s_environment.cpp s_playlist.cpp @@ -973,8 +971,11 @@ add_executable( zdoom WIN32 fragglescript/t_spec.cpp fragglescript/t_variable.cpp fragglescript/t_cmd.cpp - resources/colormaps.cpp - resources/voxels.cpp + r_data/colormaps.cpp + r_data/voxels.cpp + r_data/renderstyle.cpp + r_data/r_interpolate.cpp + r_data/r_translate.cpp autozend.cpp ) diff --git a/src/actor.h b/src/actor.h index 4afd5500..5f8b8fb1 100644 --- a/src/actor.h +++ b/src/actor.h @@ -37,7 +37,7 @@ #include "doomdef.h" #include "textures/textures.h" -#include "r_blend.h" +#include "r_data/renderstyle.h" #include "s_sound.h" #include "memarena.h" diff --git a/src/am_map.cpp b/src/am_map.cpp index 4fa8149a..a411fb57 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -33,7 +33,7 @@ #include "w_wad.h" #include "a_sharedglobal.h" #include "statnums.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "d_event.h" #include "gi.h" #include "r_bsp.h" @@ -63,7 +63,7 @@ #include "a_artifacts.h" #include "po_man.h" #include "a_keys.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" //============================================================================= // diff --git a/src/b_game.cpp b/src/b_game.cpp index 2ff74a28..7d8e94ff 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -48,7 +48,6 @@ Everything that is changed is marked (maybe commented) with "Added by MC" #include "b_bot.h" #include "g_game.h" #include "m_random.h" -#include "r_things.h" #include "doomstat.h" #include "cmdlib.h" #include "sc_man.h" diff --git a/src/c_console.cpp b/src/c_console.cpp index c19ff3f2..c8cac63b 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -54,7 +54,6 @@ #include "v_text.h" #include "w_wad.h" #include "r_main.h" -#include "r_draw.h" #include "sbar.h" #include "s_sound.h" #include "s_sndseq.h" diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index c5da6a0e..931c656c 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -60,14 +60,13 @@ #include "gi.h" #include "c_dispatch.h" #include "decallib.h" -#include "r_draw.h" #include "v_palette.h" #include "a_sharedglobal.h" #include "thingdef/thingdef.h" #include "thingdef/thingdef_exp.h" #include "vectors.h" #include "dobject.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "sc_man.h" #include "i_system.h" #include "doomerrors.h" diff --git a/src/d_main.cpp b/src/d_main.cpp index e59ebe6f..070fc916 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -765,7 +765,7 @@ void D_Display () } if (!automapactive || viewactive) { - R_RefreshViewBorder (); + V_RefreshViewBorder (); } if (hud_althud && viewheight == SCREENHEIGHT && screenblocks > 10) diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index def80065..45ae686c 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -47,13 +47,12 @@ #include "v_palette.h" #include "v_video.h" #include "i_system.h" -#include "r_draw.h" #include "r_state.h" #include "sbar.h" #include "gi.h" #include "m_random.h" #include "teaminfo.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "templates.h" #include "cmdlib.h" diff --git a/src/decallib.cpp b/src/decallib.cpp index 3f8c5deb..2ebc3557 100644 --- a/src/decallib.cpp +++ b/src/decallib.cpp @@ -42,9 +42,8 @@ #include "weightedlist.h" #include "statnums.h" #include "templates.h" -#include "r_draw.h" #include "a_sharedglobal.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "gi.h" #include "g_level.h" #include "colormatcher.h" diff --git a/src/decallib.h b/src/decallib.h index 70804b0e..4b457192 100644 --- a/src/decallib.h +++ b/src/decallib.h @@ -37,7 +37,7 @@ #include #include "doomtype.h" -#include "r_blend.h" +#include "r_data/renderstyle.h" #include "textures/textures.h" class FScanner; diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index 05d7f3e5..1bc05269 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -67,7 +67,7 @@ #include "c_dispatch.h" #include "p_acs.h" #include "s_sndseq.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "doomstat.h" #include "m_argv.h" #include "po_man.h" diff --git a/src/doomstat.cpp b/src/doomstat.cpp index cd93ac18..27c50b81 100644 --- a/src/doomstat.cpp +++ b/src/doomstat.cpp @@ -67,3 +67,5 @@ int NextSkill = -1; int SinglePlayerClass[MAXPLAYERS]; bool ToggleFullscreen; +int BorderTopRefresh; + diff --git a/src/dsectoreffect.cpp b/src/dsectoreffect.cpp index 6c717b99..d678ac37 100644 --- a/src/dsectoreffect.cpp +++ b/src/dsectoreffect.cpp @@ -26,7 +26,7 @@ #include "gi.h" #include "p_local.h" #include "p_3dmidtex.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "statnums.h" IMPLEMENT_CLASS (DSectorEffect) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 473ac356..ba4ac70e 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -65,7 +65,7 @@ #include "g_level.h" #include "v_palette.h" #include "v_font.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include "gl/gl_functions.h" diff --git a/src/g_doom/a_scriptedmarine.cpp b/src/g_doom/a_scriptedmarine.cpp index a6dd7f7b..67bbbf0b 100644 --- a/src/g_doom/a_scriptedmarine.cpp +++ b/src/g_doom/a_scriptedmarine.cpp @@ -2,12 +2,11 @@ #include "actor.h" #include "p_enemy.h" #include "a_action.h" -#include "r_draw.h" #include "m_random.h" #include "p_local.h" #include "a_doomglobal.h" #include "s_sound.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "thingdef/thingdef.h" #include "g_level.h" */ diff --git a/src/g_game.cpp b/src/g_game.cpp index 6feb318f..dda2e975 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -62,7 +62,6 @@ #include "s_sound.h" #include "gstrings.h" #include "r_sky.h" -#include "r_draw.h" #include "g_game.h" #include "g_level.h" #include "b_bot.h" //Added by MC: @@ -72,13 +71,13 @@ #include "gi.h" #include "a_keys.h" #include "a_artifacts.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "cmdlib.h" #include "d_net.h" #include "d_event.h" #include "p_acs.h" #include "m_joy.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include diff --git a/src/g_heretic/a_hereticmisc.cpp b/src/g_heretic/a_hereticmisc.cpp index 7fc24937..4304b820 100644 --- a/src/g_heretic/a_hereticmisc.cpp +++ b/src/g_heretic/a_hereticmisc.cpp @@ -12,7 +12,7 @@ #include "g_level.h" #include "a_sharedglobal.h" #include "templates.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "doomstat.h" // Include all the other Heretic stuff here to reduce compile time diff --git a/src/g_heretic/a_hereticweaps.cpp b/src/g_heretic/a_hereticweaps.cpp index f6c9df7f..d7c083be 100644 --- a/src/g_heretic/a_hereticweaps.cpp +++ b/src/g_heretic/a_hereticweaps.cpp @@ -10,7 +10,7 @@ #include "p_local.h" #include "gstrings.h" #include "gi.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "thingdef/thingdef.h" #include "doomstat.h" */ diff --git a/src/g_level.cpp b/src/g_level.cpp index 5167908a..bfa7ef1d 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -69,16 +69,16 @@ #include "version.h" #include "statnums.h" #include "sbarinfo.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "p_lnspec.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "cmdlib.h" #include "d_net.h" #include "d_netinf.h" #include "v_palette.h" #include "menu/menu.h" #include "a_strifeglobal.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include "gi.h" diff --git a/src/g_shared/a_action.cpp b/src/g_shared/a_action.cpp index 4a10ff08..ddac7a40 100644 --- a/src/g_shared/a_action.cpp +++ b/src/g_shared/a_action.cpp @@ -11,7 +11,7 @@ #include "p_enemy.h" #include "statnums.h" #include "templates.h" -#include "r_translate.h" +#include "r_data/r_translate.h" static FRandom pr_freezedeath ("FreezeDeath"); static FRandom pr_icesettics ("IceSetTics"); diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp index 98f93ebc..3fab6b55 100644 --- a/src/g_shared/a_artifacts.cpp +++ b/src/g_shared/a_artifacts.cpp @@ -19,7 +19,7 @@ #include "g_level.h" #include "doomstat.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" static FRandom pr_torch ("Torch"); diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index c469bb73..6583881b 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -50,7 +50,7 @@ #include "i_system.h" #include "sbarinfo.h" #include "gi.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "r_main.h" #include "a_weaponpiece.h" #include "a_strifeglobal.h" @@ -993,7 +993,7 @@ public: if(script->completeBorder) //Fill the statusbar with the border before we draw. { FTexture *b = TexMan[gameinfo.border->b]; - R_DrawBorder(viewwindowx, viewwindowy + viewheight + b->GetHeight(), viewwindowx + viewwidth, SCREENHEIGHT); + V_DrawBorder(viewwindowx, viewwindowy + viewheight + b->GetHeight(), viewwindowx + viewwidth, SCREENHEIGHT); if(screenblocks == 10) screen->FlatFill(viewwindowx, viewwindowy + viewheight, viewwindowx + viewwidth, viewwindowy + viewheight + b->GetHeight(), b, true); } diff --git a/src/g_shared/shared_sbar.cpp b/src/g_shared/shared_sbar.cpp index 0a0817a3..0a8badb8 100644 --- a/src/g_shared/shared_sbar.cpp +++ b/src/g_shared/shared_sbar.cpp @@ -41,7 +41,6 @@ #include "c_console.h" #include "v_video.h" #include "m_swap.h" -#include "r_draw.h" #include "w_wad.h" #include "v_text.h" #include "s_sound.h" @@ -1053,8 +1052,8 @@ void DBaseStatusBar::RefreshBackground () const y = x == ST_X ? ST_Y : ::ST_Y; x2 = !(ratio & 3) || !Scaled ? ST_X+HorizontalResolution : SCREENWIDTH - (SCREENWIDTH*(48-BaseRatioSizes[ratio][3])+48*2-1)/(48*2); - R_DrawBorder (0, y, x, SCREENHEIGHT); - R_DrawBorder (x2, y, SCREENWIDTH, SCREENHEIGHT); + V_DrawBorder (0, y, x, SCREENHEIGHT); + V_DrawBorder (x2, y, SCREENWIDTH, SCREENHEIGHT); if (setblocks >= 10) { diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index 721a8d4e..9aa74498 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -42,7 +42,7 @@ #include "doomtype.h" #include "colormatcher.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "i_system.h" #include "p_local.h" #include "p_lnspec.h" diff --git a/src/gl/data/gl_portaldata.cpp b/src/gl/data/gl_portaldata.cpp index 161bf559..638dcb4e 100644 --- a/src/gl/data/gl_portaldata.cpp +++ b/src/gl/data/gl_portaldata.cpp @@ -41,7 +41,7 @@ #include "doomtype.h" #include "colormatcher.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "i_system.h" #include "p_local.h" #include "p_lnspec.h" diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index 55bbe0be..1657bf2d 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -42,7 +42,7 @@ #include "gl/system/gl_system.h" #include "doomtype.h" #include "colormatcher.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "i_system.h" #include "p_local.h" #include "p_lnspec.h" diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index e9ccc68d..15ca5485 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -3,7 +3,7 @@ #include "gl/utility/gl_geometric.h" #include "p_pspr.h" -#include "resources/voxels.h" +#include "r_data/voxels.h" #define MAX_LODS 4 diff --git a/src/gl/renderer/gl_colormap.h b/src/gl/renderer/gl_colormap.h index 27ff7e4a..32c1eb2f 100644 --- a/src/gl/renderer/gl_colormap.h +++ b/src/gl/renderer/gl_colormap.h @@ -3,7 +3,7 @@ #include "doomtype.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" extern DWORD gl_fixedcolormap; diff --git a/src/gl/renderer/gl_lightdata.h b/src/gl/renderer/gl_lightdata.h index ec41872c..b97e61fd 100644 --- a/src/gl/renderer/gl_lightdata.h +++ b/src/gl/renderer/gl_lightdata.h @@ -2,7 +2,7 @@ #define __GL_LIGHTDATA #include "v_palette.h" -#include "r_blend.h" +#include "r_data/renderstyle.h" #include "gl/renderer/gl_colormap.h" bool gl_BrightmapsActive(); diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 46654aa2..e5d6d6f0 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -44,6 +44,7 @@ #include "r_draw.h" #include "v_video.h" #include "r_main.h" +#include "r_data/r_translate.h" #include "m_png.h" #include "m_crc32.h" #include "w_wad.h" diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index ec1e968c..794ec4dc 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -277,7 +277,7 @@ static void AddPolyobjs(subsector_t *sub) { if (sub->BSP == NULL || sub->BSP->bDirty) { - R_BuildPolyBSP(sub); + sub->BuildPolyBSP(); } if (sub->BSP->Nodes.Size() == 0) { diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index ee0d5b14..e04ac086 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -42,6 +42,7 @@ #include "gl/system/gl_system.h" #include "r_sky.h" #include "r_main.h" +#include "r_defs.h" #include "gl/system/gl_cvars.h" #include "gl/data/gl_data.h" @@ -1060,7 +1061,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo Colormap.LightColor.r = Colormap.LightColor.g = Colormap.LightColor.b = 0xff; lightlevel=255; } - else lightlevel=abs(ceiling? GetCeilingLight(sec) : GetFloorLight(sec)); + else lightlevel=abs(ceiling? sec->GetCeilingLight() : sec->GetFloorLight()); } int rel = extralight * gl_weaponlight; diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index c598d988..793d60f8 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -3,10 +3,6 @@ #include "gl/scene/gl_wall.h" - -int GetFloorLight (const sector_t *sec); -int GetCeilingLight (const sector_t *sec); - enum GLDrawItemType { GLDIT_WALL, diff --git a/src/gl/scene/gl_fakeflat.cpp b/src/gl/scene/gl_fakeflat.cpp index 7f683ef8..8e964915 100644 --- a/src/gl/scene/gl_fakeflat.cpp +++ b/src/gl/scene/gl_fakeflat.cpp @@ -1,9 +1,9 @@ /* -** gl_renderutil.cpp -** Utility functions for the renderer +** gl_fakeflat.cpp +** Fake flat functions to render stacked sectors ** **--------------------------------------------------------------------------- -** Copyright 2001-2008 Christoph Oelckers +** Copyright 2001-2011 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -192,14 +192,6 @@ void gl_CheckViewArea(vertex_t *v1, vertex_t *v2, sector_t *frontsector, sector_ } -//========================================================================== -// -// -// -//========================================================================== - -bool CopyPlaneIfValid (secplane_t *dest, const secplane_t *source, const secplane_t *opp); - //========================================================================== // // This is mostly like R_FakeFlat but with a few alterations necessitated @@ -252,7 +244,7 @@ sector_t * gl_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac // Replace floor and ceiling height with control sector's heights. if (diffTex) { - if (CopyPlaneIfValid (&dest->floorplane, &s->floorplane, &sec->ceilingplane)) + if (s->floorplane.CopyPlaneIfValid (&dest->floorplane, &sec->ceilingplane)) { dest->SetTexture(sector_t::floor, s->GetTexture(sector_t::floor), false); dest->SetPlaneTexZ(sector_t::floor, s->GetPlaneTexZ(sector_t::floor)); @@ -290,7 +282,7 @@ sector_t * gl_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac { if (diffTex) { - if (CopyPlaneIfValid (&dest->ceilingplane, &s->ceilingplane, &sec->floorplane)) + if (s->ceilingplane.CopyPlaneIfValid (&dest->ceilingplane, &sec->floorplane)) { dest->SetTexture(sector_t::ceiling, s->GetTexture(sector_t::ceiling), false); dest->SetPlaneTexZ(sector_t::ceiling, s->GetPlaneTexZ(sector_t::ceiling)); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index bb4e320c..2427d078 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -40,6 +40,7 @@ #include "gl/system/gl_system.h" #include "a_sharedglobal.h" +#include "r_defs.h" #include "r_sky.h" #include "r_main.h" #include "g_level.h" @@ -599,7 +600,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) srf |= SSRF_RENDERFLOOR; - lightlevel = gl_ClampLight(GetFloorLight(frontsector)); + lightlevel = gl_ClampLight(frontsector->GetFloorLight()); Colormap=frontsector->ColorMap; if ((stack = (frontsector->portals[sector_t::floor] != NULL))) { @@ -647,7 +648,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) srf |= SSRF_RENDERCEILING; - lightlevel = gl_ClampLight(GetCeilingLight(frontsector)); + lightlevel = gl_ClampLight(frontsector->GetCeilingLight()); Colormap=frontsector->ColorMap; if ((stack = (frontsector->portals[sector_t::ceiling] != NULL))) { diff --git a/src/gl/scene/gl_renderhacks.cpp b/src/gl/scene/gl_renderhacks.cpp index 3a27d0e0..c6831282 100644 --- a/src/gl/scene/gl_renderhacks.cpp +++ b/src/gl/scene/gl_renderhacks.cpp @@ -40,6 +40,7 @@ #include "a_sharedglobal.h" #include "r_main.h" +#include "r_defs.h" #include "r_sky.h" #include "g_level.h" @@ -53,9 +54,6 @@ #include "gl/utility/gl_clock.h" #include "gl/utility/gl_templates.h" -int GetFloorLight (const sector_t *sec); -int GetCeilingLight (const sector_t *sec); - // This is for debugging maps. @@ -768,7 +766,7 @@ bool FDrawInfo::CheckAnchorFloor(subsector_t * sub) // using such crap hacks is simply too small if (sub->render_sector->GetTexture(sector_t::floor)==backsub->render_sector->GetTexture(sector_t::floor) && sub->render_sector->GetPlaneTexZ(sector_t::floor)==backsub->render_sector->GetPlaneTexZ(sector_t::floor) && - GetFloorLight(sub->render_sector)==GetFloorLight(backsub->render_sector)) + sub->render_sector->GetFloorLight() == backsub->render_sector->GetFloorLight()) { continue; } @@ -806,7 +804,7 @@ bool FDrawInfo::CollectSubsectorsFloor(subsector_t * sub, sector_t * anchor) if (sub->render_sector->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) || sub->render_sector->GetPlaneTexZ(sector_t::floor)!=anchor->GetPlaneTexZ(sector_t::floor) || - GetFloorLight(sub->render_sector)!=GetFloorLight(anchor)) + sub->render_sector->GetFloorLight() != anchor->GetFloorLight()) { if (sub==viewsubsector && viewzGetPlaneTexZ(sector_t::floor)) inview=true; HandledSubsectors.Push (sub); @@ -835,7 +833,7 @@ bool FDrawInfo::CollectSubsectorsFloor(subsector_t * sub, sector_t * anchor) // Any anchor not within the original anchor's visplane terminates the processing. if (sub->render_sector->GetTexture(sector_t::floor)!=anchor->GetTexture(sector_t::floor) || sub->render_sector->GetPlaneTexZ(sector_t::floor)!=anchor->GetPlaneTexZ(sector_t::floor) || - GetFloorLight(sub->render_sector)!=GetFloorLight(anchor)) + sub->render_sector->GetFloorLight() != anchor->GetFloorLight()) { return false; } @@ -874,7 +872,7 @@ bool FDrawInfo::CheckAnchorCeiling(subsector_t * sub) // using such crap hacks is simply too small if (sub->render_sector->GetTexture(sector_t::ceiling)==backsub->render_sector->GetTexture(sector_t::ceiling) && sub->render_sector->GetPlaneTexZ(sector_t::ceiling)==backsub->render_sector->GetPlaneTexZ(sector_t::ceiling) && - GetCeilingLight(sub->render_sector)==GetCeilingLight(backsub->render_sector)) + sub->render_sector->GetCeilingLight() == backsub->render_sector->GetCeilingLight()) { continue; } @@ -908,7 +906,7 @@ bool FDrawInfo::CollectSubsectorsCeiling(subsector_t * sub, sector_t * anchor) if (sub->render_sector->GetTexture(sector_t::ceiling)!=anchor->GetTexture(sector_t::ceiling) || sub->render_sector->GetPlaneTexZ(sector_t::ceiling)!=anchor->GetPlaneTexZ(sector_t::ceiling) || - GetCeilingLight(sub->render_sector)!=GetCeilingLight(anchor)) + sub->render_sector->GetCeilingLight() != anchor->GetCeilingLight()) { HandledSubsectors.Push (sub); } @@ -936,7 +934,7 @@ bool FDrawInfo::CollectSubsectorsCeiling(subsector_t * sub, sector_t * anchor) // Any anchor not within the original anchor's visplane terminates the processing. if (sub->render_sector->GetTexture(sector_t::ceiling)!=anchor->GetTexture(sector_t::ceiling) || sub->render_sector->GetPlaneTexZ(sector_t::ceiling)!=anchor->GetPlaneTexZ(sector_t::ceiling) || - GetCeilingLight(sub->render_sector)!=GetCeilingLight(anchor)) + sub->render_sector->GetCeilingLight() != anchor->GetCeilingLight()) { return false; } @@ -1068,7 +1066,7 @@ void FDrawInfo::CollectSectorStacksCeiling(subsector_t * sub, sector_t * anchor) sector_t * me = gl_FakeFlat(sub->render_sector, &fake, false); if (me->GetTexture(sector_t::ceiling) != anchor->GetTexture(sector_t::ceiling) || me->ceilingplane != anchor->ceilingplane || - GetCeilingLight(me) != GetCeilingLight(anchor) || + me->GetCeilingLight() != anchor->GetCeilingLight() || me->ColorMap != anchor->ColorMap || me->GetXOffset(sector_t::ceiling) != anchor->GetXOffset(sector_t::ceiling) || me->GetYOffset(sector_t::ceiling) != anchor->GetYOffset(sector_t::ceiling) || @@ -1116,7 +1114,7 @@ void FDrawInfo::CollectSectorStacksFloor(subsector_t * sub, sector_t * anchor) sector_t * me = gl_FakeFlat(sub->render_sector, &fake, false); if (me->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) || me->floorplane != anchor->floorplane || - GetFloorLight(me) != GetFloorLight(anchor) || + me->GetFloorLight() != anchor->GetFloorLight() || me->ColorMap != anchor->ColorMap || me->GetXOffset(sector_t::floor) != anchor->GetXOffset(sector_t::floor) || me->GetYOffset(sector_t::floor) != anchor->GetYOffset(sector_t::floor) || diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 2597b25e..7ab94f4d 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -46,7 +46,7 @@ #include "dobject.h" #include "doomstat.h" #include "g_level.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "r_main.h" #include "r_things.h" #include "sbar.h" diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index ab19e549..1154c09e 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -39,10 +39,11 @@ */ #include "gl/system/gl_system.h" #include "p_local.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "g_level.h" #include "doomstat.h" #include "gl/gl_functions.h" +#include "r_defs.h" #include "r_sky.h" #include "gl/system/gl_framebuffer.h" @@ -676,7 +677,8 @@ void GLSprite::Process(AActor* thing,sector_t * sector) (!gl_BrightmapsActive() || !gltexture || !gltexture->tex->gl_info.bBrightmapDisablesFullbright); lightlevel=fullbright? 255 : - gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? GetCeilingLight(rendersector) : GetFloorLight(rendersector)); + gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? + rendersector->GetCeilingLight() : rendersector->GetFloorLight()); foglevel = (BYTE)clamp(rendersector->lightlevel, 0, 255); lightlevel = (byte)gl_CheckSpriteGlow(rendersector->GetTexture(sector_t::floor), lightlevel, thingz-thing->floorz); @@ -862,7 +864,8 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s if (particle->trans==0) return; - lightlevel = gl_ClampLight(sector->GetTexture(sector_t::ceiling) == skyflatnum ? GetCeilingLight(sector) : GetFloorLight(sector)); + lightlevel = gl_ClampLight(sector->GetTexture(sector_t::ceiling) == skyflatnum ? + sector->GetCeilingLight() : sector->GetFloorLight()); foglevel = sector->lightlevel; if (gl_fixedcolormap) diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index b4d82e9d..16cdfae3 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -45,6 +45,7 @@ #include "g_level.h" #include "templates.h" #include "vectors.h" +#include "r_defs.h" #include "r_sky.h" #include "gl/system/gl_cvars.h" @@ -508,7 +509,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) { type = RENDERWALL_HORIZON; hi.plane.GetFromSector(fs, true); - hi.lightlevel = gl_ClampLight(GetCeilingLight(fs)); + hi.lightlevel = gl_ClampLight(fs->GetCeilingLight()); hi.colormap = fs->ColorMap; if (fs->e->XFloor.ffloors.Size()) @@ -537,7 +538,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) { type = RENDERWALL_HORIZON; hi.plane.GetFromSector(fs, false); - hi.lightlevel = gl_ClampLight(GetFloorLight(fs)); + hi.lightlevel = gl_ClampLight(fs->GetFloorLight()); hi.colormap = fs->ColorMap; if (fs->e->XFloor.ffloors.Size()) diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index dda580b8..5bf64f6d 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -42,7 +42,7 @@ #include "p_local.h" #include "p_lnspec.h" #include "a_sharedglobal.h" -#include "r_blend.h" +//#include "r_data/r_blend.h" #include "gl/gl_functions.h" #include "gl/system/gl_cvars.h" diff --git a/src/gl/textures/gl_bitmap.cpp b/src/gl/textures/gl_bitmap.cpp index 6900edd4..a70a3eb7 100644 --- a/src/gl/textures/gl_bitmap.cpp +++ b/src/gl/textures/gl_bitmap.cpp @@ -37,7 +37,7 @@ */ -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "v_palette.h" #include "templates.h" #include "gl/renderer/gl_lightdata.h" diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 2f2c3e23..4703ffdf 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -47,7 +47,7 @@ #include "r_main.h" #include "templates.h" #include "sc_man.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "colormatcher.h" //#include "gl/gl_intern.h" diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index a77fcb66..24cbd9d2 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -40,7 +40,7 @@ #include "w_wad.h" #include "templates.h" #include "colormatcher.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "c_dispatch.h" #ifdef _WIN32 #include "win32gliface.h" diff --git a/src/gl/textures/gl_translate.cpp b/src/gl/textures/gl_translate.cpp index 9865f127..2670cd48 100644 --- a/src/gl/textures/gl_translate.cpp +++ b/src/gl/textures/gl_translate.cpp @@ -39,6 +39,7 @@ */ #include "doomtype.h" +#include "r_data/r_translate.h" #include "gl/textures/gl_translate.h" #include "m_crc32.h" diff --git a/src/gl/textures/gl_translate.h b/src/gl/textures/gl_translate.h index 1bdc92e5..b382fb4e 100644 --- a/src/gl/textures/gl_translate.h +++ b/src/gl/textures/gl_translate.h @@ -2,7 +2,7 @@ #define __GL_TRANSLATE__ #include "doomtype.h" -#include "r_translate.h" +//#include "r_data/r_translate.h" #include "v_video.h" enum diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 556f9156..1ef24689 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -45,7 +45,7 @@ #include "actor.h" #include "d_player.h" #include "r_state.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "c_bind.h" #include "g_level.h" #include "p_conversation.h" diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index e2a41ddf..0bb699f8 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -40,7 +40,7 @@ #include "a_keys.h" #include "templates.h" #include "c_console.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "g_level.h" #include "d_net.h" #include "d_dehacked.h" diff --git a/src/menu/menu.h b/src/menu/menu.h index dc333b42..8a484b7b 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -6,7 +6,7 @@ #include "dobject.h" #include "d_player.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "c_cvars.h" #include "v_font.h" #include "version.h" diff --git a/src/menu/playermenu.cpp b/src/menu/playermenu.cpp index de0292f7..7aa668ea 100644 --- a/src/menu/playermenu.cpp +++ b/src/menu/playermenu.cpp @@ -45,7 +45,7 @@ #include "teaminfo.h" #include "v_palette.h" #include "r_state.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "v_text.h" EXTERN_CVAR (String, playerclass) diff --git a/src/nodebuild_extract.cpp b/src/nodebuild_extract.cpp index c4546bb5..b502fa8b 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -165,6 +165,7 @@ void FNodeBuilder::ExtractMini (FMiniBSP *bsp) { unsigned int i; + bsp->bDirty = false; bsp->Verts.Resize(Vertices.Size()); for (i = 0; i < Vertices.Size(); ++i) { diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index 2469f5d6..0d3e160b 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -41,7 +41,7 @@ #include "w_wad.h" #include "sc_man.h" #include "g_level.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #ifdef _3DFLOORS EXTERN_CVAR(Int, vid_renderer) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index ac7e94fa..653a309f 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -66,7 +66,7 @@ #include "sc_man.h" #include "c_bind.h" #include "info.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "cmdlib.h" #include "m_png.h" #include "p_setup.h" diff --git a/src/p_buildmap.cpp b/src/p_buildmap.cpp index 1290c3ef..69287f29 100644 --- a/src/p_buildmap.cpp +++ b/src/p_buildmap.cpp @@ -16,7 +16,7 @@ #include "r_defs.h" #include "p_setup.h" #include "g_level.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/src/p_effect.cpp b/src/p_effect.cpp index c5ea4e2d..12453abb 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -44,7 +44,6 @@ #include "v_video.h" #include "m_random.h" #include "r_defs.h" -#include "r_things.h" #include "s_sound.h" #include "templates.h" #include "gi.h" diff --git a/src/p_floor.cpp b/src/p_floor.cpp index 3fff563f..4d7a6c13 100644 --- a/src/p_floor.cpp +++ b/src/p_floor.cpp @@ -30,7 +30,7 @@ #include "r_state.h" #include "tables.h" #include "p_3dmidtex.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" //========================================================================== // diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 7f537611..eb1c2b1c 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -52,11 +52,11 @@ #include "m_random.h" #include "p_conversation.h" #include "a_strifeglobal.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "p_3dmidtex.h" #include "d_net.h" #include "d_event.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #define FUNC(a) static int a (line_t *ln, AActor *it, bool backSide, \ int arg0, int arg1, int arg2, int arg3, int arg4) diff --git a/src/p_map.cpp b/src/p_map.cpp index 01d695aa..9e927698 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -50,7 +50,7 @@ #include "a_sharedglobal.h" #include "p_conversation.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "g_level.h" #define WATER_SINK_FACTOR 3 diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 457c6471..adaef861 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -53,7 +53,7 @@ #include "thingdef/thingdef.h" #include "g_game.h" #include "teaminfo.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "r_sky.h" #include "g_level.h" #include "d_event.h" @@ -61,7 +61,7 @@ #include "v_palette.h" #include "p_enemy.h" #include "gstrings.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/src/p_pillar.cpp b/src/p_pillar.cpp index 4faed647..2f2c1551 100644 --- a/src/p_pillar.cpp +++ b/src/p_pillar.cpp @@ -37,7 +37,7 @@ #include "p_spec.h" #include "g_level.h" #include "s_sndseq.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" IMPLEMENT_POINTY_CLASS (DPillar) DECLARE_POINTER(m_Interp_Floor) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index fa1267f0..9b84694a 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -44,11 +44,11 @@ #include "s_sndseq.h" #include "v_palette.h" #include "a_sharedglobal.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "g_level.h" #include "po_man.h" #include "p_setup.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" static void CopyPlayer (player_t *dst, player_t *src, const char *name); static void ReadOnePlayer (FArchive &arc, bool skipload); diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 6397bcae..a54033b0 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -24,8 +24,11 @@ #include "p_spec.h" #include "c_cvars.h" #include "doomstat.h" +#include "g_level.h" #include "r_main.h" -#include "resources/colormaps.h" +#include "nodebuild.h" +#include "po_man.h" +#include "r_data/colormaps.h" // [RH] @@ -774,6 +777,61 @@ bool sector_t::PlaneMoving(int pos) } +int sector_t::GetFloorLight () const +{ + if (GetFlags(sector_t::floor) & PLANEF_ABSLIGHTING) + { + return GetPlaneLight(floor); + } + else + { + return ClampLight(lightlevel + GetPlaneLight(floor)); + } +} + +int sector_t::GetCeilingLight () const +{ + if (GetFlags(ceiling) & PLANEF_ABSLIGHTING) + { + return GetPlaneLight(ceiling); + } + else + { + return ClampLight(lightlevel + GetPlaneLight(ceiling)); + } +} + +bool secplane_t::CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const +{ + bool copy = false; + + // If the planes do not have matching slopes, then always copy them + // because clipping would require creating new sectors. + if (a != dest->a || b != dest->b || c != dest->c) + { + copy = true; + } + else if (opp->a != -dest->a || opp->b != -dest->b || opp->c != -dest->c) + { + if (d < dest->d) + { + copy = true; + } + } + else if (d < dest->d && d > -opp->d) + { + copy = true; + } + + if (copy) + { + *dest = *this; + } + + return copy; +} + + //========================================================================== // // P_AlignFlat @@ -805,3 +863,108 @@ bool P_AlignFlat (int linenum, int side, int fc) sec->SetBase(fc, dist & ((1<<(FRACBITS+8))-1), 0-angle); return true; } + +//========================================================================== +// +// P_BuildPolyBSP +// +//========================================================================== +static FNodeBuilder::FLevel PolyNodeLevel; +static FNodeBuilder PolyNodeBuilder(PolyNodeLevel); + +void subsector_t::BuildPolyBSP() +{ + assert((BSP == NULL || BSP->bDirty) && "BSP computed more than once"); + + // Set up level information for the node builder. + PolyNodeLevel.Sides = sides; + PolyNodeLevel.NumSides = numsides; + PolyNodeLevel.Lines = lines; + PolyNodeLevel.NumLines = numlines; + + // Feed segs to the nodebuilder and build the nodes. + PolyNodeBuilder.Clear(); + PolyNodeBuilder.AddSegs(firstline, numlines); + for (FPolyNode *pn = polys; pn != NULL; pn = pn->pnext) + { + PolyNodeBuilder.AddPolySegs(&pn->segs[0], (int)pn->segs.Size()); + } + PolyNodeBuilder.BuildMini(false); + if (BSP == NULL) + { + BSP = new FMiniBSP; + } + PolyNodeBuilder.ExtractMini(BSP); + for (unsigned int i = 0; i < BSP->Subsectors.Size(); ++i) + { + BSP->Subsectors[i].sector = sector; + } +} + +//========================================================================== +// +// +// +//========================================================================== + +CUSTOM_CVAR(Int, r_fakecontrast, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +{ + if (self < 0) self = 1; + else if (self > 2) self = 2; +} + +//========================================================================== +// +// +// +//========================================================================== + +int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const +{ + if (Flags & WALLF_ABSLIGHTING) + { + baselight = Light; + } + + if (pfakecontrast != NULL) + { + *pfakecontrast = 0; + } + + if (!foggy) // Don't do relative lighting in foggy sectors + { + if (!(Flags & WALLF_NOFAKECONTRAST) && r_fakecontrast != 0) + { + int rel; + if (((level.flags2 & LEVEL2_SMOOTHLIGHTING) || (Flags & WALLF_SMOOTHLIGHTING) || r_fakecontrast == 2) && + linedef->dx != 0) + { + rel = xs_RoundToInt // OMG LEE KILLOUGH LIVES! :/ + ( + level.WallHorizLight + + fabs(atan(double(linedef->dy) / linedef->dx) / 1.57079) + * (level.WallVertLight - level.WallHorizLight) + ); + } + else + { + rel = linedef->dx == 0 ? level.WallVertLight : + linedef->dy == 0 ? level.WallHorizLight : 0; + } + if (pfakecontrast != NULL) + { + *pfakecontrast = rel; + } + else + { + baselight += rel; + } + } + if (!(Flags & WALLF_ABSLIGHTING)) + { + baselight += this->Light; + } + } + return baselight; +} + diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 466a8f0f..c3c55ea4 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -58,15 +58,15 @@ #include "s_sndseq.h" #include "sbar.h" #include "p_setup.h" -#include "r_translate.h" -#include "r_interpolate.h" +#include "r_data/r_translate.h" +#include "r_data/r_interpolate.h" #include "r_sky.h" #include "cmdlib.h" #include "g_level.h" #include "md5.h" #include "compatibility.h" #include "po_man.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include "gl/gl_functions.h" diff --git a/src/p_spec.cpp b/src/p_spec.cpp index f052a2e3..7cf24b98 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -66,7 +66,7 @@ #include "c_console.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" static FRandom pr_playerinspecialsector ("PlayerInSpecialSector"); void P_SetupPortals(); diff --git a/src/p_tick.cpp b/src/p_tick.cpp index c0e5dfb1..b2ef3d37 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -29,7 +29,7 @@ #include "s_sound.h" #include "doomstat.h" #include "sbar.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "i_sound.h" #include "g_level.h" diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 1ad67850..53922ab6 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -43,7 +43,7 @@ #include "v_palette.h" #include "p_udmf.h" #include "r_state.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" //=========================================================================== // diff --git a/src/p_user.cpp b/src/p_user.cpp index d18a31b6..c8b615d0 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -30,7 +30,6 @@ #include "doomstat.h" #include "s_sound.h" #include "i_system.h" -#include "r_draw.h" #include "gi.h" #include "m_random.h" #include "p_pspr.h" diff --git a/src/po_man.cpp b/src/po_man.cpp index 0f9b0b15..0afe9538 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -24,7 +24,7 @@ #include "a_sharedglobal.h" #include "r_main.h" #include "p_lnspec.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "g_level.h" #include "po_man.h" #include "p_setup.h" diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 6aab9d64..4758ae7d 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -45,7 +45,6 @@ #include "r_3dfloors.h" #include "a_sharedglobal.h" #include "g_level.h" -#include "nodebuild.h" // State. #include "doomstat.h" @@ -54,7 +53,7 @@ #include "v_palette.h" #include "r_sky.h" #include "po_man.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" int WallMost (short *mostbuf, const secplane_t &plane); @@ -112,9 +111,6 @@ WORD MirrorFlags; seg_t *ActiveWallMirror; TArray WallMirrors; -static FNodeBuilder::FLevel PolyNodeLevel; -static FNodeBuilder PolyNodeBuilder(PolyNodeLevel); - static subsector_t *InSubsector; CVAR (Bool, r_drawflat, false, 0) // [RH] Don't texture segs? @@ -313,59 +309,6 @@ void R_ClearClipSegs (short left, short right) newend = solidsegs+2; } -int GetFloorLight (const sector_t *sec) -{ - if (sec->GetFlags(sector_t::floor) & PLANEF_ABSLIGHTING) - { - return sec->GetPlaneLight(sector_t::floor); - } - else - { - return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::floor)); - } -} - -int GetCeilingLight (const sector_t *sec) -{ - if (sec->GetFlags(sector_t::ceiling) & PLANEF_ABSLIGHTING) - { - return sec->GetPlaneLight(sector_t::ceiling); - } - else - { - return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling)); - } -} - -bool CopyPlaneIfValid (secplane_t *dest, const secplane_t *source, const secplane_t *opp) -{ - bool copy = false; - - // If the planes do not have matching slopes, then always copy them - // because clipping would require creating new sectors. - if (source->a != dest->a || source->b != dest->b || source->c != dest->c) - { - copy = true; - } - else if (opp->a != -dest->a || opp->b != -dest->b || opp->c != -dest->c) - { - if (source->d < dest->d) - { - copy = true; - } - } - else if (source->d < dest->d && source->d > -opp->d) - { - copy = true; - } - - if (copy) - { - *dest = *source; - } - - return copy; -} // // killough 3/7/98: Hack floor/ceiling heights for deep water etc. @@ -387,12 +330,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, // [RH] allow per-plane lighting if (floorlightlevel != NULL) { - *floorlightlevel = GetFloorLight (sec); + *floorlightlevel = sec->GetFloorLight (); } if (ceilinglightlevel != NULL) { - *ceilinglightlevel = GetCeilingLight (sec); + *ceilinglightlevel = sec->GetCeilingLight (); } FakeSide = FAKED_Center; @@ -412,7 +355,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, // Replace floor and ceiling height with control sector's heights. if (diffTex) { - if (CopyPlaneIfValid (&tempsec->floorplane, &s->floorplane, &sec->ceilingplane)) + if (s->floorplane.CopyPlaneIfValid (&tempsec->floorplane, &sec->ceilingplane)) { tempsec->SetTexture(sector_t::floor, s->GetTexture(sector_t::floor), false); } @@ -427,12 +370,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, if (floorlightlevel != NULL) { - *floorlightlevel = GetFloorLight (s); + *floorlightlevel = s->GetFloorLight (); } if (ceilinglightlevel != NULL) { - *ceilinglightlevel = GetCeilingLight (s); + *ceilinglightlevel = s->GetCeilingLight (); } } FakeSide = FAKED_BelowFloor; @@ -450,7 +393,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, { if (diffTex) { - if (CopyPlaneIfValid (&tempsec->ceilingplane, &s->ceilingplane, &sec->floorplane)) + if (s->ceilingplane.CopyPlaneIfValid (&tempsec->ceilingplane, &sec->floorplane)) { tempsec->SetTexture(sector_t::ceiling, s->GetTexture(sector_t::ceiling), false); } @@ -528,12 +471,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, if (floorlightlevel != NULL) { - *floorlightlevel = GetFloorLight (s); + *floorlightlevel = s->GetFloorLight (); } if (ceilinglightlevel != NULL) { - *ceilinglightlevel = GetCeilingLight (s); + *ceilinglightlevel = s->GetCeilingLight (); } } FakeSide = FAKED_BelowFloor; @@ -565,12 +508,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, if (floorlightlevel != NULL) { - *floorlightlevel = GetFloorLight (s); + *floorlightlevel = s->GetFloorLight (); } if (ceilinglightlevel != NULL) { - *ceilinglightlevel = GetCeilingLight (s); + *ceilinglightlevel = s->GetCeilingLight (); } } FakeSide = FAKED_AboveCeiling; @@ -1021,62 +964,13 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static return true; } -//========================================================================== -// -// FMiniBSP Constructor -// -//========================================================================== - -FMiniBSP::FMiniBSP() -{ - bDirty = false; -} - -//========================================================================== -// -// P_BuildPolyBSP -// -//========================================================================== - -void R_BuildPolyBSP(subsector_t *sub) -{ - assert((sub->BSP == NULL || sub->BSP->bDirty) && "BSP computed more than once"); - - // Set up level information for the node builder. - PolyNodeLevel.Sides = sides; - PolyNodeLevel.NumSides = numsides; - PolyNodeLevel.Lines = lines; - PolyNodeLevel.NumLines = numlines; - - // Feed segs to the nodebuilder and build the nodes. - PolyNodeBuilder.Clear(); - PolyNodeBuilder.AddSegs(sub->firstline, sub->numlines); - for (FPolyNode *pn = sub->polys; pn != NULL; pn = pn->pnext) - { - PolyNodeBuilder.AddPolySegs(&pn->segs[0], (int)pn->segs.Size()); - } - PolyNodeBuilder.BuildMini(false); - if (sub->BSP == NULL) - { - sub->BSP = new FMiniBSP; - } - else - { - sub->BSP->bDirty = false; - } - PolyNodeBuilder.ExtractMini(sub->BSP); - for (unsigned int i = 0; i < sub->BSP->Subsectors.Size(); ++i) - { - sub->BSP->Subsectors[i].sector = sub->sector; - } -} void R_Subsector (subsector_t *sub); static void R_AddPolyobjs(subsector_t *sub) { if (sub->BSP == NULL || sub->BSP->bDirty) { - R_BuildPolyBSP(sub); + sub->BuildPolyBSP(); } if (sub->BSP->Nodes.Size() == 0) { diff --git a/src/r_bsp.h b/src/r_bsp.h index 2cbdb233..867bb3fc 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -80,7 +80,6 @@ EXTERN_CVAR (Bool, r_drawflat) // [RH] Don't texture segs? // BSP? void R_ClearClipSegs (short left, short right); void R_ClearDrawSegs (); -void R_BuildPolyBSP(subsector_t *sub); void R_RenderBSPNode (void *node); // killough 4/13/98: fake floors/ceilings for deep water / fake ceilings: diff --git a/src/resources/colormaps.cpp b/src/r_data/colormaps.cpp similarity index 96% rename from src/resources/colormaps.cpp rename to src/r_data/colormaps.cpp index c0ce25c2..50cf5ced 100644 --- a/src/resources/colormaps.cpp +++ b/src/r_data/colormaps.cpp @@ -47,8 +47,6 @@ #include "v_text.h" #include "st_start.h" #include "doomstat.h" -#include "r_bsp.h" -#include "r_segs.h" #include "v_palette.h" #include "colormatcher.h" #include "colormaps.h" diff --git a/src/resources/colormaps.h b/src/r_data/colormaps.h similarity index 91% rename from src/resources/colormaps.h rename to src/r_data/colormaps.h index ba55410a..81f9080e 100644 --- a/src/resources/colormaps.h +++ b/src/r_data/colormaps.h @@ -6,7 +6,7 @@ void R_DeinitColormaps (); DWORD R_ColormapNumForName(const char *name); // killough 4/4/98 void R_SetDefaultColormap (const char *name); // [RH] change normal fadetable -DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap +DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap extern BYTE *realcolormaps; // [RH] make the colormaps externally visible extern size_t numfakecmaps; diff --git a/src/r_interpolate.cpp b/src/r_data/r_interpolate.cpp similarity index 95% rename from src/r_interpolate.cpp rename to src/r_data/r_interpolate.cpp index 9bdaeb21..1e0c0a3b 100644 --- a/src/r_interpolate.cpp +++ b/src/r_data/r_interpolate.cpp @@ -35,7 +35,7 @@ #include "p_3dmidtex.h" #include "stats.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "p_local.h" #include "i_system.h" #include "po_man.h" diff --git a/src/r_interpolate.h b/src/r_data/r_interpolate.h similarity index 100% rename from src/r_interpolate.h rename to src/r_data/r_interpolate.h diff --git a/src/r_translate.cpp b/src/r_data/r_translate.cpp similarity index 93% rename from src/r_translate.cpp rename to src/r_data/r_translate.cpp index fc3d1274..81b84060 100644 --- a/src/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -35,9 +35,8 @@ #include #include "templates.h" -#include "r_draw.h" #include "r_main.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "v_video.h" #include "g_game.h" #include "colormatcher.h" @@ -47,13 +46,14 @@ #include "doomerrors.h" #include "i_system.h" #include "w_wad.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include "gi.h" #include "stats.h" TAutoGrowArray translationtables[NUM_TRANSLATION_TABLES]; + const BYTE IcePalette[16][3] = { { 10, 8, 18 }, @@ -681,7 +681,7 @@ static void PushIdentityTable(int slot) void R_InitTranslationTables () { - int i, j; + int i; // Each player gets two translations. Doom and Strife don't use the // extra ones, but Heretic and Hexen do. These are set up during @@ -815,41 +815,6 @@ void R_InitTranslationTables () remap->Remap[i] = IcePaletteRemap[v]; remap->Palette[i] = PalEntry(255, IcePalette[v][0], IcePalette[v][1], IcePalette[v][2]); } - - // set up shading tables for shaded columns - // 16 colormap sets, progressing from full alpha to minimum visible alpha - - BYTE *table = shadetables; - - // Full alpha - for (i = 0; i < 16; ++i) - { - ShadeFakeColormap[i].Color = ~0u; - ShadeFakeColormap[i].Desaturate = ~0u; - ShadeFakeColormap[i].Next = NULL; - ShadeFakeColormap[i].Maps = table; - - for (j = 0; j < NUMCOLORMAPS; ++j) - { - int a = (NUMCOLORMAPS - j) * 256 / NUMCOLORMAPS * (16-i); - for (int k = 0; k < 256; ++k) - { - BYTE v = (((k+2) * a) + 256) >> 14; - table[k] = MIN (v, 64); - } - table += 256; - } - } - for (i = 0; i < NUMCOLORMAPS*16*256; ++i) - { - assert(shadetables[i] <= 64); - } - - // Set up a guaranteed identity map - for (i = 0; i < 256; ++i) - { - identitymap[i] = i; - } } //---------------------------------------------------------------------------- diff --git a/src/r_translate.h b/src/r_data/r_translate.h similarity index 100% rename from src/r_translate.h rename to src/r_data/r_translate.h diff --git a/src/r_data/renderstyle.cpp b/src/r_data/renderstyle.cpp new file mode 100644 index 00000000..4b1d9fed --- /dev/null +++ b/src/r_data/renderstyle.cpp @@ -0,0 +1,195 @@ +/* +** r_data.cpp +** +**--------------------------------------------------------------------------- +** Copyright 2008-2011 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "farchive.h" +#include "templates.h" +#include "renderstyle.h" +#include "c_cvars.h" + +CVAR (Bool, r_drawtrans, true, 0) +CVAR (Int, r_drawfuzz, 1, CVAR_ARCHIVE) + +// Convert legacy render styles to flexible render styles. + +// Apple's GCC 4.0.1 apparently wants to initialize the AsDWORD member of FRenderStyle +// rather than the struct before it, which goes against the standard. +#ifndef __APPLE__ +FRenderStyle LegacyRenderStyles[STYLE_Count] = +{ + /* STYLE_None */ {{ STYLEOP_None, STYLEALPHA_Zero, STYLEALPHA_Zero, 0 }}, + /* STYLE_Normal */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 }}, + /* STYLE_Fuzzy */ {{ STYLEOP_Fuzz, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_SoulTrans */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_TransSoulsAlpha }}, + /* STYLE_OptFuzzy */ {{ STYLEOP_FuzzOrAdd, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_Stencil */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 | STYLEF_ColorIsFixed }}, + /* STYLE_Translucent */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_Add */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_One, 0 }}, + /* STYLE_Shaded */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_RedIsAlpha | STYLEF_ColorIsFixed }}, +/* STYLE_TranslucentStencil */{{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed }}, + /* STYLE_Shadow */{{ STYLEOP_Shadow, 0, 0, 0 }}, +}; +#else +FRenderStyle LegacyRenderStyles[STYLE_Count]; + +static const BYTE Styles[STYLE_Count * 4] = +{ + STYLEOP_None, STYLEALPHA_Zero, STYLEALPHA_Zero, 0, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1, + STYLEOP_Fuzz, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_TransSoulsAlpha, + STYLEOP_FuzzOrAdd, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 | STYLEF_ColorIsFixed, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_One, 0, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_RedIsAlpha | STYLEF_ColorIsFixed, + STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed, + STYLEOP_Shadow, 0, 0, 0 +}; + +static struct LegacyInit +{ + LegacyInit() + { + for (int i = 0; i < STYLE_Count; ++i) + { + LegacyRenderStyles[i].BlendOp = Styles[i*4]; + LegacyRenderStyles[i].SrcAlpha = Styles[i*4+1]; + LegacyRenderStyles[i].DestAlpha = Styles[i*4+2]; + LegacyRenderStyles[i].Flags = Styles[i*4+3]; + } + } +} DoLegacyInit; + +#endif + +FArchive &operator<< (FArchive &arc, FRenderStyle &style) +{ + arc << style.BlendOp << style.SrcAlpha << style.DestAlpha << style.Flags; + return arc; +} + +//========================================================================== +// +// FRenderStyle :: IsVisible +// +// Coupled with the given alpha, will this render style produce something +// visible on-screen? +// +//========================================================================== + +bool FRenderStyle::IsVisible(fixed_t alpha) const throw() +{ + if (BlendOp == STYLEOP_None) + { + return false; + } + if (BlendOp == STYLEOP_Add || BlendOp == STYLEOP_RevSub) + { + if (Flags & STYLEF_Alpha1) + { + alpha = FRACUNIT; + } + else + { + alpha = clamp(alpha, 0, FRACUNIT); + } + return GetAlpha(SrcAlpha, alpha) != 0 || GetAlpha(DestAlpha, alpha) != FRACUNIT; + } + // Treat anything else as visible. + return true; +} + + +//========================================================================== +// +// FRenderStyle :: CheckFuzz +// +// Adjusts settings based on r_drawfuzz CVAR +// +//========================================================================== + +void FRenderStyle::CheckFuzz() +{ + switch (BlendOp) + { + default: + return; + + case STYLEOP_FuzzOrAdd: + if (r_drawtrans && r_drawfuzz == 0) + { + BlendOp = STYLEOP_Add; + return; + } + break; + + case STYLEOP_FuzzOrSub: + if (r_drawtrans && r_drawfuzz == 0) + { + BlendOp = STYLEOP_Sub; + return; + } + break; + + case STYLEOP_FuzzOrRevSub: + if (r_drawtrans && r_drawfuzz == 0) + { + BlendOp = STYLEOP_RevSub; + return; + } + break; + } + + if (r_drawfuzz == 2) + { + BlendOp = STYLEOP_Shadow; + } + else + { + BlendOp = STYLEOP_Fuzz; + } +} + +fixed_t GetAlpha(int type, fixed_t alpha) +{ + switch (type) + { + case STYLEALPHA_Zero: return 0; + case STYLEALPHA_One: return FRACUNIT; + case STYLEALPHA_Src: return alpha; + case STYLEALPHA_InvSrc: return FRACUNIT - alpha; + default: return 0; + } +} + diff --git a/src/r_blend.h b/src/r_data/renderstyle.h similarity index 96% rename from src/r_blend.h rename to src/r_data/renderstyle.h index f9fefc9d..8133557d 100644 --- a/src/r_blend.h +++ b/src/r_data/renderstyle.h @@ -148,5 +148,6 @@ inline FRenderStyle &FRenderStyle::operator= (ERenderStyle legacy) class FArchive; FArchive &operator<< (FArchive &arc, FRenderStyle &style); +fixed_t GetAlpha(int type, fixed_t alpha); #endif diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp new file mode 100644 index 00000000..4def26d8 --- /dev/null +++ b/src/r_data/sprites.cpp @@ -0,0 +1,995 @@ + +#include "doomtype.h" +#include "w_wad.h" +#include "i_system.h" +#include "s_sound.h" +#include "c_console.h" +#include "d_player.h" +#include "d_netinf.h" +#include "gi.h" +#include "colormatcher.h" +#include "c_dispatch.h" +#include "r_defs.h" +#include "v_text.h" +#include "r_data/sprites.h" +#include "r_data/voxels.h" +#include "textures/textures.h" + +// variables used to look up +// and range check thing_t sprites patches +TArray sprites; +TArray SpriteFrames; +DWORD NumStdSprites; // The first x sprites that don't belong to skins. + +struct spriteframewithrotate : public spriteframe_t +{ + int rotate; +} +sprtemp[MAX_SPRITE_FRAMES]; +int maxframe; +char* spritename; + +// [RH] skin globals +FPlayerSkin *skins; +size_t numskins; +BYTE OtherGameSkinRemap[256]; +PalEntry OtherGameSkinPalette[256]; + + + +// +// R_InstallSpriteLump +// Local function for R_InitSprites. +// +// [RH] Removed checks for coexistance of rotation 0 with other +// rotations and made it look more like BOOM's version. +// +static bool R_InstallSpriteLump (FTextureID lump, unsigned frame, char rot, bool flipped) +{ + unsigned rotation; + + if (rot >= '0' && rot <= '9') + { + rotation = rot - '0'; + } + else if (rot >= 'A') + { + rotation = rot - 'A' + 10; + } + else + { + rotation = 17; + } + + if (frame >= MAX_SPRITE_FRAMES || rotation > 16) + { + Printf (TEXTCOLOR_RED"R_InstallSpriteLump: Bad frame characters in lump %s\n", TexMan[lump]->Name); + return false; + } + + if ((int)frame > maxframe) + maxframe = frame; + + if (rotation == 0) + { + // the lump should be used for all rotations + // false=0, true=1, but array initialised to -1 + // allows doom to have a "no value set yet" boolean value! + int r; + + for (r = 14; r >= 0; r -= 2) + { + if (!sprtemp[frame].Texture[r].isValid()) + { + sprtemp[frame].Texture[r] = lump; + if (flipped) + { + sprtemp[frame].Flip |= 1 << r; + } + sprtemp[frame].rotate = false; + } + } + } + else + { + if (rotation <= 8) + { + rotation = (rotation - 1) * 2; + } + else + { + rotation = (rotation - 9) * 2 + 1; + } + + if (!sprtemp[frame].Texture[rotation].isValid()) + { + // the lump is only used for one rotation + sprtemp[frame].Texture[rotation] = lump; + if (flipped) + { + sprtemp[frame].Flip |= 1 << rotation; + } + sprtemp[frame].rotate = true; + } + } + return true; +} + + +// [RH] Seperated out of R_InitSpriteDefs() +static void R_InstallSprite (int num) +{ + int frame; + int framestart; + int rot; +// int undefinedFix; + + if (maxframe == -1) + { + sprites[num].numframes = 0; + return; + } + + maxframe++; + + // [RH] If any frames are undefined, but there are some defined frames, map + // them to the first defined frame. This is a fix for Doom Raider, which actually + // worked with ZDoom 2.0.47, because of a bug here. It does not define frames A, + // B, or C for the sprite PSBG, but because I had sprtemp[].rotate defined as a + // bool, this code never detected that it was not actually present. After switching + // to the unified texture system, this caused it to crash while loading the wad. + +// [RH] Let undefined frames actually be blank because LWM uses this in at least +// one of her wads. +// for (frame = 0; frame < maxframe && sprtemp[frame].rotate == -1; ++frame) +// { } +// +// undefinedFix = frame; + + for (frame = 0; frame < maxframe; ++frame) + { + switch (sprtemp[frame].rotate) + { + case -1: + // no rotations were found for that frame at all + //I_FatalError ("R_InstallSprite: No patches found for %s frame %c", sprites[num].name, frame+'A'); + break; + + case 0: + // only the first rotation is needed + for (rot = 1; rot < 16; ++rot) + { + sprtemp[frame].Texture[rot] = sprtemp[frame].Texture[0]; + } + // If the frame is flipped, they all should be + if (sprtemp[frame].Flip & 1) + { + sprtemp[frame].Flip = 0xFFFF; + } + break; + + case 1: + // must have all 8 frame pairs + for (rot = 0; rot < 8; ++rot) + { + if (!sprtemp[frame].Texture[rot*2+1].isValid()) + { + sprtemp[frame].Texture[rot*2+1] = sprtemp[frame].Texture[rot*2]; + if (sprtemp[frame].Flip & (1 << (rot*2))) + { + sprtemp[frame].Flip |= 1 << (rot*2+1); + } + } + if (!sprtemp[frame].Texture[rot*2].isValid()) + { + sprtemp[frame].Texture[rot*2] = sprtemp[frame].Texture[rot*2+1]; + if (sprtemp[frame].Flip & (1 << (rot*2+1))) + { + sprtemp[frame].Flip |= 1 << (rot*2); + } + } + + } + for (rot = 0; rot < 16; ++rot) + { + if (!sprtemp[frame].Texture[rot].isValid()) + I_FatalError ("R_InstallSprite: Sprite %s frame %c is missing rotations", + sprites[num].name, frame+'A'); + } + break; + } + } + + for (frame = 0; frame < maxframe; ++frame) + { + if (sprtemp[frame].rotate == -1) + { + memset (&sprtemp[frame].Texture, 0, sizeof(sprtemp[0].Texture)); + sprtemp[frame].Flip = 0; + sprtemp[frame].rotate = 0; + } + } + + // allocate space for the frames present and copy sprtemp to it + sprites[num].numframes = maxframe; + sprites[num].spriteframes = WORD(framestart = SpriteFrames.Reserve (maxframe)); + for (frame = 0; frame < maxframe; ++frame) + { + memcpy (SpriteFrames[framestart+frame].Texture, sprtemp[frame].Texture, sizeof(sprtemp[frame].Texture)); + SpriteFrames[framestart+frame].Flip = sprtemp[frame].Flip; + SpriteFrames[framestart+frame].Voxel = sprtemp[frame].Voxel; + } + + // Let the textures know about the rotations + for (frame = 0; frame < maxframe; ++frame) + { + if (sprtemp[frame].rotate == 1) + { + for (int rot = 0; rot < 16; ++rot) + { + TexMan[sprtemp[frame].Texture[rot]]->Rotations = framestart + frame; + } + } + } +} + + +// +// R_InitSpriteDefs +// Pass a null terminated list of sprite names +// (4 chars exactly) to be used. +// Builds the sprite rotation matrices to account +// for horizontally flipped sprites. +// Will report an error if the lumps are inconsistant. +// Only called at startup. +// +// Sprite lump names are 4 characters for the actor, +// a letter for the frame, and a number for the rotation. +// A sprite that is flippable will have an additional +// letter/number appended. +// The rotation character can be 0 to signify no rotations. +// +void R_InitSpriteDefs () +{ + struct Hasher + { + int Head, Next; + } *hashes; + struct VHasher + { + int Head, Next, Name, Spin; + char Frame; + } *vhashes; + unsigned int i, j, smax, vmax; + DWORD intname; + + // Create a hash table to speed up the process + smax = TexMan.NumTextures(); + hashes = new Hasher[smax]; + clearbuf(hashes, sizeof(Hasher)*smax/4, -1); + for (i = 0; i < smax; ++i) + { + FTexture *tex = TexMan.ByIndex(i); + if (tex->UseType == FTexture::TEX_Sprite && strlen(tex->Name) >= 6) + { + size_t bucket = tex->dwName % smax; + hashes[i].Next = hashes[bucket].Head; + hashes[bucket].Head = i; + } + } + + // Repeat, for voxels + vmax = Wads.GetNumLumps(); + vhashes = new VHasher[vmax]; + clearbuf(vhashes, sizeof(VHasher)*vmax/4, -1); + for (i = 0; i < vmax; ++i) + { + if (Wads.GetLumpNamespace(i) == ns_voxels) + { + char name[9]; + size_t namelen; + int spin; + int sign; + + Wads.GetLumpName(name, i); + name[8] = 0; + namelen = strlen(name); + if (namelen < 4) + { // name is too short + continue; + } + if (name[4] != '\0' && name[4] != ' ' && (name[4] < 'A' || name[4] >= 'A' + MAX_SPRITE_FRAMES)) + { // frame char is invalid + continue; + } + spin = 0; + sign = 2; // 2 to convert from deg/halfsec to deg/sec + j = 5; + if (j < namelen && name[j] == '-') + { // a minus sign is okay, but only before any digits + j++; + sign = -2; + } + for (; j < namelen; ++j) + { // the remainder to the end of the name must be digits + if (name[j] >= '0' && name[j] <= '9') + { + spin = spin * 10 + name[j] - '0'; + } + else + { + break; + } + } + if (j < namelen) + { // the spin part is invalid + continue; + } + memcpy(&vhashes[i].Name, name, 4); + vhashes[i].Frame = name[4]; + vhashes[i].Spin = spin * sign; + size_t bucket = vhashes[i].Name % vmax; + vhashes[i].Next = vhashes[bucket].Head; + vhashes[bucket].Head = i; + } + } + + // scan all the lump names for each of the names, noting the highest frame letter. + for (i = 0; i < sprites.Size(); ++i) + { + memset (sprtemp, 0xFF, sizeof(sprtemp)); + for (j = 0; j < MAX_SPRITE_FRAMES; ++j) + { + sprtemp[j].Flip = 0; + sprtemp[j].Voxel = NULL; + } + + maxframe = -1; + intname = sprites[i].dwName; + + // scan the lumps, filling in the frames for whatever is found + int hash = hashes[intname % smax].Head; + while (hash != -1) + { + FTexture *tex = TexMan[hash]; + if (tex->dwName == intname) + { + bool res = R_InstallSpriteLump (FTextureID(hash), tex->Name[4] - 'A', tex->Name[5], false); + + if (tex->Name[6] && res) + R_InstallSpriteLump (FTextureID(hash), tex->Name[6] - 'A', tex->Name[7], true); + } + hash = hashes[hash].Next; + } + + // repeat, for voxels + hash = vhashes[intname % vmax].Head; + while (hash != -1) + { + VHasher *vh = &vhashes[hash]; + if (vh->Name == (int)intname) + { + FVoxelDef *voxdef = R_LoadVoxelDef(hash, vh->Spin); + if (voxdef != NULL) + { + if (vh->Frame == ' ' || vh->Frame == '\0') + { // voxel applies to every sprite frame + for (j = 0; j < MAX_SPRITE_FRAMES; ++j) + { + if (sprtemp[j].Voxel == NULL) + { + sprtemp[j].Voxel = voxdef; + } + } + maxframe = MAX_SPRITE_FRAMES-1; + } + else + { // voxel applies to a specific frame + j = vh->Frame - 'A'; + sprtemp[j].Voxel = voxdef; + maxframe = MAX(maxframe, j); + } + } + } + hash = vh->Next; + } + + R_InstallSprite ((int)i); + } + + delete[] hashes; + delete[] vhashes; +} + +//========================================================================== +// +// R_ExtendSpriteFrames +// +// Extends a sprite so that it can hold the desired frame. +// +//========================================================================== + +static void R_ExtendSpriteFrames(spritedef_t &spr, int frame) +{ + unsigned int i, newstart; + + if (spr.numframes >= ++frame) + { // The sprite already has enough frames, so do nothing. + return; + } + + if (spr.numframes == 0 || (spr.spriteframes + spr.numframes == SpriteFrames.Size())) + { // Sprite's frames are at the end of the array, or it has no frames + // at all, so we can tack the new frames directly on to the end + // of the SpriteFrames array. + newstart = SpriteFrames.Reserve(frame - spr.numframes); + } + else + { // We need to allocate space for all the sprite's frames and copy + // the existing ones over to the new space. The old space will be + // lost. + newstart = SpriteFrames.Reserve(frame); + for (i = 0; i < spr.numframes; ++i) + { + SpriteFrames[newstart + i] = SpriteFrames[spr.spriteframes + i]; + } + spr.spriteframes = WORD(newstart); + newstart += i; + } + // Initialize all new frames to 0. + memset(&SpriteFrames[newstart], 0, sizeof(spriteframe_t)*(frame - spr.numframes)); + spr.numframes = frame; +} + +//========================================================================== +// +// VOX_AddVoxel +// +// Sets a voxel for a single sprite frame. +// +//========================================================================== + +void VOX_AddVoxel(int sprnum, int frame, FVoxelDef *def) +{ + R_ExtendSpriteFrames(sprites[sprnum], frame); + SpriteFrames[sprites[sprnum].spriteframes + frame].Voxel = def; +} + + + +// [RH] +// R_InitSkins +// Reads in everything applicable to a skin. The skins should have already +// been counted and had their identifiers assigned to namespaces. +// +#define NUMSKINSOUNDS 17 +static const char *skinsoundnames[NUMSKINSOUNDS][2] = +{ // The *painXXX sounds must be the first four + { "dsplpain", "*pain100" }, + { "dsplpain", "*pain75" }, + { "dsplpain", "*pain50" }, + { "dsplpain", "*pain25" }, + { "dsplpain", "*poison" }, + + { "dsoof", "*grunt" }, + { "dsoof", "*land" }, + + { "dspldeth", "*death" }, + { "dspldeth", "*wimpydeath" }, + + { "dspdiehi", "*xdeath" }, + { "dspdiehi", "*crazydeath" }, + + { "dsnoway", "*usefail" }, + { "dsnoway", "*puzzfail" }, + + { "dsslop", "*gibbed" }, + { "dsslop", "*splat" }, + + { "dspunch", "*fist" }, + { "dsjump", "*jump" } +}; + +/* +static int STACK_ARGS skinsorter (const void *a, const void *b) +{ + return stricmp (((FPlayerSkin *)a)->name, ((FPlayerSkin *)b)->name); +} +*/ + +void R_InitSkins (void) +{ + FSoundID playersoundrefs[NUMSKINSOUNDS]; + spritedef_t temp; + int sndlumps[NUMSKINSOUNDS]; + char key[65]; + DWORD intname, crouchname; + size_t i; + int j, k, base; + int lastlump; + int aliasid; + bool remove; + const PClass *basetype, *transtype; + + key[sizeof(key)-1] = 0; + i = PlayerClasses.Size () - 1; + lastlump = 0; + + for (j = 0; j < NUMSKINSOUNDS; ++j) + { + playersoundrefs[j] = skinsoundnames[j][1]; + } + + while ((base = Wads.FindLump ("S_SKIN", &lastlump, true)) != -1) + { + // The player sprite has 23 frames. This means that the S_SKIN + // marker needs a minimum of 23 lumps after it. + if (base >= Wads.GetNumLumps() - 23 || base == -1) + continue; + + i++; + for (j = 0; j < NUMSKINSOUNDS; j++) + sndlumps[j] = -1; + skins[i].namespc = Wads.GetLumpNamespace (base); + + FScanner sc(base); + intname = 0; + crouchname = 0; + + remove = false; + basetype = NULL; + transtype = NULL; + + // Data is stored as "key = data". + while (sc.GetString ()) + { + strncpy (key, sc.String, sizeof(key)-1); + if (!sc.GetString() || sc.String[0] != '=') + { + Printf (PRINT_BOLD, "Bad format for skin %d: %s\n", (int)i, key); + break; + } + sc.GetString (); + if (0 == stricmp (key, "name")) + { + strncpy (skins[i].name, sc.String, 16); + for (j = 0; (size_t)j < i; j++) + { + if (stricmp (skins[i].name, skins[j].name) == 0) + { + mysnprintf (skins[i].name, countof(skins[i].name), "skin%d", (int)i); + Printf (PRINT_BOLD, "Skin %s duplicated as %s\n", + skins[j].name, skins[i].name); + break; + } + } + } + else if (0 == stricmp (key, "sprite")) + { + for (j = 3; j >= 0; j--) + sc.String[j] = toupper (sc.String[j]); + intname = *((DWORD *)sc.String); + } + else if (0 == stricmp (key, "crouchsprite")) + { + for (j = 3; j >= 0; j--) + sc.String[j] = toupper (sc.String[j]); + crouchname = *((DWORD *)sc.String); + } + else if (0 == stricmp (key, "face")) + { + for (j = 2; j >= 0; j--) + skins[i].face[j] = toupper (sc.String[j]); + skins[i].face[3] = '\0'; + } + else if (0 == stricmp (key, "gender")) + { + skins[i].gender = D_GenderToInt (sc.String); + } + else if (0 == stricmp (key, "scale")) + { + skins[i].ScaleX = clamp (FLOAT2FIXED(atof (sc.String)), 1, 256*FRACUNIT); + skins[i].ScaleY = skins[i].ScaleX; + } + else if (0 == stricmp (key, "game")) + { + if (gameinfo.gametype == GAME_Heretic) + basetype = PClass::FindClass (NAME_HereticPlayer); + else if (gameinfo.gametype == GAME_Strife) + basetype = PClass::FindClass (NAME_StrifePlayer); + else + basetype = PClass::FindClass (NAME_DoomPlayer); + + transtype = basetype; + + if (stricmp (sc.String, "heretic") == 0) + { + if (gameinfo.gametype & GAME_DoomChex) + { + transtype = PClass::FindClass (NAME_HereticPlayer); + skins[i].othergame = true; + } + else if (gameinfo.gametype != GAME_Heretic) + { + remove = true; + } + } + else if (stricmp (sc.String, "strife") == 0) + { + if (gameinfo.gametype != GAME_Strife) + { + remove = true; + } + } + else + { + if (gameinfo.gametype == GAME_Heretic) + { + transtype = PClass::FindClass (NAME_DoomPlayer); + skins[i].othergame = true; + } + else if (!(gameinfo.gametype & GAME_DoomChex)) + { + remove = true; + } + } + + if (remove) + break; + } + else if (0 == stricmp (key, "class")) + { // [GRB] Define the skin for a specific player class + int pclass = D_PlayerClassToInt (sc.String); + + if (pclass < 0) + { + remove = true; + break; + } + + basetype = transtype = PlayerClasses[pclass].Type; + } + else if (key[0] == '*') + { // Player sound replacment (ZDoom extension) + int lump = Wads.CheckNumForName (sc.String, skins[i].namespc); + if (lump == -1) + { + lump = Wads.CheckNumForFullName (sc.String, true, ns_sounds); + } + if (lump != -1) + { + if (stricmp (key, "*pain") == 0) + { // Replace all pain sounds in one go + aliasid = S_AddPlayerSound (skins[i].name, skins[i].gender, + playersoundrefs[0], lump, true); + for (int l = 3; l > 0; --l) + { + S_AddPlayerSoundExisting (skins[i].name, skins[i].gender, + playersoundrefs[l], aliasid, true); + } + } + else + { + int sndref = S_FindSoundNoHash (key); + if (sndref != 0) + { + S_AddPlayerSound (skins[i].name, skins[i].gender, sndref, lump, true); + } + } + } + } + else + { + for (j = 0; j < NUMSKINSOUNDS; j++) + { + if (stricmp (key, skinsoundnames[j][0]) == 0) + { + sndlumps[j] = Wads.CheckNumForName (sc.String, skins[i].namespc); + if (sndlumps[j] == -1) + { // Replacement not found, try finding it in the global namespace + sndlumps[j] = Wads.CheckNumForFullName (sc.String, true, ns_sounds); + } + } + } + //if (j == 8) + // Printf ("Funny info for skin %i: %s = %s\n", i, key, sc.String); + } + } + + // [GRB] Assume Doom skin by default + if (!remove && basetype == NULL) + { + if (gameinfo.gametype & GAME_DoomChex) + { + basetype = transtype = PClass::FindClass (NAME_DoomPlayer); + } + else if (gameinfo.gametype == GAME_Heretic) + { + basetype = PClass::FindClass (NAME_HereticPlayer); + transtype = PClass::FindClass (NAME_DoomPlayer); + skins[i].othergame = true; + } + else + { + remove = true; + } + } + + if (!remove) + { + skins[i].range0start = transtype->Meta.GetMetaInt (APMETA_ColorRange) & 0xff; + skins[i].range0end = transtype->Meta.GetMetaInt (APMETA_ColorRange) >> 8; + + remove = true; + for (j = 0; j < (int)PlayerClasses.Size (); j++) + { + const PClass *type = PlayerClasses[j].Type; + + if (type->IsDescendantOf (basetype) && + GetDefaultByType (type)->SpawnState->sprite == GetDefaultByType (basetype)->SpawnState->sprite && + type->Meta.GetMetaInt (APMETA_ColorRange) == basetype->Meta.GetMetaInt (APMETA_ColorRange)) + { + PlayerClasses[j].Skins.Push ((int)i); + remove = false; + } + } + } + + if (!remove) + { + if (skins[i].name[0] == 0) + mysnprintf (skins[i].name, countof(skins[i].name), "skin%d", (int)i); + + // Now collect the sprite frames for this skin. If the sprite name was not + // specified, use whatever immediately follows the specifier lump. + if (intname == 0) + { + char name[9]; + Wads.GetLumpName (name, base+1); + memcpy(&intname, name, 4); + } + + int basens = Wads.GetLumpNamespace(base); + + for(int spr = 0; spr<2; spr++) + { + memset (sprtemp, 0xFFFF, sizeof(sprtemp)); + for (k = 0; k < MAX_SPRITE_FRAMES; ++k) + { + sprtemp[k].Flip = 0; + sprtemp[k].Voxel = NULL; + } + maxframe = -1; + + if (spr == 1) + { + if (crouchname !=0 && crouchname != intname) + { + intname = crouchname; + } + else + { + skins[i].crouchsprite = -1; + break; + } + } + + for (k = base + 1; Wads.GetLumpNamespace(k) == basens; k++) + { + char lname[9]; + DWORD lnameint; + Wads.GetLumpName (lname, k); + memcpy(&lnameint, lname, 4); + if (lnameint == intname) + { + FTextureID picnum = TexMan.CreateTexture(k, FTexture::TEX_SkinSprite); + bool res = R_InstallSpriteLump (picnum, lname[4] - 'A', lname[5], false); + + if (lname[6] && res) + R_InstallSpriteLump (picnum, lname[6] - 'A', lname[7], true); + } + } + + if (spr == 0 && maxframe <= 0) + { + Printf (PRINT_BOLD, "Skin %s (#%d) has no frames. Removing.\n", skins[i].name, (int)i); + remove = true; + break; + } + + Wads.GetLumpName (temp.name, base+1); + temp.name[4] = 0; + int sprno = (int)sprites.Push (temp); + if (spr==0) skins[i].sprite = sprno; + else skins[i].crouchsprite = sprno; + R_InstallSprite (sprno); + } + } + + if (remove) + { + if (i < numskins-1) + memmove (&skins[i], &skins[i+1], sizeof(skins[0])*(numskins-i-1)); + i--; + continue; + } + + // Register any sounds this skin provides + aliasid = 0; + for (j = 0; j < NUMSKINSOUNDS; j++) + { + if (sndlumps[j] != -1) + { + if (j == 0 || sndlumps[j] != sndlumps[j-1]) + { + aliasid = S_AddPlayerSound (skins[i].name, skins[i].gender, + playersoundrefs[j], sndlumps[j], true); + } + else + { + S_AddPlayerSoundExisting (skins[i].name, skins[i].gender, + playersoundrefs[j], aliasid, true); + } + } + } + + // Make sure face prefix is a full 3 chars + if (skins[i].face[1] == 0 || skins[i].face[2] == 0) + { + skins[i].face[0] = 0; + } + } + + if (numskins > PlayerClasses.Size ()) + { // The sound table may have changed, so rehash it. + S_HashSounds (); + S_ShrinkPlayerSoundLists (); + } +} + +// [RH] Find a skin by name +int R_FindSkin (const char *name, int pclass) +{ + if (stricmp ("base", name) == 0) + { + return pclass; + } + + for (unsigned i = PlayerClasses.Size(); i < numskins; i++) + { + if (strnicmp (skins[i].name, name, 16) == 0) + { + if (PlayerClasses[pclass].CheckSkin (i)) + return i; + else + return pclass; + } + } + return pclass; +} + +// [RH] List the names of all installed skins +CCMD (skins) +{ + int i; + + for (i = PlayerClasses.Size ()-1; i < (int)numskins; i++) + Printf ("% 3d %s\n", i-PlayerClasses.Size ()+1, skins[i].name); +} + + +static void R_CreateSkinTranslation (const char *palname) +{ + FMemLump lump = Wads.ReadLump (palname); + const BYTE *otherPal = (BYTE *)lump.GetMem(); + + for (int i = 0; i < 256; ++i) + { + OtherGameSkinRemap[i] = ColorMatcher.Pick (otherPal[0], otherPal[1], otherPal[2]); + OtherGameSkinPalette[i] = PalEntry(otherPal[0], otherPal[1], otherPal[2]); + otherPal += 3; + } +} + + +// +// R_InitSprites +// Called at program start. +// +void R_InitSprites () +{ + int lump, lastlump; + unsigned int i, j; + + // [RH] Create a standard translation to map skins between Heretic and Doom + if (gameinfo.gametype == GAME_DoomChex) + { + R_CreateSkinTranslation ("SPALHTIC"); + } + else + { + R_CreateSkinTranslation ("SPALDOOM"); + } + + // [RH] Count the number of skins. + numskins = PlayerClasses.Size (); + lastlump = 0; + while ((lump = Wads.FindLump ("S_SKIN", &lastlump, true)) != -1) + { + numskins++; + } + + SpriteFrames.Clear(); + + // [RH] Do some preliminary setup + if (skins != NULL) delete [] skins; + skins = new FPlayerSkin[numskins]; + memset (skins, 0, sizeof(*skins) * numskins); + for (i = 0; i < numskins; i++) + { // Assume Doom skin by default + const PClass *type = PlayerClasses[0].Type; + skins[i].range0start = type->Meta.GetMetaInt (APMETA_ColorRange) & 255; + skins[i].range0end = type->Meta.GetMetaInt (APMETA_ColorRange) >> 8; + skins[i].ScaleX = GetDefaultByType (type)->scaleX; + skins[i].ScaleY = GetDefaultByType (type)->scaleY; + } + + R_InitSpriteDefs (); + R_InitVoxels(); // [RH] Parse VOXELDEF + NumStdSprites = sprites.Size(); + R_InitSkins (); // [RH] Finish loading skin data + + // [RH] Set up base skin + // [GRB] Each player class has its own base skin + for (i = 0; i < PlayerClasses.Size (); i++) + { + const PClass *basetype = PlayerClasses[i].Type; + const char *pclassface = basetype->Meta.GetMetaString (APMETA_Face); + + strcpy (skins[i].name, "Base"); + if (pclassface == NULL || strcmp(pclassface, "None") == 0) + { + skins[i].face[0] = 'S'; + skins[i].face[1] = 'T'; + skins[i].face[2] = 'F'; + skins[i].face[3] = '\0'; + } + else + { + strcpy(skins[i].face, pclassface); + } + skins[i].range0start = basetype->Meta.GetMetaInt (APMETA_ColorRange) & 255; + skins[i].range0end = basetype->Meta.GetMetaInt (APMETA_ColorRange) >> 8; + skins[i].ScaleX = GetDefaultByType (basetype)->scaleX; + skins[i].ScaleY = GetDefaultByType (basetype)->scaleY; + skins[i].sprite = GetDefaultByType (basetype)->SpawnState->sprite; + skins[i].namespc = ns_global; + + PlayerClasses[i].Skins.Push (i); + + if (memcmp (sprites[skins[i].sprite].name, "PLAY", 4) == 0) + { + for (j = 0; j < sprites.Size (); j++) + { + if (memcmp (sprites[j].name, deh.PlayerSprite, 4) == 0) + { + skins[i].sprite = (int)j; + break; + } + } + } + } + + // [RH] Sort the skins, but leave base as skin 0 + //qsort (&skins[PlayerClasses.Size ()], numskins-PlayerClasses.Size (), sizeof(FPlayerSkin), skinsorter); +} + +void R_DeinitSpriteData() +{ + // Free skins + if (skins != NULL) + { + delete[] skins; + skins = NULL; + } +} \ No newline at end of file diff --git a/src/r_data/sprites.h b/src/r_data/sprites.h new file mode 100644 index 00000000..475b5ea0 --- /dev/null +++ b/src/r_data/sprites.h @@ -0,0 +1,69 @@ +#ifndef __RES_SPRITES_H +#define __RES_SPRITES_H + +#define MAX_SPRITE_FRAMES 29 // [RH] Macro-ized as in BOOM. + +// +// Sprites are patches with a special naming convention so they can be +// recognized by R_InitSprites. The base name is NNNNFx or NNNNFxFx, with +// x indicating the rotation, x = 0, 1-7. The sprite and frame specified +// by a thing_t is range checked at run time. +// A sprite is a patch_t that is assumed to represent a three dimensional +// object and may have multiple rotations pre drawn. Horizontal flipping +// is used to save space, thus NNNNF2F5 defines a mirrored patch. +// Some sprites will only have one picture used for all views: NNNNF0 +// +struct spriteframe_t +{ + struct FVoxelDef *Voxel;// voxel to use for this frame + FTextureID Texture[16]; // texture to use for view angles 0-15 + WORD Flip; // flip (1 = flip) to use for view angles 0-15. +}; + +// +// A sprite definition: +// a number of animation frames. +// + +struct spritedef_t +{ + union + { + char name[5]; + DWORD dwName; + }; + BYTE numframes; + WORD spriteframes; +}; + +extern TArray SpriteFrames; + + +// +// [RH] Internal "skin" definition. +// +class FPlayerSkin +{ +public: + char name[17]; // 16 chars + NULL + char face[4]; // 3 chars ([MH] + NULL so can use as a C string) + BYTE gender; // This skin's gender (not really used) + BYTE range0start; + BYTE range0end; + bool othergame; // [GRB] + fixed_t ScaleX; + fixed_t ScaleY; + int sprite; + int crouchsprite; + int namespc; // namespace for this skin +}; + +extern size_t numskins; // [RH] +extern FPlayerSkin * skins; // [RH] + +extern BYTE OtherGameSkinRemap[256]; +extern PalEntry OtherGameSkinPalette[256]; + + + +#endif diff --git a/src/resources/voxels.cpp b/src/r_data/voxels.cpp similarity index 95% rename from src/resources/voxels.cpp rename to src/r_data/voxels.cpp index 15ed679b..d5a1cca6 100644 --- a/src/resources/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -58,12 +58,9 @@ #include "d_net.h" #include "colormatcher.h" #include "d_netinf.h" -#include "r_bsp.h" -#include "r_plane.h" -#include "r_segs.h" #include "v_palette.h" -#include "r_translate.h" -#include "resources/colormaps.h" +#include "r_data/r_translate.h" +#include "r_data/colormaps.h" #include "voxels.h" void VOX_AddVoxel(int sprnum, int frame, FVoxelDef *def); diff --git a/src/resources/voxels.h b/src/r_data/voxels.h similarity index 100% rename from src/resources/voxels.h rename to src/r_data/voxels.h diff --git a/src/r_defs.h b/src/r_defs.h index d0aa8c0a..ffecfea5 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -334,6 +334,9 @@ struct secplane_t { return -TMulScale16 (a, v->x, b, v->y, z, c); } + + bool CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const; + }; inline FArchive &operator<< (FArchive &arc, secplane_t &plane) @@ -478,6 +481,8 @@ struct sector_t void SetColor(int r, int g, int b, int desat); void SetFade(int r, int g, int b); void ClosestPoint(fixed_t x, fixed_t y, fixed_t &ox, fixed_t &oy) const; + int GetFloorLight () const; + int GetCeilingLight () const; DInterpolation *SetInterpolation(int position, bool attach); void StopInterpolation(int position); @@ -1089,6 +1094,7 @@ struct subsector_t DWORD numlines; int flags; + void BuildPolyBSP(); // subsector related GL data FLightNode * lighthead[2]; // Light nodes (blended and additive) int validcount; @@ -1125,8 +1131,6 @@ struct node_t struct FMiniBSP { - FMiniBSP(); - bool bDirty; TArray Nodes; @@ -1187,60 +1191,6 @@ enum FAKED_AboveCeiling }; -// -// Sprites are patches with a special naming convention so they can be -// recognized by R_InitSprites. The base name is NNNNFx or NNNNFxFx, with -// x indicating the rotation, x = 0, 1-7. The sprite and frame specified -// by a thing_t is range checked at run time. -// A sprite is a patch_t that is assumed to represent a three dimensional -// object and may have multiple rotations pre drawn. Horizontal flipping -// is used to save space, thus NNNNF2F5 defines a mirrored patch. -// Some sprites will only have one picture used for all views: NNNNF0 -// -struct spriteframe_t -{ - struct FVoxelDef *Voxel;// voxel to use for this frame - FTextureID Texture[16]; // texture to use for view angles 0-15 - WORD Flip; // flip (1 = flip) to use for view angles 0-15. -}; - -// -// A sprite definition: -// a number of animation frames. -// - -struct spritedef_t -{ - union - { - char name[5]; - DWORD dwName; - }; - BYTE numframes; - WORD spriteframes; -}; - -extern TArray SpriteFrames; - -// -// [RH] Internal "skin" definition. -// -class FPlayerSkin -{ -public: - char name[17]; // 16 chars + NULL - char face[4]; // 3 chars ([MH] + NULL so can use as a C string) - BYTE gender; // This skin's gender (not really used) - BYTE range0start; - BYTE range0end; - bool othergame; // [GRB] - fixed_t ScaleX; - fixed_t ScaleY; - int sprite; - int crouchsprite; - int namespc; // namespace for this skin -}; - // [RH] A c-buffer. Used for keeping track of offscreen voxel spans. diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 3103772e..7003a65a 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -36,9 +36,9 @@ #include "a_hexenglobal.h" #include "g_game.h" #include "g_level.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #include "gi.h" #include "stats.h" @@ -125,67 +125,48 @@ BYTE shadetables[NUMCOLORMAPS*16*256]; FDynamicColormap ShadeFakeColormap[16]; BYTE identitymap[256]; -// Convert legacy render styles to flexible render styles. +EXTERN_CVAR (Int, r_columnmethod) -// Apple's GCC 4.0.1 apparently wants to initialize the AsDWORD member of FRenderStyle -// rather than the struct before it, which goes against the standard. -#ifndef __APPLE__ -FRenderStyle LegacyRenderStyles[STYLE_Count] = -{ - /* STYLE_None */ {{ STYLEOP_None, STYLEALPHA_Zero, STYLEALPHA_Zero, 0 }}, - /* STYLE_Normal */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 }}, - /* STYLE_Fuzzy */ {{ STYLEOP_Fuzz, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, - /* STYLE_SoulTrans */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_TransSoulsAlpha }}, - /* STYLE_OptFuzzy */ {{ STYLEOP_FuzzOrAdd, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, - /* STYLE_Stencil */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 | STYLEF_ColorIsFixed }}, - /* STYLE_Translucent */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, - /* STYLE_Add */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_One, 0 }}, - /* STYLE_Shaded */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_RedIsAlpha | STYLEF_ColorIsFixed }}, -/* STYLE_TranslucentStencil */{{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed }}, - /* STYLE_Shadow */{{ STYLEOP_Shadow, 0, 0, 0 }}, -}; -#else -FRenderStyle LegacyRenderStyles[STYLE_Count]; -static const BYTE Styles[STYLE_Count * 4] = +void R_InitShadeMaps() { - STYLEOP_None, STYLEALPHA_Zero, STYLEALPHA_Zero, 0, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1, - STYLEOP_Fuzz, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_TransSoulsAlpha, - STYLEOP_FuzzOrAdd, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 | STYLEF_ColorIsFixed, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_One, 0, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_RedIsAlpha | STYLEF_ColorIsFixed, - STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed, - STYLEOP_Shadow, 0, 0, 0 -}; + int i,j; + // set up shading tables for shaded columns + // 16 colormap sets, progressing from full alpha to minimum visible alpha -static struct LegacyInit -{ - LegacyInit() + BYTE *table = shadetables; + + // Full alpha + for (i = 0; i < 16; ++i) { - for (int i = 0; i < STYLE_Count; ++i) + ShadeFakeColormap[i].Color = ~0u; + ShadeFakeColormap[i].Desaturate = ~0u; + ShadeFakeColormap[i].Next = NULL; + ShadeFakeColormap[i].Maps = table; + + for (j = 0; j < NUMCOLORMAPS; ++j) { - LegacyRenderStyles[i].BlendOp = Styles[i*4]; - LegacyRenderStyles[i].SrcAlpha = Styles[i*4+1]; - LegacyRenderStyles[i].DestAlpha = Styles[i*4+2]; - LegacyRenderStyles[i].Flags = Styles[i*4+3]; + int a = (NUMCOLORMAPS - j) * 256 / NUMCOLORMAPS * (16-i); + for (int k = 0; k < 256; ++k) + { + BYTE v = (((k+2) * a) + 256) >> 14; + table[k] = MIN (v, 64); + } + table += 256; } } -} DoLegacyInit; + for (i = 0; i < NUMCOLORMAPS*16*256; ++i) + { + assert(shadetables[i] <= 64); + } -#endif - -FArchive &operator<< (FArchive &arc, FRenderStyle &style) -{ - arc << style.BlendOp << style.SrcAlpha << style.DestAlpha << style.Flags; - return arc; + // Set up a guaranteed identity map + for (i = 0; i < 256; ++i) + { + identitymap[i] = i; + } } -EXTERN_CVAR (Int, r_columnmethod) - /************************************/ /* */ /* Palettized drawers (C versions) */ @@ -2020,29 +2001,6 @@ void tmvline4_revsubclamp () } -void R_DrawBorder (int x1, int y1, int x2, int y2) -{ - FTextureID picnum; - - if (level.info != NULL && level.info->bordertexture[0] != 0) - { - picnum = TexMan.CheckForTexture (level.info->bordertexture, FTexture::TEX_Flat); - } - else - { - picnum = TexMan.CheckForTexture (gameinfo.borderFlat, FTexture::TEX_Flat); - } - - if (picnum.isValid()) - { - screen->FlatFill (x1, y1, x2, y2, TexMan(picnum)); - } - else - { - screen->Clear (x1, y1, x2, y2, 0, 0); - } -} - //========================================================================== // // R_GetColumn @@ -2055,91 +2013,6 @@ const BYTE *R_GetColumn (FTexture *tex, int col) } -/* -================== -= -= R_DrawViewBorder -= -= Draws the border around the view for different size windows -================== -*/ - -int BorderNeedRefresh; - -void V_MarkRect (int x, int y, int width, int height); -void V_DrawFrame (int x, int y, int width, int height); - -void R_DrawViewBorder (void) -{ - // [RH] Redraw the status bar if SCREENWIDTH > status bar width. - // Will draw borders around itself, too. - if (SCREENWIDTH > 320) - { - SB_state = screen->GetPageCount (); - } - - if (viewwidth == SCREENWIDTH) - { - return; - } - - R_DrawBorder (0, 0, SCREENWIDTH, viewwindowy); - R_DrawBorder (0, viewwindowy, viewwindowx, viewheight + viewwindowy); - R_DrawBorder (viewwindowx + viewwidth, viewwindowy, SCREENWIDTH, viewheight + viewwindowy); - R_DrawBorder (0, viewwindowy + viewheight, SCREENWIDTH, ST_Y); - - V_DrawFrame (viewwindowx, viewwindowy, viewwidth, viewheight); - V_MarkRect (0, 0, SCREENWIDTH, ST_Y); -} - -/* -================== -= -= R_DrawTopBorder -= -= Draws the top border around the view for different size windows -================== -*/ - -int BorderTopRefresh; - -void R_DrawTopBorder () -{ - FTexture *p; - int offset; - - if (viewwidth == SCREENWIDTH) - return; - - offset = gameinfo.border->offset; - - if (viewwindowy < 34) - { - R_DrawBorder (0, 0, viewwindowx, 34); - R_DrawBorder (viewwindowx, 0, viewwindowx + viewwidth, viewwindowy); - R_DrawBorder (viewwindowx + viewwidth, 0, SCREENWIDTH, 34); - p = TexMan(gameinfo.border->t); - screen->FlatFill(viewwindowx, viewwindowy - p->GetHeight(), - viewwindowx + viewwidth, viewwindowy, p, true); - - p = TexMan(gameinfo.border->l); - screen->FlatFill(viewwindowx - p->GetWidth(), viewwindowy, - viewwindowx, 35, p, true); - p = TexMan(gameinfo.border->r); - screen->FlatFill(viewwindowx + viewwidth, viewwindowy, - viewwindowx + viewwidth + p->GetWidth(), 35, p, true); - - p = TexMan(gameinfo.border->tl); - screen->DrawTexture (p, viewwindowx - offset, viewwindowy - offset, TAG_DONE); - - p = TexMan(gameinfo.border->tr); - screen->DrawTexture (p, viewwindowx + viewwidth, viewwindowy - offset, TAG_DONE); - } - else - { - R_DrawBorder (0, 0, SCREENWIDTH, 34); - } -} // [RH] Initialize the column drawer pointers void R_InitColumnDrawers () { @@ -2175,8 +2048,8 @@ void R_InitColumnDrawers () // [RH] Choose column drawers in a single place EXTERN_CVAR (Int, r_drawfuzz) +EXTERN_CVAR (Bool, r_drawtrans) EXTERN_CVAR (Float, transsouls) -CVAR (Bool, r_drawtrans, true, 0) static FDynamicColormap *basecolormapsave; @@ -2323,18 +2196,6 @@ static bool R_SetBlendFunc (int op, fixed_t fglevel, fixed_t bglevel, int flags) } } -static fixed_t GetAlpha(int type, fixed_t alpha) -{ - switch (type) - { - case STYLEALPHA_Zero: return 0; - case STYLEALPHA_One: return FRACUNIT; - case STYLEALPHA_Src: return alpha; - case STYLEALPHA_InvSrc: return FRACUNIT - alpha; - default: return 0; - } -} - ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color) { fixed_t fglevel, bglevel; @@ -2461,84 +2322,3 @@ bool R_GetTransMaskDrawers (fixed_t (**tmvline1)(), void (**tmvline4)()) return false; } -//========================================================================== -// -// FRenderStyle :: IsVisible -// -// Coupled with the given alpha, will this render style produce something -// visible on-screen? -// -//========================================================================== - -bool FRenderStyle::IsVisible(fixed_t alpha) const throw() -{ - if (BlendOp == STYLEOP_None) - { - return false; - } - if (BlendOp == STYLEOP_Add || BlendOp == STYLEOP_RevSub) - { - if (Flags & STYLEF_Alpha1) - { - alpha = FRACUNIT; - } - else - { - alpha = clamp(alpha, 0, FRACUNIT); - } - return GetAlpha(SrcAlpha, alpha) != 0 || GetAlpha(DestAlpha, alpha) != FRACUNIT; - } - // Treat anything else as visible. - return true; -} - - -//========================================================================== -// -// FRenderStyle :: CheckFuzz -// -// Adjusts settings based on r_drawfuzz CVAR -// -//========================================================================== - -void FRenderStyle::CheckFuzz() -{ - switch (BlendOp) - { - default: - return; - - case STYLEOP_FuzzOrAdd: - if (r_drawtrans && r_drawfuzz == 0) - { - BlendOp = STYLEOP_Add; - return; - } - break; - - case STYLEOP_FuzzOrSub: - if (r_drawtrans && r_drawfuzz == 0) - { - BlendOp = STYLEOP_Sub; - return; - } - break; - - case STYLEOP_FuzzOrRevSub: - if (r_drawtrans && r_drawfuzz == 0) - { - BlendOp = STYLEOP_RevSub; - return; - } - break; - } - - if (r_drawfuzz == 2) - { - BlendOp = STYLEOP_Shadow; - } - else - { - BlendOp = STYLEOP_Fuzz; - } -} diff --git a/src/r_draw.h b/src/r_draw.h index 8ff62d34..ace6bde0 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -251,13 +251,8 @@ extern FDynamicColormap ShadeFakeColormap[16]; extern BYTE identitymap[256]; extern BYTE *dc_translation; - -// If the view size is not full screen, draws a border around it. -void R_DrawViewBorder (void); -void R_DrawTopBorder (void); -void R_DrawBorder (int x1, int y1, int x2, int y2); - // [RH] Added for muliresolution support +void R_InitShadeMaps(); void R_InitFuzzTable (int fuzzoff); // [RH] Consolidate column drawer selection diff --git a/src/r_jpeg.h b/src/r_jpeg.h deleted file mode 100644 index 0df98ddd..00000000 --- a/src/r_jpeg.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __R_JPEG_H -#define __R_JPEG_H - -extern "C" -{ -#include -} - -class FileReader; - - -struct FLumpSourceMgr : public jpeg_source_mgr -{ - FileReader *Lump; - JOCTET Buffer[4096]; - bool StartOfFile; - - FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo); - static void InitSource (j_decompress_ptr cinfo); - static boolean FillInputBuffer (j_decompress_ptr cinfo); - static void SkipInputData (j_decompress_ptr cinfo, long num_bytes); - static void TermSource (j_decompress_ptr cinfo); -}; - - -void JPEG_ErrorExit (j_common_ptr cinfo); -void JPEG_OutputMessage (j_common_ptr cinfo); - - -#endif diff --git a/src/r_main.cpp b/src/r_main.cpp index ddb7bdbc..cf6b5bbb 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -44,9 +44,9 @@ #include "i_video.h" #include "i_system.h" #include "a_sharedglobal.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "p_3dmidtex.h" -#include "r_interpolate.h" +#include "r_data/r_interpolate.h" #include "r_bsp.h" #include "r_plane.h" #include "r_3dfloors.h" @@ -54,7 +54,7 @@ #include "po_man.h" #include "st_start.h" #include "v_font.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" //#include "gl/data/gl_data.h" #include "gl/gl_functions.h" @@ -816,6 +816,8 @@ void R_Init () { atterm (R_Shutdown); + clearbufshort (zeroarray, MAXWIDTH, 0); + StartScreen->Progress(); V_InitFonts(); StartScreen->Progress(); @@ -830,6 +832,7 @@ void R_Init () R_SetViewSize (screenblocks); R_InitPlanes (); R_InitTranslationTables (); + R_InitShadeMaps(); R_InitParticles (); // [RH] Setup particle engine R_InitColumnDrawers (); @@ -1408,35 +1411,6 @@ void R_SetupFrame (AActor *actor) } } -//========================================================================== -// -// R_RefreshViewBorder -// -// Draws the border around the player view, if needed. -// -//========================================================================== - -void R_RefreshViewBorder () -{ - if (setblocks < 10) - { - if (BorderNeedRefresh) - { - BorderNeedRefresh--; - if (BorderTopRefresh) - { - BorderTopRefresh--; - } - R_DrawViewBorder(); - } - else if (BorderTopRefresh) - { - BorderTopRefresh--; - R_DrawTopBorder(); - } - } -} - //========================================================================== // // R_EnterMirror diff --git a/src/r_main.h b/src/r_main.h index 2259b0db..3dff4a79 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -30,7 +30,7 @@ #include "d_player.h" #include "r_state.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // @@ -186,7 +186,6 @@ void R_SetViewAngle (); // Called by G_Drawer. void R_RenderActorView (AActor *actor, bool dontmaplines = false); -void R_RefreshViewBorder (); void R_SetupBuffer (); void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines = false); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index bb0ddb7d..4275f553 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -57,7 +57,7 @@ #include "r_segs.h" #include "r_3dfloors.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #ifdef _MSC_VER #pragma warning(disable:4244) diff --git a/src/r_polymost.cpp b/src/r_polymost.cpp index 3d4ea523..4cee72f0 100644 --- a/src/r_polymost.cpp +++ b/src/r_polymost.cpp @@ -82,7 +82,7 @@ Low priority: #include "v_palette.h" #include "v_font.h" #include "v_video.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" EXTERN_CVAR (Int, r_polymost) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 3eac266e..7e69190e 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -51,7 +51,7 @@ #include "r_segs.h" #include "r_3dfloors.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" #define WALLYREPEAT 8 @@ -2047,62 +2047,6 @@ void R_NewWall (bool needlights) } } -CUSTOM_CVAR(Int, r_fakecontrast, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -{ - if (self < 0) self = 1; - else if (self > 2) self = 2; -} - -int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const -{ - if (Flags & WALLF_ABSLIGHTING) - { - baselight = Light; - } - - if (pfakecontrast != NULL) - { - *pfakecontrast = 0; - } - - if (!foggy) // Don't do relative lighting in foggy sectors - { - if (!(Flags & WALLF_NOFAKECONTRAST) && r_fakecontrast != 0) - { - int rel; - if (((level.flags2 & LEVEL2_SMOOTHLIGHTING) || (Flags & WALLF_SMOOTHLIGHTING) || r_fakecontrast == 2) && - linedef->dx != 0) - { - rel = xs_RoundToInt // OMG LEE KILLOUGH LIVES! :/ - ( - level.WallHorizLight - + fabs(atan(double(linedef->dy) / linedef->dx) / 1.57079) - * (level.WallVertLight - level.WallHorizLight) - ); - } - else - { - rel = linedef->dx == 0 ? level.WallVertLight : - linedef->dy == 0 ? level.WallHorizLight : 0; - } - if (pfakecontrast != NULL) - { - *pfakecontrast = rel; - } - else - { - baselight += rel; - } - } - if (!(Flags & WALLF_ABSLIGHTING)) - { - baselight += this->Light; - } - } - return baselight; -} - - // // R_CheckDrawSegs diff --git a/src/r_state.h b/src/r_state.h index 4736e232..9c77ffc8 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -25,6 +25,7 @@ // Need data structure definitions. #include "d_player.h" +#include "r_data/sprites.h" // // Refresh internal data structures, @@ -34,18 +35,6 @@ extern "C" int viewwidth; extern "C" int viewheight; -// Sprite.... -extern int firstspritelump; -extern int lastspritelump; -extern int numspritelumps; - -extern size_t numskins; // [RH] -extern FPlayerSkin * skins; // [RH] - -extern BYTE OtherGameSkinRemap[256]; -extern PalEntry OtherGameSkinPalette[256]; - - // // Lookup tables for map data. // diff --git a/src/r_things.cpp b/src/r_things.cpp index 9876fe1d..0b7b26cc 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -58,9 +58,12 @@ #include "r_segs.h" #include "r_3dfloors.h" #include "v_palette.h" -#include "r_translate.h" -#include "resources/colormaps.h" -#include "resources/voxels.h" +#include "r_data/r_translate.h" +#include "r_data/colormaps.h" +#include "r_data/voxels.h" + + +void R_DeinitSpriteData(); extern fixed_t globaluclip, globaldclip; @@ -69,8 +72,8 @@ extern fixed_t globaluclip, globaldclip; #define BASEYCENTER (100) EXTERN_CVAR (Bool, st_scale) -CVAR (Int, r_drawfuzz, 1, CVAR_ARCHIVE) EXTERN_CVAR(Bool, r_shadercolormaps) +EXTERN_CVAR(Int, r_drawfuzz) // // Sprite rotation 0 is facing the viewer, @@ -105,30 +108,10 @@ CVAR (Bool, r_drawvoxels, true, 0) // INITIALIZATION FUNCTIONS // -// variables used to look up -// and range check thing_t sprites patches -TArray sprites; -TArray SpriteFrames; -DWORD NumStdSprites; // The first x sprites that don't belong to skins. - int OffscreenBufferWidth, OffscreenBufferHeight; BYTE *OffscreenColorBuffer; FCoverageBuffer *OffscreenCoverageBuffer; -struct spriteframewithrotate : public spriteframe_t -{ - int rotate; -} -sprtemp[MAX_SPRITE_FRAMES]; -int maxframe; -char* spritename; - -// [RH] skin globals -FPlayerSkin *skins; -size_t numskins; -BYTE OtherGameSkinRemap[256]; -PalEntry OtherGameSkinPalette[256]; - // [RH] particle globals WORD NumParticles; WORD ActiveParticles; @@ -137,845 +120,6 @@ particle_t *Particles; CVAR (Bool, r_particles, true, 0); - -// -// R_InstallSpriteLump -// Local function for R_InitSprites. -// -// [RH] Removed checks for coexistance of rotation 0 with other -// rotations and made it look more like BOOM's version. -// -static bool R_InstallSpriteLump (FTextureID lump, unsigned frame, char rot, bool flipped) -{ - unsigned rotation; - - if (rot >= '0' && rot <= '9') - { - rotation = rot - '0'; - } - else if (rot >= 'A') - { - rotation = rot - 'A' + 10; - } - else - { - rotation = 17; - } - - if (frame >= MAX_SPRITE_FRAMES || rotation > 16) - { - Printf (TEXTCOLOR_RED"R_InstallSpriteLump: Bad frame characters in lump %s\n", TexMan[lump]->Name); - return false; - } - - if ((int)frame > maxframe) - maxframe = frame; - - if (rotation == 0) - { - // the lump should be used for all rotations - // false=0, true=1, but array initialised to -1 - // allows doom to have a "no value set yet" boolean value! - int r; - - for (r = 14; r >= 0; r -= 2) - { - if (!sprtemp[frame].Texture[r].isValid()) - { - sprtemp[frame].Texture[r] = lump; - if (flipped) - { - sprtemp[frame].Flip |= 1 << r; - } - sprtemp[frame].rotate = false; - } - } - } - else - { - if (rotation <= 8) - { - rotation = (rotation - 1) * 2; - } - else - { - rotation = (rotation - 9) * 2 + 1; - } - - if (!sprtemp[frame].Texture[rotation].isValid()) - { - // the lump is only used for one rotation - sprtemp[frame].Texture[rotation] = lump; - if (flipped) - { - sprtemp[frame].Flip |= 1 << rotation; - } - sprtemp[frame].rotate = true; - } - } - return true; -} - - -// [RH] Seperated out of R_InitSpriteDefs() -static void R_InstallSprite (int num) -{ - int frame; - int framestart; - int rot; -// int undefinedFix; - - if (maxframe == -1) - { - sprites[num].numframes = 0; - return; - } - - maxframe++; - - // [RH] If any frames are undefined, but there are some defined frames, map - // them to the first defined frame. This is a fix for Doom Raider, which actually - // worked with ZDoom 2.0.47, because of a bug here. It does not define frames A, - // B, or C for the sprite PSBG, but because I had sprtemp[].rotate defined as a - // bool, this code never detected that it was not actually present. After switching - // to the unified texture system, this caused it to crash while loading the wad. - -// [RH] Let undefined frames actually be blank because LWM uses this in at least -// one of her wads. -// for (frame = 0; frame < maxframe && sprtemp[frame].rotate == -1; ++frame) -// { } -// -// undefinedFix = frame; - - for (frame = 0; frame < maxframe; ++frame) - { - switch (sprtemp[frame].rotate) - { - case -1: - // no rotations were found for that frame at all - //I_FatalError ("R_InstallSprite: No patches found for %s frame %c", sprites[num].name, frame+'A'); - break; - - case 0: - // only the first rotation is needed - for (rot = 1; rot < 16; ++rot) - { - sprtemp[frame].Texture[rot] = sprtemp[frame].Texture[0]; - } - // If the frame is flipped, they all should be - if (sprtemp[frame].Flip & 1) - { - sprtemp[frame].Flip = 0xFFFF; - } - break; - - case 1: - // must have all 8 frame pairs - for (rot = 0; rot < 8; ++rot) - { - if (!sprtemp[frame].Texture[rot*2+1].isValid()) - { - sprtemp[frame].Texture[rot*2+1] = sprtemp[frame].Texture[rot*2]; - if (sprtemp[frame].Flip & (1 << (rot*2))) - { - sprtemp[frame].Flip |= 1 << (rot*2+1); - } - } - if (!sprtemp[frame].Texture[rot*2].isValid()) - { - sprtemp[frame].Texture[rot*2] = sprtemp[frame].Texture[rot*2+1]; - if (sprtemp[frame].Flip & (1 << (rot*2+1))) - { - sprtemp[frame].Flip |= 1 << (rot*2); - } - } - - } - for (rot = 0; rot < 16; ++rot) - { - if (!sprtemp[frame].Texture[rot].isValid()) - I_FatalError ("R_InstallSprite: Sprite %s frame %c is missing rotations", - sprites[num].name, frame+'A'); - } - break; - } - } - - for (frame = 0; frame < maxframe; ++frame) - { - if (sprtemp[frame].rotate == -1) - { - memset (&sprtemp[frame].Texture, 0, sizeof(sprtemp[0].Texture)); - sprtemp[frame].Flip = 0; - sprtemp[frame].rotate = 0; - } - } - - // allocate space for the frames present and copy sprtemp to it - sprites[num].numframes = maxframe; - sprites[num].spriteframes = WORD(framestart = SpriteFrames.Reserve (maxframe)); - for (frame = 0; frame < maxframe; ++frame) - { - memcpy (SpriteFrames[framestart+frame].Texture, sprtemp[frame].Texture, sizeof(sprtemp[frame].Texture)); - SpriteFrames[framestart+frame].Flip = sprtemp[frame].Flip; - SpriteFrames[framestart+frame].Voxel = sprtemp[frame].Voxel; - } - - // Let the textures know about the rotations - for (frame = 0; frame < maxframe; ++frame) - { - if (sprtemp[frame].rotate == 1) - { - for (int rot = 0; rot < 16; ++rot) - { - TexMan[sprtemp[frame].Texture[rot]]->Rotations = framestart + frame; - } - } - } -} - - -// -// R_InitSpriteDefs -// Pass a null terminated list of sprite names -// (4 chars exactly) to be used. -// Builds the sprite rotation matrices to account -// for horizontally flipped sprites. -// Will report an error if the lumps are inconsistant. -// Only called at startup. -// -// Sprite lump names are 4 characters for the actor, -// a letter for the frame, and a number for the rotation. -// A sprite that is flippable will have an additional -// letter/number appended. -// The rotation character can be 0 to signify no rotations. -// -void R_InitSpriteDefs () -{ - struct Hasher - { - int Head, Next; - } *hashes; - struct VHasher - { - int Head, Next, Name, Spin; - char Frame; - } *vhashes; - unsigned int i, j, smax, vmax; - DWORD intname; - - // Create a hash table to speed up the process - smax = TexMan.NumTextures(); - hashes = new Hasher[smax]; - clearbuf(hashes, sizeof(Hasher)*smax/4, -1); - for (i = 0; i < smax; ++i) - { - FTexture *tex = TexMan.ByIndex(i); - if (tex->UseType == FTexture::TEX_Sprite && strlen(tex->Name) >= 6) - { - size_t bucket = tex->dwName % smax; - hashes[i].Next = hashes[bucket].Head; - hashes[bucket].Head = i; - } - } - - // Repeat, for voxels - vmax = Wads.GetNumLumps(); - vhashes = new VHasher[vmax]; - clearbuf(vhashes, sizeof(VHasher)*vmax/4, -1); - for (i = 0; i < vmax; ++i) - { - if (Wads.GetLumpNamespace(i) == ns_voxels) - { - char name[9]; - size_t namelen; - int spin; - int sign; - - Wads.GetLumpName(name, i); - name[8] = 0; - namelen = strlen(name); - if (namelen < 4) - { // name is too short - continue; - } - if (name[4] != '\0' && name[4] != ' ' && (name[4] < 'A' || name[4] >= 'A' + MAX_SPRITE_FRAMES)) - { // frame char is invalid - continue; - } - spin = 0; - sign = 2; // 2 to convert from deg/halfsec to deg/sec - j = 5; - if (j < namelen && name[j] == '-') - { // a minus sign is okay, but only before any digits - j++; - sign = -2; - } - for (; j < namelen; ++j) - { // the remainder to the end of the name must be digits - if (name[j] >= '0' && name[j] <= '9') - { - spin = spin * 10 + name[j] - '0'; - } - else - { - break; - } - } - if (j < namelen) - { // the spin part is invalid - continue; - } - memcpy(&vhashes[i].Name, name, 4); - vhashes[i].Frame = name[4]; - vhashes[i].Spin = spin * sign; - size_t bucket = vhashes[i].Name % vmax; - vhashes[i].Next = vhashes[bucket].Head; - vhashes[bucket].Head = i; - } - } - - // scan all the lump names for each of the names, noting the highest frame letter. - for (i = 0; i < sprites.Size(); ++i) - { - memset (sprtemp, 0xFF, sizeof(sprtemp)); - for (j = 0; j < MAX_SPRITE_FRAMES; ++j) - { - sprtemp[j].Flip = 0; - sprtemp[j].Voxel = NULL; - } - - maxframe = -1; - intname = sprites[i].dwName; - - // scan the lumps, filling in the frames for whatever is found - int hash = hashes[intname % smax].Head; - while (hash != -1) - { - FTexture *tex = TexMan[hash]; - if (tex->dwName == intname) - { - bool res = R_InstallSpriteLump (FTextureID(hash), tex->Name[4] - 'A', tex->Name[5], false); - - if (tex->Name[6] && res) - R_InstallSpriteLump (FTextureID(hash), tex->Name[6] - 'A', tex->Name[7], true); - } - hash = hashes[hash].Next; - } - - // repeat, for voxels - hash = vhashes[intname % vmax].Head; - while (hash != -1) - { - VHasher *vh = &vhashes[hash]; - if (vh->Name == (int)intname) - { - FVoxelDef *voxdef = R_LoadVoxelDef(hash, vh->Spin); - if (voxdef != NULL) - { - if (vh->Frame == ' ' || vh->Frame == '\0') - { // voxel applies to every sprite frame - for (j = 0; j < MAX_SPRITE_FRAMES; ++j) - { - if (sprtemp[j].Voxel == NULL) - { - sprtemp[j].Voxel = voxdef; - } - } - maxframe = MAX_SPRITE_FRAMES-1; - } - else - { // voxel applies to a specific frame - j = vh->Frame - 'A'; - sprtemp[j].Voxel = voxdef; - maxframe = MAX(maxframe, j); - } - } - } - hash = vh->Next; - } - - R_InstallSprite ((int)i); - } - - delete[] hashes; - delete[] vhashes; -} - -//========================================================================== -// -// R_ExtendSpriteFrames -// -// Extends a sprite so that it can hold the desired frame. -// -//========================================================================== - -static void R_ExtendSpriteFrames(spritedef_t &spr, int frame) -{ - unsigned int i, newstart; - - if (spr.numframes >= ++frame) - { // The sprite already has enough frames, so do nothing. - return; - } - - if (spr.numframes == 0 || (spr.spriteframes + spr.numframes == SpriteFrames.Size())) - { // Sprite's frames are at the end of the array, or it has no frames - // at all, so we can tack the new frames directly on to the end - // of the SpriteFrames array. - newstart = SpriteFrames.Reserve(frame - spr.numframes); - } - else - { // We need to allocate space for all the sprite's frames and copy - // the existing ones over to the new space. The old space will be - // lost. - newstart = SpriteFrames.Reserve(frame); - for (i = 0; i < spr.numframes; ++i) - { - SpriteFrames[newstart + i] = SpriteFrames[spr.spriteframes + i]; - } - spr.spriteframes = WORD(newstart); - newstart += i; - } - // Initialize all new frames to 0. - memset(&SpriteFrames[newstart], 0, sizeof(spriteframe_t)*(frame - spr.numframes)); - spr.numframes = frame; -} - -//========================================================================== -// -// VOX_AddVoxel -// -// Sets a voxel for a single sprite frame. -// -//========================================================================== - -void VOX_AddVoxel(int sprnum, int frame, FVoxelDef *def) -{ - R_ExtendSpriteFrames(sprites[sprnum], frame); - SpriteFrames[sprites[sprnum].spriteframes + frame].Voxel = def; -} - -// [RH] -// R_InitSkins -// Reads in everything applicable to a skin. The skins should have already -// been counted and had their identifiers assigned to namespaces. -// -#define NUMSKINSOUNDS 17 -static const char *skinsoundnames[NUMSKINSOUNDS][2] = -{ // The *painXXX sounds must be the first four - { "dsplpain", "*pain100" }, - { "dsplpain", "*pain75" }, - { "dsplpain", "*pain50" }, - { "dsplpain", "*pain25" }, - { "dsplpain", "*poison" }, - - { "dsoof", "*grunt" }, - { "dsoof", "*land" }, - - { "dspldeth", "*death" }, - { "dspldeth", "*wimpydeath" }, - - { "dspdiehi", "*xdeath" }, - { "dspdiehi", "*crazydeath" }, - - { "dsnoway", "*usefail" }, - { "dsnoway", "*puzzfail" }, - - { "dsslop", "*gibbed" }, - { "dsslop", "*splat" }, - - { "dspunch", "*fist" }, - { "dsjump", "*jump" } -}; - -/* -static int STACK_ARGS skinsorter (const void *a, const void *b) -{ - return stricmp (((FPlayerSkin *)a)->name, ((FPlayerSkin *)b)->name); -} -*/ - -void R_InitSkins (void) -{ - FSoundID playersoundrefs[NUMSKINSOUNDS]; - spritedef_t temp; - int sndlumps[NUMSKINSOUNDS]; - char key[65]; - DWORD intname, crouchname; - size_t i; - int j, k, base; - int lastlump; - int aliasid; - bool remove; - const PClass *basetype, *transtype; - - key[sizeof(key)-1] = 0; - i = PlayerClasses.Size () - 1; - lastlump = 0; - - for (j = 0; j < NUMSKINSOUNDS; ++j) - { - playersoundrefs[j] = skinsoundnames[j][1]; - } - - while ((base = Wads.FindLump ("S_SKIN", &lastlump, true)) != -1) - { - // The player sprite has 23 frames. This means that the S_SKIN - // marker needs a minimum of 23 lumps after it. - if (base >= Wads.GetNumLumps() - 23 || base == -1) - continue; - - i++; - for (j = 0; j < NUMSKINSOUNDS; j++) - sndlumps[j] = -1; - skins[i].namespc = Wads.GetLumpNamespace (base); - - FScanner sc(base); - intname = 0; - crouchname = 0; - - remove = false; - basetype = NULL; - transtype = NULL; - - // Data is stored as "key = data". - while (sc.GetString ()) - { - strncpy (key, sc.String, sizeof(key)-1); - if (!sc.GetString() || sc.String[0] != '=') - { - Printf (PRINT_BOLD, "Bad format for skin %d: %s\n", (int)i, key); - break; - } - sc.GetString (); - if (0 == stricmp (key, "name")) - { - strncpy (skins[i].name, sc.String, 16); - for (j = 0; (size_t)j < i; j++) - { - if (stricmp (skins[i].name, skins[j].name) == 0) - { - mysnprintf (skins[i].name, countof(skins[i].name), "skin%d", (int)i); - Printf (PRINT_BOLD, "Skin %s duplicated as %s\n", - skins[j].name, skins[i].name); - break; - } - } - } - else if (0 == stricmp (key, "sprite")) - { - for (j = 3; j >= 0; j--) - sc.String[j] = toupper (sc.String[j]); - intname = *((DWORD *)sc.String); - } - else if (0 == stricmp (key, "crouchsprite")) - { - for (j = 3; j >= 0; j--) - sc.String[j] = toupper (sc.String[j]); - crouchname = *((DWORD *)sc.String); - } - else if (0 == stricmp (key, "face")) - { - for (j = 2; j >= 0; j--) - skins[i].face[j] = toupper (sc.String[j]); - skins[i].face[3] = '\0'; - } - else if (0 == stricmp (key, "gender")) - { - skins[i].gender = D_GenderToInt (sc.String); - } - else if (0 == stricmp (key, "scale")) - { - skins[i].ScaleX = clamp (FLOAT2FIXED(atof (sc.String)), 1, 256*FRACUNIT); - skins[i].ScaleY = skins[i].ScaleX; - } - else if (0 == stricmp (key, "game")) - { - if (gameinfo.gametype == GAME_Heretic) - basetype = PClass::FindClass (NAME_HereticPlayer); - else if (gameinfo.gametype == GAME_Strife) - basetype = PClass::FindClass (NAME_StrifePlayer); - else - basetype = PClass::FindClass (NAME_DoomPlayer); - - transtype = basetype; - - if (stricmp (sc.String, "heretic") == 0) - { - if (gameinfo.gametype & GAME_DoomChex) - { - transtype = PClass::FindClass (NAME_HereticPlayer); - skins[i].othergame = true; - } - else if (gameinfo.gametype != GAME_Heretic) - { - remove = true; - } - } - else if (stricmp (sc.String, "strife") == 0) - { - if (gameinfo.gametype != GAME_Strife) - { - remove = true; - } - } - else - { - if (gameinfo.gametype == GAME_Heretic) - { - transtype = PClass::FindClass (NAME_DoomPlayer); - skins[i].othergame = true; - } - else if (!(gameinfo.gametype & GAME_DoomChex)) - { - remove = true; - } - } - - if (remove) - break; - } - else if (0 == stricmp (key, "class")) - { // [GRB] Define the skin for a specific player class - int pclass = D_PlayerClassToInt (sc.String); - - if (pclass < 0) - { - remove = true; - break; - } - - basetype = transtype = PlayerClasses[pclass].Type; - } - else if (key[0] == '*') - { // Player sound replacment (ZDoom extension) - int lump = Wads.CheckNumForName (sc.String, skins[i].namespc); - if (lump == -1) - { - lump = Wads.CheckNumForFullName (sc.String, true, ns_sounds); - } - if (lump != -1) - { - if (stricmp (key, "*pain") == 0) - { // Replace all pain sounds in one go - aliasid = S_AddPlayerSound (skins[i].name, skins[i].gender, - playersoundrefs[0], lump, true); - for (int l = 3; l > 0; --l) - { - S_AddPlayerSoundExisting (skins[i].name, skins[i].gender, - playersoundrefs[l], aliasid, true); - } - } - else - { - int sndref = S_FindSoundNoHash (key); - if (sndref != 0) - { - S_AddPlayerSound (skins[i].name, skins[i].gender, sndref, lump, true); - } - } - } - } - else - { - for (j = 0; j < NUMSKINSOUNDS; j++) - { - if (stricmp (key, skinsoundnames[j][0]) == 0) - { - sndlumps[j] = Wads.CheckNumForName (sc.String, skins[i].namespc); - if (sndlumps[j] == -1) - { // Replacement not found, try finding it in the global namespace - sndlumps[j] = Wads.CheckNumForFullName (sc.String, true, ns_sounds); - } - } - } - //if (j == 8) - // Printf ("Funny info for skin %i: %s = %s\n", i, key, sc.String); - } - } - - // [GRB] Assume Doom skin by default - if (!remove && basetype == NULL) - { - if (gameinfo.gametype & GAME_DoomChex) - { - basetype = transtype = PClass::FindClass (NAME_DoomPlayer); - } - else if (gameinfo.gametype == GAME_Heretic) - { - basetype = PClass::FindClass (NAME_HereticPlayer); - transtype = PClass::FindClass (NAME_DoomPlayer); - skins[i].othergame = true; - } - else - { - remove = true; - } - } - - if (!remove) - { - skins[i].range0start = transtype->Meta.GetMetaInt (APMETA_ColorRange) & 0xff; - skins[i].range0end = transtype->Meta.GetMetaInt (APMETA_ColorRange) >> 8; - - remove = true; - for (j = 0; j < (int)PlayerClasses.Size (); j++) - { - const PClass *type = PlayerClasses[j].Type; - - if (type->IsDescendantOf (basetype) && - GetDefaultByType (type)->SpawnState->sprite == GetDefaultByType (basetype)->SpawnState->sprite && - type->Meta.GetMetaInt (APMETA_ColorRange) == basetype->Meta.GetMetaInt (APMETA_ColorRange)) - { - PlayerClasses[j].Skins.Push ((int)i); - remove = false; - } - } - } - - if (!remove) - { - if (skins[i].name[0] == 0) - mysnprintf (skins[i].name, countof(skins[i].name), "skin%d", (int)i); - - // Now collect the sprite frames for this skin. If the sprite name was not - // specified, use whatever immediately follows the specifier lump. - if (intname == 0) - { - char name[9]; - Wads.GetLumpName (name, base+1); - memcpy(&intname, name, 4); - } - - int basens = Wads.GetLumpNamespace(base); - - for(int spr = 0; spr<2; spr++) - { - memset (sprtemp, 0xFFFF, sizeof(sprtemp)); - for (k = 0; k < MAX_SPRITE_FRAMES; ++k) - { - sprtemp[k].Flip = 0; - sprtemp[k].Voxel = NULL; - } - maxframe = -1; - - if (spr == 1) - { - if (crouchname !=0 && crouchname != intname) - { - intname = crouchname; - } - else - { - skins[i].crouchsprite = -1; - break; - } - } - - for (k = base + 1; Wads.GetLumpNamespace(k) == basens; k++) - { - char lname[9]; - DWORD lnameint; - Wads.GetLumpName (lname, k); - memcpy(&lnameint, lname, 4); - if (lnameint == intname) - { - FTextureID picnum = TexMan.CreateTexture(k, FTexture::TEX_SkinSprite); - bool res = R_InstallSpriteLump (picnum, lname[4] - 'A', lname[5], false); - - if (lname[6] && res) - R_InstallSpriteLump (picnum, lname[6] - 'A', lname[7], true); - } - } - - if (spr == 0 && maxframe <= 0) - { - Printf (PRINT_BOLD, "Skin %s (#%d) has no frames. Removing.\n", skins[i].name, (int)i); - remove = true; - break; - } - - Wads.GetLumpName (temp.name, base+1); - temp.name[4] = 0; - int sprno = (int)sprites.Push (temp); - if (spr==0) skins[i].sprite = sprno; - else skins[i].crouchsprite = sprno; - R_InstallSprite (sprno); - } - } - - if (remove) - { - if (i < numskins-1) - memmove (&skins[i], &skins[i+1], sizeof(skins[0])*(numskins-i-1)); - i--; - continue; - } - - // Register any sounds this skin provides - aliasid = 0; - for (j = 0; j < NUMSKINSOUNDS; j++) - { - if (sndlumps[j] != -1) - { - if (j == 0 || sndlumps[j] != sndlumps[j-1]) - { - aliasid = S_AddPlayerSound (skins[i].name, skins[i].gender, - playersoundrefs[j], sndlumps[j], true); - } - else - { - S_AddPlayerSoundExisting (skins[i].name, skins[i].gender, - playersoundrefs[j], aliasid, true); - } - } - } - - // Make sure face prefix is a full 3 chars - if (skins[i].face[1] == 0 || skins[i].face[2] == 0) - { - skins[i].face[0] = 0; - } - } - - if (numskins > PlayerClasses.Size ()) - { // The sound table may have changed, so rehash it. - S_HashSounds (); - S_ShrinkPlayerSoundLists (); - } -} - -// [RH] Find a skin by name -int R_FindSkin (const char *name, int pclass) -{ - if (stricmp ("base", name) == 0) - { - return pclass; - } - - for (unsigned i = PlayerClasses.Size(); i < numskins; i++) - { - if (strnicmp (skins[i].name, name, 16) == 0) - { - if (PlayerClasses[pclass].CheckSkin (i)) - return i; - else - return pclass; - } - } - return pclass; -} - -// [RH] List the names of all installed skins -CCMD (skins) -{ - int i; - - for (i = PlayerClasses.Size ()-1; i < (int)numskins; i++) - Printf ("% 3d %s\n", i-PlayerClasses.Size ()+1, skins[i].name); -} - // // GAME FUNCTIONS // @@ -990,122 +134,10 @@ static vissprite_t **spritesorter; static int spritesortersize = 0; static int vsprcount; -static void R_CreateSkinTranslation (const char *palname) -{ - FMemLump lump = Wads.ReadLump (palname); - const BYTE *otherPal = (BYTE *)lump.GetMem(); - - for (int i = 0; i < 256; ++i) - { - OtherGameSkinRemap[i] = ColorMatcher.Pick (otherPal[0], otherPal[1], otherPal[2]); - OtherGameSkinPalette[i] = PalEntry(otherPal[0], otherPal[1], otherPal[2]); - otherPal += 3; - } -} - - -// -// R_InitSprites -// Called at program start. -// -void R_InitSprites () -{ - int lump, lastlump; - unsigned int i, j; - - clearbufshort (zeroarray, MAXWIDTH, 0); - - // [RH] Create a standard translation to map skins between Heretic and Doom - if (gameinfo.gametype == GAME_DoomChex) - { - R_CreateSkinTranslation ("SPALHTIC"); - } - else - { - R_CreateSkinTranslation ("SPALDOOM"); - } - - // [RH] Count the number of skins. - numskins = PlayerClasses.Size (); - lastlump = 0; - while ((lump = Wads.FindLump ("S_SKIN", &lastlump, true)) != -1) - { - numskins++; - } - - SpriteFrames.Clear(); - - // [RH] Do some preliminary setup - if (skins != NULL) delete [] skins; - skins = new FPlayerSkin[numskins]; - memset (skins, 0, sizeof(*skins) * numskins); - for (i = 0; i < numskins; i++) - { // Assume Doom skin by default - const PClass *type = PlayerClasses[0].Type; - skins[i].range0start = type->Meta.GetMetaInt (APMETA_ColorRange) & 255; - skins[i].range0end = type->Meta.GetMetaInt (APMETA_ColorRange) >> 8; - skins[i].ScaleX = GetDefaultByType (type)->scaleX; - skins[i].ScaleY = GetDefaultByType (type)->scaleY; - } - - R_InitSpriteDefs (); - R_InitVoxels(); // [RH] Parse VOXELDEF - NumStdSprites = sprites.Size(); - R_InitSkins (); // [RH] Finish loading skin data - - // [RH] Set up base skin - // [GRB] Each player class has its own base skin - for (i = 0; i < PlayerClasses.Size (); i++) - { - const PClass *basetype = PlayerClasses[i].Type; - const char *pclassface = basetype->Meta.GetMetaString (APMETA_Face); - - strcpy (skins[i].name, "Base"); - if (pclassface == NULL || strcmp(pclassface, "None") == 0) - { - skins[i].face[0] = 'S'; - skins[i].face[1] = 'T'; - skins[i].face[2] = 'F'; - skins[i].face[3] = '\0'; - } - else - { - strcpy(skins[i].face, pclassface); - } - skins[i].range0start = basetype->Meta.GetMetaInt (APMETA_ColorRange) & 255; - skins[i].range0end = basetype->Meta.GetMetaInt (APMETA_ColorRange) >> 8; - skins[i].ScaleX = GetDefaultByType (basetype)->scaleX; - skins[i].ScaleY = GetDefaultByType (basetype)->scaleY; - skins[i].sprite = GetDefaultByType (basetype)->SpawnState->sprite; - skins[i].namespc = ns_global; - - PlayerClasses[i].Skins.Push (i); - - if (memcmp (sprites[skins[i].sprite].name, "PLAY", 4) == 0) - { - for (j = 0; j < sprites.Size (); j++) - { - if (memcmp (sprites[j].name, deh.PlayerSprite, 4) == 0) - { - skins[i].sprite = (int)j; - break; - } - } - } - } - - // [RH] Sort the skins, but leave base as skin 0 - //qsort (&skins[PlayerClasses.Size ()], numskins-PlayerClasses.Size (), sizeof(FPlayerSkin), skinsorter); -} void R_DeinitSprites() { - // Free skins - if (skins != NULL) - { - delete[] skins; - skins = NULL; - } + R_DeinitSpriteData(); // Free vissprites for (int i = 0; i < MaxVisSprites; ++i) diff --git a/src/r_things.h b/src/r_things.h index 0e345227..da31daf7 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -23,8 +23,6 @@ #ifndef __R_THINGS__ #define __R_THINGS__ -#define MAX_SPRITE_FRAMES 29 // [RH] Macro-ized as in BOOM. - // [RH] Particle details struct particle_t { diff --git a/src/svnrevision.h b/src/svnrevision.h index 9297a1cf..00ab6898 100644 --- a/src/svnrevision.h +++ b/src/svnrevision.h @@ -3,5 +3,5 @@ // This file was automatically generated by the // updaterevision tool. Do not edit by hand. -#define ZD_SVN_REVISION_STRING "3249" -#define ZD_SVN_REVISION_NUMBER 3249 +#define ZD_SVN_REVISION_STRING "3257" +#define ZD_SVN_REVISION_NUMBER 3257 diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index beec0d3f..4da12b9c 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -34,9 +34,9 @@ #include "bitmap.h" #include "templates.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" //=========================================================================== diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index f8e732d4..3a87f70a 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -33,15 +33,35 @@ ** */ +#include +extern "C" +{ +#include +} + #include "doomtype.h" #include "files.h" -#include "r_jpeg.h" #include "w_wad.h" #include "v_text.h" #include "bitmap.h" #include "v_video.h" #include "textures/textures.h" + +struct FLumpSourceMgr : public jpeg_source_mgr +{ + FileReader *Lump; + JOCTET Buffer[4096]; + bool StartOfFile; + + FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo); + static void InitSource (j_decompress_ptr cinfo); + static boolean FillInputBuffer (j_decompress_ptr cinfo); + static void SkipInputData (j_decompress_ptr cinfo, long num_bytes); + static void TermSource (j_decompress_ptr cinfo); +}; + + //========================================================================== // // diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index d75dc6b0..0bfb979a 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -42,14 +42,14 @@ #include "st_start.h" #include "sc_man.h" #include "templates.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "bitmap.h" #include "colormatcher.h" #include "v_palette.h" #include "v_video.h" #include "m_fixed.h" #include "textures/textures.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // On the Alpha, accessing the shorts directly if they aren't aligned on a // 4-byte boundary causes unaligned access warnings. Why it does this at diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index fa2c564d..093bf303 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -38,7 +38,7 @@ #include "w_wad.h" #include "templates.h" #include "i_system.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "bitmap.h" #include "colormatcher.h" #include "c_dispatch.h" diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index daf47e22..3f6ee054 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -39,7 +39,7 @@ #include "w_wad.h" #include "templates.h" #include "i_system.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "c_dispatch.h" #include "v_text.h" #include "sc_man.h" diff --git a/src/thingdef/olddecorations.cpp b/src/thingdef/olddecorations.cpp index 7b4aa0ba..421ff1e8 100644 --- a/src/thingdef/olddecorations.cpp +++ b/src/thingdef/olddecorations.cpp @@ -40,7 +40,6 @@ #include "tarray.h" #include "templates.h" #include "r_defs.h" -#include "r_draw.h" #include "a_pickups.h" #include "s_sound.h" #include "cmdlib.h" @@ -49,7 +48,7 @@ #include "decallib.h" #include "i_system.h" #include "thingdef.h" -#include "r_translate.h" +#include "r_data/r_translate.h" // TYPES ------------------------------------------------------------------- diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 0d9dfad3..ea067ae8 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -46,7 +46,6 @@ #include "w_wad.h" #include "templates.h" #include "r_defs.h" -#include "r_draw.h" #include "a_pickups.h" #include "s_sound.h" #include "cmdlib.h" diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 9d5a19f9..e1c5e136 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -47,7 +47,6 @@ #include "w_wad.h" #include "templates.h" #include "r_defs.h" -#include "r_draw.h" #include "a_pickups.h" #include "s_sound.h" #include "cmdlib.h" diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 487a5fdd..558caa6c 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -45,7 +45,6 @@ #include "w_wad.h" #include "templates.h" #include "r_defs.h" -#include "r_draw.h" #include "a_pickups.h" #include "s_sound.h" #include "cmdlib.h" @@ -64,12 +63,12 @@ #include "v_text.h" #include "thingdef.h" #include "a_sharedglobal.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "a_morph.h" #include "colormatcher.h" #include "teaminfo.h" #include "v_video.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" //========================================================================== diff --git a/src/v_draw.cpp b/src/v_draw.cpp index abbf8278..6c5da30a 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -42,17 +42,19 @@ #include "r_draw.h" #include "r_main.h" #include "r_things.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "doomstat.h" #include "v_palette.h" #include "gi.h" +#include "g_level.h" +#include "st_stuff.h" #include "i_system.h" #include "i_video.h" #include "templates.h" #include "d_net.h" #include "colormatcher.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // [RH] Stretch values to make a 320x200 image best fit the screen // without using fractional steppings @@ -66,6 +68,7 @@ int CleanXfac_1, CleanYfac_1, CleanWidth_1, CleanHeight_1; // FillSimplePoly uses this extern "C" short spanend[MAXHEIGHT]; +extern int setblocks; CVAR (Bool, hud_scale, false, CVAR_ARCHIVE); @@ -1384,4 +1387,143 @@ void V_DrawFrame (int left, int top, int width, int height) screen->DrawTexture (TexMan[border->tr], left+width, top-offset, TAG_DONE); screen->DrawTexture (TexMan[border->bl], left-offset, top+height, TAG_DONE); screen->DrawTexture (TexMan[border->br], left+width, top+height, TAG_DONE); -} \ No newline at end of file +} + +//========================================================================== +// +// +// +//========================================================================== + +void V_DrawBorder (int x1, int y1, int x2, int y2) +{ + FTextureID picnum; + + if (level.info != NULL && level.info->bordertexture[0] != 0) + { + picnum = TexMan.CheckForTexture (level.info->bordertexture, FTexture::TEX_Flat); + } + else + { + picnum = TexMan.CheckForTexture (gameinfo.borderFlat, FTexture::TEX_Flat); + } + + if (picnum.isValid()) + { + screen->FlatFill (x1, y1, x2, y2, TexMan(picnum)); + } + else + { + screen->Clear (x1, y1, x2, y2, 0, 0); + } +} + +//========================================================================== +// +// R_DrawViewBorder +// +// Draws the border around the view for different size windows +// +//========================================================================== + +int BorderNeedRefresh; + + +static void V_DrawViewBorder (void) +{ + // [RH] Redraw the status bar if SCREENWIDTH > status bar width. + // Will draw borders around itself, too. + if (SCREENWIDTH > 320) + { + SB_state = screen->GetPageCount (); + } + + if (viewwidth == SCREENWIDTH) + { + return; + } + + V_DrawBorder (0, 0, SCREENWIDTH, viewwindowy); + V_DrawBorder (0, viewwindowy, viewwindowx, viewheight + viewwindowy); + V_DrawBorder (viewwindowx + viewwidth, viewwindowy, SCREENWIDTH, viewheight + viewwindowy); + V_DrawBorder (0, viewwindowy + viewheight, SCREENWIDTH, ST_Y); + + V_DrawFrame (viewwindowx, viewwindowy, viewwidth, viewheight); + V_MarkRect (0, 0, SCREENWIDTH, ST_Y); +} + +//========================================================================== +// +// R_DrawTopBorder +// +// Draws the top border around the view for different size windows +// +//========================================================================== + +static void V_DrawTopBorder () +{ + FTexture *p; + int offset; + + if (viewwidth == SCREENWIDTH) + return; + + offset = gameinfo.border->offset; + + if (viewwindowy < 34) + { + V_DrawBorder (0, 0, viewwindowx, 34); + V_DrawBorder (viewwindowx, 0, viewwindowx + viewwidth, viewwindowy); + V_DrawBorder (viewwindowx + viewwidth, 0, SCREENWIDTH, 34); + p = TexMan(gameinfo.border->t); + screen->FlatFill(viewwindowx, viewwindowy - p->GetHeight(), + viewwindowx + viewwidth, viewwindowy, p, true); + + p = TexMan(gameinfo.border->l); + screen->FlatFill(viewwindowx - p->GetWidth(), viewwindowy, + viewwindowx, 35, p, true); + p = TexMan(gameinfo.border->r); + screen->FlatFill(viewwindowx + viewwidth, viewwindowy, + viewwindowx + viewwidth + p->GetWidth(), 35, p, true); + + p = TexMan(gameinfo.border->tl); + screen->DrawTexture (p, viewwindowx - offset, viewwindowy - offset, TAG_DONE); + + p = TexMan(gameinfo.border->tr); + screen->DrawTexture (p, viewwindowx + viewwidth, viewwindowy - offset, TAG_DONE); + } + else + { + V_DrawBorder (0, 0, SCREENWIDTH, 34); + } +} + +//========================================================================== +// +// R_RefreshViewBorder +// +// Draws the border around the player view, if needed. +// +//========================================================================== + +void V_RefreshViewBorder () +{ + if (setblocks < 10) + { + if (BorderNeedRefresh) + { + BorderNeedRefresh--; + if (BorderTopRefresh) + { + BorderTopRefresh--; + } + V_DrawViewBorder(); + } + else if (BorderTopRefresh) + { + BorderTopRefresh--; + V_DrawTopBorder(); + } + } +} + diff --git a/src/v_font.cpp b/src/v_font.cpp index 410e6515..29f2b363 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -90,8 +90,9 @@ The FON2 header is followed by variable length data: #include "cmdlib.h" #include "sc_man.h" #include "hu_stuff.h" -#include "r_draw.h" -#include "r_translate.h" +#include "farchive.h" +#include "textures/textures.h" +#include "r_data/r_translate.h" #include "colormatcher.h" #include "v_palette.h" diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 605a57fa..a745d3c5 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -57,7 +57,7 @@ #include "x86.h" #include "colormatcher.h" #include "v_palette.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" FPalette GPalette; FColorMatcher ColorMatcher; diff --git a/src/v_video.cpp b/src/v_video.cpp index b6289077..35b5c6b5 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -29,7 +29,6 @@ #include "x86.h" #include "i_video.h" #include "r_local.h" -#include "r_draw.h" #include "r_state.h" #include "doomdef.h" @@ -56,14 +55,14 @@ #include "templates.h" #include "sbar.h" #include "hardware.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "f_wipe.h" #include "m_png.h" #include "colormatcher.h" #include "v_palette.h" #include "r_sky.h" #include "menu/menu.h" -#include "resources/voxels.h" +#include "r_data/voxels.h" IMPLEMENT_ABSTRACT_CLASS (DCanvas) diff --git a/src/v_video.h b/src/v_video.h index b56a4d28..b414d665 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -38,7 +38,7 @@ #include "doomdef.h" #include "dobject.h" -#include "r_blend.h" +#include "r_data/renderstyle.h" #include "c_cvars.h" extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac; @@ -499,6 +499,11 @@ FString V_GetColorStringByName (const char *name); int V_GetColor (const DWORD *palette, const char *str); void V_DrawFrame (int left, int top, int width, int height); +// If the view size is not full screen, draws a border around it. +void V_DrawBorder (int x1, int y1, int x2, int y2); +void V_RefreshViewBorder (); + + #if defined(X86_ASM) || defined(X64_ASM) extern "C" void ASM_PatchPitch (void); #endif diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index dbf8446a..f0dbc5d8 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -45,7 +45,7 @@ #include "sc_man.h" #include "v_text.h" #include "gi.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "templates.h" #include "gstrings.h" diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 48c6423e..0c22f451 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -64,14 +64,14 @@ #include "stats.h" #include "doomerrors.h" #include "r_main.h" -#include "r_translate.h" +#include "r_data/r_translate.h" #include "f_wipe.h" #include "st_stuff.h" #include "win32iface.h" #include "doomstat.h" #include "v_palette.h" #include "w_wad.h" -#include "resources/colormaps.h" +#include "r_data/colormaps.h" // MACROS ------------------------------------------------------------------