From ffed52b94f09b2cd1fbb40e8cc59d7684605e80d Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 10 Oct 2019 19:17:35 +0300 Subject: CMoneyMessages moved to SpecialFX.cpp --- src/control/Pickups.cpp | 2 +- src/render/MoneyMessages.cpp | 86 ------------------------------------------- src/render/MoneyMessages.h | 24 ------------ src/render/SpecialFX.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++- src/render/SpecialFX.h | 26 ++++++++++++- 5 files changed, 111 insertions(+), 114 deletions(-) delete mode 100644 src/render/MoneyMessages.cpp delete mode 100644 src/render/MoneyMessages.h diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 8a67e248..d77975e6 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -18,7 +18,7 @@ #include "Garages.h" #include "Explosion.h" #include "WaterLevel.h" -#include "MoneyMessages.h" +#include "SpecialFX.h" #include "PointLights.h" #include "Sprite.h" #include "Font.h" diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp deleted file mode 100644 index 53d6db58..00000000 --- a/src/render/MoneyMessages.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "MoneyMessages.h" -#include "Timer.h" -#include "Sprite.h" -#include "Font.h" -#include "Text.h" - -#define MONEY_MESSAGE_LIFETIME_MS 2000 - -CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES]; - -void -CMoneyMessage::Render() -{ - const float MAX_SCALE = 4.0f; - uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; - if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0; - else { - float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS; - RwV3d vecOut; - float fDistX, fDistY; - if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) { - fDistX *= (0.7 * fLifeTime + 2.0) * m_fSize; - fDistY *= (0.7 * fLifeTime + 2.0) * m_fSize; - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - - float fScaleY = fDistY / 100.0f; - if (fScaleY > MAX_SCALE) fScaleY = MAX_SCALE; - - float fScaleX = fDistX / 100.0f; - if (fScaleX > MAX_SCALE) fScaleX = MAX_SCALE; - - CFont::SetScale(fScaleX, fScaleY); // maybe use SCREEN_SCALE_X and SCREEN_SCALE_Y here? - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_WIDTH); - CFont::SetJustifyOff(); - CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity)); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_BANK); - CFont::PrintString(vecOut.x, vecOut.y, m_aText); - } - } -} - -void -CMoneyMessages::Init() -{ - for (int32 i = 0; i < NUMMONEYMESSAGES; i++) - aMoneyMessages[i].m_nTimeRegistered = 0; -} - -void -CMoneyMessages::Render() -{ - for (int32 i = 0; i < NUMMONEYMESSAGES; i++) { - if (aMoneyMessages[i].m_nTimeRegistered != 0) - aMoneyMessages[i].Render(); - } -} - -void -CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity) -{ - uint32 nIndex = 0; - while (aMoneyMessages[nIndex].m_nTimeRegistered != 0) { - if (++nIndex >= NUMMONEYMESSAGES) return; - } - - // Add data of this money message to the array - AsciiToUnicode(pText, aMoneyMessages[nIndex].m_aText); - - aMoneyMessages[nIndex].m_nTimeRegistered = CTimer::GetTimeInMilliseconds(); - aMoneyMessages[nIndex].m_vecPosition = vecPos; - aMoneyMessages[nIndex].m_Colour.red = bRed; - aMoneyMessages[nIndex].m_Colour.green = bGreen; - aMoneyMessages[nIndex].m_Colour.blue = bBlue; - aMoneyMessages[nIndex].m_fSize = fSize; - aMoneyMessages[nIndex].m_fOpacity = fOpacity; -} - -STARTPATCHES - InjectHook(0x51AF70, CMoneyMessages::Init, PATCH_JUMP); - InjectHook(0x51B030, CMoneyMessages::Render, PATCH_JUMP); -ENDPATCHES diff --git a/src/render/MoneyMessages.h b/src/render/MoneyMessages.h deleted file mode 100644 index f0a48a84..00000000 --- a/src/render/MoneyMessages.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -class CMoneyMessage -{ - friend class CMoneyMessages; - - uint32 m_nTimeRegistered; - CVector m_vecPosition; - wchar m_aText[16]; - CRGBA m_Colour; - float m_fSize; - float m_fOpacity; -public: - void Render(); -}; - -class CMoneyMessages -{ - static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES]; -public: - static void Init(); - static void Render(); - static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity); -}; \ No newline at end of file diff --git a/src/render/SpecialFX.cpp b/src/render/SpecialFX.cpp index bed5af50..44e1e029 100644 --- a/src/render/SpecialFX.cpp +++ b/src/render/SpecialFX.cpp @@ -1,6 +1,10 @@ #include "common.h" #include "patcher.h" #include "SpecialFX.h" +#include "Timer.h" +#include "Sprite.h" +#include "Font.h" +#include "Text.h" WRAPPER void CSpecialFX::Render(void) { EAXJMP(0x518DC0); } @@ -13,4 +17,85 @@ WRAPPER void CBulletTraces::Init(void) { EAXJMP(0x518DE0); } WRAPPER void CBrightLights::RegisterOne(CVector pos, CVector up, CVector right, CVector fwd, uint8 type, uint8 unk1, uint8 unk2, uint8 unk3) { EAXJMP(0x51A410); } -WRAPPER void C3dMarkers::PlaceMarkerSet(uint32 id, uint16 type, CVector& pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) { EAXJMP(0x51BB80); } \ No newline at end of file +WRAPPER void C3dMarkers::PlaceMarkerSet(uint32 id, uint16 type, CVector& pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) { EAXJMP(0x51BB80); } + + + +#define MONEY_MESSAGE_LIFETIME_MS 2000 + +CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES]; + +void +CMoneyMessage::Render() +{ + const float MAX_SCALE = 4.0f; + uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; + if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0; + else { + float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS; + RwV3d vecOut; + float fDistX, fDistY; + if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) { + fDistX *= (0.7 * fLifeTime + 2.0) * m_fSize; + fDistY *= (0.7 * fLifeTime + 2.0) * m_fSize; + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + + float fScaleY = fDistY / 100.0f; + if (fScaleY > MAX_SCALE) fScaleY = MAX_SCALE; + + float fScaleX = fDistX / 100.0f; + if (fScaleX > MAX_SCALE) fScaleX = MAX_SCALE; + + CFont::SetScale(fScaleX, fScaleY); // maybe use SCREEN_SCALE_X and SCREEN_SCALE_Y here? + CFont::SetCentreOn(); + CFont::SetCentreSize(SCREEN_WIDTH); + CFont::SetJustifyOff(); + CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity)); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetFontStyle(FONT_BANK); + CFont::PrintString(vecOut.x, vecOut.y, m_aText); + } + } +} + +void +CMoneyMessages::Init() +{ + for (int32 i = 0; i < NUMMONEYMESSAGES; i++) + aMoneyMessages[i].m_nTimeRegistered = 0; +} + +void +CMoneyMessages::Render() +{ + for (int32 i = 0; i < NUMMONEYMESSAGES; i++) { + if (aMoneyMessages[i].m_nTimeRegistered != 0) + aMoneyMessages[i].Render(); + } +} + +void +CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity) +{ + uint32 nIndex = 0; + while (aMoneyMessages[nIndex].m_nTimeRegistered != 0) { + if (++nIndex >= NUMMONEYMESSAGES) return; + } + + // Add data of this money message to the array + AsciiToUnicode(pText, aMoneyMessages[nIndex].m_aText); + + aMoneyMessages[nIndex].m_nTimeRegistered = CTimer::GetTimeInMilliseconds(); + aMoneyMessages[nIndex].m_vecPosition = vecPos; + aMoneyMessages[nIndex].m_Colour.red = bRed; + aMoneyMessages[nIndex].m_Colour.green = bGreen; + aMoneyMessages[nIndex].m_Colour.blue = bBlue; + aMoneyMessages[nIndex].m_fSize = fSize; + aMoneyMessages[nIndex].m_fOpacity = fOpacity; +} + +STARTPATCHES + InjectHook(0x51AF70, CMoneyMessages::Init, PATCH_JUMP); + InjectHook(0x51B030, CMoneyMessages::Render, PATCH_JUMP); +ENDPATCHES diff --git a/src/render/SpecialFX.h b/src/render/SpecialFX.h index 9c61c0fb..bdd74bee 100644 --- a/src/render/SpecialFX.h +++ b/src/render/SpecialFX.h @@ -39,5 +39,27 @@ class C3dMarkers { public: static void PlaceMarkerSet(uint32 id, uint16 type, CVector& pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); -}; - +}; + +class CMoneyMessage +{ + friend class CMoneyMessages; + + uint32 m_nTimeRegistered; + CVector m_vecPosition; + wchar m_aText[16]; + CRGBA m_Colour; + float m_fSize; + float m_fOpacity; +public: + void Render(); +}; + +class CMoneyMessages +{ + static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES]; +public: + static void Init(); + static void Render(); + static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity); +}; \ No newline at end of file -- cgit v1.2.3