Skip to content

Commit

Permalink
Add step wallmark option for engine_external
Browse files Browse the repository at this point in the history
AIW compatibility
  • Loading branch information
ForserX committed Dec 6, 2024
1 parent ea40b23 commit 3a1dda7
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 74 deletions.
22 changes: 17 additions & 5 deletions gamedata/configs/engine_external.ltx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[general]
title = st_ixray_title ; Mod name

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Engine features
[ui]
HQIcons = false
DisableCharacterInfo = false
Expand All @@ -17,16 +19,26 @@ EnableNPCLookAtActor = false
EnableBlockSprintInReload = true
EnableAutoreload = false
EnableMonstersInventory = true
EnableWeaponInertion = false ;Shoker Mod Style
EnableWeaponCollision = false ;Shoker Mod Style
EnableWeaponInertion = false ; Shoker Mod Style
EnableWeaponCollision = false ; Shoker Mod Style
EnableArtefactDegradation = false
DisableSprintWhileOverweight = false

[player_hud]
;PlayerHudOmfAdditional = dynamics\weapons\hud_hands_animation\*.omf
EnableActorStepWallmarks = false ; AIW Style

[render]
DisableLoadScreenTips = false

[environment]
ReadSunConfig = false

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Extended sections

[player_hud]
;PlayerHudOmfAdditional = dynamics\weapons\hud_hands_animation\*.omf ; Place your omf file pathes

; Need [gameplay]:EnableActorStepWallmarks
[step_wallmark]
materials = earth, test1 ; Material names
left_mark = l_foot ; left foot wallmark section
right_mark = r_foot ; right foot wallmark section
17 changes: 13 additions & 4 deletions src/Layers/xrRender/WallmarksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void CWallmarksEngine::BuildMatrix (Fmatrix &mView, float invsz, const Fvector&
mView.mulA_43 (mScale);
}

void CWallmarksEngine::AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz)
void CWallmarksEngine::AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz, bool UseCameraDirection)
{
// query for polygons in bounding box
// calculate adjacency
Expand Down Expand Up @@ -219,7 +219,16 @@ void CWallmarksEngine::AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVer
// build 3D ortho-frustum
Fmatrix mView,mRot;
BuildMatrix (mView,1/sz,contact_point);
mRot.rotateZ (::Random.randF(deg2rad(-20.f),deg2rad(20.f)));

if (UseCameraDirection)
{
mRot.rotateZ(::Random.randF(-0.175f, 0.175f) - Device.vCameraDirection.getH());
}
else
{
mRot.rotateZ(::Random.randF(deg2rad(-20.f), deg2rad(20.f)));
}

mView.mulA_43 (mRot);
sml_clipper.CreateFromMatrix (mView,FRUSTUM_P_LRTB);

Expand Down Expand Up @@ -273,15 +282,15 @@ void CWallmarksEngine::AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVer
//}
}

void CWallmarksEngine::AddStaticWallmark (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz)
void CWallmarksEngine::AddStaticWallmark (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz, bool UseCameraDirection)
{
// optimization cheat: don't allow wallmarks more than 100 m from viewer/actor
if (contact_point.distance_to_sqr(Device.vCameraPosition) > _sqr(100.f))
return;

// Physics may add wallmarks in parallel with rendering
lock.Enter ();
AddWallmark_internal (pTri,pVerts,contact_point,hShader,sz);
AddWallmark_internal (pTri,pVerts,contact_point,hShader,sz, UseCameraDirection);
lock.Leave ();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/WallmarksEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CWallmarksEngine
private:
void BuildMatrix (Fmatrix &dest, float invsz, const Fvector& from);
void RecurseTri (u32 T, Fmatrix &mView, static_wallmark &W);
void AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hTexture, float sz);
void AddWallmark_internal (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hTexture, float sz, bool UseCameraDirection);

static_wallmark* static_wm_allocate ();
void static_wm_render (static_wallmark* W, FVF::LIT* &V);
Expand All @@ -61,7 +61,7 @@ class CWallmarksEngine
CWallmarksEngine ();
~CWallmarksEngine ();
// edit wallmarks
void AddStaticWallmark (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hTexture, float sz);
void AddStaticWallmark (CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hTexture, float sz, bool UseCameraDirection = false);
void AddSkeletonWallmark (intrusive_ptr<CSkeletonWallmark> wm);
void AddSkeletonWallmark (const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size);

Expand Down
19 changes: 10 additions & 9 deletions src/Layers/xrRenderPC_R1/FStaticRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,25 @@ void CRender::add_Visual (IRenderVisual* V, bool ignore_opt)
add_leafs_Dynamic ((dxRender_Visual*)V, ignore_opt);
}
void CRender::add_Geometry (IRenderVisual* V ){ add_Static((dxRender_Visual*)V,View->getMask()); }
void CRender::add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts)

void CRender::add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts, bool UseCameraDirection)
{
if (T->suppress_wm) return;
VERIFY2 (_valid(P) && _valid(s) && T && verts && (s>EPS_L), "Invalid static wallmark params");
Wallmarks->AddStaticWallmark (T,verts,P,&*S,s);
VERIFY2(_valid(P) && _valid(s) && T && verts && (s > EPS_L), "Invalid static wallmark params");
Wallmarks->AddStaticWallmark(T, verts, P, &*S, s, UseCameraDirection);
}

void CRender::add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V)
void CRender::add_StaticWallmark(IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection)
{
dxWallMarkArray *pWMA = (dxWallMarkArray *)pArray;
ref_shader *pShader = pWMA->dxGenerateWallmark();
if (pShader) add_StaticWallmark (*pShader, P, s, T, V);
dxWallMarkArray* pWMA = (dxWallMarkArray*)pArray;
ref_shader* pShader = pWMA->dxGenerateWallmark();
if (pShader) add_StaticWallmark(*pShader, P, s, T, V, UseCameraDirection);
}

void CRender::add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V)
void CRender::add_StaticWallmark(const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V)
{
dxUIShader* pShader = (dxUIShader*)&*S;
add_StaticWallmark (pShader->hShader, P, s, T, V);
add_StaticWallmark(pShader->hShader, P, s, T, V);
}

void CRender::clear_static_wallmarks ()
Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRenderPC_R1/FStaticRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ class CRender : public R_dsgraph_structure
virtual void add_Geometry (IRenderVisual* V ); // add visual(s) (all culling performed)

// wallmarks
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false);
virtual void add_StaticWallmark (IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false) override;
virtual void add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void clear_static_wallmarks ();
virtual void add_SkeletonWallmark (intrusive_ptr<CSkeletonWallmark> wm);
virtual void add_SkeletonWallmark (const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size);
Expand Down
15 changes: 8 additions & 7 deletions src/Layers/xrRenderPC_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,19 @@ BOOL CRender::occ_visible (Fbox& P) { return HOM.visible(P); }

void CRender::add_Visual (IRenderVisual* V, bool ignore_opt) { add_leafs_Dynamic((dxRender_Visual*)V, ignore_opt); }
void CRender::add_Geometry (IRenderVisual* V ) { add_Static((dxRender_Visual*)V,View->getMask()); }
void CRender::add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts)

void CRender::add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts, bool UseCameraDirection)
{
if (T->suppress_wm) return;
VERIFY2 (_valid(P) && _valid(s) && T && verts && (s>EPS_L), "Invalid static wallmark params");
Wallmarks->AddStaticWallmark (T,verts,P,&*S,s);
VERIFY2(_valid(P) && _valid(s) && T && verts && (s > EPS_L), "Invalid static wallmark params");
Wallmarks->AddStaticWallmark(T, verts, P, &*S, s, UseCameraDirection);
}

void CRender::add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V)
void CRender::add_StaticWallmark(IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection)
{
dxWallMarkArray *pWMA = (dxWallMarkArray *)pArray;
ref_shader *pShader = pWMA->dxGenerateWallmark();
if (pShader) add_StaticWallmark (*pShader, P, s, T, V);
dxWallMarkArray* pWMA = (dxWallMarkArray*)pArray;
ref_shader* pShader = pWMA->dxGenerateWallmark();
if (pShader) add_StaticWallmark(*pShader, P, s, T, V, UseCameraDirection);
}

void CRender::add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V)
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderPC_R2/r2.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ class CRender : public R_dsgraph_structure
virtual void add_Geometry (IRenderVisual* V ); // add visual(s) (all culling performed)

// wallmarks
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false);
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false) override;
virtual void add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void clear_static_wallmarks ();
virtual void add_SkeletonWallmark (intrusive_ptr<CSkeletonWallmark> wm);
Expand Down
9 changes: 5 additions & 4 deletions src/Layers/xrRenderPC_R4/r4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,20 @@ void CRender::add_Geometry(IRenderVisual* V) {
add_Static((dxRender_Visual*)V, View->getMask());
}

void CRender::add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts) {
void CRender::add_StaticWallmark(ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* verts, bool UseCameraDirection)
{
if(T->suppress_wm) {
return;
}
VERIFY2(_valid(P) && _valid(s) && T && verts && (s > EPS_L), "Invalid static wallmark params");
Wallmarks->AddStaticWallmark(T, verts, P, &*S, s);
Wallmarks->AddStaticWallmark(T, verts, P, &*S, s, UseCameraDirection);
}

void CRender::add_StaticWallmark(IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V) {
void CRender::add_StaticWallmark(IWallMarkArray* pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection) {
dxWallMarkArray* pWMA = (dxWallMarkArray*)pArray;
ref_shader* pShader = pWMA->dxGenerateWallmark();
if(pShader) {
add_StaticWallmark(*pShader, P, s, T, V);
add_StaticWallmark(*pShader, P, s, T, V, UseCameraDirection);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderPC_R4/r4.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class CRender : public R_dsgraph_structure
virtual void add_Geometry (IRenderVisual* V ); // add visual(s) (all culling performed)

// wallmarks
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void add_StaticWallmark (ref_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false);
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false) override;
virtual void add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V);
virtual void clear_static_wallmarks ();
virtual void add_SkeletonWallmark (intrusive_ptr<CSkeletonWallmark> wm);
Expand Down
38 changes: 35 additions & 3 deletions src/xrEngine/EngineExternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ CEngineExternal::CEngineExternal()
pOptions = new CInifile(fname);
}

CEngineExternal::~CEngineExternal() {
CEngineExternal::~CEngineExternal()
{
xr_delete(pOptions);
}

xr_string CEngineExternal::GetTitle() const {
xr_string CEngineExternal::GetTitle() const
{
return READ_IF_EXISTS(pOptions, r_string_wb, "general", "title", "IX-Ray Platform").c_str();
}

Expand All @@ -23,6 +25,35 @@ const char* CEngineExternal::GetPlayerHudOmfAdditional() const
return READ_IF_EXISTS(pOptions, r_string_wb, "player_hud", "PlayerHudOmfAdditional", "").c_str();
}

const xr_vector<shared_str> CEngineExternal::StepWallmarksMaterials() const
{
xr_vector<shared_str> TempVector;
xr_string Items = READ_IF_EXISTS(pOptions, r_string_wb, "step_wallmark", "materials", "").c_str();

size_t MaterialsCount = _GetItemCount(Items.c_str());
TempVector.resize(MaterialsCount);

size_t Iter = 0;
for (shared_str& Item : TempVector)
{
xr_string _temp;
Item = _GetItem(Items.c_str(), (int)Iter, _temp);
Iter++;
}

return std::move(TempVector);
}

const xr_string CEngineExternal::WallmarkLeft() const
{
return READ_IF_EXISTS(pOptions, r_string_wb, "step_wallmark", "left_mark", "").c_str();
}

const xr_string CEngineExternal::WallmarkRight() const
{
return READ_IF_EXISTS(pOptions, r_string_wb, "step_wallmark", "right_mark", "").c_str();
}

bool CEngineExternal::operator[](const EEngineExternalUI& ID) const
{
return READ_IF_EXISTS(pOptions, r_bool, "ui", magic_enum::enum_name(ID).data(), false);
Expand All @@ -47,7 +78,8 @@ bool CEngineExternal::operator[](const EEngineExternalEnvironment& ID) const {
return READ_IF_EXISTS(pOptions, r_bool, "environment", magic_enum::enum_name(ID).data(), false);
}

ENGINE_API CEngineExternal& EngineExternal() {
ENGINE_API CEngineExternal& EngineExternal()
{
if (g_pEngineExternal == nullptr) {
g_pEngineExternal = new CEngineExternal;
}
Expand Down
4 changes: 4 additions & 0 deletions src/xrEngine/EngineExternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum class EEngineExternalGame
EnableWeaponInertion,
EnableWeaponCollision,
EnableArtefactDegradation,
EnableActorStepWallmarks,
DisableSprintWhileOverweight
};

Expand All @@ -49,6 +50,9 @@ class ENGINE_API CEngineExternal final

xr_string GetTitle() const;
const char* GetPlayerHudOmfAdditional() const;
const xr_vector<shared_str> StepWallmarksMaterials() const;
const xr_string WallmarkLeft() const;
const xr_string WallmarkRight() const;

bool operator[](const EEngineExternalUI& ID) const;
bool operator[](const EEngineExternalPhysical& ID) const;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/Render.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ENGINE_API IRender_interface
virtual void add_StaticWallmark (const wm_shader& S, const Fvector& P, float s, CDB::TRI* T, Fvector* V) {};

// Prefer this function when possible
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V) {};
virtual void add_StaticWallmark (IWallMarkArray *pArray, const Fvector& P, float s, CDB::TRI* T, Fvector* V, bool UseCameraDirection = false) {};
virtual void clear_static_wallmarks () {};

// Prefer this function when possible
Expand Down
52 changes: 50 additions & 2 deletions src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ if(!g_dedicated_server)
}
}

cam_Set(eacFirstEye);
cam_Set(eacFirstEye);

// sheduler
shedule.t_min = shedule.t_max = 1;
Expand Down Expand Up @@ -740,7 +740,55 @@ void CActor::HitMark (float P,
xr_sprintf( sect_name, "effector_fire_hit_%d", id );
AddEffector( this, effFireHit, sect_name, P * 0.001f );

}//if hit_type
}
}

void CActor::FootStepCallback(float power, bool b_play, bool b_on_ground, bool b_hud_view)
{
static bool EnableStepWallmarks = EngineExternal()[EEngineExternalGame::EnableActorStepWallmarks];
if (EnableStepWallmarks)
{
u16 mtl_idx = Actor()->material().last_material_idx();
if (mtl_idx != GAMEMTL_NONE_IDX)
{
static CWalmarkManager m_wallmark_r;
static CWalmarkManager m_wallmark_l;
static bool inited = false;
static bool left_step = false;

static shared_str RightSect = EngineExternal().WallmarkRight().c_str();
static shared_str LeftSect = EngineExternal().WallmarkLeft().c_str();
if (!inited)
{
m_wallmark_r.m_owner = this;
m_wallmark_l.m_owner = this;
m_wallmark_r.Load(RightSect.c_str());
m_wallmark_l.Load(LeftSect.c_str());
bool inited = true;
}

const SGameMtl* mtl = GMLib.GetMaterialByIdx(mtl_idx);
static auto MaterialsList = EngineExternal().StepWallmarksMaterials();
for (const shared_str& MaterialName : MaterialsList)
{
if (MaterialName == mtl->m_Name)
{
if (left_step)
{
m_wallmark_r.PlaceWallmarks(Position(), RightSect);
left_step = false;
}
else
{
m_wallmark_l.PlaceWallmarks(Position(), LeftSect);
left_step = true;
}

break;
}
}
}
}
}

void CActor::HitSignal(float perc, Fvector& vLocalDir, CObject* who, s16 element)
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct SDefNewsMsg{
virtual void HitSignal (float P, Fvector &vLocalDir, CObject* who, s16 element);
void HitSector (CObject* who, CObject* weapon);
void HitMark (float P, Fvector dir, CObject* who, s16 element, Fvector position_in_bone_space, float impulse, ALife::EHitType hit_type);
virtual void FootStepCallback(float power, bool b_play, bool b_on_ground, bool b_hud_view);

void Feel_Grenade_Update( float rad );

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const animation_movement_controller* animation_movement ( ) const { return m_an
return (m_story_id);
}

void FootStepCallback(float power, bool b_play, bool b_on_ground, bool b_hud_view);
virtual void FootStepCallback(float power, bool b_play, bool b_on_ground, bool b_hud_view);

public:
virtual u32 ef_creature_type () const;
Expand Down
Loading

0 comments on commit 3a1dda7

Please sign in to comment.