ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.6k stars 599 forks source link

[HL] Permanent crosshair #692

Open Matthaiks opened 11 years ago

Matthaiks commented 11 years ago

Load some save, select a weapon with a crosshair, start a new game. The crosshair is still visible.

http://youtu.be/eT_-c8mgmww

Protocol version 48 Exe version 1.1.2.2/Stdio (valve) Exe build: 11:45:32 Mar 1 2013 (5971)

Processor Information: Vendor: AuthenticAMD Speed: 3214 Mhz 4 logical processors 4 physical processors HyperThreading: Unsupported FCMOV: Supported SSE2: Supported SSE3: Supported SSSE3: Supported SSE4a: Supported SSE41: Unsupported SSE42: Unsupported

Network Information: Network Speed:

Operating System Version: Windows 7 (64 bit) NTFS: Supported Crypto Provider Codes: Supported 311 0x0 0x0 0x0

Video Card: Driver: ATI Radeon HD 5700 Series

DirectX Driver Name:  aticfx32.dll
Driver Version:  9.12.0.0
DirectX Driver Version:  8.17.10.1172
Driver Date: 19 Dec 2012
Desktop Color Depth: 32 bits per pixel
Monitor Refresh Rate: 60 Hz
DirectX Card: ATI Radeon HD 5700 Series
VendorID:  0x1002
DeviceID:  0x68b8
Number of Monitors:  1
Number of Logical Video Cards:  1
No SLI or Crossfire Detected
Primary Display Resolution:  1920 x 1200
Desktop Resolution: 1920 x 1200
Primary Display Size: 26.65" x 16.65"  (31.42" diag)
                                        67.7cm x 42.3cm  (79.8cm diag)
Primary Bus Type Not Detected
Primary VRAM: 1024 MB
Supported MSAA Modes:  2x 4x 8x 

Sound card: Audio device: Glosniki (ASUS Xonar DS Audio D

Memory: RAM: 8191 Mb

UCyborg commented 11 years ago

This also applies to ammo counter when you wear your HEV suit but have no weapons.

SamVanheer commented 3 years ago

This happens because the client isn't told when the player has no weapons.

To fix this CBasePlayer::UpdateClientData needs to tell the ammo hud when there is no weapon selected. This is done as follows.

First add a boolean at the start of this method: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L3949-L3951

const bool fullHUDInitRequired = m_fInitHUD != FALSE;

if (m_fInitHUD)

Then later in the method: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L4164-L4173

// Update all the items
for ( int i = 0; i < MAX_ITEM_TYPES; i++ )
{
    if ( m_rgpPlayerItems[i] )  // each item updates it's successors
        m_rgpPlayerItems[i]->UpdateClientData( this );
}

//Active item is becoming null, or we're sending all HUD state to client
//Only if we're not in Observer mode, which uses the target player's weapon
if (pev->iuser1 == OBS_NONE && !m_pActiveItem && ((m_pClientActiveItem != m_pActiveItem) || fullHUDInitRequired))
{
    //Tell ammo hud that we have no weapon selected
    MESSAGE_BEGIN(MSG_ONE, gmsgCurWeapon, NULL, pev);
    WRITE_BYTE(0);
    WRITE_BYTE(0);
    WRITE_BYTE(0);
    MESSAGE_END();
}

// Cache and client weapon change
m_pClientActiveItem = m_pActiveItem;
m_iClientFOV = m_iFOV;

This will tell the client the player no longer has any weapon selected if the player's active item is null (weapon just removed) or if the hud is being fully initialized and all state is being updated.

Additionally this code can be removed: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L852-L856

Since UpdateClientData handles this case now.

The ammo counter issue is tracked at #3063 and has a fix.