From fe19767ac28624962b86142203d7d756811d8db5 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 1 Jul 2009 02:00:36 +0000 Subject: [PATCH] - Added A_SetCrosshair. SVN r1700 (trunk) --- docs/rh-log.txt | 1 + src/d_main.cpp | 6 +- src/g_shared/a_pickups.h | 3 +- src/g_shared/a_weapons.cpp | 17 +++++ src/g_shared/sbar.h | 5 ++ src/g_shared/shared_sbar.cpp | 88 ++++++++++++++--------- src/r_things.cpp | 1 - wadsrc/static/actors/shared/inventory.txt | 2 + 8 files changed, 84 insertions(+), 39 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 7171bd8ca9..af550ecfcb 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,5 @@ June 30, 2009 +- Added A_SetCrosshair. - Added A_WeaponBob. - Dropped the Hexen player classes' JumpZ down to 9, since the original value now works as it originally did. diff --git a/src/d_main.cpp b/src/d_main.cpp index 1a9a955069..bfe7092a32 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -135,7 +135,6 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf // EXTERNAL DATA DECLARATIONS ---------------------------------------------- EXTERN_CVAR (Float, turbo) -EXTERN_CVAR (Int, crosshair) EXTERN_CVAR (Bool, freelook) EXTERN_CVAR (Float, m_pitch) EXTERN_CVAR (Float, m_yaw) @@ -541,7 +540,7 @@ void D_Display () // Refresh the console. C_NewModeAdjust (); // Reload crosshair if transitioned to a different size - crosshair.Callback (); + ST_LoadCrosshair (true); AM_NewResolution (); } } @@ -1888,9 +1887,6 @@ void D_DoomMain (void) Printf ("Texman.Init: Init texture manager.\n"); TexMan.Init(); - // Now that all textues have been loaded the crosshair can be initialized. - crosshair.Callback (); - // [CW] Parse any TEAMINFO lumps. Printf ("ParseTeamInfo: Load team definitions.\n"); TeamLibrary.ParseTeamInfo (); diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 3dbf97360b..78bb7ca594 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -263,8 +263,9 @@ public: // In-inventory instance variables TObjPtr Ammo1, Ammo2; TObjPtr SisterWeapon; - bool GivenAsMorphWeapon; float FOVScale; + int Crosshair; // 0 to use player's crosshair + bool GivenAsMorphWeapon; bool bAltFire; // Set when this weapon's alternate fire is used. diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index b7543c4db5..c91583ce4a 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -1721,3 +1721,20 @@ DEFINE_ACTION_FUNCTION_PARAMS(AWeapon, A_ZoomFactor) self->player->ReadyWeapon->FOVScale = zoom; } } + +//=========================================================================== +// +// A_SetCrosshair +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AWeapon, A_SetCrosshair) +{ + ACTION_PARAM_START(1); + ACTION_PARAM_INT(xhair, 0); + + if (self->player != NULL && self->player->ReadyWeapon != NULL) + { + self->player->ReadyWeapon->Crosshair = xhair; + } +} diff --git a/src/g_shared/sbar.h b/src/g_shared/sbar.h index 89e2b8e7ad..162947bf49 100644 --- a/src/g_shared/sbar.h +++ b/src/g_shared/sbar.h @@ -364,3 +364,8 @@ DBaseStatusBar *CreateHereticStatusBar(); DBaseStatusBar *CreateHexenStatusBar(); DBaseStatusBar *CreateStrifeStatusBar(); DBaseStatusBar *CreateCustomStatusBar(int script=0); + +// Crosshair stuff ---------------------------------------------------------- + +void ST_LoadCrosshair(bool alwaysload=false); +extern FTexture *CrosshairImage; diff --git a/src/g_shared/shared_sbar.cpp b/src/g_shared/shared_sbar.cpp index 3fe74c7c17..0a385591c3 100644 --- a/src/g_shared/shared_sbar.cpp +++ b/src/g_shared/shared_sbar.cpp @@ -79,6 +79,7 @@ int ST_X, ST_Y; int SB_state = 3; FTexture *CrosshairImage; +static int CrosshairNum; // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; @@ -94,38 +95,8 @@ CUSTOM_CVAR (Bool, st_scale, true, CVAR_ARCHIVE) } } -CUSTOM_CVAR (Int, crosshair, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) -{ - int num = self; - char name[16], size; - int lump; - - if (CrosshairImage != NULL) - { - CrosshairImage->Unload (); - } - if (num == 0) - { - CrosshairImage = NULL; - return; - } - if (num < 0) - { - num = -num; - } - size = (SCREENWIDTH < 640) ? 'S' : 'B'; - mysnprintf (name, countof(name), "XHAIR%c%d", size, num); - if ((lump = Wads.CheckNumForName (name, ns_graphics)) == -1) - { - mysnprintf (name, countof(name), "XHAIR%c1", size); - if ((lump = Wads.CheckNumForName (name, ns_graphics)) == -1) - { - strcpy (name, "XHAIRS1"); - } - } - CrosshairImage = TexMan[TexMan.CheckForTexture(name, FTexture::TEX_MiscPatch)]; -} - +CVAR (Int, crosshair, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CVAR (Bool, crosshairforce, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Color, crosshaircolor, 0xff0000, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR (Bool, crosshairhealth, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR (Bool, crosshairscale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); @@ -147,6 +118,57 @@ BYTE DBaseStatusBar::DamageToAlpha[114] = 230, 231, 232, 233, 234, 235, 235, 236, 237 }; +void ST_LoadCrosshair(bool alwaysload) +{ + int num = 0; + char name[16], size; + int lump; + + if (!crosshairforce && + players[consoleplayer].camera != NULL && + players[consoleplayer].camera->player != NULL && + players[consoleplayer].camera->player->ReadyWeapon != NULL) + { + num = players[consoleplayer].camera->player->ReadyWeapon->Crosshair; + } + if (num == 0) + { + num = crosshair; + } + if (!alwaysload && CrosshairNum == num && CrosshairImage != NULL) + { // No change. + return; + } + + if (CrosshairImage != NULL) + { + CrosshairImage->Unload (); + } + if (num == 0) + { + CrosshairNum = 0; + CrosshairImage = NULL; + return; + } + if (num < 0) + { + num = -num; + } + size = (SCREENWIDTH < 640) ? 'S' : 'B'; + mysnprintf (name, countof(name), "XHAIR%c%d", size, num); + if ((lump = Wads.CheckNumForName (name, ns_graphics)) == -1) + { + mysnprintf (name, countof(name), "XHAIR%c1", size); + if ((lump = Wads.CheckNumForName (name, ns_graphics)) == -1) + { + strcpy (name, "XHAIRS1"); + } + num = 1; + } + CrosshairNum = num; + CrosshairImage = TexMan[TexMan.CheckForTexture(name, FTexture::TEX_MiscPatch)]; +} + //--------------------------------------------------------------------------- // // Constructor @@ -1009,6 +1031,8 @@ void DBaseStatusBar::DrawCrosshair () if (players[consoleplayer].cheats & CF_CHASECAM) return; + ST_LoadCrosshair(); + // Don't draw the crosshair if there is none if (CrosshairImage == NULL || gamestate == GS_TITLELEVEL) { diff --git a/src/r_things.cpp b/src/r_things.cpp index 5763211282..6a29c87903 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -52,7 +52,6 @@ #include "v_palette.h" -extern FTexture *CrosshairImage; extern fixed_t globaluclip, globaldclip; diff --git a/wadsrc/static/actors/shared/inventory.txt b/wadsrc/static/actors/shared/inventory.txt index c226a71810..10897495bd 100644 --- a/wadsrc/static/actors/shared/inventory.txt +++ b/wadsrc/static/actors/shared/inventory.txt @@ -329,6 +329,8 @@ Actor Weapon : Inventory native action native A_ZoomFactor(float scale = 1, int flags = 0); const int ZOOM_INSTANT = 1; const int ZOOM_NOSCALETURNING = 2; + + action native A_SetCrosshair(int xhair); } ACTOR WeaponGiver : Weapon native