From 678a19ce3bfa8264dbd151baff7cabddbd65d598 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 7 Jun 2020 04:11:10 +0300 Subject: [PATCH 1/9] a bit of fonts --- src/render/Font.cpp | 414 +++++++++++++++++++++++++++--------- src/render/Font.h | 40 +++- src/render/RenderBuffer.cpp | 3 +- src/render/RenderBuffer.h | 5 +- src/render/Sprite2d.cpp | 156 +++++++------- src/render/Sprite2d.h | 20 +- 6 files changed, 446 insertions(+), 192 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index ef665fae..781604e1 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -3,10 +3,12 @@ #include "Sprite2d.h" #include "TxdStore.h" #include "Font.h" +#include "Timer.h" CFontDetails CFont::Details; int16 CFont::NewLine; CSprite2d CFont::Sprite[MAX_FONTS]; +CFontRenderState CFont::RenderState; #ifdef MORE_LANGUAGES uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; @@ -16,55 +18,24 @@ int32 CFont::Slot = -1; int16 CFont::Size[LANGSET_MAX][MAX_FONTS][193] = { { #else -int16 CFont::Size[MAX_FONTS][193] = { +int16 CFont::Size[MAX_FONTS][210] = { #endif - { - 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31, - 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26, - 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25, - 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, - 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21, - 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35, - 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26, - 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22, - 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24, - 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 20 - }, - - { - 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33, - 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33, - 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25, - 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, - 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, - 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 16 - }, - - { - 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, - 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, - 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20, - 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39, - 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23, - 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37, - 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, - 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, - 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19 - } + { + 12, 9, 22, 17, 19, 19, 25, 4, 33, 33, 25, 35, 11, 10, 6, 33, 18, 10, 17, 17, 17, 17, 17, 15, 12, 16, 5, 30, 30, 30, 30, 30, 12, 16, 19, + 16, 19, 18, 18, 17, 22, 11, 17, 18, 18, 30, 22, 19, 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 19, 19, 12, 14, 11, 11, 16, 11, + 12, 14, 14, 10, 13, 12, 10, 19, 18, 12, 16, 13, 13, 11, 12, 15, 12, 15, 13, 12, 12, 37, 33, 37, 35, 37, 16, 16, 16, 16, 33, 17, 18, 18, 18, + 18, 11, 11, 11, 11, 19, 19, 19, 19, 19, 19, 19, 19, 15, 14, 14, 14, 14, 20, 14, 11, 11, 11, 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, + 15, 24, 18, 21, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 16 + }, + { + 15, 7, 31, 25, 20, 23, 21, 7, 11, 10, 26, 14, 6, 12, 6, 26, 20, 7, 20, 20, 21, 20, 20, 19, 21, 20, 8, 30, 24, 30, 24, 19, 20, 22, 22, 21, 22, 18, 18, 22, + 22, 9, 14, 21, 18, 27, 21, 24, 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 10, 19, 10, 17, 17, 16, 17, 17, 11, 17, 17, 7, 7, 18, 7, 25, 17, + 17, 17, 17, 11, 17, 11, 17, 18, 25, 19, 18, 17, 28, 26, 20, 15, 15, 20, 20, 20, 20, 29, 22, 19, 19, 19, 19, 9, 9, 9, 9, 23, 23, 23, 23, 24, 24, 24, 24, + 20, 19, 17, 17, 17, 30, 16, 17, 17, 17, 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 19, 20, 20, 20, 18, 19, 19, 21, 19, 19, 19, 19, 19, 16, 19, + 19, 19, 20, 19, 16, 19, 19, 9, 19, 20, 14, 29, 19, 19, 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 21, 10, 9, 10, 20 + } #ifdef MORE_LANGUAGES }, { @@ -198,6 +169,10 @@ wchar foreign_table[128] = { 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, }; + +void* FontRenderStatePointer; +uint8 FontRenderStateBuf[1024]; + void CFont::Initialise(void) { @@ -228,16 +203,14 @@ CFont::Initialise(void) CTxdStore::AddRef(slot); CTxdStore::PushCurrentTxd(); CTxdStore::SetCurrentTxd(slot); - Sprite[0].SetTexture("font2", "font2_mask"); + Sprite[0].SetTexture("font2", "font2m"); #ifdef MORE_LANGUAGES if (IsJapanese()) { Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); } - else #endif // MORE_LANGUAGES - Sprite[1].SetTexture("pager", "pager_mask"); - Sprite[2].SetTexture("font1", "font1_mask"); + Sprite[1].SetTexture("font1", "font1m"); SetScale(1.0f, 1.0f); SetSlantRefPoint(SCREEN_WIDTH, 0.0f); SetSlant(0.0f); @@ -305,7 +278,6 @@ CFont::Shutdown(void) { Sprite[0].Delete(); Sprite[1].Delete(); - Sprite[2].Delete(); #ifdef MORE_LANGUAGES if (IsJapanese()) Sprite[3].Delete(); @@ -319,9 +291,13 @@ CFont::Shutdown(void) void CFont::InitPerFrame(void) { - Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); - CSprite2d::GetBank(15, Sprite[1].m_pTexture); - CSprite2d::GetBank(15, Sprite[2].m_pTexture); + //Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); + //CSprite2d::GetBank(15, Sprite[1].m_pTexture); + //CSprite2d::GetBank(15, Sprite[2].m_pTexture); + + RenderState.FontStyle = -1; + Details.anonymous_25 = 0; + FontRenderStatePointer = FontRenderStateBuf; #ifdef MORE_LANGUAGES if (IsJapanese()) CSprite2d::GetBank(15, Sprite[3].m_pTexture); @@ -333,11 +309,15 @@ CFont::InitPerFrame(void) void CFont::PrintChar(float x, float y, wchar c) { + bool bDontPrint = false; if(x <= 0.0f || x > SCREEN_WIDTH || y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again return; + bDontPrint = c == '\0'; float w = GetCharacterWidth(c) / 32.0f; + if (Details.bFontHalfTexture && c == 208) + c = '\0'; float xoff = c % 16; float yoff = c / 16; #ifdef MORE_LANGUAGES @@ -348,28 +328,17 @@ CFont::PrintChar(float x, float y, wchar c) } #endif - if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ - if(Details.dropShadowPosition != 0){ - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), - y + SCREEN_SCALE_Y(Details.dropShadowPosition), - x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, - y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f), - Details.dropColor, - xoff/16.0f, yoff/12.8f, - (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, - xoff/16.0f, (yoff+1.0f)/12.8f, - (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.0001f); - } - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + if(Details.style == FONT_STANDART || Details.style == FONT_HEADING){ + if (bDontPrint) return; + CSprite2d::AddToBuffer( CRect(x, y, - x + 32.0f * Details.scaleX * 1.0f, - y + 40.0f * Details.scaleY * 0.5f), - Details.color, - xoff/16.0f, yoff/12.8f, - (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, - xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f, - (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f); + x + 32.0f * RenderState.fTextSizeX * w, + y + 32.0f * RenderState.fTextSizeX * 0.5f), + RenderState.color, + xoff/16.0f, yoff/16.0f, + (xoff+ w)/16.0f, yoff/ 16.0f, + xoff/16.0f, (yoff+1.0f)/ 16.0f, + (xoff+ w)/16.0f - 0.0001f, (yoff+1.0f)/ 16.0f - 0.0001f); #ifdef MORE_LANGUAGES }else if (IsJapaneseFont()) { if (Details.dropShadowPosition != 0) { @@ -394,16 +363,48 @@ CFont::PrintChar(float x, float y, wchar c) xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); #endif - }else - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x, y, - x + 32.0f * Details.scaleX * w, - y + 32.0f * Details.scaleY * 0.5f), - Details.color, - xoff/16.0f, yoff/16.0f, - (xoff+w)/16.0f, yoff/16.0f, - xoff/16.0f, (yoff+1.0f)/16.0f, - (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f); + } + else + { + if (bDontPrint) return; + if (RenderState.fSlant == 0.0f) + { + if (c < 193) + { + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.fTextSizeX * 1.0f, + y + 40.0f * RenderState.fTextSizeY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f + 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f + 0.0021f); + } + else + { + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.fTextSizeX * 1.0f, + y + 33.0f * RenderState.fTextSizeY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f - 0.017f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff+1.0f) / 12.8f - 0.017f); + } + } + else + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.fTextSizeX * 1.0f, + y + 40.0f * RenderState.fTextSizeY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f + 0.01f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f + 0.0021f + 0.01f); + } } #ifdef MORE_LANGUAGES @@ -807,17 +808,87 @@ CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) { wchar *s, c, unused; + if (RenderState.FontStyle != Details.style) + { + RenderFontBuffer(); + RenderState.FontStyle = Details.style; + } + + float v7 = CFont::Details.dropShadowPosition; + if (v7 != 0.0f && (CFont::Details.style == 0 || CFont::Details.style == 1)) + { + auto v8 = CFont::Details.color; + CFont::Details.color.r = CFont::Details.dropColor.r; + //v18 = v8; + CFont::Details.color.g = CFont::Details.dropColor.g; + CFont::Details.color.b = CFont::Details.dropColor.b; + CFont::Details.color.a = CFont::Details.dropColor.a; + CFont::Details.dropShadowPosition = 0; + CFont::Details.bIsShadow = true; + if (0.0f != CFont::Details.slant) + { + CFont::Details.slantRefX = (double)v7 + CFont::Details.slantRefX; + CFont::Details.slantRefY = (double)v7 + CFont::Details.slantRefY; + //CFont::PrintString(v7 + x, v7 + y, CFont::Details.anonymous_25, a4, a5, a6); + CFont::PrintString(v7 + x, v7 + y, start, end, spwidth); + CFont::Details.slantRefX = CFont::Details.slantRefX - (double)v7; + CFont::Details.slantRefY = CFont::Details.slantRefY - (double)v7; + } + else + { + //CFont::PrintString(v12, v11, CFont::Details.anonymous_25, a4, a5, a6); + CFont::PrintString(v7 + x, v7 + y, start, end, spwidth); + } + CFont::Details.color = v8; + CFont::Details.dropShadowPosition = v7; + CFont::Details.bIsShadow = 0; + } + if (FontRenderStatePointer >= (char*)&FontRenderStatePointer - 2 * (end - start + 26)) + CFont::RenderFontBuffer(); + CFontRenderState* v13 = (CFontRenderState*)FontRenderStatePointer; + v13->fTextPosX = x; + v13->fTextPosY = y; + v13->fTextSizeX = CFont::Details.scaleX; + v13->fTextSizeY = CFont::Details.scaleY; + v13->color.r = CFont::Details.color.r; + v13->color.g = CFont::Details.color.g; + v13->color.b = CFont::Details.color.b; + v13->color.a = CFont::Details.color.a; + v13->fExtraSpace = spwidth; + v13->fSlant = CFont::Details.slant; + v13->fSlantRefPointX = CFont::Details.slantRefX; + v13->fSlantRefPointY = CFont::Details.slantRefY; + v13->bFontHalfTexture = CFont::Details.bFontHalfTexture; + v13->bProp = CFont::Details.proportional; + v13->FontStyle = CFont::Details.style; + v13->bIsShadow = CFont::Details.bIsShadow; + FontRenderStatePointer = (char*)FontRenderStatePointer + 0x30; + for(s = start; s < end; s++){ - if(*s == '~') - s = ParseToken(s, &unused); - c = *s - ' '; + if (*s == '~') + { + for (auto i = ParseToken(s, &unused); s != i; FontRenderStatePointer = (char*)FontRenderStatePointer + 2) + { + *(wchar*)FontRenderStatePointer = *s; + } + } + else + { + *(wchar*)FontRenderStatePointer = *s; + FontRenderStatePointer = (char*)FontRenderStatePointer + 2; + } + /*c = *s - ' '; if(Details.slant != 0.0f) y = (Details.slantRefX - x)*Details.slant + Details.slantRefY; PrintChar(x, y, c); x += GetCharacterSize(c); if(c == 0) // space - x += spwidth; + x += spwidth;*/ } + *(wchar*)FontRenderStatePointer = 0; + FontRenderStatePointer = (char*)FontRenderStatePointer + 2; + if ((unsigned __int8)FontRenderStatePointer & 3) + FontRenderStatePointer = (char*)FontRenderStatePointer + 2; } #endif @@ -858,10 +929,12 @@ CFont::GetCharacterWidth(wchar c) else return Size[LanguageSet][Details.style][192]; #else + if (Details.bFontHalfTexture) + c = FindNewCharacter(c); if (Details.proportional) return Size[Details.style][c]; else - return Size[Details.style][192]; + return Size[Details.style][209]; #endif // MORE_LANGUAGES } @@ -873,7 +946,7 @@ CFont::GetCharacterSize(wchar c) if (IsJapanese()) { if (!Details.proportional) - return Size[0][Details.style][192] * Details.scaleX; + return Size[0][Details.style][209] * Details.scaleX; if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { switch (Details.style) { @@ -901,12 +974,14 @@ CFont::GetCharacterSize(wchar c) else if(Details.proportional) return Size[LanguageSet][Details.style][c] * Details.scaleX; else - return Size[LanguageSet][Details.style][192] * Details.scaleX; + return Size[LanguageSet][Details.style][209] * Details.scaleX; #else + if (Details.bFontHalfTexture) + c = FindNewCharacter(c); if (Details.proportional) return Size[Details.style][c] * Details.scaleX; else - return Size[Details.style][192] * Details.scaleX; + return Size[Details.style][209] * Details.scaleX; #endif // MORE_LANGUAGES } @@ -1064,13 +1139,148 @@ CFont::ParseToken(wchar *s, wchar*) void CFont::DrawFonts(void) { - CSprite2d::DrawBank(Details.bank); - CSprite2d::DrawBank(Details.bank+1); - CSprite2d::DrawBank(Details.bank+2); -#ifdef MORE_LANGUAGES - if (IsJapanese()) - CSprite2d::DrawBank(Details.bank+3); -#endif + RenderFontBuffer(); + //CSprite2d::DrawBank(Details.bank); + //CSprite2d::DrawBank(Details.bank+1); + //CSprite2d::DrawBank(Details.bank+2); +//#ifdef MORE_LANGUAGES +// if (IsJapanese()) +// CSprite2d::DrawBank(Details.bank+3); +//#endif +} + +void +CFont::RenderFontBuffer() +{ + int v0; // ebx + //wchar_t* v1; // esi + CFontRenderState* v2; // esi + char v3; // al + float v4; // ST04_4 + float v5; // ST04_4 + signed int v6; // eax + float v7; // [esp+Ch] [ebp-24h] + float v8; // [esp+10h] [ebp-20h] + CRGBA v9; // [esp+1Ch] [ebp-14h] + char v10; // [esp+22h] [ebp-Eh] + char v11; // [esp+23h] [ebp-Dh] + + if (FontRenderStatePointer != FontRenderStateBuf) { + v11 = 0; + v10 = 0; + Sprite[RenderState.FontStyle].SetRenderState(); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; + v7 = RenderState.fTextPosX; + v8 = RenderState.fTextPosY; + wchar* string = (wchar*)&FontRenderStateBuf[sizeof(CFontRenderState)]; + + if (string < FontRenderStatePointer) + { + do + { + if (string[0] == '\0') + { + v2 = (CFontRenderState*)((uintptr)string + sizeof(CFontRenderState)); + if ((uintptr)v2 & 3) + v2 = (CFontRenderState*)((uint8*)v2 + 2); + if (v2 >= FontRenderStatePointer) + break; + + RenderState = *v2; + + v7 = RenderState.fTextPosX; + v8 = RenderState.fTextPosY; + } + if (string[0] == '~') + { + //v1 = CFont::ParseToken(v1, &v9, (_BOOL1*)&v10, (_BOOL1*)&v11); + string = CFont::ParseToken(string, nil); + if (v10) + { + if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { + Details.bFlashState = !Details.bFlashState; + Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); + } + Details.color.alpha = Details.bFlashState ? 0 : 255; + } + if (!RenderState.bIsShadow) + RenderState.color = v9; + } + wchar v0 = string[0]; + //LOWORD(v0) = *v1; + v0 -= 32; + if (RenderState.bFontHalfTexture) + v0 = FindNewCharacter(v0); + else if (v0 > 155) + v0 = 0; + + if (RenderState.fSlant != 0.0f) + v8 = (RenderState.fSlantRefPointX - v7) * RenderState.fSlant + RenderState.fSlantRefPointY; + CFont::PrintChar(v7, v8, v0); + if (v11) { + CFont::PrintChar(v7 + 1.0f, v8, v0); + CFont::PrintChar(v7 + 2.0f, v8, v0); + v7 += 2.0f; + } + if (CFont::RenderState.bProp == true) + v6 = CFont::Size[RenderState.FontStyle][v0]; + else + v6 = CFont::Size[RenderState.FontStyle][209]; + v7 = CFont::RenderState.fTextSizeX * v6 + v7; + if (v0 == 0) + v7 += CFont::RenderState.fExtraSpace; + ++string; + } while (string < FontRenderStatePointer); + } + CSprite2d::RenderVertexBuffer(); + FontRenderStatePointer = FontRenderStateBuf; + } +} + + +void +CFont::SetFontStyle(int16 style) +{ + if (style == FONT_HEADING) + { + Details.style = FONT_BANK; + Details.bFontHalfTexture = true; + } + else + { + Details.style = style; + Details.bFontHalfTexture = false; + } +} + +wchar CFont::FindNewCharacter(wchar c) +{ + if (c >= 16 && c <= 26) + return 128; + if (c >= 8 && c <= 9) + return 86; + if (c == 4) + return 89; + if (c == 7) + return 206; + if (c == 14) + return 207; + if (c >= 33 && c <= 58) + return c + 122; + if (c >= 65 && c <= 90) + return c + 90; + if (c >= 96 && c <= 118) + return c + 85; + if (c >= 119 && c <= 140) + return c + 62; + if (c >= 141 && c <= 142) + return 204; + if (c == 143) + return 205; + if (c == 1) + return 208; + return c; } wchar diff --git a/src/render/Font.h b/src/render/Font.h index 48f5703d..7b7b91e5 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -14,22 +14,50 @@ struct CFontDetails bool background; bool backgroundOnlyText; bool proportional; + bool bIsShadow; + bool bFlash; + bool bBold; float alphaFade; CRGBA backgroundColor; float wrapX; float centreSize; float rightJustifyWrap; int16 style; - int32 bank; + bool bFontHalfTexture; + uint32 bank; int16 dropShadowPosition; CRGBA dropColor; + char bFlashState; + char anonymous_21; + int nFlashTimer; + char anonymous_23; + uint32 anonymous_25; +}; + +struct CFontRenderState +{ + uint32 anonymous_0; + float fTextPosX; + float fTextPosY; + float fTextSizeX; + float fTextSizeY; + CRGBA color; + float fExtraSpace; + float fSlant; + float fSlantRefPointX; + float fSlantRefPointY; + bool bIsShadow; + bool bFontHalfTexture; + bool bProp; + bool anonymous_14; + int16 FontStyle; }; class CSprite2d; enum { + FONT_STANDART, FONT_BANK, - FONT_PAGER, FONT_HEADING, #ifdef MORE_LANGUAGES FONT_JAPANESE, @@ -65,12 +93,13 @@ class CFont static uint8 LanguageSet; static int32 Slot; #else - static int16 Size[MAX_FONTS][193]; + static int16 Size[MAX_FONTS][210]; #endif static int16 NewLine; public: static CSprite2d Sprite[MAX_FONTS]; static CFontDetails Details; + static CFontRenderState RenderState; static void Initialise(void); static void Shutdown(void); @@ -97,6 +126,7 @@ public: static uint16 *ParseToken(wchar *s, wchar*); #endif static void DrawFonts(void); + static void RenderFontBuffer(void); static uint16 character_code(uint8 c); static CFontDetails GetDetails() { return Details; } @@ -155,14 +185,14 @@ public: static void SetBackGroundOnlyTextOff(void) { Details.backgroundOnlyText = false; } static void SetPropOn(void) { Details.proportional = true; } static void SetPropOff(void) { Details.proportional = false; } - static void SetFontStyle(int16 style) { Details.style = style; } + static void SetFontStyle(int16 style);// { Details.style = style; } static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; } static void SetAlphaFade(float fade) { Details.alphaFade = fade; } static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; } static void SetBackgroundColor(CRGBA col); static void SetColor(CRGBA col); static void SetDropColor(CRGBA col); - + static wchar FindNewCharacter(wchar c); #ifdef MORE_LANGUAGES static void ReloadFonts(uint8 set); diff --git a/src/render/RenderBuffer.cpp b/src/render/RenderBuffer.cpp index 6120dfe2..5239dc06 100644 --- a/src/render/RenderBuffer.cpp +++ b/src/render/RenderBuffer.cpp @@ -5,7 +5,8 @@ int32 TempBufferVerticesStored; int32 TempBufferIndicesStored; -RwIm3DVertex TempBufferRenderVertices[TEMPBUFFERVERTSIZE]; +RwIm2DVertex TempVertexBuffer[TEMPBUFFERVERTSIZE]; +RwIm3DVertex *TempBufferRenderVertices = (RwIm3DVertex * )TempVertexBuffer; RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; int RenderBuffer::VerticesToBeStored; diff --git a/src/render/RenderBuffer.h b/src/render/RenderBuffer.h index 485d24e3..e67a28d0 100644 --- a/src/render/RenderBuffer.h +++ b/src/render/RenderBuffer.h @@ -9,10 +9,11 @@ public: static void RenderStuffInBuffer(void); }; -#define TEMPBUFFERVERTSIZE 256 +#define TEMPBUFFERVERTSIZE 512 #define TEMPBUFFERINDEXSIZE 1024 extern int32 TempBufferVerticesStored; extern int32 TempBufferIndicesStored; -extern RwIm3DVertex TempBufferRenderVertices[TEMPBUFFERVERTSIZE]; +extern RwIm2DVertex TempVertexBuffer[TEMPBUFFERVERTSIZE]; +extern RwIm3DVertex *TempBufferRenderVertices; extern RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; \ No newline at end of file diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp index 2675c95f..d3d90964 100644 --- a/src/render/Sprite2d.cpp +++ b/src/render/Sprite2d.cpp @@ -5,13 +5,13 @@ #include "Camera.h" #include "Sprite2d.h" #include "Font.h" +#include "RenderBuffer.h" -RwIm2DVertex CSprite2d::maVertices[8]; float CSprite2d::RecipNearClip; -int32 CSprite2d::mCurrentBank; -int32 CSprite2d::mCurrentSprite[10]; -int32 CSprite2d::mBankStart[10]; -RwIm2DVertex CSprite2d::maBankVertices[500]; +float CSprite2d::NearScreenZ; +int CSprite2d::nextBufferVertex; +int CSprite2d::nextBufferIndex; +RwIm2DVertex CSprite2d::maVertices[8]; void CSprite2d::SetRecipNearClip(void) @@ -22,52 +22,11 @@ CSprite2d::SetRecipNearClip(void) void CSprite2d::InitPerFrame(void) { - int i; - + nextBufferVertex = 0; + nextBufferIndex = 0; RecipNearClip = 1.0f / RwCameraGetNearClipPlane(Scene.camera); - mCurrentBank = 0; - for(i = 0; i < 10; i++) - mCurrentSprite[i] = 0; + NearScreenZ = RwIm2DGetNearScreenZ(); } - -int32 -CSprite2d::GetBank(int32 n, RwTexture *tex) -{ - mCurrentSprite[mCurrentBank] = 0; - mBankStart[mCurrentBank+1] = mBankStart[mCurrentBank] + n; - return mCurrentBank++; -} - -void -CSprite2d::AddSpriteToBank(int32 bank, const CRect &rect, const CRGBA &col, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) -{ - SetVertices(&maBankVertices[6 * (mCurrentSprite[bank] + mBankStart[bank])], - rect, col, col, col, col, - u0, v0, u1, v1, u2, v2, u3, v3); - mCurrentSprite[bank]++; - if(mCurrentSprite[bank] + mBankStart[bank] >= mBankStart[bank+1]){ - DrawBank(bank); - mCurrentSprite[bank] = 0; - } -} - -void -CSprite2d::DrawBank(int32 bank) -{ - if(mCurrentSprite[bank] == 0) - return; - - // This is hacked III function to make it work with VC frontend. - CFont::Sprite[bank].SetRenderState(); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, &maBankVertices[6*mBankStart[bank]], 6*mCurrentSprite[bank]); - mCurrentSprite[bank] = 0; - //RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); -} - - void CSprite2d::Delete(void) { @@ -163,7 +122,7 @@ CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const C screenz = RwIm2DGetFarScreenZ(); z = RwCameraGetFarClipPlane(Scene.camera); }else{ - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; z = 1.0f/RecipNearClip; } recipz = 1.0f/z; @@ -215,7 +174,7 @@ CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const C { float screenz, z, recipz; - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; z = 1.0f/RecipNearClip; recipz = 1.0f/z; @@ -267,7 +226,7 @@ CSprite2d::SetVertices(float x1, float y1, float x2, float y2, float x3, float y float screenz, recipz; float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; recipz = RecipNearClip; RwIm2DVertexSetScreenX(&maVertices[0], x3); @@ -313,7 +272,7 @@ CSprite2d::SetVertices(int n, float *positions, float *uvs, const CRGBA &col) int i; float screenz, recipz, z; - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; recipz = RecipNearClip; z = RwCameraGetNearClipPlane(Scene.camera); // not done by game @@ -336,7 +295,7 @@ CSprite2d::SetMaskVertices(int n, float *positions) int i; float screenz, recipz, z; - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; recipz = RecipNearClip; z = RwCameraGetNearClipPlane(Scene.camera); // not done by game @@ -356,47 +315,47 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con { float screenz, recipz, z; - screenz = RwIm2DGetNearScreenZ(); + screenz = NearScreenZ; recipz = RecipNearClip; - z = RwCameraGetNearClipPlane(Scene.camera); // not done by game + //z = RwCameraGetNearClipPlane(Scene.camera); // not done by game RwIm2DVertexSetScreenX(&verts[0], r.left); RwIm2DVertexSetScreenY(&verts[0], r.top); RwIm2DVertexSetScreenZ(&verts[0], screenz); - RwIm2DVertexSetCameraZ(&verts[0], z); + //RwIm2DVertexSetCameraZ(&verts[0], z); RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); RwIm2DVertexSetU(&verts[0], u0, recipz); RwIm2DVertexSetV(&verts[0], v0, recipz); - RwIm2DVertexSetScreenX(&verts[1], r.left); - RwIm2DVertexSetScreenY(&verts[1], r.bottom); + RwIm2DVertexSetScreenX(&verts[1], r.right); + RwIm2DVertexSetScreenY(&verts[1], r.top); RwIm2DVertexSetScreenZ(&verts[1], screenz); - RwIm2DVertexSetCameraZ(&verts[1], z); + //RwIm2DVertexSetCameraZ(&verts[1], z); RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); - RwIm2DVertexSetIntRGBA(&verts[1], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&verts[1], u2, recipz); - RwIm2DVertexSetV(&verts[1], v2, recipz); + RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&verts[1], u1, recipz); + RwIm2DVertexSetV(&verts[1], v1, recipz); RwIm2DVertexSetScreenX(&verts[2], r.right); RwIm2DVertexSetScreenY(&verts[2], r.bottom); RwIm2DVertexSetScreenZ(&verts[2], screenz); - RwIm2DVertexSetCameraZ(&verts[2], z); + //RwIm2DVertexSetCameraZ(&verts[2], z); RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[2], u3, recipz); - RwIm2DVertexSetV(&verts[2], v3, recipz); + RwIm2DVertexSetU(&verts[2], u2, recipz); + RwIm2DVertexSetV(&verts[2], v2, recipz); RwIm2DVertexSetScreenX(&verts[3], r.left); - RwIm2DVertexSetScreenY(&verts[3], r.top); + RwIm2DVertexSetScreenY(&verts[3], r.bottom); RwIm2DVertexSetScreenZ(&verts[3], screenz); - RwIm2DVertexSetCameraZ(&verts[3], z); + //RwIm2DVertexSetCameraZ(&verts[3], z); RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); - RwIm2DVertexSetIntRGBA(&verts[3], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[3], u0, recipz); - RwIm2DVertexSetV(&verts[3], v0, recipz); + RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&verts[3], u3, recipz); + RwIm2DVertexSetV(&verts[3], v3, recipz); - RwIm2DVertexSetScreenX(&verts[4], r.right); + /*RwIm2DVertexSetScreenX(&verts[4], r.right); RwIm2DVertexSetScreenY(&verts[4], r.bottom); RwIm2DVertexSetScreenZ(&verts[4], screenz); RwIm2DVertexSetCameraZ(&verts[4], z); @@ -412,7 +371,7 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); RwIm2DVertexSetIntRGBA(&verts[5], c3.r, c3.g, c3.b, c3.a); RwIm2DVertexSetU(&verts[5], u1, recipz); - RwIm2DVertexSetV(&verts[5], v1, recipz); + RwIm2DVertexSetV(&verts[5], v1, recipz);*/ } @@ -488,3 +447,54 @@ void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); } + +void +CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10) +{ + RwIm2DVertex* v = TempVertexBuffer; + SetVertices( + &v[nextBufferVertex], + r, + c, + c, + c, + c, + a3, + a4, + a5, + a6, + a7, + a8, + a9, + a10); + RwImVertexIndex *v12 = &TempBufferRenderIndexList[nextBufferIndex]; + v12[0] = nextBufferVertex; + v12[1] = nextBufferVertex + 1; + v12[2] = nextBufferVertex + 2; + v12[3] = nextBufferVertex + 3; + v12[4] = nextBufferVertex; + v12[5] = nextBufferVertex + 2; + nextBufferIndex += 6; + nextBufferVertex += 4; + if (IsVertexBufferFull()) + RenderVertexBuffer(); +} + +bool CSprite2d::IsVertexBufferFull() +{ + bool result = true; + if (nextBufferVertex <= 380 && nextBufferIndex <= 1018) + result = false; + return result; +} + +void +CSprite2d::RenderVertexBuffer() +{ + if (nextBufferVertex > 0) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex); + nextBufferVertex = 0; + nextBufferIndex = 0; + } +} \ No newline at end of file diff --git a/src/render/Sprite2d.h b/src/render/Sprite2d.h index 04b40591..679ac496 100644 --- a/src/render/Sprite2d.h +++ b/src/render/Sprite2d.h @@ -3,21 +3,19 @@ class CSprite2d { static float RecipNearClip; - static int32 mCurrentBank; - static RwTexture *mpBankTextures[10]; - static int32 mCurrentSprite[10]; - static int32 mBankStart[10]; - static RwIm2DVertex maBankVertices[500]; + static float NearScreenZ; + static int nextBufferVertex; + static int nextBufferIndex; static RwIm2DVertex maVertices[8]; public: RwTexture *m_pTexture; static void SetRecipNearClip(void); static void InitPerFrame(void); - static int32 GetBank(int32 n, RwTexture *tex); - static void AddSpriteToBank(int32 bank, const CRect &rect, const CRGBA &col, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); - static void DrawBank(int32 bank); + //static int32 GetBank(int32 n, RwTexture *tex); + //static void AddSpriteToBank(int32 bank, const CRect &rect, const CRGBA &col, + // float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); + //static void DrawBank(int32 bank); CSprite2d(void) : m_pTexture(nil) {}; ~CSprite2d(void) { Delete(); }; @@ -52,4 +50,8 @@ public: static void Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color); static RwIm2DVertex* GetVertices() { return maVertices; }; + + static bool IsVertexBufferFull(); + static void AddToBuffer(const CRect &a1, const CRGBA &a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10); + static void RenderVertexBuffer(); }; -- 2.45.2 From fc7e35e1cde94938f72a89c33907668fad0c80d3 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 7 Jun 2020 04:20:02 +0300 Subject: [PATCH 2/9] fixes --- src/render/Font.cpp | 10 +++------- src/render/Font.h | 2 +- src/render/Hud.cpp | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 781604e1..9b478e90 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -328,7 +328,7 @@ CFont::PrintChar(float x, float y, wchar c) } #endif - if(Details.style == FONT_STANDART || Details.style == FONT_HEADING){ + if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ if (bDontPrint) return; CSprite2d::AddToBuffer( CRect(x, y, @@ -818,11 +818,7 @@ CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) if (v7 != 0.0f && (CFont::Details.style == 0 || CFont::Details.style == 1)) { auto v8 = CFont::Details.color; - CFont::Details.color.r = CFont::Details.dropColor.r; - //v18 = v8; - CFont::Details.color.g = CFont::Details.dropColor.g; - CFont::Details.color.b = CFont::Details.dropColor.b; - CFont::Details.color.a = CFont::Details.dropColor.a; + CFont::Details.color = CFont::Details.dropColor; CFont::Details.dropShadowPosition = 0; CFont::Details.bIsShadow = true; if (0.0f != CFont::Details.slant) @@ -1244,7 +1240,7 @@ CFont::SetFontStyle(int16 style) { if (style == FONT_HEADING) { - Details.style = FONT_BANK; + Details.style = FONT_STANDARD; Details.bFontHalfTexture = true; } else diff --git a/src/render/Font.h b/src/render/Font.h index 7b7b91e5..e08d800c 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -56,8 +56,8 @@ struct CFontRenderState class CSprite2d; enum { - FONT_STANDART, FONT_BANK, + FONT_STANDARD, FONT_HEADING, #ifdef MORE_LANGUAGES FONT_JAPANESE, diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index dc425a15..5b31bbdc 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -904,7 +904,7 @@ void CHud::Draw() CFont::SetCentreOff(); CFont::SetJustifyOff(); CFont::SetPropOff(); - CFont::SetFontStyle(FONT_PAGER); + CFont::SetFontStyle(FONT_STANDARD); CFont::PrintString(SCREEN_SCALE_X(52.0f - PagerXOffset), SCREEN_SCALE_Y(54.0f), m_PagerMessage); } -- 2.45.2 From 91e2b427efa3cdf2dedb9a79624e9897a1d5c191 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 7 Jun 2020 05:12:01 +0300 Subject: [PATCH 3/9] more font stuff --- src/render/Font.cpp | 167 ++++++++++++++++++++++++++++++++++++-------- src/render/Font.h | 5 +- src/render/Hud.cpp | 2 +- 3 files changed, 143 insertions(+), 31 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 9b478e90..bc6d925e 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -863,10 +863,23 @@ CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) for(s = start; s < end; s++){ if (*s == '~') { - for (auto i = ParseToken(s, &unused); s != i; FontRenderStatePointer = (char*)FontRenderStatePointer + 2) + for (auto i = ParseToken(s); s != i; FontRenderStatePointer = (char*)FontRenderStatePointer + 2) { + s = i; *(wchar*)FontRenderStatePointer = *s; } + if (CFont::Details.bFlash) + { + if (CTimer::GetTimeInMilliseconds() - CFont::Details.nFlashTimer > 300) + { + Details.bFlashState = !Details.bFlashState; + Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); + } + if (Details.bFlashState) + Details.color.a = 0; + else + Details.color.a = 255; + } } else { @@ -1079,7 +1092,7 @@ CFont::GetNextSpace(wchar *s) #ifdef MORE_LANGUAGES wchar* -CFont::ParseToken(wchar *s, wchar*, bool japShit) +CFont::ParseToken(wchar *s, bool japShit) { s++; if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { @@ -1109,40 +1122,138 @@ CFont::ParseToken(wchar *s, wchar*, bool japShit) } #else wchar* -CFont::ParseToken(wchar *s, wchar*) +CFont::ParseToken(wchar *s) { + Details.anonymous_23 = 0; s++; if(Details.color.r || Details.color.g || Details.color.b) switch(*s){ + case 'B': + Details.bBold = !Details.bBold; case 'N': case 'n': NewLine = 1; break; - case 'b': SetColor(CRGBA(0x80, 0xA7, 0xF3, 0xFF)); break; - case 'g': SetColor(CRGBA(0x5F, 0xA0, 0x6A, 0xFF)); break; - case 'h': SetColor(CRGBA(0xE1, 0xE1, 0xE1, 0xFF)); break; - case 'l': SetColor(CRGBA(0x00, 0x00, 0x00, 0xFF)); break; - case 'p': SetColor(CRGBA(0xA8, 0x6E, 0xFC, 0xFF)); break; - case 'r': SetColor(CRGBA(0x71, 0x2B, 0x49, 0xFF)); break; - case 'w': SetColor(CRGBA(0xAF, 0xAF, 0xAF, 0xFF)); break; - case 'y': SetColor(CRGBA(0xD2, 0xC4, 0x6A, 0xFF)); break; + case 'b': SetColor(CRGBA(27, 89, 130, 255)); Details.anonymous_23 = 1; break; + case 'f': + Details.bFlash = !Details.bFlash; + if (Details.bFlash) + Details.color.a = 255; + break; + case 'g': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = 1; break; + case 'h': SetColor(CRGBA(225, 225, 225, 255)); Details.anonymous_23 = 1; break; + case 'l': SetColor(CRGBA(0, 0, 0, 255)); Details.anonymous_23 = 1; break; + case 'o': SetColor(CRGBA(229, 125, 126, 255)); Details.anonymous_23 = 1; break; + case 'p': SetColor(CRGBA(168, 110, 252, 255)); Details.anonymous_23 = 1; break; + case 'q': SetColor(CRGBA(199, 144, 203, 255)); Details.anonymous_23 = 1; break; + case 'r': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = 1; break; + case 't': SetColor(CRGBA(86, 212, 146, 255)); Details.anonymous_23 = 1; break; + case 'w': SetColor(CRGBA(175, 175, 175, 255)); Details.anonymous_23 = 1; break; + case 'x': SetColor(CRGBA(132, 146, 197, 255)); Details.anonymous_23 = 1; break; + case 'y': SetColor(CRGBA(255, 227, 79, 255)); Details.anonymous_23 = 1; break; } while(*s != '~') s++; - return s+1; + s++; + if (*s == '~') + s = ParseToken(s); + return s; } #endif +wchar* +CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) +{ + wchar* v4; // eax + wchar* result; // eax + + Details.anonymous_23 = 0; + v4 = str + 1; + if (Details.color.r || Details.color.g || Details.color.b) + { + switch (*v4) + { + case 'B': + bold = !bold; + break; + case 'b': + color.r = 27; + color.g = 89; + color.b = 130; + break; + case 'f': + flash = !flash; + break; + case 'g': + color.r = 255; + color.g = 150; + color.b = 225; + break; + case 'h': + color.r = 225; + color.g = 225; + color.b = 225; + break; + case 'l': + color.r = 0; + color.g = 0; + color.b = 0; + break; + case 'o': + color.r = 229; + color.g = 125; + color.b = 126; + break; + case 'p': + color.r = 168; + color.g = 110; + color.b = 252; + break; + case 'q': + color.r = 199; + color.g = 144; + color.b = 203; + break; + case 'r': + color.r = 255; + color.g = 150; + color.b = 225; + break; + case 't': + color.r = 86; + color.g = 212; + color.b = 146; + break; + case 'w': + color.r = 175; + color.g = 175; + color.b = 175; + break; + case 'x': + color.r = 132; + color.g = 146; + color.b = 197; + break; + case 'y': + color.r = 255; + color.g = 227; + color.b = 79; + break; + default: + break; + } + } + while (*v4 != '~') + ++v4; + result = v4 + 1; + if (*result == '~') + result = CFont::ParseToken(result, color, flash, bold); + return result; +} + void CFont::DrawFonts(void) { RenderFontBuffer(); - //CSprite2d::DrawBank(Details.bank); - //CSprite2d::DrawBank(Details.bank+1); - //CSprite2d::DrawBank(Details.bank+2); -//#ifdef MORE_LANGUAGES -// if (IsJapanese()) -// CSprite2d::DrawBank(Details.bank+3); -//#endif } void @@ -1158,12 +1269,12 @@ CFont::RenderFontBuffer() float v7; // [esp+Ch] [ebp-24h] float v8; // [esp+10h] [ebp-20h] CRGBA v9; // [esp+1Ch] [ebp-14h] - char v10; // [esp+22h] [ebp-Eh] - char v11; // [esp+23h] [ebp-Dh] + bool v10; // [esp+22h] [ebp-Eh] + bool v11; // [esp+23h] [ebp-Dh] if (FontRenderStatePointer != FontRenderStateBuf) { - v11 = 0; - v10 = 0; + v11 = false; + v10 = false; Sprite[RenderState.FontStyle].SetRenderState(); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; @@ -1190,8 +1301,8 @@ CFont::RenderFontBuffer() } if (string[0] == '~') { - //v1 = CFont::ParseToken(v1, &v9, (_BOOL1*)&v10, (_BOOL1*)&v11); - string = CFont::ParseToken(string, nil); + string = CFont::ParseToken(string, v9, v10, v11); + //string = CFont::ParseToken(string); if (v10) { if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { @@ -1253,11 +1364,11 @@ CFont::SetFontStyle(int16 style) wchar CFont::FindNewCharacter(wchar c) { if (c >= 16 && c <= 26) - return 128; + return c + 128; if (c >= 8 && c <= 9) - return 86; + return c + 86; if (c == 4) - return 89; + return c + 89; if (c == 7) return 206; if (c == 14) diff --git a/src/render/Font.h b/src/render/Font.h index e08d800c..f4c63c21 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -121,9 +121,10 @@ public: #endif static uint16 *GetNextSpace(wchar *s); #ifdef MORE_LANGUAGES - static uint16 *ParseToken(wchar *s, wchar*, bool japShit = false); + static uint16 *ParseToken(wchar *s, bool japShit = false); #else - static uint16 *ParseToken(wchar *s, wchar*); + static uint16 *ParseToken(wchar *s); + static uint16* ParseToken(wchar *s, CRGBA &color, bool &flash, bool &bold); #endif static void DrawFonts(void); static void RenderFontBuffer(void); diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 5b31bbdc..350daff8 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -609,7 +609,7 @@ void CHud::Draw() CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_STANDARD); + CFont::SetFontStyle(FONT_BANK); CFont::SetColor(CRGBA(0, 0, 0, fZoneAlpha)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f) + SCREEN_SCALE_X(1.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f) + SCREEN_SCALE_Y(1.0f), m_ZoneToPrint); -- 2.45.2 From a44510d1dffde934bef366a7d570cd09962f1b2a Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 7 Jun 2020 10:36:37 +0300 Subject: [PATCH 4/9] more font --- src/audio/MusicManager.cpp | 2 +- src/render/Font.cpp | 492 ++++++++++++++++--------------------- src/render/Font.h | 23 +- src/render/Hud.cpp | 38 +-- src/render/Sprite2d.cpp | 29 +-- 5 files changed, 254 insertions(+), 330 deletions(-) diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index 940f41ce..f125bed2 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -160,7 +160,7 @@ cMusicManager::DisplayRadioStationName() CFont::SetBackgroundOff(); CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f)); CFont::SetPropOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONT_STANDARD); CFont::SetCentreOn(); CFont::SetCentreSize(SCREEN_SCALE_X(640.0f)); CFont::SetColor(CRGBA(0, 0, 0, 255)); diff --git a/src/render/Font.cpp b/src/render/Font.cpp index bc6d925e..99d63ea4 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -15,7 +15,7 @@ uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; int32 CFont::Slot = -1; #define JAP_TERMINATION (0x8000 | '~') -int16 CFont::Size[LANGSET_MAX][MAX_FONTS][193] = { +int16 CFont::Size[LANGSET_MAX][MAX_FONTS][210] = { { #else int16 CFont::Size[MAX_FONTS][210] = { @@ -169,8 +169,19 @@ wchar foreign_table[128] = { 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, }; +union tFontRenderStatePointer +{ + CFontRenderState *pRenderState; + wchar *pStr; -void* FontRenderStatePointer; + void Align() + { + if ((uintptr)pStr % 4) + pStr++; + } +}; + +tFontRenderStatePointer FontRenderStatePointer; uint8 FontRenderStateBuf[1024]; void @@ -291,17 +302,9 @@ CFont::Shutdown(void) void CFont::InitPerFrame(void) { - //Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); - //CSprite2d::GetBank(15, Sprite[1].m_pTexture); - //CSprite2d::GetBank(15, Sprite[2].m_pTexture); - - RenderState.FontStyle = -1; + RenderState.style = -1; Details.anonymous_25 = 0; - FontRenderStatePointer = FontRenderStateBuf; -#ifdef MORE_LANGUAGES - if (IsJapanese()) - CSprite2d::GetBank(15, Sprite[3].m_pTexture); -#endif + FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; SetDropShadowPosition(0); NewLine = 0; } @@ -328,17 +331,40 @@ CFont::PrintChar(float x, float y, wchar c) } #endif - if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ + if(Details.style == FONT_BANK || Details.style == FONT_STANDARD){ if (bDontPrint) return; - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.fTextSizeX * w, - y + 32.0f * RenderState.fTextSizeX * 0.5f), - RenderState.color, - xoff/16.0f, yoff/16.0f, - (xoff+ w)/16.0f, yoff/ 16.0f, - xoff/16.0f, (yoff+1.0f)/ 16.0f, - (xoff+ w)/16.0f - 0.0001f, (yoff+1.0f)/ 16.0f - 0.0001f); + if (RenderState.slant == 0.0f) { + if (c < 193) { + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 40.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f); + } else { + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 33.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f - 0.017f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.017f); + } + } else + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 40.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.00055f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f + 0.01f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.009f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f + 0.01f); #ifdef MORE_LANGUAGES }else if (IsJapaneseFont()) { if (Details.dropShadowPosition != 0) { @@ -363,47 +389,17 @@ CFont::PrintChar(float x, float y, wchar c) xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); #endif - } - else - { + } else { if (bDontPrint) return; - if (RenderState.fSlant == 0.0f) - { - if (c < 193) - { - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.fTextSizeX * 1.0f, - y + 40.0f * RenderState.fTextSizeY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f + 0.0021f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f + 0.0021f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f + 0.0021f); - } - else - { - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.fTextSizeX * 1.0f, - y + 33.0f * RenderState.fTextSizeY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f - 0.017f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff+1.0f) / 12.8f - 0.017f); - } - } - else - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.fTextSizeX * 1.0f, - y + 40.0f * RenderState.fTextSizeY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f + 0.01f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f + 0.0021f + 0.01f); + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * w, + y + 32.0f * RenderState.scaleX * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 16.0f, + (xoff + w) / 16.0f, yoff / 16.0f, + xoff / 16.0f, (yoff + 1.0f) / 16.0f, + (xoff + w) / 16.0f - 0.0001f, (yoff + 1.0f) / 16.0f - 0.0001f); } } @@ -484,6 +480,8 @@ CFont::PrintString(float xstart, float ystart, wchar *s) xstart; #ifdef MORE_LANGUAGES PrintString(xleft, y, start, s, spaceWidth, xstart); +#else + PrintString(xleft, y, Details.anonymous_25, start, s, spaceWidth); #endif // reset things lineLength = 0.0f; @@ -563,7 +561,7 @@ CFont::PrintString(float xstart, float ystart, wchar *s) lineLength = 0.0f; } #else - PrintString(xleft, y, start, s, 0.0f); + PrintString(xleft, y, Details.anonymous_25, start, s, 0.0f); #endif } } @@ -804,103 +802,81 @@ CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, f } #else void -CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) +CFont::PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth) { - wchar *s, c, unused; + wchar *s; - if (RenderState.FontStyle != Details.style) - { + if (RenderState.style != Details.style) { RenderFontBuffer(); - RenderState.FontStyle = Details.style; + RenderState.style = Details.style; } - float v7 = CFont::Details.dropShadowPosition; - if (v7 != 0.0f && (CFont::Details.style == 0 || CFont::Details.style == 1)) - { - auto v8 = CFont::Details.color; - CFont::Details.color = CFont::Details.dropColor; - CFont::Details.dropShadowPosition = 0; - CFont::Details.bIsShadow = true; - if (0.0f != CFont::Details.slant) - { - CFont::Details.slantRefX = (double)v7 + CFont::Details.slantRefX; - CFont::Details.slantRefY = (double)v7 + CFont::Details.slantRefY; - //CFont::PrintString(v7 + x, v7 + y, CFont::Details.anonymous_25, a4, a5, a6); - CFont::PrintString(v7 + x, v7 + y, start, end, spwidth); - CFont::Details.slantRefX = CFont::Details.slantRefX - (double)v7; - CFont::Details.slantRefY = CFont::Details.slantRefY - (double)v7; + float dropShadowPosition = CFont::Details.dropShadowPosition; + if (dropShadowPosition != 0.0f && (CFont::Details.style == FONT_BANK || CFont::Details.style == FONT_STANDARD)) { + CRGBA color = Details.color; + Details.color = Details.dropColor; + Details.dropShadowPosition = 0; + Details.bIsShadow = true; + if (Details.slant != 0.0f) { + Details.slantRefX += dropShadowPosition; + Details.slantRefY += dropShadowPosition; + PrintString(dropShadowPosition + x, dropShadowPosition + y, Details.anonymous_25, start, end, spwidth); + Details.slantRefX -= dropShadowPosition; + Details.slantRefY -= dropShadowPosition; + } else { + PrintString(dropShadowPosition + x, dropShadowPosition + y, Details.anonymous_25, start, end, spwidth); } - else - { - //CFont::PrintString(v12, v11, CFont::Details.anonymous_25, a4, a5, a6); - CFont::PrintString(v7 + x, v7 + y, start, end, spwidth); - } - CFont::Details.color = v8; - CFont::Details.dropShadowPosition = v7; - CFont::Details.bIsShadow = 0; + Details.color = color; + Details.dropShadowPosition = dropShadowPosition; + Details.bIsShadow = 0; } - if (FontRenderStatePointer >= (char*)&FontRenderStatePointer - 2 * (end - start + 26)) + if (FontRenderStatePointer.pStr >= (wchar*)&FontRenderStateBuf[1024] - (end - start + 26)) // why 26? CFont::RenderFontBuffer(); - CFontRenderState* v13 = (CFontRenderState*)FontRenderStatePointer; - v13->fTextPosX = x; - v13->fTextPosY = y; - v13->fTextSizeX = CFont::Details.scaleX; - v13->fTextSizeY = CFont::Details.scaleY; - v13->color.r = CFont::Details.color.r; - v13->color.g = CFont::Details.color.g; - v13->color.b = CFont::Details.color.b; - v13->color.a = CFont::Details.color.a; - v13->fExtraSpace = spwidth; - v13->fSlant = CFont::Details.slant; - v13->fSlantRefPointX = CFont::Details.slantRefX; - v13->fSlantRefPointY = CFont::Details.slantRefY; - v13->bFontHalfTexture = CFont::Details.bFontHalfTexture; - v13->bProp = CFont::Details.proportional; - v13->FontStyle = CFont::Details.style; - v13->bIsShadow = CFont::Details.bIsShadow; - FontRenderStatePointer = (char*)FontRenderStatePointer + 0x30; - - for(s = start; s < end; s++){ - if (*s == '~') - { - for (auto i = ParseToken(s); s != i; FontRenderStatePointer = (char*)FontRenderStatePointer + 2) - { - s = i; - *(wchar*)FontRenderStatePointer = *s; + CFontRenderState* pRenderState = FontRenderStatePointer.pRenderState; + pRenderState->fTextPosX = x; + pRenderState->fTextPosY = y; + pRenderState->scaleX = Details.scaleX; + pRenderState->scaleY = Details.scaleY; + pRenderState->color = Details.color; + pRenderState->fExtraSpace = spwidth; + pRenderState->slant = Details.slant; + pRenderState->slantRefX = Details.slantRefX; + pRenderState->slantRefY = Details.slantRefY; + pRenderState->bFontHalfTexture = Details.bFontHalfTexture; + pRenderState->proportional = Details.proportional; + pRenderState->style = Details.style; + pRenderState->bIsShadow = Details.bIsShadow; + FontRenderStatePointer.pRenderState++; + + for(s = start; s < end;){ + if (*s == '~') { + for (wchar *i = ParseToken(s); s != i; FontRenderStatePointer.pStr++) { + *FontRenderStatePointer.pStr = *(s++); } - if (CFont::Details.bFlash) - { - if (CTimer::GetTimeInMilliseconds() - CFont::Details.nFlashTimer > 300) - { + if (Details.bFlash) { + if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { Details.bFlashState = !Details.bFlashState; Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); } - if (Details.bFlashState) - Details.color.a = 0; - else - Details.color.a = 255; + Details.color.a = Details.bFlashState ? 0 : 255; } - } - else - { - *(wchar*)FontRenderStatePointer = *s; - FontRenderStatePointer = (char*)FontRenderStatePointer + 2; - } - /*c = *s - ' '; - if(Details.slant != 0.0f) - y = (Details.slantRefX - x)*Details.slant + Details.slantRefY; - PrintChar(x, y, c); - x += GetCharacterSize(c); - if(c == 0) // space - x += spwidth;*/ + } else + *(FontRenderStatePointer.pStr++) = *(s++); } - *(wchar*)FontRenderStatePointer = 0; - FontRenderStatePointer = (char*)FontRenderStatePointer + 2; - if ((unsigned __int8)FontRenderStatePointer & 3) - FontRenderStatePointer = (char*)FontRenderStatePointer + 2; + *(FontRenderStatePointer.pStr++) = '\0'; + FontRenderStatePointer.Align(); } #endif +void +CFont::PrintStringFromBottom(float x, float y, wchar *str) +{ + y -= (32.0f * Details.scaleY / 2.0f + 2.0f * Details.scaleY) * GetNumberLines(x, y, str); + if (Details.slant == 0.0f) + y -= ((Details.slantRefX - x) * Details.slant + Details.slantRefY); + PrintString(x, y, str); +} + float CFont::GetCharacterWidth(wchar c) { @@ -938,8 +914,6 @@ CFont::GetCharacterWidth(wchar c) else return Size[LanguageSet][Details.style][192]; #else - if (Details.bFontHalfTexture) - c = FindNewCharacter(c); if (Details.proportional) return Size[Details.style][c]; else @@ -1124,7 +1098,7 @@ CFont::ParseToken(wchar *s, bool japShit) wchar* CFont::ParseToken(wchar *s) { - Details.anonymous_23 = 0; + Details.anonymous_23 = false; s++; if(Details.color.r || Details.color.g || Details.color.b) switch(*s){ @@ -1134,27 +1108,26 @@ CFont::ParseToken(wchar *s) case 'n': NewLine = 1; break; - case 'b': SetColor(CRGBA(27, 89, 130, 255)); Details.anonymous_23 = 1; break; + case 'b': SetColor(CRGBA(27, 89, 130, 255)); Details.anonymous_23 = true; break; case 'f': Details.bFlash = !Details.bFlash; if (Details.bFlash) Details.color.a = 255; break; - case 'g': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = 1; break; - case 'h': SetColor(CRGBA(225, 225, 225, 255)); Details.anonymous_23 = 1; break; - case 'l': SetColor(CRGBA(0, 0, 0, 255)); Details.anonymous_23 = 1; break; - case 'o': SetColor(CRGBA(229, 125, 126, 255)); Details.anonymous_23 = 1; break; - case 'p': SetColor(CRGBA(168, 110, 252, 255)); Details.anonymous_23 = 1; break; - case 'q': SetColor(CRGBA(199, 144, 203, 255)); Details.anonymous_23 = 1; break; - case 'r': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = 1; break; - case 't': SetColor(CRGBA(86, 212, 146, 255)); Details.anonymous_23 = 1; break; - case 'w': SetColor(CRGBA(175, 175, 175, 255)); Details.anonymous_23 = 1; break; - case 'x': SetColor(CRGBA(132, 146, 197, 255)); Details.anonymous_23 = 1; break; - case 'y': SetColor(CRGBA(255, 227, 79, 255)); Details.anonymous_23 = 1; break; + case 'g': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = true; break; + case 'h': SetColor(CRGBA(225, 225, 225, 255)); Details.anonymous_23 = true; break; + case 'l': SetColor(CRGBA(0, 0, 0, 255)); Details.anonymous_23 = true; break; + case 'o': SetColor(CRGBA(229, 125, 126, 255)); Details.anonymous_23 = true; break; + case 'p': SetColor(CRGBA(168, 110, 252, 255)); Details.anonymous_23 = true; break; + case 'q': SetColor(CRGBA(199, 144, 203, 255)); Details.anonymous_23 = true; break; + case 'r': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = true; break; + case 't': SetColor(CRGBA(86, 212, 146, 255)); Details.anonymous_23 = true; break; + case 'w': SetColor(CRGBA(175, 175, 175, 255)); Details.anonymous_23 = true; break; + case 'x': SetColor(CRGBA(132, 146, 197, 255)); Details.anonymous_23 = true; break; + case 'y': SetColor(CRGBA(255, 227, 79, 255)); Details.anonymous_23 = true; break; } while(*s != '~') s++; - s++; - if (*s == '~') + if (*(++s) == '~') s = ParseToken(s); return s; } @@ -1163,14 +1136,11 @@ CFont::ParseToken(wchar *s) wchar* CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) { - wchar* v4; // eax - wchar* result; // eax - Details.anonymous_23 = 0; - v4 = str + 1; + wchar *s = str + 1; if (Details.color.r || Details.color.g || Details.color.b) { - switch (*v4) + switch (*s) { case 'B': bold = !bold; @@ -1242,12 +1212,11 @@ CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) break; } } - while (*v4 != '~') - ++v4; - result = v4 + 1; - if (*result == '~') - result = CFont::ParseToken(result, color, flash, bold); - return result; + while (*s != '~') + ++s; + if (*(++s) == '~') + s = CFont::ParseToken(s, color, flash, bold); + return s; } void @@ -1259,103 +1228,80 @@ CFont::DrawFonts(void) void CFont::RenderFontBuffer() { - int v0; // ebx - //wchar_t* v1; // esi - CFontRenderState* v2; // esi - char v3; // al - float v4; // ST04_4 - float v5; // ST04_4 - signed int v6; // eax - float v7; // [esp+Ch] [ebp-24h] - float v8; // [esp+10h] [ebp-20h] - CRGBA v9; // [esp+1Ch] [ebp-14h] - bool v10; // [esp+22h] [ebp-Eh] - bool v11; // [esp+23h] [ebp-Dh] - - if (FontRenderStatePointer != FontRenderStateBuf) { - v11 = false; - v10 = false; - Sprite[RenderState.FontStyle].SetRenderState(); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; - v7 = RenderState.fTextPosX; - v8 = RenderState.fTextPosY; - wchar* string = (wchar*)&FontRenderStateBuf[sizeof(CFontRenderState)]; - - if (string < FontRenderStatePointer) - { - do - { - if (string[0] == '\0') - { - v2 = (CFontRenderState*)((uintptr)string + sizeof(CFontRenderState)); - if ((uintptr)v2 & 3) - v2 = (CFontRenderState*)((uint8*)v2 + 2); - if (v2 >= FontRenderStatePointer) - break; + if (FontRenderStatePointer.pRenderState == (CFontRenderState*)FontRenderStateBuf) return; + + float textPosX; + float textPosY; + CRGBA color; + bool bBold = false; + bool bFlash = false; + + Sprite[RenderState.style].SetRenderState(); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; + textPosX = RenderState.fTextPosX; + textPosY = RenderState.fTextPosY; + tFontRenderStatePointer pRenderStateBufPointer; + pRenderStateBufPointer.pRenderState = (CFontRenderState*)&FontRenderStateBuf[0]; + for (++pRenderStateBufPointer.pRenderState; pRenderStateBufPointer.pStr < FontRenderStatePointer.pStr; pRenderStateBufPointer.pStr++) { + if (*pRenderStateBufPointer.pStr == '\0') { + tFontRenderStatePointer tmpPointer = pRenderStateBufPointer; + tmpPointer.pStr++; + tmpPointer.Align(); + if (tmpPointer.pStr >= FontRenderStatePointer.pStr) + break; - RenderState = *v2; + RenderState = *(tmpPointer.pRenderState++); - v7 = RenderState.fTextPosX; - v8 = RenderState.fTextPosY; - } - if (string[0] == '~') - { - string = CFont::ParseToken(string, v9, v10, v11); - //string = CFont::ParseToken(string); - if (v10) - { - if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { - Details.bFlashState = !Details.bFlashState; - Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); - } - Details.color.alpha = Details.bFlashState ? 0 : 255; - } - if (!RenderState.bIsShadow) - RenderState.color = v9; - } - wchar v0 = string[0]; - //LOWORD(v0) = *v1; - v0 -= 32; - if (RenderState.bFontHalfTexture) - v0 = FindNewCharacter(v0); - else if (v0 > 155) - v0 = 0; - - if (RenderState.fSlant != 0.0f) - v8 = (RenderState.fSlantRefPointX - v7) * RenderState.fSlant + RenderState.fSlantRefPointY; - CFont::PrintChar(v7, v8, v0); - if (v11) { - CFont::PrintChar(v7 + 1.0f, v8, v0); - CFont::PrintChar(v7 + 2.0f, v8, v0); - v7 += 2.0f; + pRenderStateBufPointer = tmpPointer; + + textPosX = RenderState.fTextPosX; + textPosY = RenderState.fTextPosY; + color = RenderState.color; + } + if (*pRenderStateBufPointer.pStr == '~') { + pRenderStateBufPointer.pStr = CFont::ParseToken(pRenderStateBufPointer.pStr, color, bFlash, bBold); + if (bFlash) { + if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { + Details.bFlashState = !Details.bFlashState; + Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); } - if (CFont::RenderState.bProp == true) - v6 = CFont::Size[RenderState.FontStyle][v0]; - else - v6 = CFont::Size[RenderState.FontStyle][209]; - v7 = CFont::RenderState.fTextSizeX * v6 + v7; - if (v0 == 0) - v7 += CFont::RenderState.fExtraSpace; - ++string; - } while (string < FontRenderStatePointer); + Details.color.alpha = Details.bFlashState ? 0 : 255; + } + if (!RenderState.bIsShadow) + RenderState.color = color; + } + wchar c = *pRenderStateBufPointer.pStr; + c -= ' '; + if (RenderState.bFontHalfTexture) + c = FindNewCharacter(c); + else if (c > 155) + c = 0; + + if (RenderState.slant != 0.0f) + textPosY = (RenderState.slantRefX - textPosX) * RenderState.slant + RenderState.slantRefY; + PrintChar(textPosX, textPosY, c); + if (bBold) { + PrintChar(textPosX + 1.0f, textPosY, c); + PrintChar(textPosX + 2.0f, textPosY, c); + textPosX += 2.0f; } - CSprite2d::RenderVertexBuffer(); - FontRenderStatePointer = FontRenderStateBuf; + textPosX += CFont::RenderState.scaleX * (RenderState.proportional ? Size[RenderState.style][c] : Size[RenderState.style][209]); + if (c == '\0') + textPosX += CFont::RenderState.fExtraSpace; } + CSprite2d::RenderVertexBuffer(); + FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; } void CFont::SetFontStyle(int16 style) { - if (style == FONT_HEADING) - { + if (style == FONT_HEADING) { Details.style = FONT_STANDARD; Details.bFontHalfTexture = true; - } - else - { + } else { Details.style = style; Details.bFontHalfTexture = false; } @@ -1363,30 +1309,18 @@ CFont::SetFontStyle(int16 style) wchar CFont::FindNewCharacter(wchar c) { - if (c >= 16 && c <= 26) - return c + 128; - if (c >= 8 && c <= 9) - return c + 86; - if (c == 4) - return c + 89; - if (c == 7) - return 206; - if (c == 14) - return 207; - if (c >= 33 && c <= 58) - return c + 122; - if (c >= 65 && c <= 90) - return c + 90; - if (c >= 96 && c <= 118) - return c + 85; - if (c >= 119 && c <= 140) - return c + 62; - if (c >= 141 && c <= 142) - return 204; - if (c == 143) - return 205; - if (c == 1) - return 208; + if (c >= 16 && c <= 26) return c + 128; + if (c >= 8 && c <= 9) return c + 86; + if (c == 4) return c + 89; + if (c == 7) return 206; + if (c == 14) return 207; + if (c >= 33 && c <= 58) return c + 122; + if (c >= 65 && c <= 90) return c + 90; + if (c >= 96 && c <= 118) return c + 85; + if (c >= 119 && c <= 140) return c + 62; + if (c >= 141 && c <= 142) return 204; + if (c == 143) return 205; + if (c == 1) return 208; return c; } diff --git a/src/render/Font.h b/src/render/Font.h index f4c63c21..e30caed6 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -30,7 +30,7 @@ struct CFontDetails char bFlashState; char anonymous_21; int nFlashTimer; - char anonymous_23; + bool anonymous_23; uint32 anonymous_25; }; @@ -39,18 +39,18 @@ struct CFontRenderState uint32 anonymous_0; float fTextPosX; float fTextPosY; - float fTextSizeX; - float fTextSizeY; + float scaleX; + float scaleY; CRGBA color; float fExtraSpace; - float fSlant; - float fSlantRefPointX; - float fSlantRefPointY; + float slant; + float slantRefX; + float slantRefY; bool bIsShadow; bool bFontHalfTexture; - bool bProp; + bool proportional; bool anonymous_14; - int16 FontStyle; + int16 style; }; class CSprite2d; @@ -62,7 +62,7 @@ enum { #ifdef MORE_LANGUAGES FONT_JAPANESE, #endif - MAX_FONTS + MAX_FONTS = FONT_HEADING }; enum { @@ -111,8 +111,9 @@ public: #ifdef MORE_LANGUAGES static bool PrintString(float x, float y, wchar *start, wchar* &end, float spwidth, float japX); #else - static void PrintString(float x, float y, wchar *start, wchar *end, float spwidth); + static void PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth); #endif + static void PrintStringFromBottom(float x, float y, wchar *str); static float GetCharacterWidth(wchar c); static float GetCharacterSize(wchar c); static float GetStringWidth(wchar *s, bool spaces = false); @@ -186,7 +187,7 @@ public: static void SetBackGroundOnlyTextOff(void) { Details.backgroundOnlyText = false; } static void SetPropOn(void) { Details.proportional = true; } static void SetPropOff(void) { Details.proportional = false; } - static void SetFontStyle(int16 style);// { Details.style = style; } + static void SetFontStyle(int16 style); static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; } static void SetAlphaFade(float fade) { Details.alphaFade = fade; } static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; } diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 350daff8..697a1483 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -412,6 +412,8 @@ void CHud::Draw() CFont::SetRightJustifyWrap(0.0f); CFont::SetRightJustifyOn(); CFont::SetPropOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); CFont::SetFontStyle(FONT_HEADING); if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 @@ -429,12 +431,12 @@ void CHud::Draw() #endif AsciiToUnicode(sTemp, sPrint); - CFont::SetColor(CRGBA(0, 0, 0, 255)); + /*CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f - 2.0f), SCREEN_SCALE_Y(65.0f + 2.0f), sPrint); if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) { CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(164.0f - 2.0f), SCREEN_SCALE_Y(65.0f + 2.0f), sPrintIcon); - } + }*/ CFont::SetColor(HEALTH_COLOR); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(65.0f), sPrint); @@ -493,11 +495,11 @@ void CHud::Draw() CFont::SetCentreOff(); CFont::SetRightJustifyOn(); CFont::SetPropOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONT_STANDARD); CFont::SetDropShadowPosition(2); // TODO(Miami): Remove that, VC keeps that open above CFont::SetDropColor(CRGBA(0,0,0,alpha)); // TODO(Miami): Remove that, VC keeps that open above - AsciiToUnicode("]", sPrintIcon); + AsciiToUnicode(">", sPrintIcon); for (int i = 0; i < 6; i++) { if (FrontEndMenuManager.m_PrefsShowHud) { @@ -609,12 +611,14 @@ void CHud::Draw() CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); CFont::SetBackGroundOnlyTextOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, fZoneAlpha)); CFont::SetFontStyle(FONT_BANK); - CFont::SetColor(CRGBA(0, 0, 0, fZoneAlpha)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f) + SCREEN_SCALE_X(1.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f) + SCREEN_SCALE_Y(1.0f), m_ZoneToPrint); + //CFont::SetColor(CRGBA(0, 0, 0, fZoneAlpha)); + //CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f) + SCREEN_SCALE_X(1.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f) + SCREEN_SCALE_Y(1.0f), m_ZoneToPrint); CFont::SetColor(CRGBA(ZONE_COLOR.r, ZONE_COLOR.g, ZONE_COLOR.b, fZoneAlpha)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f), m_ZoneToPrint); + CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f), m_ZoneToPrint); CFont::SetSlant(0.f); } @@ -708,12 +712,12 @@ void CHud::Draw() CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_STANDARD); - CFont::SetColor(CRGBA(0, 0, 0, fVehicleAlpha)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f) + SCREEN_SCALE_X(1.0f), SCREEN_SCALE_FROM_BOTTOM(105.f) + SCREEN_SCALE_Y(1.0f), m_pVehicleNameToPrint); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, fVehicleAlpha)); + CFont::SetFontStyle(FONT_BANK); CFont::SetColor(CRGBA(VEHICLE_COLOR.r, VEHICLE_COLOR.g, VEHICLE_COLOR.b, fVehicleAlpha)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f), m_pVehicleNameToPrint); + CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f), m_pVehicleNameToPrint); CFont::SetSlant(0.f); } @@ -734,6 +738,8 @@ void CHud::Draw() CFont::SetBackgroundOff(); CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); CFont::SetBackGroundOnlyTextOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); CFont::SetPropOff(); CFont::SetFontStyle(FONT_HEADING); CFont::SetRightJustifyOn(); @@ -744,7 +750,7 @@ void CHud::Draw() CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(111.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(22.0f) + SCREEN_SCALE_Y(2.0f), sPrint); + //CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(111.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(22.0f) + SCREEN_SCALE_Y(2.0f), sPrint); CFont::SetColor(CLOCK_COLOR); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(111.0f), SCREEN_SCALE_Y(22.0f), sPrint); @@ -1407,7 +1413,7 @@ void CHud::DrawAfterFade() CFont::SetPropOn(); CFont::SetRightJustifyWrap(SCREEN_SCALE_X(-500.0f)); CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONT_BANK); if (BigMessageX[1] >= SCREEN_SCALE_FROM_RIGHT(20.0f)) { BigMessageInUse[1] += CTimer::GetTimeStep(); @@ -1427,8 +1433,10 @@ void CHud::DrawAfterFade() BigMessageAlpha[1] = 255.0f; } - CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[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::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(40, 40, 40, BigMessageAlpha[1])); + //CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[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(MISSIONTITLE_COLOR.r, MISSIONTITLE_COLOR.g, MISSIONTITLE_COLOR.b, BigMessageAlpha[1])); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]); diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp index d3d90964..3f7cea44 100644 --- a/src/render/Sprite2d.cpp +++ b/src/render/Sprite2d.cpp @@ -317,12 +317,12 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con screenz = NearScreenZ; recipz = RecipNearClip; - //z = RwCameraGetNearClipPlane(Scene.camera); // not done by game + z = RwCameraGetNearClipPlane(Scene.camera); // not done by game RwIm2DVertexSetScreenX(&verts[0], r.left); RwIm2DVertexSetScreenY(&verts[0], r.top); RwIm2DVertexSetScreenZ(&verts[0], screenz); - //RwIm2DVertexSetCameraZ(&verts[0], z); + RwIm2DVertexSetCameraZ(&verts[0], z); RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); RwIm2DVertexSetU(&verts[0], u0, recipz); @@ -331,7 +331,7 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con RwIm2DVertexSetScreenX(&verts[1], r.right); RwIm2DVertexSetScreenY(&verts[1], r.top); RwIm2DVertexSetScreenZ(&verts[1], screenz); - //RwIm2DVertexSetCameraZ(&verts[1], z); + RwIm2DVertexSetCameraZ(&verts[1], z); RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); RwIm2DVertexSetU(&verts[1], u1, recipz); @@ -340,7 +340,7 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con RwIm2DVertexSetScreenX(&verts[2], r.right); RwIm2DVertexSetScreenY(&verts[2], r.bottom); RwIm2DVertexSetScreenZ(&verts[2], screenz); - //RwIm2DVertexSetCameraZ(&verts[2], z); + RwIm2DVertexSetCameraZ(&verts[2], z); RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); RwIm2DVertexSetU(&verts[2], u2, recipz); @@ -349,30 +349,11 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con RwIm2DVertexSetScreenX(&verts[3], r.left); RwIm2DVertexSetScreenY(&verts[3], r.bottom); RwIm2DVertexSetScreenZ(&verts[3], screenz); - //RwIm2DVertexSetCameraZ(&verts[3], z); + RwIm2DVertexSetCameraZ(&verts[3], z); RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); RwIm2DVertexSetU(&verts[3], u3, recipz); RwIm2DVertexSetV(&verts[3], v3, recipz); - - /*RwIm2DVertexSetScreenX(&verts[4], r.right); - RwIm2DVertexSetScreenY(&verts[4], r.bottom); - RwIm2DVertexSetScreenZ(&verts[4], screenz); - RwIm2DVertexSetCameraZ(&verts[4], z); - RwIm2DVertexSetRecipCameraZ(&verts[4], recipz); - RwIm2DVertexSetIntRGBA(&verts[4], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[4], u3, recipz); - RwIm2DVertexSetV(&verts[4], v3, recipz); - - RwIm2DVertexSetScreenX(&verts[5], r.right); - RwIm2DVertexSetScreenY(&verts[5], r.top); - RwIm2DVertexSetScreenZ(&verts[5], screenz); - RwIm2DVertexSetCameraZ(&verts[5], z); - RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); - RwIm2DVertexSetIntRGBA(&verts[5], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&verts[5], u1, recipz); - RwIm2DVertexSetV(&verts[5], v1, recipz);*/ - } void -- 2.45.2 From 1234fe9c1c5728c3b98986f0ce8f6c59011b7cd8 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 7 Jun 2020 10:24:33 +0200 Subject: [PATCH 5/9] removed a "fix" --- src/vehicles/Bike.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index 05f088bf..9c769fb0 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -1351,12 +1351,7 @@ CBike::PreRender(void) CMatrix mat; CVector headLightPos = mi->m_positions[CAR_POS_HEADLIGHTS]; -#ifdef FIX_BUGS - if(GetModelIndex() == MI_FAGGIO || GetModelIndex() == MI_PIZZABOY) -#else - if(GetModelIndex() == 152) // this is the bobcat in VC -#endif - { + if(GetModelIndex() == 152){ // this is the bobcat in VC, but we don't want that effect anyway mat.SetUnity(); mat.RotateZ(m_fWheelAngle); mat = m_leanMatrix * mat; -- 2.45.2 From 5fd330b35e0a72ccceb1323e78bd227f571b7aee Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sun, 7 Jun 2020 11:31:52 +0300 Subject: [PATCH 6/9] making it close to original --- src/vehicles/Bike.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index 9c769fb0..a7edbfd6 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -2442,16 +2442,24 @@ CBike::BurstTyre(uint8 wheel, bool applyForces) ApplyTurnForce(GetRight() * m_fTurnMass * CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), GetForward()); } -#ifdef FIX_SIGNIFICANT_BUGS // This code checks piece types originally so it is never triggered // as we have converted them to wheel indices above already. if(pDriver){ +#ifdef FIX_SIGNIFICANT_BUGS if(wheel == BIKEWHEEL_FRONT && (m_aSuspensionSpringRatioPrev[BIKESUSP_F1] < 1.0f || m_aSuspensionSpringRatioPrev[BIKESUSP_F2] < 1.0f) || wheel == BIKEWHEEL_REAR && (m_aSuspensionSpringRatioPrev[BIKESUSP_R1] < 1.0f || m_aSuspensionSpringRatioPrev[BIKESUSP_R2] < 1.0f)){ +#else + if(wheel == CAR_PIECE_WHEEL_LF && (m_aSuspensionSpringRatioPrev[BIKESUSP_F1] < 1.0f || m_aSuspensionSpringRatioPrev[BIKESUSP_F2] < 1.0f) || + wheel == CAR_PIECE_WHEEL_LR && (m_aSuspensionSpringRatioPrev[BIKESUSP_R1] < 1.0f || m_aSuspensionSpringRatioPrev[BIKESUSP_R2] < 1.0f)){ +#endif float speedSq = m_vecMoveSpeed.MagnitudeSqr(); if(speedSq > fBikeBurstFallSpeed && (GetStatus() != STATUS_PLAYER || speedSq > fBikeBurstFallSpeedPlayer)){ +#ifdef FIX_SIGNIFICANT_BUGS if(wheel == BIKEWHEEL_FRONT){ +#else + if(wheel == CAR_PIECE_WHEEL_LF){ +#endif KnockOffRider(WEAPONTYPE_RAMMEDBYCAR, 0, pDriver, false); if(pPassengers[0]) KnockOffRider(WEAPONTYPE_RAMMEDBYCAR, 0, pPassengers[0], false); @@ -2460,7 +2468,6 @@ CBike::BurstTyre(uint8 wheel, bool applyForces) } } } -#endif } } -- 2.45.2 From d1a02e6ddcd9addf60248db57ed241db6c0b98a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 7 Jun 2020 12:45:53 +0300 Subject: [PATCH 7/9] New ped objectives --- src/control/Script.cpp | 10 +- src/peds/Ped.cpp | 241 ++++++++++++++++++++++++----------------- src/peds/Ped.h | 21 ++-- src/vehicles/Bike.cpp | 2 +- 4 files changed, 158 insertions(+), 116 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index a2c60872..c7154987 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1531,7 +1531,7 @@ int8 CRunningScript::ProcessCommands0To99(int32 command) CPed* pTestedPed = ped->m_nearPeds[i]; if (!pTestedPed || !IsPedPointerValid(pTestedPed)) continue; - if (pTestedPed->m_pedInObjective == ped && pTestedPed->m_objective == OBJ_15) { + if (pTestedPed->m_pedInObjective == ped && pTestedPed->m_objective == OBJECTIVE_FOLLOW_PED_IN_FORMATION) { CVector vFollowerPos = pTestedPed->GetFormationPosition(); CTheScripts::ClearSpaceForMissionEntity(vFollowerPos, ped); bool bFound = false; @@ -10678,7 +10678,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) CPed* pTargetPed = CPools::GetPedPool()->GetAt(ScriptParams[1]); assert(pTargetPed); pPed->bScriptObjectiveCompleted = false; - pPed->SetObjective(OBJECTIVE_FOLLOW_PED_IN_FORMATION, pPed); + pPed->SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING, pPed); return 0; } //case COMMAND_IS_PICKUP_IN_ZONE: @@ -10713,8 +10713,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) CPed* pTargetPed = CPools::GetPedPool()->GetAt(ScriptParams[1]); assert(pTargetPed); pPed->bScriptObjectiveCompleted = false; - debug("SET_CHAR_OBJ_AIM_GUN_AT_CHAR is not implemented\n"); - //pPed->SetObjective(OBJECTIVE_AIM_GUN_AT_PED, pTargetPed); // TODO(MIAMI) -- when objective is implemented + pPed->SetObjective(OBJECTIVE_AIM_GUN_AT_PED, pTargetPed); return 0; } case COMMAND_SWITCH_SECURITY_CAMERA: @@ -11122,8 +11121,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) pos.y = *(float*)&ScriptParams[2]; pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); pPed->bScriptObjectiveCompleted = false; - debug("SET_CHAR_OBJ_SPRINT_TO_COORD is not implemented\n"); - //pPed->SetObjective(OBJECTIVE_SPRINT_TO_COORD, pos); // TODO(MIAMI) -- when objective is implemented + pPed->SetObjective(OBJECTIVE_SPRINT_TO_COORD, pos); return 0; } case COMMAND_CREATE_SWAT_ROPE: diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 3dfb167c..a6608a78 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -2815,14 +2815,13 @@ CPed::CanSeeEntity(CEntity *entity, float threshold = CAN_SEE_ENTITY_ANGLE_THRES return neededTurn < threshold || TWOPI - threshold < neededTurn; } +// --MIAMI: Done bool CPed::IsTemporaryObjective(eObjective objective) { return objective == OBJECTIVE_LEAVE_VEHICLE || objective == OBJECTIVE_SET_LEADER || -#ifdef VC_PED_PORTS - objective == OBJECTIVE_LEAVE_CAR_AND_DIE || -#endif - objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER; + objective == OBJECTIVE_LEAVE_CAR_AND_DIE || objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || + objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER; } void @@ -2831,6 +2830,7 @@ CPed::SetMoveState(eMoveState state) m_nMoveState = state; } +// --MIAMI: Done void CPed::SetObjectiveTimer(int time) { @@ -2841,6 +2841,7 @@ CPed::SetObjectiveTimer(int time) } } +// --MIAMI: Done void CPed::ForceStoredObjective(eObjective objective) { @@ -2849,49 +2850,65 @@ CPed::ForceStoredObjective(eObjective objective) return; } - switch (m_objective) - { + switch (m_objective) { case OBJECTIVE_FLEE_TILL_SAFE: case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_SPRINT_TO_COORD: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: return; default: m_prevObjective = m_objective; } } +// --MIAMI: Done void CPed::SetStoredObjective(void) { if (m_objective == m_prevObjective) return; - switch (m_objective) - { + switch (m_objective) { case OBJECTIVE_FLEE_TILL_SAFE: case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_KILL_CHAR_ANY_MEANS: case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_FOLLOW_PED_IN_FORMATION: - case OBJECTIVE_LEAVE_VEHICLE: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_SPRINT_TO_COORD: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: return; default: m_prevObjective = m_objective; } } +// --MIAMI: Done void CPed::RestorePreviousObjective(void) { @@ -2899,10 +2916,7 @@ CPed::RestorePreviousObjective(void) return; if (m_objective != OBJECTIVE_LEAVE_VEHICLE && m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER -#ifdef VC_PED_PORTS - && m_nPedState != PED_CARJACK -#endif - ) + && m_nPedState != PED_CARJACK) m_pedInObjective = nil; if (m_objective == OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT) { @@ -2926,6 +2940,7 @@ CPed::SetLeader(CEntity *leader) m_leader->RegisterReference((CEntity **)&m_leader); } +// TODO(Miami) void CPed::SetObjective(eObjective newObj, void *entity) { @@ -2941,7 +2956,6 @@ CPed::SetObjective(eObjective newObj, void *entity) if (entity == this) return; - SetObjectiveTimer(0); if (m_objective == newObj) { switch (newObj) { case OBJECTIVE_KILL_CHAR_ON_FOOT: @@ -2952,7 +2966,6 @@ CPed::SetObjective(eObjective newObj, void *entity) case OBJECTIVE_FIGHT_CHAR: if (m_pedInObjective == entity) return; - break; case OBJECTIVE_LEAVE_VEHICLE: case OBJECTIVE_FLEE_CAR: @@ -2967,12 +2980,14 @@ CPed::SetObjective(eObjective newObj, void *entity) case OBJECTIVE_BUY_ICE_CREAM: if (m_carInObjective == entity) return; - break; case OBJECTIVE_SET_LEADER: if (m_leader == entity) return; - + break; + case OBJECTIVE_AIM_GUN_AT_PED: + if (m_pedInObjective == entity) + return; break; default: break; @@ -2986,9 +3001,8 @@ CPed::SetObjective(eObjective newObj, void *entity) return; } -#ifdef VC_PED_PORTS ClearPointGunAt(); -#endif + m_objectiveTimer = 0; bObjectiveCompleted = false; if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) { if (m_objective != newObj) { @@ -3022,6 +3036,8 @@ CPed::SetObjective(eObjective newObj, void *entity) case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_FIGHT_CHAR: m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_pedInObjective = (CPed*)entity; @@ -3081,6 +3097,10 @@ CPed::SetObjective(eObjective newObj, void *entity) SetLeader((CEntity*)entity); RestorePreviousObjective(); break; + case OBJECTIVE_AIM_GUN_AT_PED: + m_pedInObjective = (CPed*)entity; + m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); + break; default: break; } @@ -3103,21 +3123,16 @@ CPed::SetIdle(void) } } +// --MIAMI: Done void CPed::SetObjective(eObjective newObj) { - if (DyingOrDead()) + if (DyingOrDead() || m_attachedTo) return; if (newObj == OBJECTIVE_NONE) { if ((m_objective == OBJECTIVE_LEAVE_VEHICLE || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER -#ifdef VC_PED_PORTS - || m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) - && !IsPlayer() -#else - ) -#endif - && !IsPedInControl()) { + || m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) && !IsPlayer() && !IsPedInControl()) { bStartWanderPathOnFoot = true; return; @@ -3194,6 +3209,7 @@ CPed::SetObjective(eObjective newObj, int16 routePoint, int16 routeType) } } +// --MIAMI: Done void CPed::ClearChat(void) { @@ -3205,6 +3221,11 @@ CPed::ClearChat(void) bIsTalking = false; ClearLookFlag(); RestorePreviousState(); + if (m_objective == OBJECTIVE_BUY_ICE_CREAM) { + bBoughtIceCream = true; + SetObjective(OBJECTIVE_NONE); + SetWanderPath(CGeneral::GetRandomNumberInRange(0, 8)); + } } bool @@ -4555,28 +4576,23 @@ CPed::ClearLook(void) ClearLookFlag(); } +// --MIAMI: Done void CPed::ClearObjective(void) { if (IsPedInControl() || m_nPedState == PED_DRIVING) { m_objective = OBJECTIVE_NONE; -#ifdef VC_PED_PORTS m_pedInObjective = nil; m_carInObjective = nil; -#endif if (m_nPedState == PED_DRIVING && m_pMyVehicle) { if (m_pMyVehicle->pDriver != this) { -#ifdef VC_PED_PORTS if(!IsPlayer()) -#endif bWanderPathAfterExitingCar = true; SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle); } -#ifdef VC_PED_PORTS m_nLastPedState = PED_NONE; -#endif } else { SetIdle(); SetMoveState(PEDMOVE_STILL); @@ -8086,7 +8102,9 @@ CPed::Seek(void) } else if (m_objective != OBJECTIVE_FOLLOW_PED_IN_FORMATION) { - if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || m_objective == OBJECTIVE_RUN_TO_AREA || bIsRunning) + if (m_objective == OBJECTIVE_SPRINT_TO_COORD) + nextMove = PEDMOVE_SPRINT; + else if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || m_objective == OBJECTIVE_RUN_TO_AREA || bIsRunning) nextMove = PEDMOVE_RUN; else nextMove = PEDMOVE_WALK; @@ -8108,7 +8126,7 @@ CPed::Seek(void) } if (seekPosDist >= distanceToCountItDone) { - if (bIsRunning) + if (bIsRunning && nextMove != PEDMOVE_SPRINT) nextMove = PEDMOVE_RUN; if (CTimer::GetTimeInMilliseconds() <= m_nPedStateTimer) { @@ -8180,7 +8198,9 @@ CPed::Seek(void) m_actionY = 0; } - if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_GOTO_AREA_ANY_MEANS) { + if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_COORD || + m_objective == OBJECTIVE_GOTO_AREA_ANY_MEANS) { + if (m_pNextPathNode) m_pNextPathNode = nil; else @@ -10326,6 +10346,7 @@ CPed::ProcessControl(void) && (!IsPlayer() || m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA + || m_objective == OBJECTIVE_SPRINT_TO_COORD || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)) { if (collidingVeh != m_pCurrentPhysSurface || IsPlayer()) { @@ -11166,7 +11187,7 @@ CPed::ProcessControl(void) if (!IsPlayer() && m_pMyVehicle->IsBoat() && FindPlayerPed()->m_pCurrentPhysSurface == m_pMyVehicle && CharCreatedBy != MISSION_CHAR || !bIsPlayerFriend) { - SetObjective(OBJ_50, FindPlayerPed()); + SetObjective(OBJECTIVE_KILL_CHAR_ON_BOAT, FindPlayerPed()); Say(SOUND_PED_CAR_JACKED); } @@ -12290,10 +12311,11 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) veh->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS; veh->AutoPilot.m_nCruiseSpeed = 25; } - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { - if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) + if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT + || ped->m_prevObjective == OBJECTIVE_SPRINT_TO_COORD || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) ped->m_prevObjective = OBJECTIVE_NONE; ped->RestorePreviousObjective(); @@ -12319,7 +12341,8 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } ped->m_nPedState = PED_DRIVING; - if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) + if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT + || ped->m_prevObjective == OBJECTIVE_SPRINT_TO_COORD || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) ped->m_prevObjective = OBJECTIVE_NONE; ped->RestorePreviousObjective(); @@ -12342,6 +12365,13 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_SPRINT_TO_COORD: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: break; default: ped->SetObjective(OBJECTIVE_NONE); @@ -13205,8 +13235,8 @@ CPed::ProcessObjective(void) case OBJECTIVE_FOLLOW_CAR_IN_CAR: case OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE: case OBJECTIVE_DESTROY_OBJ: - case OBJECTIVE_26: - case OBJECTIVE_27: + case OBJECTIVE_GOTO_AREA_IN_CAR: + case OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET: case OBJECTIVE_SET_LEADER: break; case OBJECTIVE_IDLE: @@ -13752,6 +13782,8 @@ CPed::ProcessObjective(void) break; } case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: { if (m_pedInObjective) { float safeDistance = 2.0f; @@ -13797,6 +13829,8 @@ CPed::ProcessObjective(void) } } } + if (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING && m_nMoveState > PEDMOVE_STILL) + SetMoveState(PEDMOVE_WALK); } } else { SetObjective(OBJECTIVE_NONE); @@ -14089,8 +14123,9 @@ CPed::ProcessObjective(void) } case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_SPRINT_TO_COORD: { - if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA) + if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_COORD) && InVehicle()) { SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle); } else { @@ -14105,11 +14140,22 @@ CPed::ProcessObjective(void) CVector bestCoords(0.0f, 0.0f, 0.0f); m_vecSeekPos = m_nextRoutePointPos; - if (!m_pNextPathNode) - FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + if (!m_pNextPathNode) { + bool found = FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + if (m_pNextPathNode) { + // Because it already does that if it finds better coords. + if (!found) { + bestCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + } + if ((bestCoords - GetPosition()).Magnitude2D() < m_distanceToCountSeekDone) { + m_pNextPathNode = nil; + bUsePedNodeSeek = false; + } + } + } if (m_pNextPathNode) - m_vecSeekPos = m_pNextPathNode->GetPosition(); + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); } SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); } @@ -14336,13 +14382,18 @@ CPed::ProcessObjective(void) SetWanderPath(CGeneral::GetRandomNumber() & 7); } } else { -#ifdef VC_PED_PORTS m_objective = OBJECTIVE_NONE; -#endif ClearObjective(); } - break; } + // fall through + case OBJECTIVE_WANDER: + if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer && !bInVehicle) { + m_leaveCarTimer = 0; + m_objective = OBJECTIVE_NONE; + CPed::SetWanderPath(m_nPathDir); + } + break; case OBJECTIVE_FLEE_CAR: if (!bInVehicle && m_nPedState != PED_FLEE_ENTITY && m_pMyVehicle) { RestorePreviousObjective(); @@ -14376,6 +14427,19 @@ CPed::ProcessObjective(void) } } break; + case OBJECTIVE_AIM_GUN_AT_PED: + if (m_pedInObjective) { + if (!bObstacleShowedUpDuringKillObjective) + SetPointGunAt(m_pedInObjective); + + if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) { + SetLookFlag(m_pedInObjective, false); // TODO(Miami): new parameter: false + TurnBody(); + } + } else { + ClearObjective(); + } + break; #ifdef VC_PED_PORTS case OBJECTIVE_LEAVE_CAR_AND_DIE: { @@ -17617,6 +17681,7 @@ CPed::WarpPedIntoCar(CVehicle *car) bChangedSeat = true; } +// --MIAMI: Done void CPed::SetObjective(eObjective newObj, float heading, const CVector& pos) { @@ -17633,6 +17698,7 @@ CPed::SetObjective(eObjective newObj, float heading, const CVector& pos) } } +// --MIAMI: Done void CPed::SetObjective(eObjective newObj, CVector dest) { @@ -17642,9 +17708,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) if (m_prevObjective != OBJECTIVE_NONE && m_prevObjective == newObj) return; - SetObjectiveTimer(0); if (m_objective == newObj) { - if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { + if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA || newObj == OBJECTIVE_SPRINT_TO_COORD) { if (m_nextRoutePointPos == dest) return; } else if (newObj == OBJECTIVE_GUARD_SPOT) { @@ -17653,9 +17718,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) } } -#ifdef VC_PED_PORTS ClearPointGunAt(); -#endif + m_objectiveTimer = 0; bObjectiveCompleted = false; switch (newObj) { case OBJECTIVE_GUARD_SPOT: @@ -17671,6 +17735,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_FOLLOW_PED_IN_FORMATION: case OBJECTIVE_LEAVE_VEHICLE: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: @@ -17679,6 +17745,27 @@ CPed::SetObjective(eObjective newObj, CVector dest) case OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE: case OBJECTIVE_DESTROY_OBJ: case OBJECTIVE_DESTROY_CAR: + case OBJECTIVE_GOTO_AREA_IN_CAR: + case OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET: + case OBJECTIVE_FIGHT_CHAR: + case OBJECTIVE_SET_LEADER: + case OBJECTIVE_FOLLOW_ROUTE: + case OBJECTIVE_SOLICIT: + case OBJECTIVE_HAIL_TAXI: + case OBJECTIVE_CATCH_TRAIN: + case OBJECTIVE_BUY_ICE_CREAM: + case OBJECTIVE_STEAL_ANY_CAR: + case OBJECTIVE_STEAL_ANY_MISSION_CAR: + case OBJECTIVE_MUG_CHAR: + case OBJECTIVE_LEAVE_CAR_AND_DIE: + case OBJECTIVE_FLEE_CAR: + case OBJECTIVE_SUN_BATHE: + case OBJECTIVE_AIM_GUN_AT_PED: + case OBJECTIVE_WANDER: + case OBJECTIVE_WAIT_FOR_RAIN_TO_END: + case OBJECTIVE_KILL_CHAR_ON_BOAT: + case OBJECTIVE_SOLICIT_FOOT: + case OBJECTIVE_WAIT_FOR_BUS: break; case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GOTO_AREA_ON_FOOT: @@ -17728,6 +17815,7 @@ CPed::SetObjective(eObjective newObj, CVector dest) } break; case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_SPRINT_TO_COORD: bIsRunning = true; m_pNextPathNode = nil; m_nextRoutePointPos = dest; @@ -18141,50 +18229,6 @@ CPed::SetCarJack_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_pVehicleAnim->SetFinishCallback(PedAnimAlignCB, this); } -void -CPed::SetObjective(eObjective newObj, CVector dest, float safeDist) -{ - if (DyingOrDead()) - return; - - if (m_prevObjective != OBJECTIVE_NONE && m_prevObjective == newObj) - return; - - SetObjectiveTimer(0); - if (m_objective == newObj) { - if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { - if (m_nextRoutePointPos == dest && m_distanceToCountSeekDone == safeDist) - return; - } else if (newObj == OBJECTIVE_GUARD_SPOT) { - if (m_vecSeekPosEx == dest && m_distanceToCountSeekDoneEx == safeDist) - return; - } - } - -#ifdef VC_PED_PORTS - ClearPointGunAt(); -#endif - bObjectiveCompleted = false; - if (IsTemporaryObjective(m_objective)) { - m_prevObjective = newObj; - } else { - if (m_objective != newObj) - SetStoredObjective(); - - m_objective = newObj; - } - - if (newObj == OBJECTIVE_GUARD_SPOT) { - m_vecSeekPosEx = dest; - m_distanceToCountSeekDoneEx = safeDist; - } else if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { - m_pNextPathNode = nil; - m_nextRoutePointPos = dest; - m_vecSeekPos = m_nextRoutePointPos; - bUsePedNodeSeek = true; - } -} - void CPed::SetCarJack(CVehicle* car) { @@ -18338,6 +18382,7 @@ CPed::SetExitBoat(CVehicle *boat) m_vecMoveSpeed = boat->m_vecMoveSpeed; } +// --MIAMI: Done void CPed::SetNewAttraction(CPedAttractor* pAttractor, const CVector& pos, float heading, float time, int32 qid) { diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 8e8e3b75..8aead855 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -182,7 +182,7 @@ enum eWaitState { enum eObjective : uint32 { OBJECTIVE_NONE, OBJECTIVE_IDLE, - OBJ_2, + OBJECTIVE_IDLE_COP, OBJECTIVE_FLEE_TILL_SAFE, OBJECTIVE_GUARD_SPOT, OBJECTIVE_GUARD_AREA, // not implemented @@ -193,9 +193,9 @@ enum eObjective : uint32 { OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS, OBJECTIVE_GOTO_CHAR_ON_FOOT, + OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING, + OBJECTIVE_HASSLE_CHAR, OBJECTIVE_FOLLOW_PED_IN_FORMATION, - OBJ_14, - OBJ_15, OBJECTIVE_LEAVE_VEHICLE, OBJECTIVE_ENTER_CAR_AS_PASSENGER, OBJECTIVE_ENTER_CAR_AS_DRIVER, @@ -206,8 +206,8 @@ enum eObjective : uint32 { OBJECTIVE_GOTO_AREA_ANY_MEANS, OBJECTIVE_GOTO_AREA_ON_FOOT, OBJECTIVE_RUN_TO_AREA, - OBJECTIVE_26, // not implemented - OBJECTIVE_27, // not implemented + OBJECTIVE_GOTO_AREA_IN_CAR, // not implemented + OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET, // not implemented OBJECTIVE_FIGHT_CHAR, OBJECTIVE_SET_LEADER, OBJECTIVE_FOLLOW_ROUTE, @@ -216,22 +216,22 @@ enum eObjective : uint32 { OBJECTIVE_CATCH_TRAIN, OBJECTIVE_BUY_ICE_CREAM, OBJECTIVE_STEAL_ANY_CAR, - OBJ_36, + OBJECTIVE_STEAL_ANY_MISSION_CAR, OBJECTIVE_MUG_CHAR, OBJECTIVE_LEAVE_CAR_AND_DIE, OBJECTIVE_USE_SEAT_ATTRACTOR, OBJECTIVE_USE_ATM_ATTRACTOR, OBJECTIVE_FLEE_CAR, - OBJ_42, + OBJECTIVE_SUN_BATHE, OBJECTIVE_USE_STOP_ATTRACTOR, OBJECTIVE_USE_PIZZA_ATTRACTOR, OBJECTIVE_USE_SHELTER_ATTRACTOR, OBJECTIVE_AIM_GUN_AT_PED, - OBJ_47, + OBJECTIVE_WANDER, OBJECTIVE_WAIT_FOR_RAIN_TO_END, OBJECTIVE_SPRINT_TO_COORD, - OBJ_50, - OBJ_51, + OBJECTIVE_KILL_CHAR_ON_BOAT, + OBJECTIVE_SOLICIT_FOOT, OBJECTIVE_WAIT_FOR_BUS, OBJECTIVE_USE_ICECREAM_ATTRACTOR, OBJECTIVE_PURCHASE_ICECREAM, @@ -696,7 +696,6 @@ public: void SetObjective(eObjective); void SetObjective(eObjective, int16, int16); void SetObjective(eObjective, CVector); - void SetObjective(eObjective, CVector, float); void SetObjective(eObjective, float, const CVector&); void ClearChat(void); void InformMyGangOfAttack(CEntity*); diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index 1229f222..884ea6cc 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -1973,7 +1973,7 @@ CBike::KnockOffRider(eWeaponType weapon, uint8 direction, CPed *ped, bool bGetBa else if(ped->m_pedStats->m_temper <= ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR && ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && !CTheScripts::IsPlayerOnAMission()){ - ped->SetObjective(OBJ_47, ped->m_pMyVehicle); + ped->SetObjective(OBJECTIVE_WANDER, ped->m_pMyVehicle); ped->m_nPathDir = CGeneral::GetRandomNumberInRange(0, 8); } }else if(ped->m_leader == nil){ -- 2.45.2 From c50a61d52aea452c4950062a2363576c25f662b8 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sun, 7 Jun 2020 15:07:36 +0300 Subject: [PATCH 8/9] fixed some arithmetic --- src/control/Script.cpp | 48 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index a06a9635..66aa825d 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1681,11 +1681,11 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; - case COMMAND_MULT_INT_LVAR_BY_INT_VAR: + case COMMAND_MULT_INT_VAR_BY_INT_LVAR: nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; - case COMMAND_MULT_INT_VAR_BY_INT_LVAR: + case COMMAND_MULT_INT_LVAR_BY_INT_VAR: nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1697,11 +1697,11 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; - case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_VAR: + case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_LVAR: fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; - case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_LVAR: + case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_VAR: fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1713,11 +1713,11 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; - case COMMAND_DIV_INT_LVAR_BY_INT_VAR: + case COMMAND_DIV_INT_VAR_BY_INT_LVAR: nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; - case COMMAND_DIV_INT_VAR_BY_INT_LVAR: + case COMMAND_DIV_INT_LVAR_BY_INT_VAR: nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1729,11 +1729,11 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; - case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_VAR: + case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_LVAR: fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; - case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_LVAR: + case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_VAR: fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1759,11 +1759,19 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; +#ifdef FIX_BUGS + case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_LVAR: +#else case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_VAR: +#endif fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; +#ifdef FIX_BUGS + case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_VAR: +#else case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_LVAR: +#endif fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1789,11 +1797,19 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; +#ifdef FIX_BUGS // in SA it was fixed by reversing their order in enum + case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_LVAR: +#else case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_VAR: +#endif fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; +#ifdef FIX_BUGS + case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_VAR: +#else case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_LVAR: +#endif fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; @@ -1807,13 +1823,13 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; } - case COMMAND_SET_LVAR_INT_TO_VAR_INT: + case COMMAND_SET_VAR_INT_TO_LVAR_INT: { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; } - case COMMAND_SET_VAR_INT_TO_LVAR_INT: + case COMMAND_SET_LVAR_INT_TO_VAR_INT: { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); @@ -1831,13 +1847,13 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; } - case COMMAND_SET_LVAR_FLOAT_TO_VAR_FLOAT: + case COMMAND_SET_VAR_FLOAT_TO_LVAR_FLOAT: { float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; } - case COMMAND_SET_VAR_FLOAT_TO_LVAR_FLOAT: + case COMMAND_SET_LVAR_FLOAT_TO_VAR_FLOAT: { float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); @@ -1855,13 +1871,13 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; } - case COMMAND_CSET_LVAR_INT_TO_VAR_FLOAT: + case COMMAND_CSET_VAR_INT_TO_LVAR_FLOAT: { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; } - case COMMAND_CSET_VAR_INT_TO_LVAR_FLOAT: + case COMMAND_CSET_LVAR_INT_TO_VAR_FLOAT: { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); @@ -1879,13 +1895,13 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; } - case COMMAND_CSET_LVAR_FLOAT_TO_VAR_INT: + case COMMAND_CSET_VAR_FLOAT_TO_LVAR_INT: { float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; } - case COMMAND_CSET_VAR_FLOAT_TO_LVAR_INT: + case COMMAND_CSET_LVAR_FLOAT_TO_VAR_INT: { float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); -- 2.45.2 From fe3a3ad8b51b082a4d93b76175fc9a33700b0e34 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 7 Jun 2020 10:43:33 +0300 Subject: [PATCH 9/9] cleanup --- src/render/Font.cpp | 51 ++++++++++++++++++++++++++--------------- src/render/Font.h | 3 +-- src/render/Sprite2d.cpp | 41 ++++++++++----------------------- src/render/Sprite2d.h | 4 ---- 4 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 99d63ea4..961dc20d 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -394,7 +394,7 @@ CFont::PrintChar(float x, float y, wchar c) CSprite2d::AddToBuffer( CRect(x, y, x + 32.0f * RenderState.scaleX * w, - y + 32.0f * RenderState.scaleX * 0.5f), + y + 32.0f * RenderState.scaleY * 0.5f), RenderState.color, xoff / 16.0f, yoff / 16.0f, (xoff + w) / 16.0f, yoff / 16.0f, @@ -811,8 +811,8 @@ CFont::PrintString(float x, float y, uint32, wchar *start, wchar *end, float spw RenderState.style = Details.style; } - float dropShadowPosition = CFont::Details.dropShadowPosition; - if (dropShadowPosition != 0.0f && (CFont::Details.style == FONT_BANK || CFont::Details.style == FONT_STANDARD)) { + float dropShadowPosition = Details.dropShadowPosition; + if (dropShadowPosition != 0.0f && (Details.style == FONT_BANK || Details.style == FONT_STANDARD)) { CRGBA color = Details.color; Details.color = Details.dropColor; Details.dropShadowPosition = 0; @@ -828,11 +828,11 @@ CFont::PrintString(float x, float y, uint32, wchar *start, wchar *end, float spw } Details.color = color; Details.dropShadowPosition = dropShadowPosition; - Details.bIsShadow = 0; + Details.bIsShadow = false; } - if (FontRenderStatePointer.pStr >= (wchar*)&FontRenderStateBuf[1024] - (end - start + 26)) // why 26? - CFont::RenderFontBuffer(); - CFontRenderState* pRenderState = FontRenderStatePointer.pRenderState; + if (FontRenderStatePointer.pStr >= (wchar*)&FontRenderStateBuf[ARRAY_SIZE(FontRenderStateBuf)] - (end - start + 26)) // why 26? + RenderFontBuffer(); + CFontRenderState *pRenderState = FontRenderStatePointer.pRenderState; pRenderState->fTextPosX = x; pRenderState->fTextPosY = y; pRenderState->scaleX = Details.scaleX; @@ -994,15 +994,28 @@ CFont::GetStringWidth(wchar *s, bool spaces) } else #endif { - for (; (*s != ' ' || spaces) && *s != '\0'; s++) { - if (*s == '~') { - s++; - while (*s != '~') s++; + for (wchar c = *s; (c != ' ' || spaces) && c != '\0'; c = *(++s)) { + if (c == '~') { + + // This is original code +#if 0 s++; - if (*s == ' ' && !spaces) - break; + while (*s != '~') { + s++; + } +#else + // TODO(Miami): This is my code to prevent fuck up until InsertPlayerControlKeysInString is done + if (*(s + 1) != '~') { + s++; + while (*s != '~') { + s++; + } + } +#endif + } + else { + w += GetCharacterSize(c - ' '); } - w += GetCharacterSize(*s - ' '); } } return w; @@ -1136,7 +1149,7 @@ CFont::ParseToken(wchar *s) wchar* CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) { - Details.anonymous_23 = 0; + Details.anonymous_23 = false; wchar *s = str + 1; if (Details.color.r || Details.color.g || Details.color.b) { @@ -1215,7 +1228,7 @@ CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) while (*s != '~') ++s; if (*(++s) == '~') - s = CFont::ParseToken(s, color, flash, bold); + s = ParseToken(s, color, flash, bold); return s; } @@ -1260,7 +1273,7 @@ CFont::RenderFontBuffer() color = RenderState.color; } if (*pRenderStateBufPointer.pStr == '~') { - pRenderStateBufPointer.pStr = CFont::ParseToken(pRenderStateBufPointer.pStr, color, bFlash, bBold); + pRenderStateBufPointer.pStr = ParseToken(pRenderStateBufPointer.pStr, color, bFlash, bBold); if (bFlash) { if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { Details.bFlashState = !Details.bFlashState; @@ -1286,9 +1299,9 @@ CFont::RenderFontBuffer() PrintChar(textPosX + 2.0f, textPosY, c); textPosX += 2.0f; } - textPosX += CFont::RenderState.scaleX * (RenderState.proportional ? Size[RenderState.style][c] : Size[RenderState.style][209]); + textPosX += RenderState.scaleX * (RenderState.proportional ? Size[RenderState.style][c] : Size[RenderState.style][209]); if (c == '\0') - textPosX += CFont::RenderState.fExtraSpace; + textPosX += RenderState.fExtraSpace; } CSprite2d::RenderVertexBuffer(); FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; diff --git a/src/render/Font.h b/src/render/Font.h index e30caed6..ca0ed7d0 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -27,8 +27,7 @@ struct CFontDetails uint32 bank; int16 dropShadowPosition; CRGBA dropColor; - char bFlashState; - char anonymous_21; + bool bFlashState; int nFlashTimer; bool anonymous_23; uint32 anonymous_25; diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp index 3f7cea44..bf39d15e 100644 --- a/src/render/Sprite2d.cpp +++ b/src/render/Sprite2d.cpp @@ -430,43 +430,26 @@ void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, } void -CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10) +CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) { - RwIm2DVertex* v = TempVertexBuffer; - SetVertices( - &v[nextBufferVertex], - r, - c, - c, - c, - c, - a3, - a4, - a5, - a6, - a7, - a8, - a9, - a10); - RwImVertexIndex *v12 = &TempBufferRenderIndexList[nextBufferIndex]; - v12[0] = nextBufferVertex; - v12[1] = nextBufferVertex + 1; - v12[2] = nextBufferVertex + 2; - v12[3] = nextBufferVertex + 3; - v12[4] = nextBufferVertex; - v12[5] = nextBufferVertex + 2; + SetVertices(&TempVertexBuffer[nextBufferVertex], r, c, c, c, c, u0, v0, u1, v1, u3, v3, u2, v2); + RwImVertexIndex *pIndexList = &TempBufferRenderIndexList[nextBufferIndex]; + pIndexList[0] = nextBufferVertex; + pIndexList[1] = nextBufferVertex + 1; + pIndexList[2] = nextBufferVertex + 2; + pIndexList[3] = nextBufferVertex + 3; + pIndexList[4] = nextBufferVertex; + pIndexList[5] = nextBufferVertex + 2; nextBufferIndex += 6; nextBufferVertex += 4; if (IsVertexBufferFull()) RenderVertexBuffer(); } -bool CSprite2d::IsVertexBufferFull() +bool +CSprite2d::IsVertexBufferFull() { - bool result = true; - if (nextBufferVertex <= 380 && nextBufferIndex <= 1018) - result = false; - return result; + return (nextBufferVertex > ARRAY_SIZE(TempVertexBuffer)-128-4 || nextBufferIndex > ARRAY_SIZE(TempBufferRenderIndexList)-6); } void diff --git a/src/render/Sprite2d.h b/src/render/Sprite2d.h index 679ac496..1adb5d49 100644 --- a/src/render/Sprite2d.h +++ b/src/render/Sprite2d.h @@ -12,10 +12,6 @@ public: static void SetRecipNearClip(void); static void InitPerFrame(void); - //static int32 GetBank(int32 n, RwTexture *tex); - //static void AddSpriteToBank(int32 bank, const CRect &rect, const CRGBA &col, - // float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); - //static void DrawBank(int32 bank); CSprite2d(void) : m_pTexture(nil) {}; ~CSprite2d(void) { Delete(); }; -- 2.45.2