Skip to content

Commit

Permalink
Update hud_item_measures transform if necessary, cleanup redundant co…
Browse files Browse the repository at this point in the history
…de for hud_item_measures update
  • Loading branch information
yohjimane committed Jul 3, 2023
1 parent 7b9ec1d commit d515bfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
24 changes: 14 additions & 10 deletions src/xrGame/player_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ActorEffector.h"
#include "WeaponMagazinedWGrenade.h" // XXX: move somewhere

extern u32 hud_adj_mode;
player_hud* g_player_hud = nullptr;

// clang-format off
Expand Down Expand Up @@ -129,6 +130,9 @@ void attachable_hud_item::update(bool bForce)
{
reload_measures();
}

if (hud_adj_mode > 0)
m_measures.update(m_attach_offset);

m_parent->calc_transform(m_attach_place_idx, m_attach_offset, m_item_transform);
m_upd_firedeps_frame = Device.dwFrame;
Expand Down Expand Up @@ -217,12 +221,8 @@ Fmatrix hud_item_measures::load(const shared_str& sect_name, IKinematics* K)
m_item_attach[0] = pSettings->r_fvector3(sect_name, "item_position");
m_item_attach[1] = pSettings->r_fvector3(sect_name, "item_orientation");

Fvector ypr = m_item_attach[1];
ypr.mul(PI / 180.f);

Fmatrix attach_offset;
attach_offset.setHPB(ypr.x, ypr.y, ypr.z);
attach_offset.translate_over(m_item_attach[0]);
update(attach_offset);

shared_str bone_name;
m_prop_flags.set(e_fire_point, pSettings->line_exist(sect_name, "fire_bone"));
Expand Down Expand Up @@ -286,12 +286,8 @@ Fmatrix hud_item_measures::load_monolithic(const shared_str& sect_name, IKinemat
m_item_attach[0] = pSettings->r_fvector3(sect_name, "position");
m_item_attach[1] = pSettings->r_fvector3(sect_name, "orientation");

Fvector ypr = m_item_attach[1];
ypr.mul(PI / 180.f);

Fmatrix attach_offset;
attach_offset.setHPB(ypr.x, ypr.y, ypr.z);
attach_offset.translate_over(m_item_attach[0]);
update(attach_offset);

// fire bone
if (auto* wpn = smart_cast<CWeapon*>(owner))
Expand Down Expand Up @@ -362,6 +358,14 @@ void hud_item_measures::load_inertion_params(const shared_str& sect_name)
//--#SM+# End--
}

void hud_item_measures::update(Fmatrix& attach_offset)
{
Fvector ypr = m_item_attach[1];
ypr.mul(PI / 180.f);
attach_offset.setHPB(ypr.x, ypr.y, ypr.z);
attach_offset.translate_over(m_item_attach[0]);
}

attachable_hud_item::~attachable_hud_item()
{
IRenderVisual* v = m_model->dcast_RenderVisual();
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/player_hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct hud_item_measures
Fmatrix load(const shared_str& sect_name, IKinematics* K);
Fmatrix load_monolithic(const shared_str& sect_name, IKinematics* K, CHudItem* owner);
void load_inertion_params(const shared_str& sect_name);
void update(Fmatrix& attach_offset);

struct inertion_params
{
Expand Down
26 changes: 13 additions & 13 deletions src/xrGame/player_hud_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "debug_renderer.h"
#include "xrEngine/GameFont.h"

u32 hud_adj_mode = 0;
extern u32 hud_adj_mode = 0;
u32 hud_adj_item_idx = 0;
// "press SHIFT+NUM 0-return 1-hud_pos 2-hud_rot 3-itm_pos 4-itm_rot 5-fire_point 6-fire_2_point 7-shell_point";

Expand Down Expand Up @@ -349,32 +349,32 @@ void hud_adjust_mode_keyb(int dik)
{
if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT))
{
if (dik == SDL_SCANCODE_KP_0)
if (dik == SDL_SCANCODE_KP_0 || dik == SDL_SCANCODE_0)
hud_adj_mode = 0;
if (dik == SDL_SCANCODE_KP_1)
if (dik == SDL_SCANCODE_KP_1 || dik == SDL_SCANCODE_1)
hud_adj_mode = 1;
if (dik == SDL_SCANCODE_KP_2)
if (dik == SDL_SCANCODE_KP_2 || dik == SDL_SCANCODE_2)
hud_adj_mode = 2;
if (dik == SDL_SCANCODE_KP_3)
if (dik == SDL_SCANCODE_KP_3 || dik == SDL_SCANCODE_3)
hud_adj_mode = 3;
if (dik == SDL_SCANCODE_KP_4)
if (dik == SDL_SCANCODE_KP_4 || dik == SDL_SCANCODE_4)
hud_adj_mode = 4;
if (dik == SDL_SCANCODE_KP_5)
if (dik == SDL_SCANCODE_KP_5 || dik == SDL_SCANCODE_5)
hud_adj_mode = 5;
if (dik == SDL_SCANCODE_KP_6)
if (dik == SDL_SCANCODE_KP_6 || dik == SDL_SCANCODE_6)
hud_adj_mode = 6;
if (dik == SDL_SCANCODE_KP_7)
if (dik == SDL_SCANCODE_KP_7 || dik == SDL_SCANCODE_7)
hud_adj_mode = 7;
if (dik == SDL_SCANCODE_KP_8)
if (dik == SDL_SCANCODE_KP_8 || dik == SDL_SCANCODE_8)
hud_adj_mode = 8;
if (dik == SDL_SCANCODE_KP_9)
if (dik == SDL_SCANCODE_KP_9 || dik == SDL_SCANCODE_9)
hud_adj_mode = 9;
}
if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LCTRL))
{
if (dik == SDL_SCANCODE_KP_0)
if (dik == SDL_SCANCODE_KP_0 || dik == SDL_SCANCODE_0)
hud_adj_item_idx = 0;
if (dik == SDL_SCANCODE_KP_1)
if (dik == SDL_SCANCODE_KP_1 || dik == SDL_SCANCODE_1)
hud_adj_item_idx = 1;
}
}

0 comments on commit d515bfa

Please sign in to comment.