Add Weapon::ModifyBobLayer , Weapon::ModifyBobLayer3D and Weapon::ModifyBobPivotLayer3D
This commit is contained in:
parent
9bc1a6e421
commit
b0d6d82dfd
2 changed files with 88 additions and 0 deletions
|
|
@ -46,6 +46,8 @@
|
|||
#include "flatvertices.h"
|
||||
#include "hw_renderstate.h"
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
EXTERN_CVAR(Float, transsouls)
|
||||
EXTERN_CVAR(Int, gl_fuzztype)
|
||||
EXTERN_CVAR(Bool, r_drawplayersprites)
|
||||
|
|
@ -670,6 +672,10 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, FRenderState& state, DPSprite *psp
|
|||
//==========================================================================
|
||||
void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area, FRenderState& state)
|
||||
{
|
||||
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;
|
||||
|
||||
|
|
@ -680,6 +686,17 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area, F
|
|||
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;
|
||||
|
|
@ -701,6 +718,18 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area, F
|
|||
|
||||
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;
|
||||
|
|
@ -719,6 +748,14 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area, F
|
|||
|
||||
void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area, FRenderState& state)
|
||||
{
|
||||
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;
|
||||
|
||||
|
|
@ -729,6 +766,23 @@ void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area, F
|
|||
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;
|
||||
|
|
@ -747,6 +801,34 @@ void HWDrawInfo::PreparePlayerSprites3D(sector_t * viewsector, area_t in_area, F
|
|||
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…
Add table
Add a link
Reference in a new issue