mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 06:42:08 +00:00
Add Weapon::ModifyBobLayer , Weapon::ModifyBobLayer3D and Weapon::ModifyBobPivotLayer3D
This commit is contained in:
parent
e6124627e4
commit
bcbb85b1dd
2 changed files with 88 additions and 0 deletions
|
@ -47,6 +47,8 @@
|
|||
#include "hw_lightbuffer.h"
|
||||
#include "hw_renderstate.h"
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
EXTERN_CVAR(Float, transsouls)
|
||||
EXTERN_CVAR(Int, gl_fuzztype)
|
||||
EXTERN_CVAR(Bool, r_drawplayersprites)
|
||||
|
@ -671,6 +673,10 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy,
|
|||
//==========================================================================
|
||||
void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area)
|
||||
{
|
||||
static PClass * wpCls = PClass::FindClass("Weapon");
|
||||
static unsigned ModifyBobLayerVIndex = GetVirtualIndex(wpCls, "ModifyBobLayer");
|
||||
static VMFunction * ModifyBobLayerOrigFunc = wpCls->Virtuals.Size() > ModifyBobLayerVIndex ? wpCls->Virtuals[ModifyBobLayerVIndex] : nullptr;
|
||||
|
||||
AActor * playermo = players[consoleplayer].camera;
|
||||
player_t * player = playermo->player;
|
||||
|
||||
|
@ -681,6 +687,17 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area)
|
|||
WeaponPosition2D weap = GetWeaponPosition2D(camera->player, vp.TicFrac);
|
||||
WeaponLighting light = GetWeaponLighting(viewsector, vp.Pos, isFullbrightScene(), in_area, camera->Pos());
|
||||
|
||||
VMFunction * ModifyBobLayer = nullptr;
|
||||
DVector2 bobxy = DVector2(weap.bobx , weap.boby);
|
||||
|
||||
if(weap.weapon)
|
||||
{
|
||||
PClass * cls = weap.weapon->GetCaller()->GetClass();
|
||||
ModifyBobLayer = cls->Virtuals.Size() > ModifyBobLayerVIndex ? cls->Virtuals[ModifyBobLayerVIndex] : nullptr;
|
||||
|
||||
if( ModifyBobLayer == ModifyBobLayerOrigFunc) ModifyBobLayer = nullptr;
|
||||
}
|
||||
|
||||
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
|
||||
// light mode here to draw the weapon sprite.
|
||||
auto oldlightmode = lightmode;
|
||||
|
@ -702,6 +719,18 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area)
|
|||
|
||||
if (!hudsprite.GetWeaponRenderStyle(psp, camera, viewsector, light)) continue;
|
||||
|
||||
if(ModifyBobLayer && (psp->Flags & PSPF_ADDBOB))
|
||||
{
|
||||
DVector2 out;
|
||||
VMValue param[] = { weap.weapon->GetCaller() , bobxy.X , bobxy.Y , psp->GetID() , vp.TicFrac };
|
||||
VMReturn ret(&out);
|
||||
|
||||
VMCall(ModifyBobLayer, param, 5, &ret, 1);
|
||||
|
||||
weap.bobx = out.X;
|
||||
weap.boby = out.Y;
|
||||
}
|
||||
|
||||
FVector2 spos = BobWeapon2D(weap, psp, vp.TicFrac);
|
||||
|
||||
hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0;
|
||||
|
@ -720,6 +749,14 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area)
|
|||
|
||||
void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area)
|
||||
{
|
||||
static PClass * wpCls = PClass::FindClass("Weapon");
|
||||
|
||||
static unsigned ModifyBobLayer3DVIndex = GetVirtualIndex(wpCls, "ModifyBobLayer3D");
|
||||
static unsigned ModifyBobPivotLayer3DVIndex = GetVirtualIndex(wpCls, "ModifyBobPivotLayer3D");
|
||||
|
||||
static VMFunction * ModifyBobLayer3DOrigFunc = wpCls->Virtuals.Size() > ModifyBobLayer3DVIndex ? wpCls->Virtuals[ModifyBobLayer3DVIndex] : nullptr;
|
||||
static VMFunction * ModifyBobPivotLayer3DOrigFunc = wpCls->Virtuals.Size() > ModifyBobPivotLayer3DVIndex ? wpCls->Virtuals[ModifyBobPivotLayer3DVIndex] : nullptr;
|
||||
|
||||
AActor * playermo = players[consoleplayer].camera;
|
||||
player_t * player = playermo->player;
|
||||
|
||||
|
@ -730,6 +767,23 @@ void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area)
|
|||
WeaponPosition3D weap = GetWeaponPosition3D(camera->player, vp.TicFrac);
|
||||
WeaponLighting light = GetWeaponLighting(viewsector, vp.Pos, isFullbrightScene(), in_area, camera->Pos());
|
||||
|
||||
VMFunction * ModifyBobLayer3D = nullptr;
|
||||
VMFunction * ModifyBobPivotLayer3D = nullptr;
|
||||
|
||||
DVector3 translation = DVector3(weap.translation);
|
||||
DVector3 rotation = DVector3(weap.rotation);
|
||||
DVector3 pivot = DVector3(weap.pivot);
|
||||
|
||||
if(weap.weapon)
|
||||
{
|
||||
PClass * cls = weap.weapon->GetCaller()->GetClass();
|
||||
ModifyBobLayer3D = cls->Virtuals.Size() > ModifyBobLayer3DVIndex ? cls->Virtuals[ModifyBobLayer3DVIndex] : nullptr;
|
||||
ModifyBobPivotLayer3D = cls->Virtuals.Size() > ModifyBobPivotLayer3DVIndex ? cls->Virtuals[ModifyBobPivotLayer3DVIndex] : nullptr;
|
||||
|
||||
if( ModifyBobLayer3D == ModifyBobLayer3DOrigFunc) ModifyBobLayer3D = nullptr;
|
||||
if( ModifyBobPivotLayer3D == ModifyBobPivotLayer3DOrigFunc) ModifyBobPivotLayer3D = nullptr;
|
||||
}
|
||||
|
||||
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
|
||||
// light mode here to draw the weapon sprite.
|
||||
auto oldlightmode = lightmode;
|
||||
|
@ -748,6 +802,34 @@ void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area)
|
|||
hudsprite.mframe = smf;
|
||||
hudsprite.weapon = psp;
|
||||
|
||||
if(ModifyBobLayer3D && (psp->Flags & PSPF_ADDBOB))
|
||||
{
|
||||
DVector3 t, r;
|
||||
|
||||
VMReturn returns[2];
|
||||
|
||||
returns[0].Vec3At(&t);
|
||||
returns[1].Vec3At(&r);
|
||||
|
||||
VMValue param[] = { weap.weapon->GetCaller() , translation.X, translation.Y, translation.Z, rotation.X, rotation.Y, rotation.Z, psp->GetID() , vp.TicFrac };
|
||||
VMCall(ModifyBobLayer3D, param, 9, returns, 2);
|
||||
|
||||
weap.translation = FVector3(t);
|
||||
weap.rotation = FVector3(r);
|
||||
}
|
||||
|
||||
if(ModifyBobPivotLayer3D && (psp->Flags & PSPF_ADDBOB))
|
||||
{
|
||||
DVector3 p;
|
||||
|
||||
VMReturn ret(&p);
|
||||
|
||||
VMValue param[] = { weap.weapon->GetCaller() , pivot.X, pivot.Y, pivot.Z, psp->GetID() , vp.TicFrac };
|
||||
VMCall(ModifyBobPivotLayer3D, param, 6, &ret, 1);
|
||||
|
||||
weap.pivot = FVector3(p);
|
||||
}
|
||||
|
||||
if (!hudsprite.GetWeaponRenderStyle(psp, camera, viewsector, light)) continue;
|
||||
|
||||
//FVector2 spos = BobWeapon3D(weap, psp, hudsprite.translation, hudsprite.rotation, hudsprite.pivot, vp.TicFrac);
|
||||
|
|
|
@ -39,6 +39,12 @@ class Weapon : StateProvider
|
|||
meta double SlotPriority;
|
||||
|
||||
Vector3 BobPivot3D; // Pivot used for BobWeapon3D
|
||||
|
||||
virtual ui Vector2 ModifyBobLayer(Vector2 Bob, int layer, double ticfrac) { return Bob; }
|
||||
|
||||
virtual ui Vector3, Vector3 ModifyBobLayer3D(Vector3 Translation, Vector3 Rotation, int layer, double ticfrac) { return Translation, Rotation; }
|
||||
|
||||
virtual ui Vector3 ModifyBobPivotLayer3D(int layer, double ticfrac) { return BobPivot3D; }
|
||||
|
||||
property AmmoGive: AmmoGive1;
|
||||
property AmmoGive1: AmmoGive1;
|
||||
|
|
Loading…
Reference in a new issue