diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/Hud.cpp | 279 | ||||
-rw-r--r-- | src/render/Hud.h | 73 | ||||
-rw-r--r-- | src/render/Lights.cpp | 333 | ||||
-rw-r--r-- | src/render/Lights.h | 18 | ||||
-rw-r--r-- | src/render/VisibilityPlugins.cpp | 889 | ||||
-rw-r--r-- | src/render/VisibilityPlugins.h | 133 |
6 files changed, 195 insertions, 1530 deletions
diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 80d7fe47..f8b86bd2 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -21,54 +21,52 @@ #include "User.h" #include "World.h" -wchar *CHud::m_HelpMessage = (wchar*)0x86B888; -wchar *CHud::m_LastHelpMessage = (wchar*)0x6E8F28; -int32 &CHud::m_HelpMessageState = *(int32*)0x880E1C; -int32 &CHud::m_HelpMessageTimer = *(int32*)0x880FA4; -int32 &CHud::m_HelpMessageFadeTimer = *(int32*)0x8F6258; -wchar *CHud::m_HelpMessageToPrint = (wchar*)0x664480; -float &CHud::m_HelpMessageDisplayTime = *(float*)0x8E2C28; -float &CHud::m_fTextBoxNumLines = *(float*)0x8E2C28; -float &CHud::m_fHelpMessageTime = *(float *)0x8E2C28; -bool &CHud::m_HelpMessageQuick = *(bool *)0x95CCF7; -int32 CHud::m_ZoneState = *(int32*)0x8F29AC; +wchar CHud::m_HelpMessage[256]; // = (wchar*)0x86B888; +wchar CHud::m_LastHelpMessage[256]; // = (wchar*)0x6E8F28; +uint32 CHud::m_HelpMessageState; // = *(int32*)0x880E1C; +uint32 CHud::m_HelpMessageTimer; // = *(int32*)0x880FA4; +int32 CHud::m_HelpMessageFadeTimer; // = *(int32*)0x8F6258; +wchar CHud::m_HelpMessageToPrint[256]; // = (wchar*)0x664480; +float CHud::m_fHelpMessageTime; // *(float *)0x8E2C28; +bool CHud::m_HelpMessageQuick; // = *(bool*)0x95CCF7; +uint32 CHud::m_ZoneState; // = *(int32*)0x8F29AC; int32 CHud::m_ZoneFadeTimer; -int32 CHud::m_ZoneNameTimer = *(int32*)0x8F1A50; -wchar *&CHud::m_pZoneName = *(wchar **)0x8E2C2C; -wchar *CHud::m_pLastZoneName = (wchar*)0x8F432C; +uint32 CHud::m_ZoneNameTimer; // = *(int32*)0x8F1A50; +wchar *CHud::m_pZoneName; // = *(wchar**)0x8E2C2C; +wchar *CHud::m_pLastZoneName; // = (wchar*)0x8F432C; wchar *CHud::m_ZoneToPrint; -int32 CHud::m_VehicleState = *(int32*)0x940560; +uint32 CHud::m_VehicleState; // = *(int32*)0x940560; int32 CHud::m_VehicleFadeTimer; -int32 CHud::m_VehicleNameTimer = *(int32*)0x8F2A14; -wchar *&CHud::m_VehicleName = *(wchar **)0x942FB4; -wchar *CHud::m_pLastVehicleName = *(wchar **)0x8E2DD8; +uint32 CHud::m_VehicleNameTimer; // = *(int32*)0x8F2A14; +wchar *CHud::m_VehicleName; // = *(wchar**)0x942FB4; +wchar *CHud::m_pLastVehicleName; // = *(wchar**)0x8E2DD8; wchar *CHud::m_pVehicleNameToPrint; -wchar *CHud::m_Message = (wchar*)0x72E318; -wchar *CHud::m_PagerMessage = (wchar*)0x878840; -bool &CHud::m_Wants_To_Draw_Hud = *(bool*)0x95CD89; -bool &CHud::m_Wants_To_Draw_3dMarkers = *(bool*)0x95CD62; -wchar(&CHud::m_BigMessage)[6][128] = *(wchar(*)[6][128])*(uintptr*)0x664CE0; -int16 &CHud::m_ItemToFlash = *(int16*)0x95CC82; +wchar CHud::m_Message[256];// = (wchar*)0x72E318; +wchar CHud::m_PagerMessage[256]; // = (wchar*)0x878840; +bool CHud::m_Wants_To_Draw_Hud; // (bool*)0x95CD89; +bool CHud::m_Wants_To_Draw_3dMarkers; // = *(bool*)0x95CD62; +wchar CHud::m_BigMessage[6][128]; // = *(wchar(*)[6][128]) * (uintptr*)0x664CE0; +int16 CHud::m_ItemToFlash; // = *(int16*)0x95CC82; // These aren't really in CHud float CHud::BigMessageInUse[6]; float CHud::BigMessageAlpha[6]; float CHud::BigMessageX[6]; -float &CHud::OddJob2OffTimer = *(float*)0x942FA0; -int8 &CHud::CounterOnLastFrame = *(int8*)0x95CD67; -float &CHud::OddJob2XOffset = *(float*)0x8F1B5C; -int16 &CHud::CounterFlashTimer = *(int16*)0x95CC20; -int16 &CHud::OddJob2Timer = *(int16*)0x95CC52; -int8 &CHud::TimerOnLastFrame = *(int8*)0x95CDA7; -int16 &CHud::OddJob2On = *(int16*)0x95CC78; -int16 &CHud::TimerFlashTimer = *(int16*)0x95CC6C; -int16 &CHud::PagerSoundPlayed = *(int16*)0x95CC4A; -int32 &CHud::SpriteBrightness = *(int32*)0x95CC54; -float &CHud::PagerXOffset = *(float*)0x941590; -int16 &CHud::PagerTimer = *(int16*)0x95CC3A; -int16 &CHud::PagerOn = *(int16*)0x95CCA0; - -CSprite2d *CHud::Sprites = (CSprite2d*)0x95CB9C; +float CHud::OddJob2OffTimer; // = *(float*)0x942FA0; +bool CHud::CounterOnLastFrame; // = *(int8*)0x95CD67; +float CHud::OddJob2XOffset; // = *(float*)0x8F1B5C; +uint16 CHud::CounterFlashTimer; // = *(int16*)0x95CC20; +uint16 CHud::OddJob2Timer; // = *(int16*)0x95CC52; +bool CHud::TimerOnLastFrame; //= *(int8*)0x95CDA7; +int16 CHud::OddJob2On; //= *(int16*)0x95CC78; +uint16 CHud::TimerFlashTimer; //= *(int16*)0x95CC6C; +int16 CHud::PagerSoundPlayed; //= *(int16*)0x95CC4A; +int32 CHud::SpriteBrightness; //= *(int32*)0x95CC54; +float CHud::PagerXOffset; //= *(float*)0x941590; +int16 CHud::PagerTimer; //= *(int16*)0x95CC3A; +int16 CHud::PagerOn; //= *(int16*)0x95CCA0; + +CSprite2d CHud::Sprites[NUM_HUD_SPRITES]; // = (CSprite2d*)0x95CB9C; struct { @@ -90,14 +88,14 @@ struct {"detonator", "detonator_mask"}, {"", ""}, {"", ""}, - {"radardisc", "radardiscm"}, + {"radardisc", "radardisc"}, {"pager", "pagerm"}, {"", ""}, {"", ""}, {"bleeder", ""}, {"sitesniper", "sitesniperm"}, {"siteM16", "siteM16m"}, - {"siterocket", "siterocketm"} + {"siterocket", "siterocket"} }; RwTexture *&gpSniperSightTex = *(RwTexture**)0x8F5834; @@ -415,7 +413,7 @@ void CHud::Draw() DrawZoneName */ if (m_pZoneName) { - float fZoneAlpha = 0.0f; + float fZoneAlpha = 255.0f; if (m_pZoneName != m_pLastZoneName) { switch (m_ZoneState) { @@ -429,7 +427,7 @@ void CHud::Draw() case 2: case 3: case 4: - m_ZoneNameTimer = 0; + m_ZoneNameTimer = 5; m_ZoneState = 4; break; default: @@ -441,6 +439,7 @@ void CHud::Draw() if (m_ZoneState) { switch (m_ZoneState) { case 1: + m_ZoneFadeTimer = 1000; if (m_ZoneNameTimer > 10000) { m_ZoneFadeTimer = 1000; m_ZoneState = 3; @@ -468,7 +467,6 @@ void CHud::Draw() if (m_ZoneFadeTimer < 0) { m_ZoneFadeTimer = 0; m_ZoneToPrint = m_pLastZoneName; - m_ZoneNameTimer = 0; m_ZoneState = 2; } fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; @@ -500,12 +498,6 @@ void CHud::Draw() } } } - /*else { - m_pLastZoneName = nil; - m_ZoneState = 0; - m_ZoneFadeTimer = 0; - m_ZoneNameTimer = 0; - }*/ /* DrawVehicleName @@ -633,9 +625,9 @@ void CHud::Draw() wchar sTimer[16]; if (!CUserDisplay::OnscnTimer.m_sEntries[0].m_bTimerProcessed) - TimerOnLastFrame = 0; + TimerOnLastFrame = false; if (!CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterProcessed) - CounterOnLastFrame = 0; + CounterOnLastFrame = false; #ifdef FIX_BUGS #define TIMER_RIGHT_OFFSET 34.0f // Taken from VC frenzy timer @@ -647,7 +639,7 @@ void CHud::Draw() if (!TimerOnLastFrame) TimerFlashTimer = 1; - TimerOnLastFrame = 1; + TimerOnLastFrame = true; if (TimerFlashTimer) { if (++TimerFlashTimer > 50) @@ -685,7 +677,7 @@ void CHud::Draw() if (!CounterOnLastFrame) CounterFlashTimer = 1; - CounterOnLastFrame = 1; + CounterOnLastFrame = true; if (CounterFlashTimer) { if (++CounterFlashTimer > 50) @@ -739,11 +731,9 @@ void CHud::Draw() /* DrawPager */ - if (!m_PagerMessage[0]) { - if (PagerOn == 1) { - PagerSoundPlayed = false; - PagerOn = 2; - } + if (!m_PagerMessage[0] && PagerOn == 1) { + PagerSoundPlayed = false; + PagerOn = 2; } if (m_PagerMessage[0] || PagerOn == 2) { if (!PagerOn) { @@ -752,7 +742,7 @@ void CHud::Draw() } if (PagerOn == 1) { if (PagerXOffset > 0.0f) { - float fStep = PagerXOffset * 0.05f; + float fStep = PagerXOffset * 0.1f; if (fStep > 10.0f) fStep = 10.0f; PagerXOffset -= fStep * CTimer::GetTimeStep(); @@ -763,10 +753,10 @@ void CHud::Draw() } } else if (PagerOn == 2) { - float fStep = PagerXOffset * 0.05f; + float fStep = PagerXOffset * 0.1f; if (fStep < 2.0f) fStep = 2.0f; - PagerXOffset += fStep * CTimer::GetTimeStep(); + PagerXOffset += fStep; if (PagerXOffset > 150.0f) { PagerXOffset = 150.0f; PagerOn = 0; @@ -815,9 +805,7 @@ void CHud::Draw() DrawScriptText */ if (!CTimer::GetIsUserPaused()) { - intro_text_line* IntroText = CTheScripts::IntroTextLines; - - for (int i = 0; i < MAX_NUM_INTRO_TEXT_LINES; i++) { + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { if (CTheScripts::IntroTextLines[i].m_Text[0] && CTheScripts::IntroTextLines[i].m_bTextBeforeFade) { CFont::SetScale(SCREEN_SCALE_X(CTheScripts::IntroTextLines[i].m_fScaleX), SCREEN_SCALE_Y(CTheScripts::IntroTextLines[i].m_fScaleY * 0.5f)); CFont::SetColor(CTheScripts::IntroTextLines[i].m_sColor); @@ -858,31 +846,31 @@ void CHud::Draw() CFont::SetPropOff(); CFont::SetFontStyle(CTheScripts::IntroTextLines[i].m_nFont); - CFont::PrintString(SCREEN_SCALE_X(640.0f - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_SCALE_Y(448.0f - CTheScripts::IntroTextLines[i].m_fAtY), IntroText->m_Text); + CFont::PrintString(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - CTheScripts::IntroTextLines[i].m_fAtY), CTheScripts::IntroTextLines[i].m_Text); } } + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { + intro_script_rectangle &IntroRect = CTheScripts::IntroRectangles[i]; - intro_script_rectangle* IntroRect = CTheScripts::IntroRectangles; - - for (int i = 0; i < 16; i++) { - if (CTheScripts::IntroRectangles[i].m_bIsUsed && CTheScripts::IntroRectangles[i].m_bBeforeFade) { - if (CTheScripts::IntroRectangles[i].m_nTextureId >= 0) { + // Yeah, top and bottom changed place. R* vision + if (IntroRect.m_bIsUsed && IntroRect.m_bBeforeFade) { + if (IntroRect.m_nTextureId >= 0) { CRect rect = { - CTheScripts::IntroRectangles[i].m_sRect.left, - CTheScripts::IntroRectangles[i].m_sRect.bottom, - CTheScripts::IntroRectangles[i].m_sRect.right, - CTheScripts::IntroRectangles[i].m_sRect.bottom }; + IntroRect.m_sRect.left, + IntroRect.m_sRect.top, + IntroRect.m_sRect.right, + IntroRect.m_sRect.bottom }; - CTheScripts::ScriptSprites[CTheScripts::IntroRectangles[i].m_nTextureId].Draw(rect, IntroRect->m_sColor); + CTheScripts::ScriptSprites[IntroRect.m_nTextureId].Draw(rect, IntroRect.m_sColor); } else { CRect rect = { - CTheScripts::IntroRectangles[i].m_sRect.left, - CTheScripts::IntroRectangles[i].m_sRect.bottom, - CTheScripts::IntroRectangles[i].m_sRect.right, - CTheScripts::IntroRectangles[i].m_sRect.bottom }; + IntroRect.m_sRect.left, + IntroRect.m_sRect.top, + IntroRect.m_sRect.right, + IntroRect.m_sRect.bottom }; - CSprite2d::DrawRect(rect, IntroRect->m_sColor); + CSprite2d::DrawRect(rect, IntroRect.m_sColor); } } } @@ -928,7 +916,7 @@ void CHud::Draw() CFont::SetCentreSize(SCREEN_SCALE_X(615.0f)); CFont::SetFontStyle(FONT_HEADING); - if (BigMessageX[0] >= (SCREEN_WIDTH - 20)) { + if (BigMessageX[0] >= SCREEN_SCALE_FROM_RIGHT(20.0f)) { BigMessageInUse[0] += CTimer::GetTimeStep(); if (BigMessageInUse[0] >= 120.0f) { @@ -945,7 +933,7 @@ void CHud::Draw() BigMessageX[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); BigMessageAlpha[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); - if (BigMessageAlpha[0] >= 255.0f) + if (BigMessageAlpha[0] > 255.0f) BigMessageAlpha[0] = 255.0f; } @@ -989,7 +977,7 @@ void CHud::Draw() CFont::SetFontStyle(FONT_HEADING); CFont::SetColor(CRGBA(0, 0, 0, BigMessageAlpha[2])); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f + 4.0f), SCREEN_SCALE_FROM_BOTTOM(78.0f), m_BigMessage[2]); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f - 4.0f), SCREEN_SCALE_FROM_BOTTOM(78.0f), m_BigMessage[2]); CFont::SetColor(CRGBA(170, 123, 87, BigMessageAlpha[2])); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(82.0f), m_BigMessage[2]); @@ -1018,7 +1006,7 @@ void CHud::DrawAfterFade() m_HelpMessageState = 2; m_HelpMessageTimer = 0; CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, 256); - m_HelpMessageDisplayTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; + m_fHelpMessageTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; if (TheCamera.m_ScreenReductionPercentage == 0.0f) DMAudio.PlayFrontEndSound(SOUND_A0, 0); @@ -1036,14 +1024,14 @@ void CHud::DrawAfterFade() CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, 256); } - float fAlpha = 255.0f; + float fAlpha = 225.0f; - if (m_HelpMessageState) { + if (m_HelpMessageState != 0) { switch (m_HelpMessageState) { case 1: - fAlpha = 255.0f; + fAlpha = 225.0f; m_HelpMessageFadeTimer = 600; - if (m_HelpMessageTimer > m_fHelpMessageTime * 1000 || m_HelpMessageQuick && m_HelpMessageTimer > 1500) { + if (m_HelpMessageTimer > m_fHelpMessageTime * 1000.0f || m_HelpMessageQuick && m_HelpMessageTimer > 1500.0f) { m_HelpMessageFadeTimer = 600; m_HelpMessageState = 3; } @@ -1054,24 +1042,24 @@ void CHud::DrawAfterFade() m_HelpMessageState = 1; m_HelpMessageFadeTimer = 0; } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 255.0f; + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; break; case 3: m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); - if (m_HelpMessageFadeTimer >= 0) { + if (m_HelpMessageFadeTimer < 0) { m_HelpMessageState = 0; m_HelpMessageFadeTimer = 0; } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 255.0f; + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; break; case 4: m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); - if (m_HelpMessageFadeTimer >= 0) { + if (m_HelpMessageFadeTimer < 0) { m_HelpMessageState = 2; m_HelpMessageFadeTimer = 0; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, 400); + CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, 256); } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 255.0f; + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; break; default: break; @@ -1088,19 +1076,75 @@ void CHud::DrawAfterFade() else CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); + CFont::SetColor(CRGBA(175, 175, 175, 255)); CFont::SetJustifyOff(); CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 26.0f - 4.0f)); CFont::SetFontStyle(FONT_BANK); CFont::SetBackgroundOn(); CFont::SetBackGroundOnlyTextOff(); - CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.8f)); - CFont::SetColor(CRGBA(175, 175, 175, 255)); + CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.9f)); CFont::PrintString(SCREEN_SCALE_X(26.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), CHud::m_HelpMessageToPrint); CFont::SetAlphaFade(255.0f); } } - else - m_HelpMessageState = 0; + + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { + intro_text_line &line = CTheScripts::IntroTextLines[i]; + if (line.m_Text[0] != '\0' && !line.m_bTextBeforeFade) { + CFont::SetScale(SCREEN_SCALE_X(line.m_fScaleX), SCREEN_SCALE_Y(line.m_fScaleY) / 2); + + CFont::SetColor(line.m_sColor); + if (line.m_bJustify) + CFont::SetJustifyOn(); + else + CFont::SetJustifyOff(); + + if (line.m_bRightJustify) + CFont::SetRightJustifyOn(); + else + CFont::SetRightJustifyOff(); + + if (line.m_bCentered) + CFont::SetCentreOn(); + else + CFont::SetCentreOff(); + + CFont::SetWrapx(SCREEN_SCALE_X(line.m_fWrapX)); + CFont::SetCentreSize(SCREEN_SCALE_X(line.m_fCenterSize)); + if (line.m_bBackground) + CFont::SetBackgroundOn(); + else + CFont::SetBackgroundOff(); + + CFont::SetBackgroundColor(line.m_sBackgroundColor); + if (line.m_bBackgroundOnly) + CFont::SetBackGroundOnlyTextOn(); + else + CFont::SetBackGroundOnlyTextOff(); + + if (line.m_bTextProportional) + CFont::SetPropOn(); + else + CFont::SetPropOff(); + + CFont::SetFontStyle(line.m_nFont); + CFont::PrintString(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH - line.m_fAtX), SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - line.m_fAtY), line.m_Text); + } + } + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { + intro_script_rectangle &rectangle = CTheScripts::IntroRectangles[i]; + if (rectangle.m_bIsUsed && !rectangle.m_bBeforeFade) { + + // Yeah, top and bottom changed place. R* vision + if (rectangle.m_nTextureId >= 0) { + CTheScripts::ScriptSprites[rectangle.m_nTextureId].Draw(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, + rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); + } else { + CSprite2d::DrawRect(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, + rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); + } + } + } /* DrawBigMessage2 @@ -1142,10 +1186,9 @@ void CHud::DrawAfterFade() if (OddJob2OffTimer > 0) OddJob2OffTimer -= CTimer::GetTimeStepInMilliseconds(); - static float fStep; + float fStep; if (m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) { - if (OddJob2On <= 3) { - switch (OddJob2On) { + switch (OddJob2On) { case 0: OddJob2On = 1; OddJob2XOffset = 380.0f; @@ -1156,9 +1199,7 @@ void CHud::DrawAfterFade() OddJob2On = 2; } else { - fStep = 40.0f; - if ((OddJob2XOffset / 6.0f) <= 40.0f) - fStep = OddJob2XOffset / 6.0f; + fStep = min(40.0f, OddJob2XOffset / 6.0f); OddJob2XOffset = OddJob2XOffset - fStep; } break; @@ -1169,9 +1210,7 @@ void CHud::DrawAfterFade() } break; case 3: - fStep = 30.0f; - if ((OddJob2XOffset / 5.0f) >= 30.0f) - fStep = OddJob2XOffset / 5.0f; + fStep = max(30.0f, OddJob2XOffset / 5.0f); OddJob2XOffset = OddJob2XOffset - fStep; @@ -1182,7 +1221,6 @@ void CHud::DrawAfterFade() break; default: break; - } } if (!m_BigMessage[1][0]) { @@ -1216,10 +1254,10 @@ void CHud::DrawAfterFade() CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f)); CFont::SetPropOn(); - CFont::SetRightJustifyWrap(-500.0f); + CFont::SetRightJustifyWrap(SCREEN_SCALE_X(-500.0f)); CFont::SetRightJustifyOn(); CFont::SetFontStyle(FONT_HEADING); - if (BigMessageX[1] >= (SCREEN_WIDTH - 20)) { + if (BigMessageX[1] >= SCREEN_SCALE_FROM_RIGHT(20.0f)) { BigMessageInUse[1] += CTimer::GetTimeStep(); if (BigMessageInUse[1] >= 120.0f) { @@ -1230,12 +1268,11 @@ void CHud::DrawAfterFade() m_BigMessage[1][0] = 0; BigMessageAlpha[1] = 0.0f; } - } - else { + } else { BigMessageX[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); BigMessageAlpha[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); - if (BigMessageAlpha[1] >= 255.0f) + if (BigMessageAlpha[1] > 255.0f) BigMessageAlpha[1] = 255.0f; } @@ -1273,7 +1310,7 @@ void CHud::GetRidOfAllHudMessages() m_HelpMessageFadeTimer = 0; m_HelpMessageState = 0; m_HelpMessageQuick = 0; - m_HelpMessageDisplayTime = 1.0f; + m_fHelpMessageTime = 1.0f; m_VehicleName = nil; m_pLastVehicleName = nil; m_pVehicleNameToPrint = nil; @@ -1303,7 +1340,7 @@ void CHud::Initialise() CTxdStore::PopCurrentTxd(); CTxdStore::SetCurrentTxd(HudTXD); - for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); i++) { + for (int i = 0; i < NUM_HUD_SPRITES; i++) { Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); } @@ -1314,14 +1351,14 @@ void CHud::Initialise() if (gpRocketSightTex == nil) gpRocketSightTex = RwTextureRead("siterocket", nil); - CounterOnLastFrame = 0; + CounterOnLastFrame = false; m_ItemToFlash = ITEM_NONE; OddJob2Timer = 0; OddJob2OffTimer = 0.0f; OddJob2On = 0; OddJob2XOffset = 0.0f; CounterFlashTimer = 0; - TimerOnLastFrame = 0; + TimerOnLastFrame = false; TimerFlashTimer = 0; SpriteBrightness = 0; PagerOn = 0; @@ -1338,14 +1375,14 @@ void CHud::ReInitialise() { GetRidOfAllHudMessages(); - CounterOnLastFrame = 0; + CounterOnLastFrame = false; m_ItemToFlash = ITEM_NONE; OddJob2Timer = 0; OddJob2OffTimer = 0.0f; OddJob2On = 0; OddJob2XOffset = 0.0f; CounterFlashTimer = 0; - TimerOnLastFrame = 0; + TimerOnLastFrame = false; TimerFlashTimer = 0; SpriteBrightness = 0; PagerOn = 0; @@ -1435,7 +1472,7 @@ void CHud::SetZoneName(wchar *name) void CHud::Shutdown() { - for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); ++i) { + for (int i = 0; i < NUM_HUD_SPRITES; ++i) { Sprites[i].Delete(); } diff --git a/src/render/Hud.h b/src/render/Hud.h index d3482ae6..701e47e2 100644 --- a/src/render/Hud.h +++ b/src/render/Hud.h @@ -27,59 +27,60 @@ enum eSprites HUD_RADARDISC = 15, HUD_PAGER = 16, HUD_SITESNIPER = 20, - HUD_SITEM16 = 21 + HUD_SITEM16, + HUD_SITEROCKET, + NUM_HUD_SPRITES, }; class CHud { public: - static CSprite2d *Sprites; - static int32 &SpriteBrightness; - static wchar *m_HelpMessage; - static wchar *m_LastHelpMessage; - static int32 &m_HelpMessageState; - static int32 &m_HelpMessageTimer; - static int32 &m_HelpMessageFadeTimer; - static wchar *m_HelpMessageToPrint; + static CSprite2d Sprites[NUM_HUD_SPRITES]; + static wchar m_HelpMessage[256]; + static wchar m_LastHelpMessage[256]; + static uint32 m_HelpMessageState; + static uint32 m_HelpMessageTimer; + static int32 m_HelpMessageFadeTimer; + static wchar m_HelpMessageToPrint[256]; static float &m_HelpMessageDisplayTime; - static float &m_fTextBoxNumLines; - static float &m_fHelpMessageTime; - static bool &m_HelpMessageQuick; - static int32 m_ZoneState; + static float m_fHelpMessageTime; + static bool m_HelpMessageQuick; + static uint32 m_ZoneState; static int32 m_ZoneFadeTimer; - static int32 m_ZoneNameTimer; - static wchar *&m_pZoneName; + static uint32 m_ZoneNameTimer; + static wchar *m_pZoneName; static wchar *m_pLastZoneName; static wchar *m_ZoneToPrint; - static wchar *&m_VehicleName; + static wchar *m_VehicleName; static wchar *m_pLastVehicleName; static wchar *m_pVehicleNameToPrint; - static int32 m_VehicleState; + static uint32 m_VehicleState; static int32 m_VehicleFadeTimer; - static int32 m_VehicleNameTimer; - static wchar *m_Message; - static wchar *m_PagerMessage; - static bool &m_Wants_To_Draw_Hud; - static bool &m_Wants_To_Draw_3dMarkers; - static wchar(&m_BigMessage)[6][128]; - static int16 &m_ItemToFlash; + static uint32 m_VehicleNameTimer; + static wchar m_Message[256]; + static wchar m_PagerMessage[256]; + static bool m_Wants_To_Draw_Hud; + static bool m_Wants_To_Draw_3dMarkers; + static wchar m_BigMessage[6][128]; + static int16 m_ItemToFlash; // These aren't really in CHud static float BigMessageInUse[6]; static float BigMessageAlpha[6]; static float BigMessageX[6]; - static float &OddJob2OffTimer; - static int8 &CounterOnLastFrame; - static float &OddJob2XOffset; - static int16 &CounterFlashTimer; - static int16 &OddJob2Timer; - static int8 &TimerOnLastFrame; - static int16 &OddJob2On; - static int16 &TimerFlashTimer; - static int16 &PagerSoundPlayed; - static float &PagerXOffset; - static int16 &PagerTimer; - static int16 &PagerOn; + static float OddJob2OffTimer; + static bool CounterOnLastFrame; + static float OddJob2XOffset; + static uint16 CounterFlashTimer; + static uint16 OddJob2Timer; + static bool TimerOnLastFrame; + static int16 OddJob2On; + static uint16 TimerFlashTimer; + static int16 PagerSoundPlayed; + static int32 SpriteBrightness; + static float PagerXOffset; + static int16 PagerTimer; + static int16 PagerOn; public: static void Draw(); diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp deleted file mode 100644 index cd83a898..00000000 --- a/src/render/Lights.cpp +++ /dev/null @@ -1,333 +0,0 @@ -#include "common.h" -#include <rwcore.h> -#include <rpworld.h> -#include "patcher.h" -#include "Lights.h" -#include "Timecycle.h" -#include "Coronas.h" -#include "Weather.h" -#include "ZoneCull.h" -#include "Frontend.h" - -RpLight *&pAmbient = *(RpLight**)0x885B6C; -RpLight *&pDirect = *(RpLight**)0x880F7C; -RpLight **pExtraDirectionals = (RpLight**)0x60009C; -int *LightStrengths = (int*)0x87BEF0; -int &NumExtraDirLightsInWorld = *(int*)0x64C608; - -RwRGBAReal &AmbientLightColourForFrame = *(RwRGBAReal*)0x6F46F8; -RwRGBAReal &AmbientLightColourForFrame_PedsCarsAndObjects = *(RwRGBAReal*)0x6F1D10; -RwRGBAReal &DirectionalLightColourForFrame = *(RwRGBAReal*)0x87C6B8; - -RwRGBAReal &AmbientLightColour = *(RwRGBAReal*)0x86B0F8; -RwRGBAReal &DirectionalLightColour = *(RwRGBAReal*)0x72E308; - -void -SetLightsWithTimeOfDayColour(RpWorld *) -{ - CVector vec1, vec2, vecsun; - RwMatrix mat; - - if(pAmbient){ - AmbientLightColourForFrame.red = CTimeCycle::GetAmbientRed() * CCoronas::LightsMult; - AmbientLightColourForFrame.green = CTimeCycle::GetAmbientGreen() * CCoronas::LightsMult; - AmbientLightColourForFrame.blue = CTimeCycle::GetAmbientBlue() * CCoronas::LightsMult; - if(CWeather::LightningFlash && !CCullZones::CamNoRain()){ - AmbientLightColourForFrame.red = 1.0f; - AmbientLightColourForFrame.green = 1.0f; - AmbientLightColourForFrame.blue = 1.0f; - } - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame.red*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame.green*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame.blue*1.3f); - RpLightSetColor(pAmbient, &AmbientLightColourForFrame); - } - - if(pDirect){ - DirectionalLightColourForFrame.red = CTimeCycle::GetDirectionalRed() * CCoronas::LightsMult; - DirectionalLightColourForFrame.green = CTimeCycle::GetDirectionalGreen() * CCoronas::LightsMult; - DirectionalLightColourForFrame.blue = CTimeCycle::GetDirectionalBlue() * CCoronas::LightsMult; - RpLightSetColor(pDirect, &DirectionalLightColourForFrame); - - vecsun = CTimeCycle::m_VectorToSun[CTimeCycle::m_CurrentStoredValue]; - vec1 = CVector(0.0f, 0.0f, 1.0f); - vec2 = CrossProduct(vec1, vecsun); - vec2.Normalise(); - vec1 = CrossProduct(vec2, vecsun); - mat.at.x = -vecsun.x; - mat.at.y = -vecsun.y; - mat.at.z = -vecsun.z; - mat.right.x = vec1.x; - mat.right.y = vec1.y; - mat.right.z = vec1.z; - mat.up.x = vec2.x; - mat.up.y = vec2.y; - mat.up.z = vec2.z; - RwFrameTransform(RpLightGetFrame(pDirect), &mat, rwCOMBINEREPLACE); - } - - if(CMenuManager::m_PrefsBrightness > 256){ - float f1 = 2.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - float f2 = 3.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - - AmbientLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f2); - AmbientLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f2); - AmbientLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f2); - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); -#ifdef FIX_BUGS - DirectionalLightColourForFrame.red = min(1.0f, DirectionalLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = min(1.0f, DirectionalLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = min(1.0f, DirectionalLightColourForFrame.blue * f1); -#else - DirectionalLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f1); -#endif - } -} - -RpWorld* -LightsCreate(RpWorld *world) -{ - int i; - RwRGBAReal color; - RwFrame *frame; - - if(world == nil) - return nil; - - pAmbient = RpLightCreate(rpLIGHTAMBIENT); - RpLightSetFlags(pAmbient, rpLIGHTLIGHTATOMICS); - color.red = 0.25f; - color.green = 0.25f; - color.blue = 0.2f; - RpLightSetColor(pAmbient, &color); - - pDirect = RpLightCreate(rpLIGHTDIRECTIONAL); - RpLightSetFlags(pDirect, rpLIGHTLIGHTATOMICS); - color.red = 1.0f; - color.green = 0.84f; - color.blue = 0.45f; - RpLightSetColor(pDirect, &color); - RpLightSetRadius(pDirect, 2.0f); - frame = RwFrameCreate(); - RpLightSetFrame(pDirect, frame); - RwV3d axis = { 1.0f, 1.0f, 0.0f }; - RwFrameRotate(frame, &axis, 160.0f, rwCOMBINEPRECONCAT); - - RpWorldAddLight(world, pAmbient); - RpWorldAddLight(world, pDirect); - - for(i = 0; i < NUMEXTRADIRECTIONALS; i++){ - pExtraDirectionals[i] = RpLightCreate(rpLIGHTDIRECTIONAL); - RpLightSetFlags(pExtraDirectionals[i], 0); - color.red = 1.0f; - color.green = 0.5f; - color.blue = 0.0f; - RpLightSetColor(pExtraDirectionals[i], &color); - RpLightSetRadius(pExtraDirectionals[i], 2.0f); - frame = RwFrameCreate(); - RpLightSetFrame(pExtraDirectionals[i], frame); - RpWorldAddLight(world, pExtraDirectionals[i]); - } - - return world; -} - -void -LightsDestroy(RpWorld *world) -{ - int i; - - if(world == nil) - return; - - if(pAmbient){ - RpWorldRemoveLight(world, pAmbient); - RpLightDestroy(pAmbient); - pAmbient = nil; - } - - if(pDirect){ - RpWorldRemoveLight(world, pDirect); - RwFrameDestroy(RpLightGetFrame(pDirect)); - RpLightDestroy(pDirect); - pDirect = nil; - } - - for(i = 0; i < NUMEXTRADIRECTIONALS; i++) - if(pExtraDirectionals[i]){ - RpWorldRemoveLight(world, pExtraDirectionals[i]); - RwFrameDestroy(RpLightGetFrame(pExtraDirectionals[i])); - RpLightDestroy(pExtraDirectionals[i]); - pExtraDirectionals[i] = nil; - } -} - -void -WorldReplaceNormalLightsWithScorched(RpWorld *world, float l) -{ - RwRGBAReal color; - color.red = l; - color.green = l; - color.blue = l; - RpLightSetColor(pAmbient, &color); - RpLightSetFlags(pDirect, 0); -} - -void -WorldReplaceScorchedLightsWithNormal(RpWorld *world) -{ - RpLightSetColor(pAmbient, &AmbientLightColourForFrame); - RpLightSetFlags(pDirect, rpLIGHTLIGHTATOMICS); -} - -void -AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, float red, float green, float blue) -{ - float strength; - int weakest; - int i, n; - RwRGBAReal color; - RwV3d *dir; - - strength = max(max(red, green), blue); - n = -1; - if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) - n = NumExtraDirLightsInWorld; - else{ - weakest = strength; - for(i = 0; i < NUMEXTRADIRECTIONALS; i++) - if(LightStrengths[i] < weakest){ - weakest = LightStrengths[i]; - n = i; - } - } - - if(n < 0) - return; - - color.red = red; - color.green = green; - color.blue = blue; - RpLightSetColor(pExtraDirectionals[n], &color); - dir = RwMatrixGetAt(RwFrameGetMatrix(RpLightGetFrame(pExtraDirectionals[n]))); - dir->x = -dirx; - dir->y = -diry; - dir->z = -dirz; - RwMatrixUpdate(RwFrameGetMatrix(RpLightGetFrame(pExtraDirectionals[n]))); - RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); - RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); - LightStrengths[n] = strength; - NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); -} - -void -RemoveExtraDirectionalLights(RpWorld *world) -{ - int i; - for(i = 0; i < NumExtraDirLightsInWorld; i++) - RpLightSetFlags(pExtraDirectionals[i], 0); - NumExtraDirLightsInWorld = 0; -} - -void -SetAmbientAndDirectionalColours(float f) -{ - AmbientLightColour.red = AmbientLightColourForFrame.red * f; - AmbientLightColour.green = AmbientLightColourForFrame.green * f; - AmbientLightColour.blue = AmbientLightColourForFrame.blue * f; - - DirectionalLightColour.red = DirectionalLightColourForFrame.red * f; - DirectionalLightColour.green = DirectionalLightColourForFrame.green * f; - DirectionalLightColour.blue = DirectionalLightColourForFrame.blue * f; - - RpLightSetColor(pAmbient, &AmbientLightColour); - RpLightSetColor(pDirect, &DirectionalLightColour); -} - -void -SetBrightMarkerColours(float f) -{ - AmbientLightColour.red = 0.6f; - AmbientLightColour.green = 0.6f; - AmbientLightColour.blue = 0.6f; - - DirectionalLightColour.red = (1.0f - DirectionalLightColourForFrame.red) * 0.4f + DirectionalLightColourForFrame.red; - DirectionalLightColour.green = (1.0f - DirectionalLightColourForFrame.green) * 0.4f + DirectionalLightColourForFrame.green; - DirectionalLightColour.blue = (1.0f - DirectionalLightColourForFrame.blue) * 0.4f + DirectionalLightColourForFrame.blue; - - RpLightSetColor(pAmbient, &AmbientLightColour); - RpLightSetColor(pDirect, &DirectionalLightColour); -} - -void -ReSetAmbientAndDirectionalColours(void) -{ - RpLightSetColor(pAmbient, &AmbientLightColourForFrame); - RpLightSetColor(pDirect, &DirectionalLightColourForFrame); -} - -void -DeActivateDirectional(void) -{ - RpLightSetFlags(pDirect, 0); -} - -void -ActivateDirectional(void) -{ - RpLightSetFlags(pDirect, rpLIGHTLIGHTATOMICS); -} - -void -SetAmbientColours(void) -{ - RpLightSetColor(pAmbient, &AmbientLightColourForFrame); -} - -void -SetAmbientColoursForPedsCarsAndObjects(void) -{ - RpLightSetColor(pAmbient, &AmbientLightColourForFrame_PedsCarsAndObjects); -} - -uint8 IndicateR[] = { 0, 255, 0, 0, 255, 255, 0 }; -uint8 IndicateG[] = { 0, 0, 255, 0, 255, 0, 255 }; -uint8 IndicateB[] = { 0, 0, 0, 255, 0, 255, 255 }; - -void -SetAmbientColoursToIndicateRoadGroup(int i) -{ - AmbientLightColour.red = IndicateR[i%7]/255.0f; - AmbientLightColour.green = IndicateG[i%7]/255.0f; - AmbientLightColour.blue = IndicateB[i%7]/255.0f; - RpLightSetColor(pAmbient, &AmbientLightColour); -} - -void -SetAmbientColours(RwRGBAReal *color) -{ - RpLightSetColor(pAmbient, color); -} - - -STARTPATCHES - InjectHook(0x526510, SetLightsWithTimeOfDayColour, PATCH_JUMP); - InjectHook(0x5269A0, LightsCreate, PATCH_JUMP); - InjectHook(0x526B40, LightsDestroy, PATCH_JUMP); - InjectHook(0x526C10, WorldReplaceNormalLightsWithScorched, PATCH_JUMP); - InjectHook(0x526C50, WorldReplaceScorchedLightsWithNormal, PATCH_JUMP); - InjectHook(0x526C70, AddAnExtraDirectionalLight, PATCH_JUMP); - InjectHook(0x526DB0, RemoveExtraDirectionalLights, PATCH_JUMP); - InjectHook(0x526DE0, SetAmbientAndDirectionalColours, PATCH_JUMP); - InjectHook(0x526E60, SetBrightMarkerColours, PATCH_JUMP); - InjectHook(0x526F10, ReSetAmbientAndDirectionalColours, PATCH_JUMP); - InjectHook(0x526F40, DeActivateDirectional, PATCH_JUMP); - InjectHook(0x526F50, ActivateDirectional, PATCH_JUMP); - InjectHook(0x526F60, (void (*)(void))SetAmbientColours, PATCH_JUMP); - InjectHook(0x526F80, SetAmbientColoursForPedsCarsAndObjects, PATCH_JUMP); - InjectHook(0x526FA0, (void (*)(RwRGBAReal*))SetAmbientColours, PATCH_JUMP); -ENDPATCHES diff --git a/src/render/Lights.h b/src/render/Lights.h deleted file mode 100644 index 6fdd51de..00000000 --- a/src/render/Lights.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -void SetLightsWithTimeOfDayColour(RpWorld *); -RpWorld *LightsCreate(RpWorld *world); -void LightsDestroy(RpWorld *world); -void WorldReplaceNormalLightsWithScorched(RpWorld *world, float l); -void WorldReplaceScorchedLightsWithNormal(RpWorld *world); -void AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, float red, float green, float blue); -void RemoveExtraDirectionalLights(RpWorld *world); -void SetAmbientAndDirectionalColours(float f); -void SetBrightMarkerColours(float f); -void ReSetAmbientAndDirectionalColours(void); -void DeActivateDirectional(void); -void ActivateDirectional(void); -void SetAmbientColours(void); -void SetAmbientColoursForPedsCarsAndObjects(void); -void SetAmbientColoursToIndicateRoadGroup(int i); -void SetAmbientColours(RwRGBAReal *color); diff --git a/src/render/VisibilityPlugins.cpp b/src/render/VisibilityPlugins.cpp deleted file mode 100644 index f8b1f6b2..00000000 --- a/src/render/VisibilityPlugins.cpp +++ /dev/null @@ -1,889 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "templates.h" -#include "Entity.h" -#include "ModelInfo.h" -#include "Lights.h" -#include "Renderer.h" -#include "Camera.h" -#include "VisibilityPlugins.h" -#include "World.h" - -#define FADE_DISTANCE 20.0f - -/* -CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList; -CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList; - -int32 CVisibilityPlugins::ms_atomicPluginOffset = -1; -int32 CVisibilityPlugins::ms_framePluginOffset = -1; -int32 CVisibilityPlugins::ms_clumpPluginOffset = -1; -*/ -CLinkList<CVisibilityPlugins::AlphaObjectInfo> &CVisibilityPlugins::m_alphaList = *(CLinkList<CVisibilityPlugins::AlphaObjectInfo>*)0x8F42E4; -CLinkList<CVisibilityPlugins::AlphaObjectInfo> &CVisibilityPlugins::m_alphaEntityList = *(CLinkList<CVisibilityPlugins::AlphaObjectInfo>*)0x943084; - -int32 &CVisibilityPlugins::ms_atomicPluginOffset = *(int32*)0x600124; -int32 &CVisibilityPlugins::ms_framePluginOffset = *(int32*)0x600128; -int32 &CVisibilityPlugins::ms_clumpPluginOffset = *(int32*)0x60012C; - -RwCamera *&CVisibilityPlugins::ms_pCamera = *(RwCamera**)0x8F2514; -RwV3d *&CVisibilityPlugins::ms_pCameraPosn = *(RwV3d**)0x8F6270; -float &CVisibilityPlugins::ms_cullCompsDist = *(float*)0x8F2BC4; -float &CVisibilityPlugins::ms_vehicleLod0Dist = *(float*)0x885B28; -float &CVisibilityPlugins::ms_vehicleLod1Dist = *(float*)0x885B30; -float &CVisibilityPlugins::ms_vehicleFadeDist = *(float*)0x8E28B4; -float &CVisibilityPlugins::ms_bigVehicleLod0Dist = *(float*)0x8E2A84; -float &CVisibilityPlugins::ms_bigVehicleLod1Dist = *(float*)0x8E2A8C; -float &CVisibilityPlugins::ms_pedLod0Dist = *(float*)0x8F2BD4; -float &CVisibilityPlugins::ms_pedLod1Dist = *(float*)0x8F2BD8; -float &CVisibilityPlugins::ms_pedFadeDist = *(float*)0x8E2C34; - -void -CVisibilityPlugins::Initialise(void) -{ - m_alphaList.Init(20); - m_alphaList.head.item.sort = 0.0f; - m_alphaList.tail.item.sort = 100000000.0f; - m_alphaEntityList.Init(150); - m_alphaEntityList.head.item.sort = 0.0f; - m_alphaEntityList.tail.item.sort = 100000000.0f; -} - -void -CVisibilityPlugins::Shutdown(void) -{ - m_alphaList.Shutdown(); - m_alphaEntityList.Shutdown(); -} - -void -CVisibilityPlugins::InitAlphaEntityList(void) -{ - m_alphaEntityList.Clear(); -} - -bool -CVisibilityPlugins::InsertEntityIntoSortedList(CEntity *e, float dist) -{ - AlphaObjectInfo item; - item.entity = e; - item.sort = dist; - bool ret = !!m_alphaEntityList.InsertSorted(item); -// if(!ret) -// printf("list full %d\n", m_alphaEntityList.Count()); - return ret; -} - -void -CVisibilityPlugins::InitAlphaAtomicList(void) -{ - m_alphaList.Clear(); -} - -bool -CVisibilityPlugins::InsertAtomicIntoSortedList(RpAtomic *a, float dist) -{ - AlphaObjectInfo item; - item.atomic = a; - item.sort = dist; - bool ret = !!m_alphaList.InsertSorted(item); -// if(!ret) -// printf("list full %d\n", m_alphaList.Count()); - return ret; -} - -void -CVisibilityPlugins::SetRenderWareCamera(RwCamera *camera) -{ - ms_pCamera = camera; - ms_pCameraPosn = RwMatrixGetPos(RwFrameGetMatrix(RwCameraGetFrame(camera))); - - if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED) - ms_cullCompsDist = 1000000.0f; - else - ms_cullCompsDist = sq(TheCamera.LODDistMultiplier * 20.0f); - - ms_vehicleLod0Dist = sq(70.0f * TheCamera.GenerationDistMultiplier); - ms_vehicleLod1Dist = sq(90.0f * TheCamera.GenerationDistMultiplier); - ms_vehicleFadeDist = sq(100.0f * TheCamera.GenerationDistMultiplier); - ms_bigVehicleLod0Dist = sq(60.0f * TheCamera.GenerationDistMultiplier); - ms_bigVehicleLod1Dist = sq(150.0f * TheCamera.GenerationDistMultiplier); - ms_pedLod0Dist = sq(25.0f * TheCamera.LODDistMultiplier); - ms_pedLod1Dist = sq(60.0f * TheCamera.LODDistMultiplier); - ms_pedFadeDist = sq(70.0f * TheCamera.LODDistMultiplier); -} - -RpMaterial* -SetAlphaCB(RpMaterial *material, void *data) -{ - ((RwRGBA*)RpMaterialGetColor(material))->alpha = (uint8)(uint32)data; - return material; -} - -RpMaterial* -SetTextureCB(RpMaterial *material, void *data) -{ - RpMaterialSetTexture(material, (RwTexture*)data); - return material; -} - -void -CVisibilityPlugins::RenderAlphaAtomics(void) -{ - CLink<AlphaObjectInfo> *node; - for(node = m_alphaList.tail.prev; - node != &m_alphaList.head; - node = node->prev) - AtomicDefaultRenderCallBack(node->item.atomic); -} - -void -CVisibilityPlugins::RenderFadingEntities(void) -{ - CLink<AlphaObjectInfo> *node; - CSimpleModelInfo *mi; - for(node = m_alphaEntityList.tail.prev; - node != &m_alphaEntityList.head; - node = node->prev){ - CEntity *e = node->item.entity; - if(e->m_rwObject == nil) - continue; - mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(e->m_modelIndex); - if(mi->m_noZwrite) - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - - if(e->bDistanceFade){ - DeActivateDirectional(); - SetAmbientColours(); - e->bImBeingRendered = true; - RenderFadingAtomic((RpAtomic*)e->m_rwObject, node->item.sort); - e->bImBeingRendered = false; - }else - CRenderer::RenderOneNonRoad(e); - - if(mi->m_noZwrite) - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - } -} - -RpAtomic* -CVisibilityPlugins::RenderWheelAtomicCB(RpAtomic *atomic) -{ - RpAtomic *lodatm; - RwMatrix *m; - RwV3d view; - float len; - CSimpleModelInfo *mi; - - mi = GetAtomicModelInfo(atomic); - m = RwFrameGetLTM(RpAtomicGetFrame(atomic)); - RwV3dSub(&view, RwMatrixGetPos(m), ms_pCameraPosn); - len = RwV3dLength(&view); - lodatm = mi->GetAtomicFromDistance(len); - if(lodatm){ - if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic)) - RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE); - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderObjNormalAtomic(RpAtomic *atomic) -{ - RwMatrix *m; - RwV3d view; - float len; - - m = RwFrameGetLTM(RpAtomicGetFrame(atomic)); - RwV3dSub(&view, RwMatrixGetPos(m), ms_pCameraPosn); - len = RwV3dLength(&view); - if(RwV3dDotProduct(&view, RwMatrixGetUp(m)) < -0.3f*len && len > 8.0f) - return atomic; - AtomicDefaultRenderCallBack(atomic); - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha) -{ - RpGeometry *geo; - uint32 flags; - - geo = RpAtomicGetGeometry(atomic); - flags = RpGeometryGetFlags(geo); - RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR); - RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha); - AtomicDefaultRenderCallBack(atomic); - RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255); - RpGeometrySetFlags(geo, flags); - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist) -{ - RpAtomic *lodatm; - float fadefactor; - uint8 alpha; - CSimpleModelInfo *mi; - - mi = GetAtomicModelInfo(atomic); - lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE); - if(mi->m_additive){ - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - AtomicDefaultRenderCallBack(atomic); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - }else{ - fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE; - if(fadefactor > 1.0f) - fadefactor = 1.0f; - alpha = mi->m_alpha * fadefactor; - if(alpha == 255) - AtomicDefaultRenderCallBack(atomic); - else{ - RpGeometry *geo = RpAtomicGetGeometry(lodatm); - uint32 flags = RpGeometryGetFlags(geo); - RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR); - RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha); - if(geo != RpAtomicGetGeometry(atomic)) - RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) - AtomicDefaultRenderCallBack(atomic); - RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255); - RpGeometrySetFlags(geo, flags); - } - } - return atomic; -} - - - -RpAtomic* -CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_vehicleLod0Dist){ - flags = GetAtomicId(atomic); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0){ - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) - return atomic; - } - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleHiDetailAlphaCB(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_vehicleLod0Dist){ - flags = GetAtomicId(atomic); - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0) - if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) - return atomic; - - if(flags & ATOMIC_FLAG_DRAWLAST){ - // sort before clump - if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f)) - AtomicDefaultRenderCallBack(atomic); - }else{ - if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) - AtomicDefaultRenderCallBack(atomic); - } - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_bigVehicleLod0Dist){ - flags = GetAtomicId(atomic); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0){ - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f) - return atomic; - } - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_bigVehicleLod0Dist){ - flags = GetAtomicId(atomic); - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f) - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0) - return atomic; - - if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_bigVehicleLod1Dist) - AtomicDefaultRenderCallBack(atomic); - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq >= ms_bigVehicleLod0Dist && - distsq < ms_bigVehicleLod1Dist){ - flags = GetAtomicId(atomic); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0){ - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f) - return atomic; - } - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq >= ms_bigVehicleLod0Dist && - distsq < ms_bigVehicleLod1Dist){ - flags = GetAtomicId(atomic); - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f) - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0) - return atomic; - - if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleReallyLowDetailCB(RpAtomic *atomic) -{ - RpClump *clump; - float dist; - int32 alpha; - - clump = RpAtomicGetClump(atomic); - dist = GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)); - if(dist >= ms_vehicleLod0Dist){ - alpha = GetClumpAlpha(clump); - if(alpha == 255) - AtomicDefaultRenderCallBack(atomic); - else - RenderAlphaAtomic(atomic, alpha); - } - return atomic; - -} - -RpAtomic* -CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq >= ms_bigVehicleLod1Dist) - AtomicDefaultRenderCallBack(atomic); - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderTrainHiDetailCB(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_bigVehicleLod1Dist){ - flags = GetAtomicId(atomic); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0){ - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) - return atomic; - } - AtomicDefaultRenderCallBack(atomic); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderTrainHiDetailAlphaCB(RpAtomic *atomic) -{ - RwFrame *clumpframe; - float distsq, dot; - uint32 flags; - - clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); - distsq = GetDistanceSquaredFromCamera(clumpframe); - if(distsq < ms_bigVehicleLod1Dist){ - flags = GetAtomicId(atomic); - dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)), - RwFrameGetLTM(clumpframe), flags); - if(distsq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0) - if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) - return atomic; - - if(flags & ATOMIC_FLAG_DRAWLAST){ - // sort before clump - if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f)) - AtomicDefaultRenderCallBack(atomic); - }else{ - if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) - AtomicDefaultRenderCallBack(atomic); - } - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic) -{ - if(CWorld::Players[0].m_pSkinTexture) - RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetTextureCB, CWorld::Players[0].m_pSkinTexture); - AtomicDefaultRenderCallBack(atomic); - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderPedLowDetailCB(RpAtomic *atomic) -{ - RpClump *clump; - float dist; - int32 alpha; - - clump = RpAtomicGetClump(atomic); - dist = GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)); - if(dist >= ms_pedLod0Dist){ - alpha = GetClumpAlpha(clump); - if(alpha == 255) - AtomicDefaultRenderCallBack(atomic); - else - RenderAlphaAtomic(atomic, alpha); - } - return atomic; -} - -RpAtomic* -CVisibilityPlugins::RenderPedHiDetailCB(RpAtomic *atomic) -{ - RpClump *clump; - float dist; - int32 alpha; - - clump = RpAtomicGetClump(atomic); - dist = GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)); - if(dist < ms_pedLod0Dist){ - alpha = GetClumpAlpha(clump); - if(alpha == 255) - AtomicDefaultRenderCallBack(atomic); - else - RenderAlphaAtomic(atomic, alpha); - } - return atomic; -} - -float -CVisibilityPlugins::GetDistanceSquaredFromCamera(RwFrame *frame) -{ - RwMatrix *m; - RwV3d dist; - m = RwFrameGetLTM(frame); - RwV3dSub(&dist, RwMatrixGetPos(m), ms_pCameraPosn); - return RwV3dDotProduct(&dist, &dist); -} - -float -CVisibilityPlugins::GetDotProductWithCameraVector(RwMatrix *atomicMat, RwMatrix *clumpMat, uint32 flags) -{ - RwV3d dist; - float dot, dotdoor; - - // Vehicle forward is the y axis (RwMatrix.up) - // Vehicle right is the x axis (RwMatrix.right) - - RwV3dSub(&dist, RwMatrixGetPos(atomicMat), ms_pCameraPosn); - // forward/backward facing - if(flags & (ATOMIC_FLAG_FRONT | ATOMIC_FLAG_REAR)) - dot = RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat)); - // left/right facing - else if(flags & (ATOMIC_FLAG_LEFT | ATOMIC_FLAG_RIGHT)) - dot = RwV3dDotProduct(&dist, RwMatrixGetRight(clumpMat)); - else - dot = 0.0f; - if(flags & (ATOMIC_FLAG_LEFT | ATOMIC_FLAG_REAR)) - dot = -dot; - - if(flags & (ATOMIC_FLAG_REARDOOR | ATOMIC_FLAG_FRONTDOOR)){ - if(flags & ATOMIC_FLAG_REARDOOR) - dotdoor = -RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat)); - else if(flags & ATOMIC_FLAG_FRONTDOOR) - dotdoor = RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat)); - else - dotdoor = 0.0f; - - if(dot < 0.0f && dotdoor < 0.0f) - dot += dotdoor; - if(dot > 0.0f && dotdoor > 0.0f) - dot += dotdoor; - } - - return dot; -} - -/* These are all unused */ - -bool -CVisibilityPlugins::DefaultVisibilityCB(RpClump *clump) -{ - return true; -} - -bool -CVisibilityPlugins::FrustumSphereCB(RpClump *clump) -{ - RwSphere sphere; - RwFrame *frame = RpClumpGetFrame(clump); - - CClumpModelInfo *modelInfo = (CClumpModelInfo*)GetFrameHierarchyId(frame); - sphere.radius = modelInfo->GetColModel()->boundingSphere.radius; - sphere.center.x = modelInfo->GetColModel()->boundingSphere.center.x; - sphere.center.y = modelInfo->GetColModel()->boundingSphere.center.y; - sphere.center.z = modelInfo->GetColModel()->boundingSphere.center.z; - RwV3dTransformPoints(&sphere.center, &sphere.center, 1, RwFrameGetLTM(frame)); - return RwCameraFrustumTestSphere(ms_pCamera, &sphere) != rwSPHEREOUTSIDE; -} - -bool -CVisibilityPlugins::VehicleVisibilityCB(RpClump *clump) -{ - if (GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)) <= ms_vehicleLod1Dist) - return FrustumSphereCB(clump); - return false; -} - -bool -CVisibilityPlugins::VehicleVisibilityCB_BigVehicle(RpClump *clump) -{ - return FrustumSphereCB(clump); -} - - - - -// -// RW Plugins -// - -enum -{ - ID_VISIBILITYATOMIC = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x00), - ID_VISIBILITYCLUMP = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x01), - ID_VISIBILITYFRAME = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x02), -}; - -bool -CVisibilityPlugins::PluginAttach(void) -{ - ms_atomicPluginOffset = RpAtomicRegisterPlugin(sizeof(AtomicExt), - ID_VISIBILITYATOMIC, - AtomicConstructor, AtomicDestructor, AtomicCopyConstructor); - - ms_framePluginOffset = RwFrameRegisterPlugin(sizeof(FrameExt), - ID_VISIBILITYFRAME, - FrameConstructor, FrameDestructor, FrameCopyConstructor); - - ms_clumpPluginOffset = RpClumpRegisterPlugin(sizeof(ClumpExt), - ID_VISIBILITYCLUMP, - ClumpConstructor, ClumpDestructor, ClumpCopyConstructor); - return ms_atomicPluginOffset != -1 && ms_clumpPluginOffset != -1; -} - -#define ATOMICEXT(o) (RWPLUGINOFFSET(AtomicExt, o, ms_atomicPluginOffset)) -#define FRAMEEXT(o) (RWPLUGINOFFSET(FrameExt, o, ms_framePluginOffset)) -#define CLUMPEXT(o) (RWPLUGINOFFSET(ClumpExt, o, ms_clumpPluginOffset)) - -// -// Atomic -// - -void* -CVisibilityPlugins::AtomicConstructor(void *object, int32, int32) -{ - ATOMICEXT(object)->modelInfo = nil; - return object; -} - -void* -CVisibilityPlugins::AtomicDestructor(void *object, int32, int32) -{ - return object; -} - -void* -CVisibilityPlugins::AtomicCopyConstructor(void *dst, const void *src, int32, int32) -{ - *ATOMICEXT(dst) = *ATOMICEXT(src); - return dst; -} - -void -CVisibilityPlugins::SetAtomicModelInfo(RpAtomic *atomic, - CSimpleModelInfo *modelInfo) -{ - AtomicExt *ext = ATOMICEXT(atomic); - ext->modelInfo = modelInfo; - switch(modelInfo->m_type) - case MITYPE_SIMPLE: - case MITYPE_TIME: - if(modelInfo->m_normalCull) - SetAtomicRenderCallback(atomic, RenderObjNormalAtomic); -} - -CSimpleModelInfo* -CVisibilityPlugins::GetAtomicModelInfo(RpAtomic *atomic) -{ - return ATOMICEXT(atomic)->modelInfo; -} - -void -CVisibilityPlugins::SetAtomicFlag(RpAtomic *atomic, int f) -{ - ATOMICEXT(atomic)->flags |= f; -} - -void -CVisibilityPlugins::ClearAtomicFlag(RpAtomic *atomic, int f) -{ - ATOMICEXT(atomic)->flags &= ~f; -} - -int -CVisibilityPlugins::GetAtomicId(RpAtomic *atomic) -{ - return ATOMICEXT(atomic)->flags; -} - -// This is rather useless, but whatever -void -CVisibilityPlugins::SetAtomicRenderCallback(RpAtomic *atomic, RpAtomicCallBackRender cb) -{ - if(cb == nil) - cb = AtomicDefaultRenderCallBack; // not necessary - RpAtomicSetRenderCallBack(atomic, cb); -} - -// -// Frame -// - -void* -CVisibilityPlugins::FrameConstructor(void *object, int32, int32) -{ - FRAMEEXT(object)->id = 0; - return object; -} - -void* -CVisibilityPlugins::FrameDestructor(void *object, int32, int32) -{ - return object; -} - -void* -CVisibilityPlugins::FrameCopyConstructor(void *dst, const void *src, int32, int32) -{ - *FRAMEEXT(dst) = *FRAMEEXT(src); - return dst; -} - -void -CVisibilityPlugins::SetFrameHierarchyId(RwFrame *frame, int32 id) -{ - FRAMEEXT(frame)->id = id; -} - -int32 -CVisibilityPlugins::GetFrameHierarchyId(RwFrame *frame) -{ - return FRAMEEXT(frame)->id; -} - - -// -// Clump -// - -void* -CVisibilityPlugins::ClumpConstructor(void *object, int32, int32) -{ - ClumpExt *ext = CLUMPEXT(object); - ext->visibilityCB = DefaultVisibilityCB; - ext->alpha = 0xFF; - return object; -} - -void* -CVisibilityPlugins::ClumpDestructor(void *object, int32, int32) -{ - return object; -} - -void* -CVisibilityPlugins::ClumpCopyConstructor(void *dst, const void *src, int32, int32) -{ - CLUMPEXT(dst)->visibilityCB = CLUMPEXT(src)->visibilityCB; - return dst; -} - -void -CVisibilityPlugins::SetClumpModelInfo(RpClump *clump, CClumpModelInfo *modelInfo) -{ - CVehicleModelInfo *vmi; - SetFrameHierarchyId(RpClumpGetFrame(clump), (int32)modelInfo); - - // Unused - switch(modelInfo->m_type){ - // ignore MLO - case MITYPE_VEHICLE: - vmi = (CVehicleModelInfo*)modelInfo; - if(vmi->m_vehicleType == VEHICLE_TYPE_TRAIN || - vmi->m_vehicleType == VEHICLE_TYPE_HELI || - vmi->m_vehicleType == VEHICLE_TYPE_PLANE) - CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB_BigVehicle; - else - CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB; - break; - } -} - -void -CVisibilityPlugins::SetClumpAlpha(RpClump *clump, int alpha) -{ - CLUMPEXT(clump)->alpha = alpha; -} - -int -CVisibilityPlugins::GetClumpAlpha(RpClump *clump) -{ - return CLUMPEXT(clump)->alpha; -} - - -STARTPATCHES - InjectHook(0x527E50, CVisibilityPlugins::Initialise, PATCH_JUMP); - InjectHook(0x527EA0, CVisibilityPlugins::Shutdown, PATCH_JUMP); - InjectHook(0x528F90, CVisibilityPlugins::InitAlphaEntityList, PATCH_JUMP); - InjectHook(0x528FF0, CVisibilityPlugins::InsertEntityIntoSortedList, PATCH_JUMP); - InjectHook(0x528F80, CVisibilityPlugins::InitAlphaAtomicList, PATCH_JUMP); - InjectHook(0x528FA0, CVisibilityPlugins::InsertAtomicIntoSortedList, PATCH_JUMP); - InjectHook(0x528C50, CVisibilityPlugins::SetRenderWareCamera, PATCH_JUMP); - - InjectHook(0x527F60, SetAlphaCB, PATCH_JUMP); - InjectHook(0x529040, CVisibilityPlugins::RenderAlphaAtomics, PATCH_JUMP); - InjectHook(0x529070, CVisibilityPlugins::RenderFadingEntities, PATCH_JUMP); - - InjectHook(0x527F70, CVisibilityPlugins::RenderWheelAtomicCB, PATCH_JUMP); - InjectHook(0x528000, CVisibilityPlugins::RenderObjNormalAtomic, PATCH_JUMP); - InjectHook(0x5280B0, CVisibilityPlugins::RenderAlphaAtomic, PATCH_JUMP); - InjectHook(0x528100, CVisibilityPlugins::RenderFadingAtomic, PATCH_JUMP); - - InjectHook(0x5283E0, CVisibilityPlugins::RenderVehicleHiDetailCB, PATCH_JUMP); - InjectHook(0x5284B0, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB, PATCH_JUMP); - InjectHook(0x5288A0, CVisibilityPlugins::RenderVehicleHiDetailCB_BigVehicle, PATCH_JUMP); - InjectHook(0x528A10, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle, PATCH_JUMP); - InjectHook(0x528AD0, CVisibilityPlugins::RenderVehicleHiDetailCB_Boat, PATCH_JUMP); - InjectHook(0x5287F0, CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle, PATCH_JUMP); - InjectHook(0x528940, CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle, PATCH_JUMP); - InjectHook(0x528240, CVisibilityPlugins::RenderVehicleReallyLowDetailCB, PATCH_JUMP); - InjectHook(0x5287B0, CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle, PATCH_JUMP); - InjectHook(0x5285D0, CVisibilityPlugins::RenderTrainHiDetailCB, PATCH_JUMP); - InjectHook(0x5286A0, CVisibilityPlugins::RenderTrainHiDetailAlphaCB, PATCH_JUMP); - - InjectHook(0x528BC0, CVisibilityPlugins::RenderPedHiDetailCB, PATCH_JUMP); - InjectHook(0x528B60, CVisibilityPlugins::RenderPedLowDetailCB, PATCH_JUMP); - - - InjectHook(0x527DC0, CVisibilityPlugins::PluginAttach, PATCH_JUMP); - - InjectHook(0x527EC0, CVisibilityPlugins::SetAtomicModelInfo, PATCH_JUMP); - InjectHook(0x527F00, CVisibilityPlugins::GetAtomicModelInfo, PATCH_JUMP); - InjectHook(0x527F10, CVisibilityPlugins::SetAtomicFlag, PATCH_JUMP); - InjectHook(0x527F30, CVisibilityPlugins::ClearAtomicFlag, PATCH_JUMP); - InjectHook(0x527F50, CVisibilityPlugins::GetAtomicId, PATCH_JUMP); - InjectHook(0x528C20, CVisibilityPlugins::SetAtomicRenderCallback, PATCH_JUMP); - - InjectHook(0x528D60, CVisibilityPlugins::SetFrameHierarchyId, PATCH_JUMP); - InjectHook(0x528D80, CVisibilityPlugins::GetFrameHierarchyId, PATCH_JUMP); - - InjectHook(0x528ED0, CVisibilityPlugins::SetClumpModelInfo, PATCH_JUMP); - InjectHook(0x528F50, CVisibilityPlugins::SetClumpAlpha, PATCH_JUMP); - InjectHook(0x528F70, CVisibilityPlugins::GetClumpAlpha, PATCH_JUMP); - - - InjectHook(0x529120, CVisibilityPlugins::GetDistanceSquaredFromCamera, PATCH_JUMP); - InjectHook(0x5282A0, CVisibilityPlugins::GetDotProductWithCameraVector, PATCH_JUMP); -ENDPATCHES diff --git a/src/render/VisibilityPlugins.h b/src/render/VisibilityPlugins.h deleted file mode 100644 index 65d2675a..00000000 --- a/src/render/VisibilityPlugins.h +++ /dev/null @@ -1,133 +0,0 @@ -#pragma once - -#include "templates.h" - -class CEntity; -class CSimpleModelInfo; -class CClumpModelInfo; - -typedef bool (*ClumpVisibilityCB)(RpClump*); - -class CVisibilityPlugins -{ -public: - struct AlphaObjectInfo - { - union { - CEntity *entity; - RpAtomic *atomic; - }; - float sort; - }; - - static CLinkList<AlphaObjectInfo> &m_alphaList; - static CLinkList<AlphaObjectInfo> &m_alphaEntityList; - static RwCamera *&ms_pCamera; - static RwV3d *&ms_pCameraPosn; - static float &ms_cullCompsDist; - static float &ms_vehicleLod0Dist; - static float &ms_vehicleLod1Dist; - static float &ms_vehicleFadeDist; - static float &ms_bigVehicleLod0Dist; - static float &ms_bigVehicleLod1Dist; - static float &ms_pedLod0Dist; - static float &ms_pedLod1Dist; - static float &ms_pedFadeDist; - - static void Initialise(void); - static void Shutdown(void); - static void InitAlphaEntityList(void); - static bool InsertEntityIntoSortedList(CEntity *e, float dist); - static void InitAlphaAtomicList(void); - static bool InsertAtomicIntoSortedList(RpAtomic *a, float dist); - - static void SetRenderWareCamera(RwCamera *camera); - - static RpAtomic *RenderWheelAtomicCB(RpAtomic *atomic); - static RpAtomic *RenderObjNormalAtomic(RpAtomic *atomic); - static RpAtomic *RenderAlphaAtomic(RpAtomic *atomic, int alpha); - static RpAtomic *RenderFadingAtomic(RpAtomic *atm, float dist); - - static RpAtomic *RenderVehicleHiDetailCB(RpAtomic *atomic); - static RpAtomic *RenderVehicleHiDetailAlphaCB(RpAtomic *atomic); - static RpAtomic *RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic); - static RpAtomic *RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic); - static RpAtomic *RenderVehicleHiDetailCB_Boat(RpAtomic *atomic); - static RpAtomic *RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic); - static RpAtomic *RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic); - static RpAtomic *RenderVehicleReallyLowDetailCB(RpAtomic *atomic); - static RpAtomic *RenderVehicleReallyLowDetailCB_BigVehicle(RpAtomic *atomic); - static RpAtomic *RenderTrainHiDetailCB(RpAtomic *atomic); - static RpAtomic *RenderTrainHiDetailAlphaCB(RpAtomic *atomic); - - static RpAtomic *RenderPlayerCB(RpAtomic *atomic); - static RpAtomic *RenderPedLowDetailCB(RpAtomic *atomic); - static RpAtomic *RenderPedHiDetailCB(RpAtomic *atomic); - - static void RenderAlphaAtomics(void); - static void RenderFadingEntities(void); - - // All actually unused - static bool DefaultVisibilityCB(RpClump *clump); - static bool FrustumSphereCB(RpClump *clump); -// static bool MloVisibilityCB(RpClump *clump); - static bool VehicleVisibilityCB(RpClump *clump); - static bool VehicleVisibilityCB_BigVehicle(RpClump *clump); - - static float GetDistanceSquaredFromCamera(RwFrame *frame); - static float GetDotProductWithCameraVector(RwMatrix *atomicMat, RwMatrix *clumpMat, uint32 flags); - - // - // RW Plugins - // - - union AtomicExt - { - CSimpleModelInfo *modelInfo; // used by SimpleModelInfo - int flags; // used by ClumpModelInfo - }; - static void SetAtomicModelInfo(RpAtomic*, CSimpleModelInfo*); - static CSimpleModelInfo *GetAtomicModelInfo(RpAtomic *atomic); - static void SetAtomicFlag(RpAtomic*, int); - static void ClearAtomicFlag(RpAtomic*, int); - static int GetAtomicId(RpAtomic *atomic); - static void SetAtomicRenderCallback(RpAtomic*, RpAtomicCallBackRender); - - static void *AtomicConstructor(void *object, int32 offset, int32 len); - static void *AtomicDestructor(void *object, int32 offset, int32 len); - static void *AtomicCopyConstructor(void *dst, const void *src, - int32 offset, int32 len); - static int32 &ms_atomicPluginOffset; - - struct FrameExt - { - // BUG: this is abused to hold a pointer by SetClumpModelInfo - int32 id; - }; - static void SetFrameHierarchyId(RwFrame *frame, int32 id); - static int32 GetFrameHierarchyId(RwFrame *frame); - - static void *FrameConstructor(void *object, int32 offset, int32 len); - static void *FrameDestructor(void *object, int32 offset, int32 len); - static void *FrameCopyConstructor(void *dst, const void *src, - int32 offset, int32 len); - static int32 &ms_framePluginOffset; - - // Not actually used - struct ClumpExt - { - ClumpVisibilityCB visibilityCB; - int alpha; - }; - static void SetClumpModelInfo(RpClump*, CClumpModelInfo*); - static void SetClumpAlpha(RpClump*, int); - static int GetClumpAlpha(RpClump*); - - static void *ClumpConstructor(void *object, int32 offset, int32 len); - static void *ClumpDestructor(void *object, int32 offset, int32 len); - static void *ClumpCopyConstructor(void *dst, const void *src, - int32 offset, int32 len); - static int32 &ms_clumpPluginOffset; - - static bool PluginAttach(void); -}; |