From 526711f5d8368cd99e2c8b92d08540459ca49b9c Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 20 May 2018 13:08:29 +0300 Subject: [PATCH 1/7] - replaced tabs with spaces in UDMF spec --- specs/udmf_zdoom.txt | 105 ++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/specs/udmf_zdoom.txt b/specs/udmf_zdoom.txt index 185d2a6de..32806245c 100644 --- a/specs/udmf_zdoom.txt +++ b/specs/udmf_zdoom.txt @@ -120,7 +120,7 @@ Note: All fields default to false unless mentioned otherwise. blockhitscan = ; // Line blocks hitscan attacks locknumber = ; // Line special is locked arg0str = ; // Alternate string-based version of arg0 - moreids = ; // Additional line IDs, specified as a space separated list of numbers (e.g. "2 666 1003 4505") + moreids = ; // Additional line IDs, specified as a space separated list of numbers (e.g. "2 666 1003 4505") transparent = ; // true = line is a Strife transparent line (alpha 0.25) @@ -171,14 +171,14 @@ Note: All fields default to false unless mentioned otherwise. yscaleceiling = ; // Y texture scale of ceiling texture, Default = 1.0. rotationfloor = ; // Rotation of floor texture in degrees, Default = 0.0. rotationceiling = ; // Rotation of ceiling texture in degrees, Default = 0.0. - ceilingplane_a = ; // Define the plane equation for the sector's ceiling. Default is a horizontal plane at 'heightceiling'. - ceilingplane_b = ; // 'heightceiling' will still be used to calculate texture alignment. - ceilingplane_c = ; // The plane equation will only be used if all 4 values are given. - ceilingplane_d = ; - floorplane_a = ; // Define the plane equation for the sector's floor. Default is a horizontal plane at 'heightfloor'. - floorplane_b = ; // 'heightfloor' will still be used to calculate texture alignment. - floorplane_c = ; // The plane equation will only be used if all 4 values are given. - floorplane_d = ; + ceilingplane_a = ; // Define the plane equation for the sector's ceiling. Default is a horizontal plane at 'heightceiling'. + ceilingplane_b = ; // 'heightceiling' will still be used to calculate texture alignment. + ceilingplane_c = ; // The plane equation will only be used if all 4 values are given. + ceilingplane_d = ; + floorplane_a = ; // Define the plane equation for the sector's floor. Default is a horizontal plane at 'heightfloor'. + floorplane_b = ; // 'heightfloor' will still be used to calculate texture alignment. + floorplane_c = ; // The plane equation will only be used if all 4 values are given. + floorplane_d = ; lightfloor = ; // The floor's light level. Default is 0. lightceiling = ; // The ceiling's light level. Default is 0. lightfloorabsolute = ; // true = 'lightfloor' is an absolute value. Default is @@ -196,8 +196,8 @@ Note: All fields default to false unless mentioned otherwise. fadecolor = ; // Sector's fog color as RRGGBB value, default = 0x000000. desaturation = ; // Color desaturation factor. 0 = none, 1 = full, default = 0. silent = ; // Actors in this sector make no sound, - nofallingdamage = ; // Falling damage is disabled in this sector - noattack = ; // Blocks monster attacks in this sector. + nofallingdamage = ; // Falling damage is disabled in this sector + noattack = ; // Blocks monster attacks in this sector. dropactors = ; // Actors drop with instantly moving floors (*) norespawn = ; // Players can not respawn in this sector soundsequence = ; // The sound sequence to play when this sector moves. Placing a @@ -215,21 +215,21 @@ Note: All fields default to false unless mentioned otherwise. damagehazard = ; // Changes damage model to Strife's delayed damage for the given sector. Default = false. floorterrain = ; // Sets the terrain for the sector's floor. Default = 'use the flat texture's terrain definition.' ceilingterrain = ; // Sets the terrain for the sector's ceiling. Default = 'use the flat texture's terrain definition.' - floor_reflect = ; // reflectiveness of floor (OpenGL only, not functional on sloped sectors) - ceiling_reflect = ; // reflectiveness of ceiling (OpenGL only, not functional on sloped sectors) - fogdensity = ; // Sets an explicit fog density for the sector, overriding the default calculation from the light level. Value range is 0-510, - // 0 meaning that the default is to be used, 2 equalling the density of a light level of 250, and 255 equalling the density of - // a light level of 0. (OpenGL only) - floorglowcolor = ; // Sector's floor glow color as RRGGBB value, default = 'use texture's definition'. Set to -1 to disable glowing. (OpenGL 3.x and newer only) - floorglowheight = ; // Height of floor glow. This only has an effect for the sector's own glow color, but not for a texture based glow. (OpenGL 3.x and newer only) - ceilingglowcolor = ; // Sector's ceiling glow color as RRGGBB value, default = 'use texture's definition'. Set to -1 to disable glowing. (OpenGL 3.x and newer only) - ceilingglowheight = ; // Height of ceiling glow. This only has an effect for the sector's own glow color, but not for a texture based glow. (OpenGL 3.x and newer only) - color_floor = ; // Material color of sector's floor. Default is white (0xffffff) - color_ceiling = ; // Material color of sector's ceiling. Default is white (0xffffff) - color_walltop = ; // Material color of top of sector's sidedefs. In OpenGL 2.x and the software renderer this will define the entire wall's color) Default is white (0xffffff) - color_wallbottom = ; // Material color of bottom of sector's sidedefs (OpenGL 3.x and later only) Default is white (0xffffff) - color_sprites = ; // Material color of sprites in sector. Default is white (0xffffff) - + floor_reflect = ; // reflectiveness of floor (OpenGL only, not functional on sloped sectors) + ceiling_reflect = ; // reflectiveness of ceiling (OpenGL only, not functional on sloped sectors) + fogdensity = ; // Sets an explicit fog density for the sector, overriding the default calculation from the light level. Value range is 0-510, + // 0 meaning that the default is to be used, 2 equalling the density of a light level of 250, and 255 equalling the density of + // a light level of 0. (OpenGL only) + floorglowcolor = ; // Sector's floor glow color as RRGGBB value, default = 'use texture's definition'. Set to -1 to disable glowing. (OpenGL 3.x and newer only) + floorglowheight = ; // Height of floor glow. This only has an effect for the sector's own glow color, but not for a texture based glow. (OpenGL 3.x and newer only) + ceilingglowcolor = ; // Sector's ceiling glow color as RRGGBB value, default = 'use texture's definition'. Set to -1 to disable glowing. (OpenGL 3.x and newer only) + ceilingglowheight = ; // Height of ceiling glow. This only has an effect for the sector's own glow color, but not for a texture based glow. (OpenGL 3.x and newer only) + color_floor = ; // Material color of sector's floor. Default is white (0xffffff) + color_ceiling = ; // Material color of sector's ceiling. Default is white (0xffffff) + color_walltop = ; // Material color of top of sector's sidedefs. In OpenGL 2.x and the software renderer this will define the entire wall's color) Default is white (0xffffff) + color_wallbottom = ; // Material color of bottom of sector's sidedefs (OpenGL 3.x and later only) Default is white (0xffffff) + color_sprites = ; // Material color of sprites in sector. Default is white (0xffffff) + portal_ceil_blocksound = // ceiling portal blocks sound. portal_ceil_disabled = // ceiling portal disabled. @@ -241,8 +241,8 @@ Note: All fields default to false unless mentioned otherwise. portal_floor_nopass = // ceiling portal blocks movement if true. portal_floor_norender = // ceiling portal not rendered. portal_floor_overlaytype = // defines translucency style, can either be "translucent" or "additive". Default is "translucent". - - + + * Note about dropactors The spec requires this to be false by default. Currently, however, ZDoom assumes this to be true @@ -253,37 +253,37 @@ Note: All fields default to false unless mentioned otherwise. thing { - skill# = // Unlike the base spec, # can range from 1-16. - class# = // Unlike the base spec, # can range from 1-16. - conversation = // Assigns a conversation dialogue to this thing. + skill# = // Unlike the base spec, # can range from 1-16. + class# = // Unlike the base spec, # can range from 1-16. + conversation = // Assigns a conversation dialogue to this thing. // Parameter is the conversation ID, 0 meaning none. countsecret = ; // Picking up this actor counts as a secret. arg0str = ; // Alternate string-based version of arg0 - gravity = ; // Set per-actor gravity. Positive values are multiplied with the class's property, - // negative values are used as their absolute. Default = 1.0. - - health = ; // Set per-actor health. Positive values are multiplied with the class's property, - // negative values are used as their absolute. Default = 1. - - renderstyle = ; // Set per-actor render style, overriding the class default. Possible values can be "normal", - // "none", "add" or "additive", "subtract" or "subtractive", "stencil", "translucentstencil", - // "addstencil", "shaded", "addshaded", "translucent", "fuzzy", "optfuzzy", "soultrans" and "shadow". - // Default is an empty string for no change. - fillcolor = ; // Fill color used by the "stencil", "addstencil" and "translucentstencil" rendestyles, as RRGGBB value, default = 0x000000. - alpha = ; // Translucency of this actor (if applicable to renderstyle), default is 1.0. - score = ; // Score value of this actor, overriding the class default if not null. Default = 0. - pitch = ; // Pitch of thing in degrees. Default = 0 (horizontal). - roll = ; // Pitch of thing in degrees. Default = 0 (horizontal). - scalex = ; // Vertical scaling on thing. Default = 0 (ignored). - scaley = ; // Horizontal scaling on thing. Default = 0 (ignored). - scale = ; // Vertical and horizontal scaling on thing. Default = 0 (ignored). - floatbobphase = ; // Sets the thing's floatbobphase. Valid phase values are 0-63. Default = -1 (use actor class default). + gravity = ; // Set per-actor gravity. Positive values are multiplied with the class's property, + // negative values are used as their absolute. Default = 1.0. + + health = ; // Set per-actor health. Positive values are multiplied with the class's property, + // negative values are used as their absolute. Default = 1. + + renderstyle = ; // Set per-actor render style, overriding the class default. Possible values can be "normal", + // "none", "add" or "additive", "subtract" or "subtractive", "stencil", "translucentstencil", + // "addstencil", "shaded", "addshaded", "translucent", "fuzzy", "optfuzzy", "soultrans" and "shadow". + // Default is an empty string for no change. + fillcolor = ; // Fill color used by the "stencil", "addstencil" and "translucentstencil" rendestyles, as RRGGBB value, default = 0x000000. + alpha = ; // Translucency of this actor (if applicable to renderstyle), default is 1.0. + score = ; // Score value of this actor, overriding the class default if not null. Default = 0. + pitch = ; // Pitch of thing in degrees. Default = 0 (horizontal). + roll = ; // Pitch of thing in degrees. Default = 0 (horizontal). + scalex = ; // Vertical scaling on thing. Default = 0 (ignored). + scaley = ; // Horizontal scaling on thing. Default = 0 (ignored). + scale = ; // Vertical and horizontal scaling on thing. Default = 0 (ignored). + floatbobphase = ; // Sets the thing's floatbobphase. Valid phase values are 0-63. Default = -1 (use actor class default). * Note about arg0str For things with ACS specials (80-86 and 226), if arg0str is present and non-null, it will be used as the name of the script to execute, and arg0 will be ignored. - On dynamic lights, arg0str can be used to set a color by name, this will supersede all args which are normally used to define a color. + On dynamic lights, arg0str can be used to set a color by name, this will supersede all args which are normally used to define a color. } @@ -430,6 +430,9 @@ sector material colors. 1.29 04.02.2018 arg0str in dynamic lights. +1.30 20.05.2018 +Replaced tabs with spaces. + =============================================================================== EOF =============================================================================== From ad31da20e5e1bbf8365a2f9243746bf7691e9818 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 20 May 2018 14:48:44 +0300 Subject: [PATCH 2/7] - added new linedef properties to UDMF spec https://forum.zdoom.org/viewtopic.php?t=59808 --- specs/udmf_zdoom.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/specs/udmf_zdoom.txt b/specs/udmf_zdoom.txt index 32806245c..84dcd4d29 100644 --- a/specs/udmf_zdoom.txt +++ b/specs/udmf_zdoom.txt @@ -122,7 +122,24 @@ Note: All fields default to false unless mentioned otherwise. arg0str = ; // Alternate string-based version of arg0 moreids = ; // Additional line IDs, specified as a space separated list of numbers (e.g. "2 666 1003 4505") - transparent = ; // true = line is a Strife transparent line (alpha 0.25) + transparent = ; // true = line is a Strife transparent line (alpha 0.25) + + automapstyle = ; // Explicit automap style. Possible values can be + // 0: Automap style is based on line properties (default). + // 1: One-sided wall. + // 2: Two-sided wall. + // 3: Floor levels of front and back sectors are different. + // 4: Ceiling levels of front and back sectors are different. + // 5: 3D floor border. + // 6: Wall with special non-door action. + // 7: Secret door. + // 8: Wall not seen yet. + // 9: Locked door. + // 10: Intra-level teleporter. + // 11: Inter-level or game-ending teleporter. + // 12: Unexplored secret wall. + // 13: Portal line. + revealed = ; // true = line is initially visible on automap. * Note about arg0str @@ -431,6 +448,7 @@ sector material colors. arg0str in dynamic lights. 1.30 20.05.2018 +Added automapstyle and revealed linedef properties. Replaced tabs with spaces. =============================================================================== From 2cdc9f9dda41f69a45de9de7b54a8ec4dc28a3cd Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 21 May 2018 10:49:29 +0300 Subject: [PATCH 3/7] - fixed applying of alpha to weapon sprites https://forum.zdoom.org/viewtopic.php?t=60638 https://forum.zdoom.org/viewtopic.php?t=60642 --- src/hwrenderer/scene/hw_weapon.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 781f3395a..ed71ceb11 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -252,14 +252,13 @@ bool HUDSprite::GetWeaponRenderStyle(DPSprite *psp, AActor *playermo, sector_t * auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha); visstyle_t vis; - float trans = 0.f; vis.RenderStyle = STYLE_Count; vis.Alpha = rs.second; vis.Invert = false; playermo->AlterWeaponSprite(&vis); - if (!(psp->Flags & PSPF_FORCEALPHA)) trans = vis.Alpha; + alpha = (psp->Flags & PSPF_FORCEALPHA) ? 0.f : vis.Alpha; if (vis.RenderStyle != STYLE_Count && !(psp->Flags & PSPF_FORCESTYLE)) { @@ -303,14 +302,10 @@ bool HUDSprite::GetWeaponRenderStyle(DPSprite *psp, AActor *playermo, sector_t * { alpha = 1.f; } - else if (trans == 0.f) + else if (alpha == 0.f) { alpha = vis.Alpha; } - else - { - alpha = trans; - } if (!RenderStyle.IsVisible(alpha)) return false; // if it isn't visible skip the rest. PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff; From cc4a09a3d2977685753c51b6df039d2c3883cb34 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 21 May 2018 14:23:30 +0200 Subject: [PATCH 4/7] - fix model interpolation bug --- src/r_data/models/models.cpp | 27 ++++++++------------------- src/r_data/models/models.h | 3 +-- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index ce41e064d..a0b76e581 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -94,8 +94,8 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s if (smf->flags & MDL_ROTATING) { - const double time = smf->rotationSpeed*GetTimeFloat() / 200.; - rotateOffset = double((time - xs_FloorToInt(time)) *360.); + double turns = (I_GetTime() % 200 + I_GetTimeFrac()) / 200.0; + rotateOffset = turns * 360.0; } // Added MDL_USEACTORPITCH and MDL_USEACTORROLL flags processing. @@ -164,7 +164,7 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s objectToWorldMatrix.scale(1, stretch, 1); BeginDrawModel(actor, smf, objectToWorldMatrix); - RenderFrameModels(smf, actor->state, actor->tics, actor->GetClass(), nullptr, translation); + RenderFrameModels(smf, actor->state, actor->tics, actor->GetClass(), translation); EndDrawModel(actor, smf); } @@ -200,16 +200,11 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) objectToWorldMatrix.rotate(-smf->rolloffset, 1, 0, 0); BeginDrawHUDModel(playermo, objectToWorldMatrix); - RenderFrameModels(smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), nullptr, 0); + RenderFrameModels(smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), 0); EndDrawHUDModel(playermo); } -void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, - const FState *curState, - const int curTics, - const PClass *ti, - Matrix3x4 *normaltransform, - int translation) +void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation) { // [BB] Frame interpolation: Find the FSpriteModelFrame smfNext which follows after smf in the animation // and the scalar value inter ( element of [0,1) ), both necessary to determine the interpolated frame. @@ -225,14 +220,13 @@ void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, // [BB] In case the tic counter is frozen we have to leave ticFraction at zero. if (ConsoleState == c_up && menuactive != MENU_On && !(level.flags2 & LEVEL2_FROZEN)) { - double time = GetTimeFloat(); - ticFraction = (time - static_cast(time)); + ticFraction = I_GetTimeFrac(); } - inter = static_cast(curState->Tics - curTics - ticFraction) / static_cast(curState->Tics); + inter = static_cast(curState->Tics - curTics + ticFraction) / static_cast(curState->Tics); // [BB] For some actors (e.g. ZPoisonShroom) spr->actor->tics can be bigger than curState->Tics. // In this case inter is negative and we need to set it to zero. - if (inter < 0.) + if (curState->Tics < curTics) inter = 0.; else { @@ -279,11 +273,6 @@ void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, } } -double FModelRenderer::GetTimeFloat() -{ - return (double)I_msTime() * (double)TICRATE / 1000.; -} - ///////////////////////////////////////////////////////////////////////////// void gl_LoadModels() diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index 91d3d14d6..802f85214 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -73,8 +73,7 @@ public: virtual void DrawElements(int numIndices, size_t offset) = 0; private: - void RenderFrameModels(const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, Matrix3x4 *normaltransform, int translation); - static double GetTimeFloat(); + void RenderFrameModels(const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); }; struct FModelVertex From 31abe3df7e108f12a07441221ebddd34ce5198ed Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 21 May 2018 17:52:03 +0200 Subject: [PATCH 5/7] - avoid reusing the same mVBuf pointer for the different renderers as that causes too many problems when switching between them - remove gl_ prefix for model functions that are no longer GL specific --- src/gl/models/gl_models.h | 1 + src/gl/renderer/gl_renderer.cpp | 6 +-- src/gl/scene/gl_scene.cpp | 4 +- src/hwrenderer/scene/hw_sprites.cpp | 4 +- src/hwrenderer/scene/hw_weapon.cpp | 4 +- src/hwrenderer/textures/hw_precache.cpp | 2 +- src/polyrenderer/scene/poly_model.cpp | 8 ---- src/polyrenderer/scene/poly_model.h | 2 + src/polyrenderer/scene/poly_playersprite.cpp | 2 +- src/polyrenderer/scene/poly_sprite.cpp | 2 +- src/r_data/models/models.cpp | 45 +++++++++++--------- src/r_data/models/models.h | 35 +++++++++------ src/r_data/models/models_md2.cpp | 12 +++--- src/r_data/models/models_md3.cpp | 16 ++++--- src/r_data/models/models_ue1.cpp | 11 ++--- src/r_data/models/models_voxel.cpp | 16 ++++--- src/swrenderer/scene/r_opaque_pass.cpp | 2 +- src/swrenderer/things/r_model.cpp | 8 ---- src/swrenderer/things/r_model.h | 2 + src/swrenderer/things/r_playersprite.cpp | 2 +- 20 files changed, 94 insertions(+), 90 deletions(-) diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index f9458890a..821705c34 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -36,6 +36,7 @@ class FGLModelRenderer : public FModelRenderer public: FGLModelRenderer(int mli) : modellightindex(mli) {} + ModelRendererType GetType() const override { return GLModelRendererType; } void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override; void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index f8d2ead8f..993d6d1ee 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -121,9 +121,6 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb) mCustomPostProcessShaders = nullptr; } -void gl_LoadModels(); -void gl_FlushModels(); - void FGLRenderer::Initialize(int width, int height) { mBuffers = new FGLRenderBuffers(); @@ -175,7 +172,6 @@ void FGLRenderer::Initialize(int width, int height) SetupLevel(); mShaderManager = new FShaderManager; mSamplerManager = new FSamplerManager; - gl_LoadModels(); GLPortal::Initialize(); } @@ -184,7 +180,7 @@ FGLRenderer::~FGLRenderer() { GLPortal::Shutdown(); - gl_FlushModels(); + FlushModels(); AActor::DeleteAllAttachedLights(); FMaterial::FlushAll(); if (legacyShaders) delete legacyShaders; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 70350b018..eadd940b7 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -510,7 +510,7 @@ void GLSceneDrawer::EndDrawScene(sector_t * viewsector) gl_RenderState.EnableFog(false); // [BB] HUD models need to be rendered here. - const bool renderHUDModel = gl_IsHUDModelForPlayerAvailable( players[consoleplayer].camera->player ); + const bool renderHUDModel = IsHUDModelForPlayerAvailable( players[consoleplayer].camera->player ); if ( renderHUDModel ) { // [BB] The HUD model should be drawn over everything else already drawn. @@ -539,7 +539,7 @@ void GLSceneDrawer::EndDrawScene(sector_t * viewsector) void GLSceneDrawer::DrawEndScene2D(sector_t * viewsector) { - const bool renderHUDModel = gl_IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); + const bool renderHUDModel = IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); // This should be removed once all 2D stuff is really done through the 2D interface. gl_RenderState.mViewMatrix.loadIdentity(); diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 6814d1760..7db0fb335 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -448,7 +448,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // exclude vertically moving objects from this check. if (!thing->Vel.isZero()) { - if (!gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, false)) + if (!FindModelFrame(thing->GetClass(), spritenum, thing->frame, false)) { return; } @@ -509,7 +509,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t z += fz; } - modelframe = isPicnumOverride ? nullptr : gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); + modelframe = isPicnumOverride ? nullptr : FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); if (!modelframe) { bool mirror; diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index ed71ceb11..c22d2183a 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -425,7 +425,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) bool brightflash = false; AActor * playermo = players[consoleplayer].camera; player_t * player = playermo->player; - const bool hudModelStep = gl_IsHUDModelForPlayerAvailable(player); + const bool hudModelStep = IsHUDModelForPlayerAvailable(player); AActor *camera = r_viewpoint.camera; @@ -448,7 +448,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) for (DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext()) { if (!psp->GetState()) continue; - FSpriteModelFrame *smf = playermo->player->ReadyWeapon ? gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false) : nullptr; + FSpriteModelFrame *smf = playermo->player->ReadyWeapon ? FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false) : nullptr; // This is an 'either-or' proposition. This maybe needs some work to allow overlays with weapon models but as originally implemented this just won't work. if (smf && !hudModelStep) continue; if (!smf && hudModelStep) continue; diff --git a/src/hwrenderer/textures/hw_precache.cpp b/src/hwrenderer/textures/hw_precache.cpp index a40a8a821..a6342d2fb 100644 --- a/src/hwrenderer/textures/hw_precache.cpp +++ b/src/hwrenderer/textures/hw_precache.cpp @@ -119,7 +119,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { auto &state = cls->GetStates()[i]; spritelist[state.sprite].Insert(gltrans, true); - FSpriteModelFrame * smf = gl_FindModelFrame(cls, state.sprite, state.Frame, false); + FSpriteModelFrame * smf = FindModelFrame(cls, state.sprite, state.Frame, false); if (smf != NULL) { for (int i = 0; i < MAX_MODELS_PER_FRAME; i++) diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index bb0c3fb52..ac29af9bb 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -33,9 +33,6 @@ #include "actorinlines.h" #include "i_time.h" -void gl_FlushModels(); -bool polymodelsInUse; - void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor) { PolyModelRenderer renderer(thread, worldToClip, stencilValue); @@ -52,11 +49,6 @@ void PolyRenderHUDModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint PolyModelRenderer::PolyModelRenderer(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue) : Thread(thread), WorldToClip(worldToClip), StencilValue(stencilValue) { - if (!polymodelsInUse) - { - gl_FlushModels(); - polymodelsInUse = true; - } } void PolyModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) diff --git a/src/polyrenderer/scene/poly_model.h b/src/polyrenderer/scene/poly_model.h index cc12f9e6e..cbfafce59 100644 --- a/src/polyrenderer/scene/poly_model.h +++ b/src/polyrenderer/scene/poly_model.h @@ -34,6 +34,8 @@ class PolyModelRenderer : public FModelRenderer public: PolyModelRenderer(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue); + ModelRendererType GetType() const override { return PolyModelRendererType; } + void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override; void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index c7d75ef33..e08857de9 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -60,7 +60,7 @@ void RenderPolyPlayerSprites::Render(PolyRenderThread *thread) (r_deathcamera && viewpoint.camera->health <= 0)) return; - renderHUDModel = r_models && gl_IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); + renderHUDModel = r_models && IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); PolyTransferHeights fakeflat(viewpoint.camera->subsector); diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index 12406b5c0..88ffb99b6 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -78,7 +78,7 @@ void RenderPolySprite::Render(PolyRenderThread *thread, AActor *thing, subsector { int spritenum = thing->sprite; bool isPicnumOverride = thing->picnum.isValid(); - FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); + FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); if (modelframe) { const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index a0b76e581..23b517352 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -171,7 +171,7 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) { AActor * playermo = players[consoleplayer].camera; - FSpriteModelFrame *smf = gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false); + FSpriteModelFrame *smf = FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false); // [BB] No model found for this sprite, so we can't render anything. if (smf == nullptr) @@ -247,7 +247,7 @@ void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, const FStat } } if (inter != 0.0) - smfNext = gl_FindModelFrame(ti, nextState->sprite, nextState->Frame, false); + smfNext = FindModelFrame(ti, nextState->sprite, nextState->Frame, false); } } } @@ -259,7 +259,7 @@ void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, const FStat FModel * mdl = Models[smf->modelIDs[i]]; FTexture *tex = smf->skinIDs[i].isValid() ? TexMan(smf->skinIDs[i]) : nullptr; mdl->BuildVertexBuffer(this); - SetVertexBuffer(mdl->mVBuf); + SetVertexBuffer(mdl->GetVertexBuffer(this)); mdl->PushSpriteMDLFrame(smf, i); @@ -275,17 +275,7 @@ void FModelRenderer::RenderFrameModels(const FSpriteModelFrame *smf, const FStat ///////////////////////////////////////////////////////////////////////////// -void gl_LoadModels() -{ - /* - for (int i = Models.Size() - 1; i >= 0; i--) - { - Models[i]->BuildVertexBuffer(); - } - */ -} - -void gl_FlushModels() +void FlushModels() { for (int i = Models.Size() - 1; i >= 0; i--) { @@ -295,9 +285,24 @@ void gl_FlushModels() ///////////////////////////////////////////////////////////////////////////// +FModel::FModel() +{ + for (int i = 0; i < NumModelRendererTypes; i++) + mVBuf[i] = nullptr; +} + FModel::~FModel() { - if (mVBuf != nullptr) delete mVBuf; + DestroyVertexBuffer(); +} + +void FModel::DestroyVertexBuffer() +{ + for (int i = 0; i < NumModelRendererTypes; i++) + { + delete mVBuf[i]; + mVBuf[i] = nullptr; + } } static TArray SpriteModelFrames; @@ -842,11 +847,11 @@ void gl_InitModels() //=========================================================================== // -// gl_FindModelFrame +// FindModelFrame // //=========================================================================== -FSpriteModelFrame * gl_FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped) +FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped) { if (GetDefaultByType(ti)->hasmodel) { @@ -887,11 +892,11 @@ FSpriteModelFrame * gl_FindModelFrame(const PClass * ti, int sprite, int frame, //=========================================================================== // -// gl_IsHUDModelForPlayerAvailable +// IsHUDModelForPlayerAvailable // //=========================================================================== -bool gl_IsHUDModelForPlayerAvailable (player_t * player) +bool IsHUDModelForPlayerAvailable (player_t * player) { if (player == nullptr || player->ReadyWeapon == nullptr) return false; @@ -902,7 +907,7 @@ bool gl_IsHUDModelForPlayerAvailable (player_t * player) return false; FState* state = psp->GetState(); - FSpriteModelFrame *smf = gl_FindModelFrame(player->ReadyWeapon->GetClass(), state->sprite, state->GetFrame(), false); + FSpriteModelFrame *smf = FindModelFrame(player->ReadyWeapon->GetClass(), state->sprite, state->GetFrame(), false); return ( smf != nullptr ); } diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index 802f85214..b0d0f0230 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -46,6 +46,14 @@ FTextureID LoadSkin(const char * path, const char * fn); struct FSpriteModelFrame; class IModelVertexBuffer; +enum ModelRendererType +{ + GLModelRendererType, + SWModelRendererType, + PolyModelRendererType, + NumModelRendererTypes +}; + class FModelRenderer { public: @@ -54,6 +62,8 @@ public: void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor); void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); + virtual ModelRendererType GetType() const = 0; + virtual void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) = 0; virtual void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) = 0; @@ -122,11 +132,7 @@ public: class FModel { public: - - FModel() - { - mVBuf = NULL; - } + FModel(); virtual ~FModel(); virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; @@ -134,19 +140,20 @@ public: virtual void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; virtual void AddSkins(uint8_t *hitlist) = 0; - void DestroyVertexBuffer() - { - delete mVBuf; - mVBuf = NULL; - } virtual float getAspectFactor() { return 1.f; } + void SetVertexBuffer(FModelRenderer *renderer, IModelVertexBuffer *buffer) { mVBuf[renderer->GetType()] = buffer; } + IModelVertexBuffer *GetVertexBuffer(FModelRenderer *renderer) const { return mVBuf[renderer->GetType()]; } + void DestroyVertexBuffer(); + const FSpriteModelFrame *curSpriteMDLFrame; int curMDLIndex; void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; - IModelVertexBuffer *mVBuf; FString mFileName; + +private: + IModelVertexBuffer *mVBuf[NumModelRendererTypes]; }; class FDMDModel : public FModel @@ -472,9 +479,9 @@ struct FSpriteModelFrame float pitchoffset, rolloffset; // I don't want to bother with type transformations, so I made this variables float. }; -FSpriteModelFrame * gl_FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped); - -bool gl_IsHUDModelForPlayerAvailable (player_t * player); +FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped); +bool IsHUDModelForPlayerAvailable(player_t * player); +void FlushModels(); class DeletingModelArray : public TArray { diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index 999e0cd82..ce9566a8f 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -279,15 +279,17 @@ FDMDModel::~FDMDModel() void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer) { - if (mVBuf == NULL) + if (!GetVertexBuffer(renderer)) { LoadGeometry(); int VertexBufferSize = info.numFrames * lodInfo[0].numTriangles * 3; unsigned int vindex = 0; - mVBuf = renderer->CreateVertexBuffer(false, info.numFrames == 1); - FModelVertex *vertptr = mVBuf->LockVertexBuffer(VertexBufferSize); + auto vbuf = renderer->CreateVertexBuffer(false, info.numFrames == 1); + SetVertexBuffer(renderer, vbuf); + + FModelVertex *vertptr = vbuf->LockVertexBuffer(VertexBufferSize); for (int i = 0; i < info.numFrames; i++) { @@ -313,7 +315,7 @@ void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer) tri++; } } - mVBuf->UnlockVertexBuffer(); + vbuf->UnlockVertexBuffer(); UnloadGeometry(); } } @@ -368,7 +370,7 @@ void FDMDModel::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame renderer->SetInterpolation(inter); renderer->SetMaterial(skin, false, translation); - mVBuf->SetupFrame(renderer, frames[frameno].vindex, frames[frameno2].vindex, lodInfo[0].numTriangles * 3); + GetVertexBuffer(renderer)->SetupFrame(renderer, frames[frameno].vindex, frames[frameno2].vindex, lodInfo[0].numTriangles * 3); renderer->DrawArrays(0, lodInfo[0].numTriangles * 3); renderer->SetInterpolation(0.f); } diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index 31f2c31cb..f47ee90cd 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -237,7 +237,7 @@ void FMD3Model::LoadGeometry() void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) { - if (mVBuf == nullptr) + if (!GetVertexBuffer(renderer)) { LoadGeometry(); @@ -251,9 +251,11 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) ibufsize += 3 * surf->numTriangles; } - mVBuf = renderer->CreateVertexBuffer(true, numFrames == 1); - FModelVertex *vertptr = mVBuf->LockVertexBuffer(vbufsize); - unsigned int *indxptr = mVBuf->LockIndexBuffer(ibufsize); + auto vbuf = renderer->CreateVertexBuffer(true, numFrames == 1); + SetVertexBuffer(renderer, vbuf); + + FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize); + unsigned int *indxptr = vbuf->LockIndexBuffer(ibufsize); assert(vertptr != nullptr && indxptr != nullptr); @@ -285,8 +287,8 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) } surf->UnloadGeometry(); } - mVBuf->UnlockVertexBuffer(); - mVBuf->UnlockIndexBuffer(); + vbuf->UnlockVertexBuffer(); + vbuf->UnlockIndexBuffer(); } } @@ -365,7 +367,7 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame } renderer->SetMaterial(surfaceSkin, false, translation); - mVBuf->SetupFrame(renderer, surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, surf->numVertices); + GetVertexBuffer(renderer)->SetupFrame(renderer, surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, surf->numVertices); renderer->DrawElements(surf->numTriangles * 3, surf->iindex * sizeof(unsigned int)); } renderer->SetInterpolation(0.f); diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 7cf292d6b..98ea08a19 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -198,7 +198,7 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FTexture *skin, int frame } } renderer->SetMaterial(sskin,false,translation); - mVBuf->SetupFrame(renderer,vofs+frame*fsize,vofs+frame2*fsize,vsize); + GetVertexBuffer(renderer)->SetupFrame(renderer,vofs+frame*fsize,vofs+frame2*fsize,vsize); renderer->DrawArrays(0,vsize); vofs += vsize; } @@ -207,14 +207,15 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FTexture *skin, int frame void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer ) { - if ( mVBuf != NULL ) + if (GetVertexBuffer(renderer)) return; int vsize = 0; for ( int i=0; iCreateVertexBuffer(false,numFrames==1); - FModelVertex *vptr = mVBuf->LockVertexBuffer(vsize); + auto vbuf = renderer->CreateVertexBuffer(false,numFrames==1); + SetVertexBuffer(renderer, vbuf); + FModelVertex *vptr = vbuf->LockVertexBuffer(vsize); int vidx = 0; for ( int i=0; iUnlockVertexBuffer(); + vbuf->UnlockVertexBuffer(); } void FUE1Model::AddSkins( uint8_t *hitlist ) diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index 3c9af2374..e25a72613 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -321,19 +321,21 @@ void FVoxelModel::Initialize() void FVoxelModel::BuildVertexBuffer(FModelRenderer *renderer) { - if (mVBuf == NULL) + if (!GetVertexBuffer(renderer)) { Initialize(); - mVBuf = renderer->CreateVertexBuffer(true, true); - FModelVertex *vertptr = mVBuf->LockVertexBuffer(mVertices.Size()); - unsigned int *indxptr = mVBuf->LockIndexBuffer(mIndices.Size()); + auto vbuf = renderer->CreateVertexBuffer(true, true); + SetVertexBuffer(renderer, vbuf); + + FModelVertex *vertptr = vbuf->LockVertexBuffer(mVertices.Size()); + unsigned int *indxptr = vbuf->LockIndexBuffer(mIndices.Size()); memcpy(vertptr, &mVertices[0], sizeof(FModelVertex)* mVertices.Size()); memcpy(indxptr, &mIndices[0], sizeof(unsigned int)* mIndices.Size()); - mVBuf->UnlockVertexBuffer(); - mVBuf->UnlockIndexBuffer(); + vbuf->UnlockVertexBuffer(); + vbuf->UnlockIndexBuffer(); mNumIndices = mIndices.Size(); // delete our temporary buffers @@ -398,7 +400,7 @@ float FVoxelModel::getAspectFactor() void FVoxelModel::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation) { renderer->SetMaterial(skin, true, translation); - mVBuf->SetupFrame(renderer, 0, 0, 0); + GetVertexBuffer(renderer)->SetupFrame(renderer, 0, 0, 0); renderer->DrawElements(mNumIndices, 0); } diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 14e42379d..5a88c8086 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -962,7 +962,7 @@ namespace swrenderer { int spritenum = thing->sprite; bool isPicnumOverride = thing->picnum.isValid(); - FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); + FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); if (modelframe && (thing->Pos() - Thread->Viewport->viewpoint.Pos).LengthSquared() < model_distance_cull) { DVector3 pos = thing->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac); diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index 8040797b5..fe5769262 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -34,9 +34,6 @@ #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/scene/r_light.h" -void gl_FlushModels(); -extern bool polymodelsInUse; - namespace swrenderer { void RenderModel::Project(RenderThread *thread, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor) @@ -83,11 +80,6 @@ namespace swrenderer SWModelRenderer::SWModelRenderer(RenderThread *thread, Fake3DTranslucent clip3DFloor) : Thread(thread), Clip3DFloor(clip3DFloor) { - if (polymodelsInUse) - { - gl_FlushModels(); - polymodelsInUse = false; - } } void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) diff --git a/src/swrenderer/things/r_model.h b/src/swrenderer/things/r_model.h index 0519d5588..004636e69 100644 --- a/src/swrenderer/things/r_model.h +++ b/src/swrenderer/things/r_model.h @@ -54,6 +54,8 @@ namespace swrenderer public: SWModelRenderer(RenderThread *thread, Fake3DTranslucent clip3DFloor); + ModelRendererType GetType() const override { return SWModelRendererType; } + void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override; void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index acb521500..e1156f4fd 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -94,7 +94,7 @@ namespace swrenderer (r_deathcamera && Thread->Viewport->viewpoint.camera->health <= 0)) return; - renderHUDModel = r_models && gl_IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); + renderHUDModel = r_models && IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); FDynamicColormap *basecolormap; CameraLight *cameraLight = CameraLight::Instance(); From 91aec1689e9a1ec47dc3c39946d2ed91e50baffb Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 22 May 2018 01:28:57 +0200 Subject: [PATCH 6/7] - move modeldef parsing to its own function (ParseModelDefLump) - rename gl_InitModels to InitModels - add commented out support for #include in modeldefs (blocked by gene tech having broken #include statements in its modeldef files) --- src/r_data/models/models.cpp | 627 ++++++++++++++++++----------------- src/r_data/sprites.cpp | 4 +- 2 files changed, 322 insertions(+), 309 deletions(-) diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 23b517352..cb260bf88 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -469,22 +469,15 @@ static unsigned FindModel(const char * path, const char * modelfile) //=========================================================================== // -// gl_InitModels +// InitModels // //=========================================================================== -void gl_InitModels() +void ParseModelDefLump(int Lump); + +void InitModels() { - int Lump, lastLump; - FString path; - int index, surface; - int i; - - FSpriteModelFrame smf; - - lastLump = 0; - - for(unsigned i=0;iVoxel->VoxelIndex]; + FSpriteModelFrame smf; memset(&smf, 0, sizeof(smf)); smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; smf.modelIDs[0] = VoxelDefs[i]->Voxel->VoxelIndex; @@ -533,302 +527,11 @@ void gl_InitModels() } } - memset(&smf, 0, sizeof(smf)); - smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; + int Lump; + int lastLump = 0; while ((Lump = Wads.FindLump("MODELDEF", &lastLump)) != -1) { - FScanner sc(Lump); - while (sc.GetString()) - { - if (sc.Compare("model")) - { - path = ""; - sc.MustGetString(); - memset(&smf, 0, sizeof(smf)); - smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; - smf.xscale=smf.yscale=smf.zscale=1.f; - - smf.type = PClass::FindClass(sc.String); - if (!smf.type || smf.type->Defaults == nullptr) - { - sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String); - } - sc.MustGetStringName("{"); - while (!sc.CheckString("}")) - { - sc.MustGetString(); - if (sc.Compare("path")) - { - sc.MustGetString(); - FixPathSeperator(sc.String); - path = sc.String; - if (path[(int)path.Len()-1]!='/') path+='/'; - } - else if (sc.Compare("model")) - { - sc.MustGetNumber(); - index = sc.Number; - if (index < 0 || index >= MAX_MODELS_PER_FRAME) - { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); - } - sc.MustGetString(); - FixPathSeperator(sc.String); - smf.modelIDs[index] = FindModel(path.GetChars(), sc.String); - if (smf.modelIDs[index] == -1) - { - Printf("%s: model not found in %s\n", sc.String, path.GetChars()); - } - } - else if (sc.Compare("scale")) - { - sc.MustGetFloat(); - smf.xscale = sc.Float; - sc.MustGetFloat(); - smf.yscale = sc.Float; - sc.MustGetFloat(); - smf.zscale = sc.Float; - } - // [BB] Added zoffset reading. - // Now it must be considered deprecated. - else if (sc.Compare("zoffset")) - { - sc.MustGetFloat(); - smf.zoffset=sc.Float; - } - // Offset reading. - else if (sc.Compare("offset")) - { - sc.MustGetFloat(); - smf.xoffset = sc.Float; - sc.MustGetFloat(); - smf.yoffset = sc.Float; - sc.MustGetFloat(); - smf.zoffset = sc.Float; - } - // angleoffset, pitchoffset and rolloffset reading. - else if (sc.Compare("angleoffset")) - { - sc.MustGetFloat(); - smf.angleoffset = sc.Float; - } - else if (sc.Compare("pitchoffset")) - { - sc.MustGetFloat(); - smf.pitchoffset = sc.Float; - } - else if (sc.Compare("rolloffset")) - { - sc.MustGetFloat(); - smf.rolloffset = sc.Float; - } - // [BB] Added model flags reading. - else if (sc.Compare("ignoretranslation")) - { - smf.flags |= MDL_IGNORETRANSLATION; - } - else if (sc.Compare("pitchfrommomentum")) - { - smf.flags |= MDL_PITCHFROMMOMENTUM; - } - else if (sc.Compare("inheritactorpitch")) - { - smf.flags |= MDL_USEACTORPITCH | MDL_BADROTATION; - } - else if (sc.Compare("inheritactorroll")) - { - smf.flags |= MDL_USEACTORROLL; - } - else if (sc.Compare("useactorpitch")) - { - smf.flags |= MDL_USEACTORPITCH; - } - else if (sc.Compare("useactorroll")) - { - smf.flags |= MDL_USEACTORROLL; - } - else if (sc.Compare("rotating")) - { - smf.flags |= MDL_ROTATING; - smf.xrotate = 0.; - smf.yrotate = 1.; - smf.zrotate = 0.; - smf.rotationCenterX = 0.; - smf.rotationCenterY = 0.; - smf.rotationCenterZ = 0.; - smf.rotationSpeed = 1.; - } - else if (sc.Compare("rotation-speed")) - { - sc.MustGetFloat(); - smf.rotationSpeed = sc.Float; - } - else if (sc.Compare("rotation-vector")) - { - sc.MustGetFloat(); - smf.xrotate = sc.Float; - sc.MustGetFloat(); - smf.yrotate = sc.Float; - sc.MustGetFloat(); - smf.zrotate = sc.Float; - } - else if (sc.Compare("rotation-center")) - { - sc.MustGetFloat(); - smf.rotationCenterX = sc.Float; - sc.MustGetFloat(); - smf.rotationCenterY = sc.Float; - sc.MustGetFloat(); - smf.rotationCenterZ = sc.Float; - } - else if (sc.Compare("interpolatedoubledframes")) - { - smf.flags |= MDL_INTERPOLATEDOUBLEDFRAMES; - } - else if (sc.Compare("nointerpolation")) - { - smf.flags |= MDL_NOINTERPOLATION; - } - else if (sc.Compare("skin")) - { - sc.MustGetNumber(); - index=sc.Number; - if (index<0 || index>=MAX_MODELS_PER_FRAME) - { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); - } - sc.MustGetString(); - FixPathSeperator(sc.String); - if (sc.Compare("")) - { - smf.skinIDs[index]=FNullTextureID(); - } - else - { - smf.skinIDs[index] = LoadSkin(path.GetChars(), sc.String); - if (!smf.skinIDs[index].isValid()) - { - Printf("Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); - } - } - } - else if (sc.Compare("surfaceskin")) - { - sc.MustGetNumber(); - index = sc.Number; - sc.MustGetNumber(); - surface = sc.Number; - - if (index<0 || index >= MAX_MODELS_PER_FRAME) - { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); - } - - if (surface<0 || surface >= MD3_MAX_SURFACES) - { - sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, smf.type->TypeName.GetChars()); - } - - sc.MustGetString(); - FixPathSeperator(sc.String); - if (sc.Compare("")) - { - smf.surfaceskinIDs[index][surface] = FNullTextureID(); - } - else - { - smf.surfaceskinIDs[index][surface] = LoadSkin(path.GetChars(), sc.String); - if (!smf.surfaceskinIDs[index][surface].isValid()) - { - Printf("Surface Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); - } - } - } - else if (sc.Compare("frameindex") || sc.Compare("frame")) - { - bool isframe=!!sc.Compare("frame"); - - sc.MustGetString(); - smf.sprite = -1; - for (i = 0; i < (int)sprites.Size (); ++i) - { - if (strnicmp (sprites[i].name, sc.String, 4) == 0) - { - if (sprites[i].numframes==0) - { - //sc.ScriptError("Sprite %s has no frames", sc.String); - } - smf.sprite = i; - break; - } - } - if (smf.sprite==-1) - { - sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars()); - } - - sc.MustGetString(); - FString framechars = sc.String; - - sc.MustGetNumber(); - index=sc.Number; - if (index<0 || index>=MAX_MODELS_PER_FRAME) - { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); - } - if (isframe) - { - sc.MustGetString(); - if (smf.modelIDs[index] != -1) - { - FModel *model = Models[smf.modelIDs[index]]; - smf.modelframes[index] = model->FindFrame(sc.String); - if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars()); - } - else smf.modelframes[index] = -1; - } - else - { - sc.MustGetNumber(); - smf.modelframes[index] = sc.Number; - } - - for(i=0; framechars[i]>0; i++) - { - char map[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - int c = toupper(framechars[i])-'A'; - - if (c<0 || c>=29) - { - sc.ScriptError("Invalid frame character %c found", c+'A'); - } - if (map[c]) continue; - smf.frame=c; - SpriteModelFrames.Push(smf); - GetDefaultByType(smf.type)->hasmodel = true; - map[c]=1; - } - } - else if (sc.Compare("dontcullbackfaces")) - { - smf.flags |= MDL_DONTCULLBACKFACES; - } - else if (sc.Compare("userotationcenter")) - { - smf.flags |= MDL_USEROTATIONCENTER; - smf.rotationCenterX = 0.; - smf.rotationCenterY = 0.; - smf.rotationCenterZ = 0.; - } - else - { - sc.ScriptMessage("Unrecognized string \"%s\"", sc.String); - } - } - } - } + ParseModelDefLump(Lump); } // create a hash table for quick access @@ -836,7 +539,7 @@ void gl_InitModels() atterm(DeleteModelHash); memset(SpriteModelHash, 0xff, SpriteModelFrames.Size () * sizeof(int)); - for (i = 0; i < (int)SpriteModelFrames.Size (); i++) + for (unsigned int i = 0; i < SpriteModelFrames.Size (); i++) { int j = ModelFrameHash(&SpriteModelFrames[i]) % SpriteModelFrames.Size (); @@ -845,6 +548,316 @@ void gl_InitModels() } } +static void ParseModelDefLump(int Lump) +{ + FScanner sc(Lump); + while (sc.GetString()) + { + if (sc.Compare("model")) + { + int index, surface; + FString path = ""; + sc.MustGetString(); + + FSpriteModelFrame smf; + memset(&smf, 0, sizeof(smf)); + smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; + smf.xscale=smf.yscale=smf.zscale=1.f; + + smf.type = PClass::FindClass(sc.String); + if (!smf.type || smf.type->Defaults == nullptr) + { + sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String); + } + sc.MustGetStringName("{"); + while (!sc.CheckString("}")) + { + sc.MustGetString(); + if (sc.Compare("path")) + { + sc.MustGetString(); + FixPathSeperator(sc.String); + path = sc.String; + if (path[(int)path.Len()-1]!='/') path+='/'; + } + else if (sc.Compare("model")) + { + sc.MustGetNumber(); + index = sc.Number; + if (index < 0 || index >= MAX_MODELS_PER_FRAME) + { + sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + } + sc.MustGetString(); + FixPathSeperator(sc.String); + smf.modelIDs[index] = FindModel(path.GetChars(), sc.String); + if (smf.modelIDs[index] == -1) + { + Printf("%s: model not found in %s\n", sc.String, path.GetChars()); + } + } + else if (sc.Compare("scale")) + { + sc.MustGetFloat(); + smf.xscale = sc.Float; + sc.MustGetFloat(); + smf.yscale = sc.Float; + sc.MustGetFloat(); + smf.zscale = sc.Float; + } + // [BB] Added zoffset reading. + // Now it must be considered deprecated. + else if (sc.Compare("zoffset")) + { + sc.MustGetFloat(); + smf.zoffset=sc.Float; + } + // Offset reading. + else if (sc.Compare("offset")) + { + sc.MustGetFloat(); + smf.xoffset = sc.Float; + sc.MustGetFloat(); + smf.yoffset = sc.Float; + sc.MustGetFloat(); + smf.zoffset = sc.Float; + } + // angleoffset, pitchoffset and rolloffset reading. + else if (sc.Compare("angleoffset")) + { + sc.MustGetFloat(); + smf.angleoffset = sc.Float; + } + else if (sc.Compare("pitchoffset")) + { + sc.MustGetFloat(); + smf.pitchoffset = sc.Float; + } + else if (sc.Compare("rolloffset")) + { + sc.MustGetFloat(); + smf.rolloffset = sc.Float; + } + // [BB] Added model flags reading. + else if (sc.Compare("ignoretranslation")) + { + smf.flags |= MDL_IGNORETRANSLATION; + } + else if (sc.Compare("pitchfrommomentum")) + { + smf.flags |= MDL_PITCHFROMMOMENTUM; + } + else if (sc.Compare("inheritactorpitch")) + { + smf.flags |= MDL_USEACTORPITCH | MDL_BADROTATION; + } + else if (sc.Compare("inheritactorroll")) + { + smf.flags |= MDL_USEACTORROLL; + } + else if (sc.Compare("useactorpitch")) + { + smf.flags |= MDL_USEACTORPITCH; + } + else if (sc.Compare("useactorroll")) + { + smf.flags |= MDL_USEACTORROLL; + } + else if (sc.Compare("rotating")) + { + smf.flags |= MDL_ROTATING; + smf.xrotate = 0.; + smf.yrotate = 1.; + smf.zrotate = 0.; + smf.rotationCenterX = 0.; + smf.rotationCenterY = 0.; + smf.rotationCenterZ = 0.; + smf.rotationSpeed = 1.; + } + else if (sc.Compare("rotation-speed")) + { + sc.MustGetFloat(); + smf.rotationSpeed = sc.Float; + } + else if (sc.Compare("rotation-vector")) + { + sc.MustGetFloat(); + smf.xrotate = sc.Float; + sc.MustGetFloat(); + smf.yrotate = sc.Float; + sc.MustGetFloat(); + smf.zrotate = sc.Float; + } + else if (sc.Compare("rotation-center")) + { + sc.MustGetFloat(); + smf.rotationCenterX = sc.Float; + sc.MustGetFloat(); + smf.rotationCenterY = sc.Float; + sc.MustGetFloat(); + smf.rotationCenterZ = sc.Float; + } + else if (sc.Compare("interpolatedoubledframes")) + { + smf.flags |= MDL_INTERPOLATEDOUBLEDFRAMES; + } + else if (sc.Compare("nointerpolation")) + { + smf.flags |= MDL_NOINTERPOLATION; + } + else if (sc.Compare("skin")) + { + sc.MustGetNumber(); + index=sc.Number; + if (index<0 || index>=MAX_MODELS_PER_FRAME) + { + sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + } + sc.MustGetString(); + FixPathSeperator(sc.String); + if (sc.Compare("")) + { + smf.skinIDs[index]=FNullTextureID(); + } + else + { + smf.skinIDs[index] = LoadSkin(path.GetChars(), sc.String); + if (!smf.skinIDs[index].isValid()) + { + Printf("Skin '%s' not found in '%s'\n", + sc.String, smf.type->TypeName.GetChars()); + } + } + } + else if (sc.Compare("surfaceskin")) + { + sc.MustGetNumber(); + index = sc.Number; + sc.MustGetNumber(); + surface = sc.Number; + + if (index<0 || index >= MAX_MODELS_PER_FRAME) + { + sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + } + + if (surface<0 || surface >= MD3_MAX_SURFACES) + { + sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, smf.type->TypeName.GetChars()); + } + + sc.MustGetString(); + FixPathSeperator(sc.String); + if (sc.Compare("")) + { + smf.surfaceskinIDs[index][surface] = FNullTextureID(); + } + else + { + smf.surfaceskinIDs[index][surface] = LoadSkin(path.GetChars(), sc.String); + if (!smf.surfaceskinIDs[index][surface].isValid()) + { + Printf("Surface Skin '%s' not found in '%s'\n", + sc.String, smf.type->TypeName.GetChars()); + } + } + } + else if (sc.Compare("frameindex") || sc.Compare("frame")) + { + bool isframe=!!sc.Compare("frame"); + + sc.MustGetString(); + smf.sprite = -1; + for (int i = 0; i < (int)sprites.Size (); ++i) + { + if (strnicmp (sprites[i].name, sc.String, 4) == 0) + { + if (sprites[i].numframes==0) + { + //sc.ScriptError("Sprite %s has no frames", sc.String); + } + smf.sprite = i; + break; + } + } + if (smf.sprite==-1) + { + sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars()); + } + + sc.MustGetString(); + FString framechars = sc.String; + + sc.MustGetNumber(); + index=sc.Number; + if (index<0 || index>=MAX_MODELS_PER_FRAME) + { + sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + } + if (isframe) + { + sc.MustGetString(); + if (smf.modelIDs[index] != -1) + { + FModel *model = Models[smf.modelIDs[index]]; + smf.modelframes[index] = model->FindFrame(sc.String); + if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars()); + } + else smf.modelframes[index] = -1; + } + else + { + sc.MustGetNumber(); + smf.modelframes[index] = sc.Number; + } + + for(int i=0; framechars[i]>0; i++) + { + char map[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + int c = toupper(framechars[i])-'A'; + + if (c<0 || c>=29) + { + sc.ScriptError("Invalid frame character %c found", c+'A'); + } + if (map[c]) continue; + smf.frame=c; + SpriteModelFrames.Push(smf); + GetDefaultByType(smf.type)->hasmodel = true; + map[c]=1; + } + } + else if (sc.Compare("dontcullbackfaces")) + { + smf.flags |= MDL_DONTCULLBACKFACES; + } + else if (sc.Compare("userotationcenter")) + { + smf.flags |= MDL_USEROTATIONCENTER; + smf.rotationCenterX = 0.; + smf.rotationCenterY = 0.; + smf.rotationCenterZ = 0.; + } + else + { + sc.ScriptMessage("Unrecognized string \"%s\"", sc.String); + } + } + } + // This code is commented out because Gene Tech has broken include statements that blocks this feature.. + /*else if (sc.Compare("#include")) + { + sc.MustGetString(); + // This is not using sc.Open because it can print a more useful error message when done here + int includelump = Wads.CheckNumForFullName(sc.String, true); + if (includelump == -1) + sc.ScriptError("Lump '%s' not found", sc.String); + else + ParseModelDefLump(includelump); + }*/ + } +} + //=========================================================================== // // FindModelFrame diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index ce6123c18..c1f1f3e02 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -34,7 +34,7 @@ #include "r_data/voxels.h" #include "vm.h" -void gl_InitModels(); +void InitModels(); // variables used to look up // and range check thing_t sprites patches @@ -1048,7 +1048,7 @@ void R_InitSprites () // [RH] Sort the skins, but leave base as skin 0 //qsort (&skins[PlayerClasses.Size ()], numskins-PlayerClasses.Size (), sizeof(FPlayerSkin), skinsorter); - gl_InitModels(); + InitModels(); } From 26ebb938c1aea5e861d0363ae4d532c189ba76a8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 22 May 2018 21:48:31 +0300 Subject: [PATCH 7/7] - fixed compilation with GCC/Clang https://forum.zdoom.org/viewtopic.php?f=2&t=60657 --- src/r_data/models/models.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index cb260bf88..4b43a4766 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -473,7 +473,7 @@ static unsigned FindModel(const char * path, const char * modelfile) // //=========================================================================== -void ParseModelDefLump(int Lump); +static void ParseModelDefLump(int Lump); void InitModels() {