Skip to content

Commit

Permalink
ImGui Hud Tuner (#1685)
Browse files Browse the repository at this point in the history
Co-authored-by: Sultan Uramaev <Xottab-DUTY@users.noreply.github.com>
  • Loading branch information
yohjimane and Xottab-DUTY committed Jun 2, 2024
1 parent 7d236bf commit b4afaa4
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 474 deletions.
4 changes: 2 additions & 2 deletions src/Layers/xrRender/ParticleEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void CParticleEffect::Render(CBackend& cmd_list, float, bool use_fast_geo)
Fmatrix FTold = Device.mFullTransform;
if (GetHudMode())
{
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, VIEWPORT_NEAR,
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, HUD_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv.far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
Expand Down Expand Up @@ -841,7 +841,7 @@ void CParticleEffect::Render(float, bool)
Fmatrix FTold = Device.mFullTransform;
if (GetHudMode())
{
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, VIEWPORT_NEAR,
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, HUD_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv.far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class hud_transform_helper

Fmatrix prj_new;
prj_new.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv.far_plane);
HUD_VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv.far_plane);
cmd_list.set_xform_project(prj_new);

RImplementation.rmNear(cmd_list);
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "xrCore/ModuleLookup.hpp"

#define VIEWPORT_NEAR 0.2f
#define HUD_VIEWPORT_NEAR 0.05f

#define DEVICE_RESET_PRECACHE_FRAME_COUNT 10

Expand Down
4 changes: 4 additions & 0 deletions src/xrEngine/editor_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class XR_NOVTABLE ENGINE_API ide_tool : public pureFrame
virtual pcstr tool_name() = 0;

bool& get_open_state() { return is_opened; }
bool is_open() const { return is_opened; }
virtual bool is_active() const { return is_opened; }

ImGuiWindowFlags get_default_window_flags() const;
};

Expand Down Expand Up @@ -57,6 +60,7 @@ class ENGINE_API ide final :
auto GetState() const { return m_state; }
void SetState(visible_state state);
void SwitchToNextState();
bool IsActiveState() const { return m_state == visible_state::full; }

public:
// Interface implementations
Expand Down
19 changes: 6 additions & 13 deletions src/xrGame/ActorInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
#include "clsid_game.h"
#include "HUDManager.h"
#include "Weapon.h"

extern u32 hud_adj_mode;
#include "GamePersistent.h"

bool g_bAutoClearCrouch = true;

void CActor::IR_OnKeyboardPress(int cmd)
{
if (hud_adj_mode && pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT))
if (GamePersistent().GetHudTuner().is_active())
return;

if (Remote())
Expand Down Expand Up @@ -213,11 +212,8 @@ void CActor::IR_OnKeyboardPress(int cmd)

void CActor::IR_OnMouseWheel(float x, float y)
{
if (hud_adj_mode)
{
g_player_hud->tune({ 0, 0, static_cast<int>(std::round(y)) });
if (GamePersistent().GetHudTuner().is_active())
return;
}

if (inventory().Action((y > 0) ? (u16)kWPN_ZOOM_INC : (u16)kWPN_ZOOM_DEC, CMD_START))
return;
Expand All @@ -230,7 +226,7 @@ void CActor::IR_OnMouseWheel(float x, float y)

void CActor::IR_OnKeyboardRelease(int cmd)
{
if (hud_adj_mode && pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT))
if (GamePersistent().GetHudTuner().is_active())
return;

if (Remote())
Expand Down Expand Up @@ -272,7 +268,7 @@ void CActor::IR_OnKeyboardRelease(int cmd)

void CActor::IR_OnKeyboardHold(int cmd)
{
if (hud_adj_mode && pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT))
if (GamePersistent().GetHudTuner().is_active())
return;

if (Remote() || !g_Alive())
Expand Down Expand Up @@ -352,11 +348,8 @@ void CActor::OnAxisMove(float x, float y, float scale, bool invert)

void CActor::IR_OnMouseMove(int dx, int dy)
{
if (hud_adj_mode)
{
g_player_hud->tune(Ivector().set(dx, dy, 0));
if (GamePersistent().GetHudTuner().is_active())
return;
}

PIItem iitem = inventory().ActiveItem();
if (iitem && iitem->cast_hud_item())
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ target_sources(xrGame PRIVATE
player_hud.cpp
player_hud.h
player_hud_tune.cpp
player_hud_tune.h
player_name_modifyer.cpp
player_name_modifyer.h
player_spot_params.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/xrGame/GamePersistent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "xrEngine/IGame_Persistent.h"
#include "player_hud_tune.h"

class Task;
class CMainMenu;
Expand Down Expand Up @@ -40,6 +41,9 @@ class CGamePersistent : public IGame_Persistent

fastdelegate::FastDelegate0<> m_intro_event;

// hud tuner
CHudTuner m_hudTuner;

void start_logo_intro();
void update_logo_intro();

Expand Down Expand Up @@ -101,6 +105,8 @@ class CGamePersistent : public IGame_Persistent
virtual void SetBaseDof(const Fvector3& dof);
virtual void OnSectorChanged(IRender_Sector::sector_id_t sector);
virtual void OnAssetsChanged();

CHudTuner GetHudTuner() { return m_hudTuner; }
};

IC CGamePersistent& GamePersistent() { return *((CGamePersistent*)g_pGamePersistent); }
Expand Down
50 changes: 49 additions & 1 deletion src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ void CHudItem::renderable_Render(u32 context_id, IRenderable* root)
if (!object().H_Parent() || (!_hud_render && !IsHidden()))
{
on_renderable_Render(context_id, root);
debug_draw_firedeps();
}
else if (object().H_Parent())
{
Expand Down Expand Up @@ -431,6 +430,55 @@ void CHudItem::OnMovementChanged(ACTOR_DEFS::EMoveCommand cmd)
}
}

extern ENGINE_API float psHUD_FOV;
void CHudItem::TransformPosFromWorldToHud(Fvector& worldPos)
{
CActor* actor = smart_cast<CActor*>(object().H_Parent());

Fmatrix mView;
mView.set(Device.mView);
if (GetHUDmode() && actor)
{
Fmatrix trans;
actor->Cameras().hud_camera_Matrix(trans);
mView.build_camera_dir(trans.c, trans.k, trans.j);
}

Fmatrix hud_project;
hud_project.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, HUD_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv.far_plane);

mView.transform_tiny(worldPos);
hud_project.transform_tiny(worldPos);

Fmatrix().set(Device.mProject).invert().transform_tiny(worldPos);
Fmatrix().set(mView).invert().transform_tiny(worldPos);
}

void CHudItem::TransformDirFromWorldToHud(Fvector& worldDir)
{
CActor* actor = smart_cast<CActor*>(object().H_Parent());

Fmatrix mView;
mView.set(Device.mView);
if (GetHUDmode() && actor)
{
Fmatrix trans;
actor->Cameras().hud_camera_Matrix(trans);
mView.build_camera_dir(trans.c, trans.k, trans.j);
}

Fmatrix hud_project;
hud_project.build_projection(deg2rad(psHUD_FOV * Device.fFOV), Device.fASPECT, HUD_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv.far_plane);

mView.transform_dir(worldDir);
hud_project.transform_dir(worldDir);

Fmatrix().set(Device.mProject).invert().transform_dir(worldDir);
Fmatrix().set(mView).invert().transform_dir(worldDir);
}

attachable_hud_item* CHudItem::HudItemData() const
{
attachable_hud_item* hi = NULL;
Expand Down
4 changes: 3 additions & 1 deletion src/xrGame/HudItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class CHudItem : public CHUDState
virtual bool Action(u16 cmd, u32 flags) { return false; }
void OnMovementChanged(ACTOR_DEFS::EMoveCommand cmd);

virtual void TransformPosFromWorldToHud(Fvector& worldPos);
virtual void TransformDirFromWorldToHud(Fvector& worldDir);

virtual u8 GetCurrentHudOffsetIdx() { return 0; }
BOOL GetHUDmode();
IC BOOL IsPending() const { return !!m_huditem_flags.test(fl_pending); }
Expand Down Expand Up @@ -178,7 +181,6 @@ class CHudItem : public CHUDState
}
IC u32 animation_slot() { return m_animation_slot; }
virtual void on_renderable_Render(u32 context_id, IRenderable* root) = 0;
virtual void debug_draw_firedeps(){};

virtual CHudItem* cast_hud_item() { return this; }
void PlayAnimIdleMovingCrouch(); //AVO: new crouch idle animation
Expand Down
5 changes: 2 additions & 3 deletions src/xrGame/Missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "xrUICore/ProgressBar/UIProgressShape.h"
#include "ui/UIXmlInit.h"
#include "PhysicsShellHolder.h"
#include "GamePersistent.h"

CUIProgressShape* g_MissileForceShape = NULL;

Expand Down Expand Up @@ -188,8 +189,6 @@ void CMissile::OnH_B_Independent(bool just_before_destroy)
}
}

extern u32 hud_adj_mode;

void CMissile::UpdateCL()
{
m_dwStateTime += Device.dwTimeDelta;
Expand All @@ -199,7 +198,7 @@ void CMissile::UpdateCL()
CActor* pActor = smart_cast<CActor*>(H_Parent());
if (pActor && !pActor->AnyMove() && this == pActor->inventory().ActiveItem())
{
if (hud_adj_mode == 0 && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000))
if (!GamePersistent().GetHudTuner().is_active() && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000))
{
SwitchState(eBore);
ResetSubStateTime();
Expand Down
13 changes: 0 additions & 13 deletions src/xrGame/UIGameSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ void CUIGameSP::SetClGame(game_cl_GameState* g)
m_game = smart_cast<game_cl_Single*>(g);
R_ASSERT(m_game);
}
#ifdef DEBUG
void attach_adjust_mode_keyb(int dik);
void attach_draw_adjust_mode();
void hud_adjust_mode_keyb(int dik);
void hud_draw_adjust_mode();
#endif

void CUIGameSP::OnFrame()
{
Expand Down Expand Up @@ -109,11 +103,6 @@ bool CUIGameSP::IR_UIOnKeyboardPress(int dik)
if (Device.Paused())
return false;

#ifdef DEBUG
hud_adjust_mode_keyb(dik);
attach_adjust_mode_keyb(dik);
#endif

CInventoryOwner* pInvOwner = smart_cast<CInventoryOwner*>(Level().CurrentEntity());
if (!pInvOwner)
return false;
Expand Down Expand Up @@ -182,8 +171,6 @@ bool CUIGameSP::IR_UIOnKeyboardPress(int dik)
void CUIGameSP::Render()
{
inherited::Render();
hud_draw_adjust_mode();
attach_draw_adjust_mode();
}
#endif

Expand Down
30 changes: 7 additions & 23 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Torch.h"
#include "xrNetServer/NET_Messages.h"
#include "xrCore/xr_token.h"
#include "GamePersistent.h"

#define WEAPON_REMOVE_TIME 60000
#define ROTATION_TIME 0.25f
Expand Down Expand Up @@ -857,7 +858,6 @@ void CWeapon::OnH_B_Chield()
m_set_next_ammoType_on_reload = undefined_ammo_type;
}

extern u32 hud_adj_mode;
bool CWeapon::AllowBore() { return true; }
void CWeapon::UpdateCL()
{
Expand All @@ -878,7 +878,7 @@ void CWeapon::UpdateCL()
CActor* pActor = smart_cast<CActor*>(H_Parent());
if (pActor && !pActor->AnyMove() && this == pActor->inventory().ActiveItem())
{
if (hud_adj_mode == 0 && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000) &&
if (!GamePersistent().GetHudTuner().is_active() && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000) &&
!IsZoomed() && g_player_hud->attached_item(1) == nullptr)
{
if (AllowBore())
Expand Down Expand Up @@ -1297,6 +1297,8 @@ bool CWeapon::SilencerAttachable() { return (ALife::eAddonAttachable == m_eSilen

void CWeapon::UpdateHUDAddonsVisibility()
{
if (GamePersistent().GetHudTuner().is_active())
return;
static shared_str wpn_scope = WPN_SCOPE;
static shared_str wpn_silencer = WPN_SILENCER;
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;
Expand Down Expand Up @@ -1344,6 +1346,9 @@ void CWeapon::UpdateHUDAddonsVisibility()

void CWeapon::UpdateAddonsVisibility()
{
if (GamePersistent().GetHudTuner().is_active())
return;

static shared_str wpn_scope = WPN_SCOPE;
static shared_str wpn_silencer = WPN_SILENCER;
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;
Expand Down Expand Up @@ -1894,27 +1899,6 @@ BOOL CWeapon::ParentIsActor()
return EA->cast_actor() != nullptr;
}

extern u32 hud_adj_mode;

void CWeapon::debug_draw_firedeps()
{
#ifdef DEBUG
if (hud_adj_mode == 5 || hud_adj_mode == 6 || hud_adj_mode == 7)
{
CDebugRenderer& render = Level().debug_renderer();

if (hud_adj_mode == 5)
render.draw_aabb(get_LastFP(), 0.005f, 0.005f, 0.005f, color_xrgb(255, 0, 0));

if (hud_adj_mode == 6)
render.draw_aabb(get_LastFP2(), 0.005f, 0.005f, 0.005f, color_xrgb(0, 0, 255));

if (hud_adj_mode == 7)
render.draw_aabb(get_LastSP(), 0.005f, 0.005f, 0.005f, color_xrgb(0, 255, 0));
}
#endif // DEBUG
}

const float& CWeapon::hit_probability() const
{
VERIFY((g_SingleGameDifficulty >= egdNovice) && (g_SingleGameDifficulty <= egdMaster));
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ class CWeapon : public CHudItemObject, public CShootingObject
return m_current_firedeps.m_FireParticlesXForm;
}
virtual void ForceUpdateFireParticles();
virtual void debug_draw_firedeps();

protected:
virtual void SetDefaults();
Expand Down
Loading

0 comments on commit b4afaa4

Please sign in to comment.