Fixed a bunch of calculation mistakes in CHud

This commit is contained in:
Sergeanur 2019-10-05 22:26:29 +03:00
parent c7d3b302f5
commit dd99edd339
3 changed files with 158 additions and 132 deletions

View File

@ -134,10 +134,10 @@ CFont::PrintChar(float x, float y, uint16 c)
if(Details.style == 0 || Details.style == 2){ if(Details.style == 0 || Details.style == 2){
if(Details.dropShadowPosition != 0){ if(Details.dropShadowPosition != 0){
CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
CRect(x + Details.dropShadowPosition, CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition),
y + Details.dropShadowPosition, y + SCREEN_SCALE_Y(Details.dropShadowPosition),
x + Details.dropShadowPosition + 32.0f * Details.scaleX * 1.0f, x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f,
y + Details.dropShadowPosition + 40.0f * Details.scaleY * 0.5f), y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f),
Details.dropColor, Details.dropColor,
xoff/16.0f, yoff/12.8f, xoff/16.0f, yoff/12.8f,
(xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,

View File

@ -46,7 +46,7 @@ wchar *CHud::m_Message = (wchar*)0x72E318;
wchar *CHud::m_PagerMessage = (wchar*)0x878840; wchar *CHud::m_PagerMessage = (wchar*)0x878840;
bool &CHud::m_Wants_To_Draw_Hud = *(bool*)0x95CD89; bool &CHud::m_Wants_To_Draw_Hud = *(bool*)0x95CD89;
bool &CHud::m_Wants_To_Draw_3dMarkers = *(bool*)0x95CD62; bool &CHud::m_Wants_To_Draw_3dMarkers = *(bool*)0x95CD62;
wchar(*CHud::m_BigMessage)[128] = (wchar(*)[128])0x664CE0; wchar(&CHud::m_BigMessage)[6][128] = *(wchar(*)[6][128])*(uintptr*)0x664CE0;
int16 &CHud::m_ItemToFlash = *(int16*)0x95CC82; int16 &CHud::m_ItemToFlash = *(int16*)0x95CC82;
// These aren't really in CHud // These aren't really in CHud
@ -68,53 +68,35 @@ int16 &CHud::PagerTimer = *(int16*)0x95CC3A;
int16 &CHud::PagerOn = *(int16*)0x95CCA0; int16 &CHud::PagerOn = *(int16*)0x95CCA0;
CSprite2d *CHud::Sprites = (CSprite2d*)0x95CB9C; CSprite2d *CHud::Sprites = (CSprite2d*)0x95CB9C;
char *WeaponFilenames[] = {
"fist", struct
"fistm", {
"bat", const char *name;
"batm", const char *mask;
"pistol", } WeaponFilenames[] = {
"pistolm", {"fist", "fistm"},
"uzi", {"bat", "batm"},
"uzim", {"pistol", "pistolm" },
"shotgun", {"uzi", "uzim"},
"shotgunm", {"shotgun", "shotgunm"},
"ak47", {"ak47", "ak47m"},
"ak47m", {"m16", "m16m"},
"m16", {"sniper", "sniperm"},
"m16m", {"rocket", "rocketm"},
"sniper", {"flame", "flamem"},
"sniperm", {"molotov", "molotovm"},
"rocket", {"grenade", "grenadem"},
"rocketm", {"detonator", "detonator_mask"},
"flame", {"", ""},
"flamem", {"", ""},
"molotov", {"radardisc", "radardiscm"},
"molotovm", {"pager", "pagerm"},
"grenade", {"", ""},
"grenadem", {"", ""},
"detonator", {"bleeder", ""},
"detonator_mask", {"sitesniper", "sitesniperm"},
"", {"siteM16", "siteM16m"},
"", {"siterocket", "siterocketm"}
"",
"",
"radardisc",
"radardiscm",
"pager",
"pagerm",
"",
"",
"",
"",
"bleeder",
"",
"sitesniper",
"sitesniperm",
"siteM16",
"siteM16m",
"siterocket",
"siterocketm"
}; };
RwTexture *&gpSniperSightTex = *(RwTexture**)0x8F5834; RwTexture *&gpSniperSightTex = *(RwTexture**)0x8F5834;
@ -892,15 +874,17 @@ void CHud::Draw()
CFont::SetPropOn(); CFont::SetPropOn();
CFont::SetFontStyle(FONT_BANK); CFont::SetFontStyle(FONT_BANK);
if (TheCamera.m_WideScreenOn) float offsetX = SCREEN_SCALE_X(40.0f) + SCREEN_SCALE_X(8.0f);
CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(120.0f)); float center = SCREEN_SCALE_FROM_RIGHT(50.0f) - SCREEN_SCALE_X(8.0f) - offsetX;
else CFont::SetCentreSize(center);
CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(280.0f));
CFont::SetDropShadowPosition(1); const int16 shadow = 1;
CFont::SetDropShadowPosition(shadow);
CFont::SetDropColor(CRGBA(0, 0, 0, 255)); CFont::SetDropColor(CRGBA(0, 0, 0, 255));
CFont::SetColor(CRGBA(235, 235, 235, 255)); CFont::SetColor(CRGBA(235, 235, 235, 255));
CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_FROM_BOTTOM(64.0f), m_Message);
// I'm not sure shadow substaction was intentional here, might be a leftover if CFont::PrintString was used for a shadow draw call
CFont::PrintString(center / 2.0f + offsetX - SCREEN_SCALE_X(shadow), SCREEN_SCALE_Y(4.0f) + SCREEN_SCALE_FROM_BOTTOM(68.0f) - SCREEN_SCALE_Y(shadow), m_Message);
CFont::SetDropShadowPosition(0); CFont::SetDropShadowPosition(0);
} }
@ -920,11 +904,11 @@ void CHud::Draw()
CFont::SetFontStyle(FONT_HEADING); CFont::SetFontStyle(FONT_HEADING);
if (BigMessageX[0] >= (SCREEN_WIDTH - 20)) { if (BigMessageX[0] >= (SCREEN_WIDTH - 20)) {
BigMessageInUse[0] += (CTimer::GetTimeStepInSeconds() * 120.0f); BigMessageInUse[0] += CTimer::GetTimeStep();
if (BigMessageInUse[0] >= 120.0f) { if (BigMessageInUse[0] >= 120.0f) {
BigMessageInUse[0] = 120.0; BigMessageInUse[0] = 120.0;
BigMessageAlpha[0] += (CTimer::GetTimeStepInSeconds() * -255.0f); BigMessageAlpha[0] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f);
} }
if (BigMessageAlpha[0] <= 0.0f) { if (BigMessageAlpha[0] <= 0.0f) {
@ -933,18 +917,22 @@ void CHud::Draw()
} }
} }
else { else {
BigMessageX[0] += (CTimer::GetTimeStepInSeconds() * 255.0f); BigMessageX[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
BigMessageAlpha[0] += (CTimer::GetTimeStepInSeconds() * 255.0f); BigMessageAlpha[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
if (BigMessageAlpha[0] >= 255.0f) if (BigMessageAlpha[0] >= 255.0f)
BigMessageAlpha[0] = 255.0f; BigMessageAlpha[0] = 255.0f;
} }
CFont::SetColor(CRGBA(0, 0, 0, BigMessageAlpha[0])); CFont::SetColor(CRGBA(0, 0, 0, BigMessageAlpha[0]));
CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f - 2.0f), m_BigMessage[0]); #ifdef FIX_BUGS
CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[0]);
#else
CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[0]);
#endif
CFont::SetColor(CRGBA(85, 119, 133, BigMessageAlpha[0])); CFont::SetColor(CRGBA(85, 119, 133, BigMessageAlpha[0]));
CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f), m_BigMessage[0]); CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f), m_BigMessage[0]);
} }
else { else {
BigMessageAlpha[0] = 0.0f; BigMessageAlpha[0] = 0.0f;
@ -1099,7 +1087,7 @@ void CHud::DrawAfterFade()
DrawBigMessage2 DrawBigMessage2
*/ */
// Oddjob // Oddjob
if (m_BigMessage[4][0]) { if (m_BigMessage[3][0]) {
CFont::SetJustifyOff(); CFont::SetJustifyOff();
CFont::SetBackgroundOff(); CFont::SetBackgroundOff();
CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f)); CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f));
@ -1109,18 +1097,35 @@ void CHud::DrawAfterFade()
CFont::SetFontStyle(FONT_BANK); CFont::SetFontStyle(FONT_BANK);
CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::SetColor(CRGBA(0, 0, 0, 255));
CFont::PrintString(SCREEN_SCALE_X(2.0f) + (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[4]); CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[3]);
CFont::SetColor(CRGBA(89, 115, 150, 255)); CFont::SetColor(CRGBA(89, 115, 150, 255));
CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[4]); CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[3]);
}
if (!m_BigMessage[1][0] && m_BigMessage[4][0]) {
CFont::SetJustifyOff();
CFont::SetBackgroundOff();
CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f));
CFont::SetCentreOn();
CFont::SetPropOn();
CFont::SetCentreSize(SCREEN_SCALE_X(620.0f));
CFont::SetColor(CRGBA(0, 0, 0, 255));
CFont::SetFontStyle(FONT_BANK);
CFont::PrintString((SCREEN_WIDTH / 2) - SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) - SCREEN_SCALE_Y(2.0f), m_BigMessage[3]);
CFont::SetColor(CRGBA(89, 115, 150, 255));
CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[3]);
} }
// Oddjob result // Oddjob result
if (OddJob2OffTimer > 0) if (OddJob2OffTimer > 0)
OddJob2OffTimer = OddJob2OffTimer - CTimer::GetTimeStepInMilliseconds(); OddJob2OffTimer -= CTimer::GetTimeStepInMilliseconds();
static float fStep; static float fStep;
if (!m_BigMessage[1][0] && m_BigMessage[4][0] && m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) { if (m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) {
if (OddJob2On <= 3) {
switch (OddJob2On) { switch (OddJob2On) {
case 0: case 0:
OddJob2On = 1; OddJob2On = 1;
@ -1133,8 +1138,8 @@ void CHud::DrawAfterFade()
} }
else { else {
fStep = 40.0f; fStep = 40.0f;
if ((OddJob2XOffset * 0.16667f) <= 40.0f) if ((OddJob2XOffset / 6.0f) <= 40.0f)
fStep = OddJob2XOffset * 0.16667f; fStep = OddJob2XOffset / 6.0f;
OddJob2XOffset = OddJob2XOffset - fStep; OddJob2XOffset = OddJob2XOffset - fStep;
} }
break; break;
@ -1146,8 +1151,8 @@ void CHud::DrawAfterFade()
break; break;
case 3: case 3:
fStep = 30.0f; fStep = 30.0f;
if ((OddJob2XOffset * 0.2f) >= 30.0f) if ((OddJob2XOffset / 5.0f) >= 30.0f)
fStep = OddJob2XOffset * 0.2f; fStep = OddJob2XOffset / 5.0f;
OddJob2XOffset = OddJob2XOffset - fStep; OddJob2XOffset = OddJob2XOffset - fStep;
@ -1159,20 +1164,23 @@ void CHud::DrawAfterFade()
default: default:
break; break;
} }
}
if (!m_BigMessage[1][0]) {
CFont::SetJustifyOff(); CFont::SetJustifyOff();
CFont::SetBackgroundOff(); CFont::SetBackgroundOff();
CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f)); CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f));
CFont::SetCentreOn(); CFont::SetCentreOn();
CFont::SetPropOn(); CFont::SetPropOn();
CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f)); CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f));
CFont::SetColor(CRGBA(0, 0, 0, 255));
CFont::SetFontStyle(FONT_BANK); CFont::SetFontStyle(FONT_BANK);
CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[5]);
CFont::PrintString(SCREEN_SCALE_X(2.0f) + (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f + 2.0f), m_BigMessage[5]);
CFont::SetColor(CRGBA(156, 91, 40, 255)); CFont::SetColor(CRGBA(156, 91, 40, 255));
CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f + 2.0f), m_BigMessage[5]); CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f), m_BigMessage[5]);
}
} }
/* /*
@ -1189,15 +1197,15 @@ void CHud::DrawAfterFade()
CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f)); CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f));
CFont::SetPropOn(); CFont::SetPropOn();
CFont::SetRightJustifyWrap(-500); CFont::SetRightJustifyWrap(-500.0f);
CFont::SetRightJustifyOn(); CFont::SetRightJustifyOn();
CFont::SetFontStyle(FONT_HEADING); CFont::SetFontStyle(FONT_HEADING);
if (BigMessageX[1] >= (SCREEN_WIDTH - 20)) { if (BigMessageX[1] >= (SCREEN_WIDTH - 20)) {
BigMessageInUse[1] += (CTimer::GetTimeStepInSeconds() * 120.0f); BigMessageInUse[1] += CTimer::GetTimeStep();
if (BigMessageInUse[1] >= 120.0f) { if (BigMessageInUse[1] >= 120.0f) {
BigMessageInUse[1] = 120.0; BigMessageInUse[1] = 120.0;
BigMessageAlpha[1] += (CTimer::GetTimeStepInSeconds() * -255.0f); BigMessageAlpha[1] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f);
} }
if (BigMessageAlpha[1] <= 0) { if (BigMessageAlpha[1] <= 0) {
m_BigMessage[1][0] = 0; m_BigMessage[1][0] = 0;
@ -1205,15 +1213,15 @@ void CHud::DrawAfterFade()
} }
} }
else { else {
BigMessageX[1] += (CTimer::GetTimeStepInSeconds() * 255.0f); BigMessageX[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
BigMessageAlpha[1] += (CTimer::GetTimeStepInSeconds() * 255.0f); BigMessageAlpha[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
if (BigMessageAlpha[1] >= 255.0f) if (BigMessageAlpha[1] >= 255.0f)
BigMessageAlpha[1] = 255.0f; BigMessageAlpha[1] = 255.0f;
} }
CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[1])); CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[1]));
CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f - 2.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[1]);
CFont::SetColor(CRGBA(220, 172, 2, BigMessageAlpha[1])); CFont::SetColor(CRGBA(220, 172, 2, BigMessageAlpha[1]));
CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]);
@ -1272,9 +1280,8 @@ void CHud::GetRidOfAllHudMessages()
void CHud::Initialise() void CHud::Initialise()
{ {
debug("Init CHud"); m_Wants_To_Draw_Hud = true;
m_Wants_To_Draw_3dMarkers = true;
ReInitialise();
int HudTXD = CTxdStore::AddTxdSlot("hud"); int HudTXD = CTxdStore::AddTxdSlot("hud");
CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD"); CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD");
@ -1282,13 +1289,32 @@ void CHud::Initialise()
CTxdStore::PopCurrentTxd(); CTxdStore::PopCurrentTxd();
CTxdStore::SetCurrentTxd(HudTXD); CTxdStore::SetCurrentTxd(HudTXD);
for (int i = 0; i < ARRAY_SIZE(WeaponFilenames) / 2; i++) { for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); i++) {
Sprites[i].SetTexture(WeaponFilenames[i * 2]); Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask);
} }
GetRidOfAllHudMessages();
if (gpSniperSightTex == nil)
gpSniperSightTex = RwTextureRead("sitesniper", nil); gpSniperSightTex = RwTextureRead("sitesniper", nil);
if (gpRocketSightTex == nil)
gpRocketSightTex = RwTextureRead("siterocket", nil); gpRocketSightTex = RwTextureRead("siterocket", nil);
CounterOnLastFrame = 0;
m_ItemToFlash = ITEM_NONE;
OddJob2Timer = 0;
OddJob2OffTimer = 0.0f;
OddJob2On = 0;
OddJob2XOffset = 0.0f;
CounterFlashTimer = 0;
TimerOnLastFrame = 0;
TimerFlashTimer = 0;
SpriteBrightness = 0;
PagerOn = 0;
PagerTimer = 0;
PagerSoundPlayed = 0;
PagerXOffset = 150.0f;
CTxdStore::PopCurrentTxd(); CTxdStore::PopCurrentTxd();
} }
@ -1324,7 +1350,7 @@ WRAPPER void CHud::SetBigMessage(wchar *message, int16 style) { EAXJMP(0x50A250)
#else #else
void CHud::SetBigMessage(wchar *message, int16 style) void CHud::SetBigMessage(wchar *message, int16 style)
{ {
int i; int i = 0;
if (style == 5) { if (style == 5) {
for (i = 0; i < 128; i++) { for (i = 0; i < 128; i++) {
@ -1375,7 +1401,7 @@ WRAPPER void CHud::SetMessage(wchar *message) { EAXJMP(0x50A210); }
#else #else
void CHud::SetMessage(wchar *message) void CHud::SetMessage(wchar *message)
{ {
int i; int i = 0;
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
if (message[i] == 0) if (message[i] == 0)
break; break;
@ -1391,7 +1417,7 @@ WRAPPER void CHud::SetPagerMessage(wchar *message) { EAXJMP(0x50A320); }
#else #else
void CHud::SetPagerMessage(wchar *message) void CHud::SetPagerMessage(wchar *message)
{ {
int i; int i = 0;
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
if (message[i] == 0) if (message[i] == 0)
break; break;
@ -1424,7 +1450,7 @@ void CHud::Shutdown()
{ {
debug("Shutdown CHud"); debug("Shutdown CHud");
for (int i = 0; i < ARRAY_SIZE(WeaponFilenames) / 2; ++i) { for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); ++i) {
Sprites[i].Delete(); Sprites[i].Delete();
} }

View File

@ -61,7 +61,7 @@ public:
static wchar *m_PagerMessage; static wchar *m_PagerMessage;
static bool &m_Wants_To_Draw_Hud; static bool &m_Wants_To_Draw_Hud;
static bool &m_Wants_To_Draw_3dMarkers; static bool &m_Wants_To_Draw_3dMarkers;
static wchar(*m_BigMessage)[128]; static wchar(&m_BigMessage)[6][128];
static int16 &m_ItemToFlash; static int16 &m_ItemToFlash;
// These aren't really in CHud // These aren't really in CHud