Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/aggresive_restream
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Aug 27, 2024
2 parents c171223 + 4e7afa2 commit 55b65f1
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 195 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/dockerimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:
- 'Dockerfile.i386'
- 'Dockerfile.armhf'
- 'Dockerfile.arm64'
- 'Dockerfile.osx-x64'
- 'Dockerfile.osx-arm64'

jobs:
build:
Expand All @@ -28,10 +26,6 @@ jobs:
dockerfile: Dockerfile.armhf
- tag: arm64
dockerfile: Dockerfile.arm64
- tag: osx-x64
dockerfile: Dockerfile.osx-x64
- tag: osx-arm64
dockerfile: Dockerfile.osx-arm64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions Client/core/CChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,11 @@ void CChat::SetCharacterLimit(int charLimit)
m_iCharacterLimit = charLimit;
}

float CChat::GetChatBottomPosition() const noexcept
{
return m_vecBackgroundSize.fY;
}

CChatLine::CChatLine()
{
m_bActive = false;
Expand Down
2 changes: 2 additions & 0 deletions Client/core/CChat.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class CChat
constexpr int GetDefaultCharacterLimit() const { return m_iDefaultCharacterLimit; }
constexpr int GetMaxCharacterLimit() const { return m_iMaxCharacterLimit; }

float GetChatBottomPosition() const noexcept;

private:
void LoadCVars();

Expand Down
5 changes: 0 additions & 5 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,11 +2181,6 @@ CModelCacheManager* CCore::GetModelCacheManager()
return m_pModelCacheManager;
}

void CCore::AddModelToPersistentCache(ushort usModelId)
{
return GetModelCacheManager()->AddModelToPersistentCache(usModelId);
}

void CCore::StaticIdleHandler()
{
g_pCore->IdleHandler();
Expand Down
1 change: 0 additions & 1 deletion Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
EDiagnosticDebugType GetDiagnosticDebug();
void SetDiagnosticDebug(EDiagnosticDebugType value);
CModelCacheManager* GetModelCacheManager();
void AddModelToPersistentCache(ushort usModelId);

static void StaticIdleHandler();
void IdleHandler();
Expand Down
5 changes: 5 additions & 0 deletions Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ CChat* CLocalGUI::GetChat()
return m_pChat;
}

float CLocalGUI::GetChatBottomPosition() const noexcept
{
return m_pChat->GetChatBottomPosition();
}

CDebugView* CLocalGUI::GetDebugView()
{
return m_pDebugView;
Expand Down
1 change: 1 addition & 0 deletions Client/core/CGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CLocalGUI : public CSingleton<CLocalGUI>
bool IsMainMenuVisible();

CChat* GetChat();
float GetChatBottomPosition() const noexcept;
void SetChatBoxVisible(bool bVisible, bool bInputBlocked = true);
bool IsChatBoxVisible();
bool IsChatBoxInputBlocked();
Expand Down
48 changes: 28 additions & 20 deletions Client/core/CGraphStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace
{
#define GRAPHSTAT_HISTORY_SIZE 256

struct SGraphStatLine
{
TIMEUS prevData;
Expand Down Expand Up @@ -113,6 +111,11 @@ void CGraphStats::AddTimingPoint(const char* szName)
if (!IsEnabled())
return;

CGraphicsInterface* pGraphics = g_pCore->GetGraphics();

std::uint32_t viewportWidth = pGraphics->GetViewportWidth();
std::uint32_t sizeX = viewportWidth / 4; // one quarter of screen width

// Start of next frame?
if (szName[0] == 0)
{
Expand All @@ -133,7 +136,7 @@ void CGraphStats::AddTimingPoint(const char* szName)
for (int i = 0; i < Dups; i++)
{
pLine->iDataPos++;
if (pLine->iDataPos > GRAPHSTAT_HISTORY_SIZE - 1)
if (pLine->iDataPos > sizeX - 1)
pLine->iDataPos = 0;
pLine->dataHistory[pLine->iDataPos] = Data;
}
Expand All @@ -153,7 +156,7 @@ void CGraphStats::AddTimingPoint(const char* szName)
// Add new line
MapSet(m_LineList, szName, SGraphStatLine());
pLine = MapFind(m_LineList, szName);
pLine->dataHistory.resize(GRAPHSTAT_HISTORY_SIZE);
pLine->dataHistory.resize(sizeX);
memset(&pLine->dataHistory[0], 0, pLine->dataHistory.size());
pLine->iDataPos = 0;
pLine->prevData = 0;
Expand All @@ -179,7 +182,7 @@ void CGraphStats::AddTimingPoint(const char* szName)

// Inc position
pLine->iDataPos++;
if (pLine->iDataPos > GRAPHSTAT_HISTORY_SIZE - 1)
if (pLine->iDataPos > sizeX - 1)
pLine->iDataPos = 0;

// Insert data point
Expand All @@ -199,44 +202,49 @@ void CGraphStats::Draw()
return;

CGraphicsInterface* pGraphics = g_pCore->GetGraphics();
CLocalGUI* pLocalGUI = g_pCore->GetLocalGUI();

std::uint32_t viewportWidth = pGraphics->GetViewportWidth(); // get width of current resolution
std::uint32_t viewportHeight = pGraphics->GetViewportHeight(); // get height of current resolution
std::uint32_t originX = 10; // offset the graph by 10 pixels from left side of screen
std::uint32_t originY = pLocalGUI->GetChatBottomPosition(); // get chat bottom screen position
std::uint32_t sizeX = viewportWidth / 4; // set the width of graph to 1/4 of current resolution
std::uint32_t sizeY = viewportHeight / 4; // set the height of graph to 1/4 of current resolution
std::uint32_t rangeY = 100; // 100ms

originY = originY + sizeY + 30; // add graph height plus a little gap to the overall Y position

uint uiViewportHeight = pGraphics->GetViewportHeight();
uint uiOriginX = 10;
uint uiOriginY = std::min<int>(500, uiViewportHeight - 10);
uint uiSizeX = GRAPHSTAT_HISTORY_SIZE;
uint uiSizeY = 150;
uint uiRangeY = 100; // 100ms
float fLineScale = 1 / 1000.f / uiRangeY * uiSizeY;
float fLineScale = 1 / 1000.f / rangeY * sizeY;
float fLineHeight = pGraphics->GetDXFontHeight();

// Backgroung box
pGraphics->DrawRectQueued(uiOriginX, uiOriginY - uiSizeY, uiSizeX, uiSizeY, SColorRGBA(0, 0, 0, 128), true);
pGraphics->DrawRectQueued(originX, originY - sizeY, sizeX, sizeY, SColorRGBA(0, 0, 0, 128), true);

// Draw data lines
float fLabelX = uiOriginX + uiSizeX + 22;
float fLabelY = uiOriginY - m_LineList.size() * fLineHeight;
float fLabelX = originX + sizeX + 22;
float fLabelY = originY - m_LineList.size() * fLineHeight;
for (const auto& dataLine : m_LineList)
{
const SGraphStatLine& line = dataLine.second;
int iDataPos = line.iDataPos;
int iDataPosPrev = iDataPos;

for (int i = uiSizeX - 1; i > 0; i--)
for (int i = sizeX - 1; i > 0; i--)
{
float fY0 = line.dataHistory[iDataPos] * fLineScale;
float fY1 = line.dataHistory[iDataPosPrev] * fLineScale;

iDataPosPrev = iDataPos;
iDataPos--;
if (iDataPos == -1)
iDataPos = GRAPHSTAT_HISTORY_SIZE - 1;
iDataPos = sizeX - 1;

pGraphics->DrawLineQueued(uiOriginX + i - 1, uiOriginY - fY0, uiOriginX + i, uiOriginY - fY1, 1, line.color, true);
pGraphics->DrawLineQueued(originX + i - 1, originY - fY0, originX + i, originY - fY1, 1, line.color, true);

if (i == uiSizeX - 1)
if (i == sizeX - 1)
{
// Line from graph to label
pGraphics->DrawLineQueued(uiOriginX + i - 1, uiOriginY - fY0, fLabelX - 2, fLabelY + fLineHeight / 2, 1, line.color, true);
pGraphics->DrawLineQueued(originX + i - 1, originY - fY0, fLabelX - 2, fLabelY + fLineHeight / 2, 1, line.color, true);
}
}

Expand Down
28 changes: 1 addition & 27 deletions Client/core/CModelCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class CModelCacheManagerImpl : public CModelCacheManager
virtual void OnClientClose();
virtual void UpdatePedModelCaching(const std::map<ushort, float>& newNeedCacheList);
virtual void UpdateVehicleModelCaching(const std::map<ushort, float>& newNeedCacheList);
virtual void AddModelToPersistentCache(ushort usModelId);
virtual void SetCustomLimits(std::optional<size_t> numVehicles, std::optional<size_t> numPeds);

// CModelCacheManagerImpl methods
Expand All @@ -72,7 +71,6 @@ class CModelCacheManagerImpl : public CModelCacheManager
bool m_IsUsingCustomVehicleCacheLimit{}; //< If `true` the value is set by the scripter, otherwise is calculated in `DoPulse()`
std::map<ushort, SModelCacheInfo> m_PedModelCacheInfoMap{};
std::map<ushort, SModelCacheInfo> m_VehicleModelCacheInfoMap{};
std::set<ushort> m_PermoLoadedModels{};
};

///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -266,22 +264,6 @@ void CModelCacheManagerImpl::DoPulse()
}
}

///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::AddModelToPersistentCache
//
// Keep this model around 4 evar now
//
///////////////////////////////////////////////////////////////
void CModelCacheManagerImpl::AddModelToPersistentCache(ushort usModelId)
{
if (!MapContains(m_PermoLoadedModels, usModelId))
{
AddModelRefCount(usModelId);
MapInsert(m_PermoLoadedModels, usModelId);
}
}

///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::UpdatePedModelCaching
Expand Down Expand Up @@ -542,13 +524,5 @@ void CModelCacheManagerImpl::OnRestreamModel(ushort usModelId)
OutputDebugLine(SString("[Cache] End caching model %d (OnRestreamModel)", usModelId));
}
}
}

// Also check the permo list
if (MapContains(m_PermoLoadedModels, usModelId))
{
SubModelRefCount(usModelId);
MapRemove(m_PermoLoadedModels, usModelId);
OutputDebugLine(SString("[Cache] End permo-caching model %d (OnRestreamModel)", usModelId));
}
}
}
1 change: 0 additions & 1 deletion Client/core/CModelCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class CModelCacheManager
virtual void OnClientClose() = 0;
virtual void UpdatePedModelCaching(const std::map<ushort, float>& newNeedCacheList) = 0;
virtual void UpdateVehicleModelCaching(const std::map<ushort, float>& newNeedCacheList) = 0;
virtual void AddModelToPersistentCache(ushort usModelId) = 0;
virtual void SetCustomLimits(std::optional<size_t> numVehicles, std::optional<size_t> numPeds) = 0;
};

Expand Down
16 changes: 5 additions & 11 deletions Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ void CPedSA::Init()

void CPedSA::SetModelIndex(DWORD dwModelIndex)
{
DWORD dwFunction = FUNC_SetModelIndex;
// Delete any existing RwObject first
GetPedInterface()->DeleteRwObject();

// Set new model
DWORD dwThis = (DWORD)GetInterface();
DWORD dwFunction = FUNC_SetModelIndex;
_asm
{
mov ecx, dwThis
Expand All @@ -116,16 +120,6 @@ void CPedSA::SetModelIndex(DWORD dwModelIndex)
}
}

// Hacky thing done for the local player when changing model
void CPedSA::RemoveGeometryRef()
{
RpClump* pClump = (RpClump*)GetInterface()->m_pRwObject;
RpAtomic* pAtomic = (RpAtomic*)((pClump->atomics.root.next) - 0x8);
RpGeometry* pGeometry = pAtomic->geometry;
if (pGeometry->refs > 1)
pGeometry->refs--;
}

bool CPedSA::IsInWater()
{
CTask* pTask = m_pPedIntelligence->GetTaskManager()->GetTask(TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);
Expand Down
1 change: 0 additions & 1 deletion Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
CPedSAInterface* GetPedInterface() { return (CPedSAInterface*)GetInterface(); }
void Init();
void SetModelIndex(DWORD dwModelIndex);
void RemoveGeometryRef();
void AttachPedToEntity(DWORD dwEntityInterface, CVector* vector, unsigned short sDirection, float fRotationLimit, eWeaponType weaponType,
bool bChangeCamera);
void DetachPedFromEntity();
Expand Down
17 changes: 1 addition & 16 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3927,22 +3927,7 @@ void CClientPed::_ChangeModel()
// So make sure clothes geometry is built now...
m_pClothes->AddAllToModel();
m_pPlayerPed->RebuildPlayer();

// ...and decrement the extra ref
#ifdef NO_CRASH_FIX_TEST2
m_pPlayerPed->RemoveGeometryRef();
#endif
}
else
{
// When the local player changes to another (non CJ) model, the geometry gets an extra ref from somewhere, causing a memory leak.
// So decrement the extra ref here
#ifdef NO_CRASH_FIX_TEST
m_pPlayerPed->RemoveGeometryRef();
#endif
// As we will have problem removing the geometry later, we might as well keep the model cached until exit
g_pCore->AddModelToPersistentCache((ushort)m_ulModel);
}
}

// Remove reference to the old model we used (Flag extra GTA reference to be removed as well)
pLoadedModel->RemoveRef(true);
Expand Down
6 changes: 5 additions & 1 deletion Client/mods/deathmatch/logic/CResourceModelStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ void CResourceModelStreamer::ReleaseAll()

void CResourceModelStreamer::FullyReleaseModel(std::uint16_t modelId)
{
std::uint16_t &refsCount = m_requestedModels[modelId];
auto refs = m_requestedModels.find(modelId);
if (refs == m_requestedModels.end())
return;

std::uint16_t& refsCount = refs->second;

if (refsCount > 0)
{
Expand Down
1 change: 0 additions & 1 deletion Client/sdk/core/CCoreInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class CCoreInterface
virtual EDiagnosticDebugType GetDiagnosticDebug() = 0;
virtual void SetDiagnosticDebug(EDiagnosticDebugType value) = 0;
virtual CModelCacheManager* GetModelCacheManager() = 0;
virtual void AddModelToPersistentCache(ushort usModelId) = 0;
virtual void UpdateDummyProgress(int iValue = -1, const char* szType = "") = 0;
virtual void SetDummyProgressUpdateAlways(bool bAlways) = 0;

Expand Down
1 change: 0 additions & 1 deletion Client/sdk/game/CPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class CPed : public virtual CPhysical
virtual void Respawn(CVector* position, bool bCameraCut) = 0;

virtual void SetModelIndex(unsigned long ulModel) = 0;
virtual void RemoveGeometryRef() = 0;

virtual float GetHealth() = 0;
virtual void SetHealth(float fHealth) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV AS_BUILDAGENT=0 \
RUN apt-get update && \
apt-get install -y software-properties-common wget ca-certificates git build-essential \
gcc-10 g++-10 curl subversion ncftp \
libncurses-dev libncursesw5 libmysqlclient-dev
libncurses-dev libncursesw6 libmysqlclient-dev

# Set build directory
VOLUME /build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN sed -i 's/deb http/deb \[arch=amd64,i386\] http/' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y make git ncftp \
gcc-10-aarch64-linux-gnu g++-10-aarch64-linux-gnu \
libncursesw5:arm64 libncursesw5-dev:arm64 libmysqlclient-dev:arm64
libncurses-dev:arm64 libncursesw6:arm64 libmysqlclient-dev:arm64

# Set build directory
VOLUME /build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.armhf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN sed -i 's/deb http/deb \[arch=amd64,i386\] http/' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y make git ncftp \
gcc-10-arm-linux-gnueabihf g++-10-arm-linux-gnueabihf \
libncursesw5:armhf libncursesw5-dev:armhf libmysqlclient-dev:armhf
libncurses-dev:armhf libncursesw6:armhf libmysqlclient-dev:armhf

# Set build directory
VOLUME /build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.i386
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV AS_BUILDAGENT=0 \
RUN dpkg --add-architecture i386 && apt-get update && \
apt-get install -y software-properties-common wget ca-certificates git build-essential \
gcc-10-multilib g++-10-multilib curl subversion ncftp \
libncurses-dev:i386 libncursesw5:i386 libmysqlclient-dev:i386
libncurses-dev:i386 libncursesw6:i386 libmysqlclient-dev:i386

# Set build directory
VOLUME /build
Expand Down
Loading

0 comments on commit 55b65f1

Please sign in to comment.