Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Dec 19, 2022
2 parents afaabab + d965e06 commit 493d9fb
Show file tree
Hide file tree
Showing 530 changed files with 5,104 additions and 10,797 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: Download DirectX
if: steps.cache-dxfiles.outputs.cache-hit != 'true'
run: Invoke-WebRequest https://mirror.mtasa.com/bdata/DXFiles.zip -OutFile utils/DXFiles.zip
run: Invoke-WebRequest https://mirror-cdn.multitheftauto.com/bdata/DXFiles.zip -OutFile utils/DXFiles.zip
shell: powershell

- name: Extract DirectX
Expand Down
161 changes: 84 additions & 77 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <cef3/cef/include/cef_task.h>
#include "CWebDevTools.h"

namespace
{
const int CEF_PIXEL_STRIDE = 4;
}

CWebView::CWebView(bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem, bool bTransparent)
{
m_bIsLocal = bIsLocal;
Expand All @@ -39,9 +44,6 @@ CWebView::~CWebView()
// Ensure that CefRefPtr::~CefRefPtr doesn't try to release it twice (it has already been released in CWebView::OnBeforeClose)
m_pWebView = nullptr;

// Make sure we don't dead lock the CEF render thread
m_RenderData.cv.notify_all();

OutputDebugLine("CWebView::~CWebView");
}

Expand Down Expand Up @@ -75,9 +77,6 @@ void CWebView::CloseBrowser()
// CefBrowserHost::CloseBrowser calls the destructor after the browser has been destroyed
m_bBeingDestroyed = true;

// Make sure we don't dead lock the CEF render thread
m_RenderData.cv.notify_all();

if (m_pWebView)
m_pWebView->GetHost()->CloseBrowser(true);
}
Expand Down Expand Up @@ -182,15 +181,17 @@ void CWebView::ClearTexture()
IDirect3DSurface9* pD3DSurface = m_pWebBrowserRenderItem->m_pD3DRenderTargetSurface;
if (!pD3DSurface)
return;

D3DLOCKED_RECT LockedRect;

D3DSURFACE_DESC SurfaceDesc;
if (FAILED(pD3DSurface->GetDesc(&SurfaceDesc)))
return;

pD3DSurface->GetDesc(&SurfaceDesc);
pD3DSurface->LockRect(&LockedRect, NULL, 0);

memset(LockedRect.pBits, 0xFF, SurfaceDesc.Width * SurfaceDesc.Height * 4);
pD3DSurface->UnlockRect();
D3DLOCKED_RECT LockedRect;
if (SUCCEEDED(pD3DSurface->LockRect(&LockedRect, NULL, D3DLOCK_DISCARD)))
{
memset(LockedRect.pBits, 0xFF, SurfaceDesc.Height * LockedRect.Pitch);
pD3DSurface->UnlockRect();
}
}

void CWebView::UpdateTexture()
Expand All @@ -210,61 +211,76 @@ void CWebView::UpdateTexture()
{
// Lock surface
D3DLOCKED_RECT LockedRect;
pSurface->LockRect(&LockedRect, nullptr, 0);

// Dirty rect implementation, don't use this as loops are significantly slower than memcpy
auto surfaceData = static_cast<byte*>(LockedRect.pBits);
auto sourceData = static_cast<const byte*>(m_RenderData.buffer);
auto pitch = LockedRect.Pitch;

// Update view area
if (m_RenderData.changed)
if (SUCCEEDED(pSurface->LockRect(&LockedRect, nullptr, 0)))
{
// Update changed state
m_RenderData.changed = false;

if (m_RenderData.dirtyRects.size() > 0 && m_RenderData.dirtyRects[0].width == m_RenderData.width &&
m_RenderData.dirtyRects[0].height == m_RenderData.height)
// Dirty rect implementation, don't use this as loops are significantly slower than memcpy
const auto destData = static_cast<byte*>(LockedRect.pBits);
const auto sourceData = static_cast<const byte*>(m_RenderData.buffer);
const auto destPitch = LockedRect.Pitch;
const auto sourcePitch = m_RenderData.width * CEF_PIXEL_STRIDE;

// Update view area
if (m_RenderData.changed)
{
// Update whole texture
memcpy(surfaceData, sourceData, m_RenderData.width * m_RenderData.height * 4);
}
else
{
// Update dirty rects
for (auto& rect : m_RenderData.dirtyRects)
// Update changed state
m_RenderData.changed = false;

if (m_RenderData.dirtyRects.size() > 0 && m_RenderData.dirtyRects[0].width == m_RenderData.width &&
m_RenderData.dirtyRects[0].height == m_RenderData.height)
{
for (int y = rect.y; y < rect.y + rect.height; ++y)
// Note that D3D texture size can be hardware dependent(especially with dynamic texture)
// When destination and source pitches differ we must copy pixels row by row
if (destPitch == sourcePitch)
memcpy(destData, sourceData, destPitch * m_RenderData.height);
else
{
int index = y * pitch + rect.x * 4;
memcpy(&surfaceData[index], &sourceData[index], rect.width * 4);
for (int y = 0; y < m_RenderData.height; ++y)
{
const int sourceIndex = y * sourcePitch;
const int destIndex = y * destPitch;

memcpy(&destData[destIndex], &sourceData[sourceIndex], std::min(sourcePitch, destPitch));
}
}
}
else
{
// Update dirty rects
for (const auto& rect : m_RenderData.dirtyRects)
{
for (int y = rect.y; y < rect.y + rect.height; ++y)
{
// Note that D3D texture size can be hardware dependent(especially with dynamic texture)
// We cannot be sure that source and destination pitches are the same
const int sourceIndex = y * sourcePitch + rect.x * CEF_PIXEL_STRIDE;
const int destIndex = y * destPitch + rect.x * CEF_PIXEL_STRIDE;

memcpy(&destData[destIndex], &sourceData[sourceIndex], rect.width * CEF_PIXEL_STRIDE);
}
}
}
}
}

// Update popup area (override certain areas of the view texture)
bool popupSizeMismatches = m_RenderData.popupRect.x + m_RenderData.popupRect.width >= (int)m_pWebBrowserRenderItem->m_uiSizeX ||
m_RenderData.popupRect.y + m_RenderData.popupRect.height >= (int)m_pWebBrowserRenderItem->m_uiSizeY;
// Update popup area (override certain areas of the view texture)
const bool popupSizeMismatches = m_RenderData.popupRect.x + m_RenderData.popupRect.width >= (int)m_pWebBrowserRenderItem->m_uiSizeX ||
m_RenderData.popupRect.y + m_RenderData.popupRect.height >= (int)m_pWebBrowserRenderItem->m_uiSizeY;

if (m_RenderData.popupShown && !popupSizeMismatches)
{
auto popupPitch = m_RenderData.popupRect.width * 4;
for (int y = 0; y < m_RenderData.popupRect.height; ++y)
if (m_RenderData.popupShown && !popupSizeMismatches)
{
int sourceIndex = y * popupPitch;
int destIndex = (y + m_RenderData.popupRect.y) * pitch + m_RenderData.popupRect.x * 4;
const auto popupPitch = m_RenderData.popupRect.width * CEF_PIXEL_STRIDE;
for (int y = 0; y < m_RenderData.popupRect.height; ++y)
{
const int sourceIndex = y * popupPitch;
const int destIndex = (y + m_RenderData.popupRect.y) * destPitch + m_RenderData.popupRect.x * CEF_PIXEL_STRIDE;

memcpy(&surfaceData[destIndex], &m_RenderData.popupBuffer[sourceIndex], popupPitch);
memcpy(&destData[destIndex], &m_RenderData.popupBuffer[sourceIndex], popupPitch);
}
}
}

// Unlock surface
pSurface->UnlockRect();
// Unlock surface
pSurface->UnlockRect();
}
}

// Resume CEF render thread
m_RenderData.cv.notify_all();
}

void CWebView::ExecuteJavascript(const SString& strJavascriptCode)
Expand Down Expand Up @@ -431,9 +447,6 @@ void CWebView::Resize(const CVector2D& size)
// Send resize event to CEF
if (m_pWebView)
m_pWebView->GetHost()->WasResized();

// Tell CEF to render a new frame
m_RenderData.cv.notify_all();
}

CVector2D CWebView::GetSize()
Expand Down Expand Up @@ -661,7 +674,7 @@ void CWebView::OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect)
m_RenderData.popupRect = rect;

// Resize buffer
m_RenderData.popupBuffer.reset(new byte[rect.width * rect.height * 4]);
m_RenderData.popupBuffer.reset(new byte[rect.width * rect.height * CEF_PIXEL_STRIDE]);
}

////////////////////////////////////////////////////////////////////
Expand All @@ -677,31 +690,25 @@ void CWebView::OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintEle
if (m_bBeingDestroyed)
return;

std::unique_lock<std::mutex> lock(m_RenderData.dataMutex);

// Copy popup buffer
if (paintType == PET_POPUP)
{
std::lock_guard<std::mutex> lock(m_RenderData.dataMutex);

// Copy popup buffer
if (paintType == PET_POPUP)
if (m_RenderData.popupBuffer)
{
if (m_RenderData.popupBuffer)
{
memcpy(m_RenderData.popupBuffer.get(), buffer, width * height * 4);
}

return; // We don't have to wait as we've copied the buffer already
memcpy(m_RenderData.popupBuffer.get(), buffer, width * height * CEF_PIXEL_STRIDE);
}

// Store render data
m_RenderData.buffer = buffer;
m_RenderData.width = width;
m_RenderData.height = height;
m_RenderData.dirtyRects = dirtyRects;
m_RenderData.changed = true;
return; // We don't have to wait as we've copied the buffer already
}

// Wait for the main thread to handle drawing the texture
std::unique_lock<std::mutex> lock(m_RenderData.cvMutex);
m_RenderData.cv.wait(lock);
// Store render data
m_RenderData.buffer = buffer;
m_RenderData.width = width;
m_RenderData.height = height;
m_RenderData.dirtyRects = dirtyRects;
m_RenderData.changed = true;
}

////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 1 addition & 3 deletions Client/cefweb/CWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CWebView : public CWebViewInterface,
CefRefPtr<CefBrowser> m_pWebView;
CWebBrowserItem* m_pWebBrowserRenderItem;

bool m_bBeingDestroyed;
std::atomic_bool m_bBeingDestroyed;
bool m_bIsLocal;
bool m_bIsRenderingPaused;
bool m_bIsTransparent;
Expand All @@ -192,8 +192,6 @@ class CWebView : public CWebViewInterface,
{
bool changed = false;
std::mutex dataMutex;
std::mutex cvMutex;
std::condition_variable cv;

const void* buffer;
int width, height;
Expand Down
1 change: 1 addition & 0 deletions Client/core/CChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include <game/CGame.h>
#include <game/CSettings.h>

using std::vector;

Expand Down
2 changes: 2 additions & 0 deletions Client/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ void CClientVariables::LoadDefaults()
DEFAULT("tyre_smoke_enabled", 1); // Enable tyre smoke
DEFAULT("high_detail_vehicles", 0); // Disable rendering high detail vehicles all the time
DEFAULT("high_detail_peds", 0); // Disable rendering high detail peds all the time
DEFAULT("blur", 1); // Enable blur
DEFAULT("corona_reflections", 0); // Disable corona rain reflections
DEFAULT("dynamic_ped_shadows", 0); // Disable dynamic ped shadows
DEFAULT("fast_clothes_loading", 1); // 0-off 1-auto 2-on
DEFAULT("allow_screen_upload", 1); // 0-off 1-on
DEFAULT("allow_external_sounds", 1); // 0-off 1-on
Expand Down
3 changes: 2 additions & 1 deletion Client/core/CCommandFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include <game/CGame.h>
#include <game/CHud.h>

using std::list;

Expand Down Expand Up @@ -464,7 +465,7 @@ void CCommandFuncs::FakeLag(const char* szCmdLine)
{
if (!CCore::GetSingleton().IsFakeLagCommandEnabled())
{
g_pCore->GetConsole()->Print("fakelag command no enabled");
g_pCore->GetConsole()->Print("fakelag command not enabled");
return;
}

Expand Down
7 changes: 7 additions & 0 deletions Client/core/CCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
val = val.substr(nOpIndex + 1);
TrimWhiteSpace(val);
CVARS_SET(key, val);

// HACK: recalculate frame rate limit on cvar change
if (key == "fps_limit" && m_FpsLimitTimer.Get() >= 500 && CCore::GetSingleton().IsConnected())
{
CCore::GetSingleton().RecalculateFrameRateLimit(-1, true);
m_FpsLimitTimer.Reset();
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions Client/core/CCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CCommands : public CCommandsInterface, public CSingleton<CCommands>
void ExecuteHandler(PFNCOMMAND pfnHandler, const char* szParameters);

std::list<COMMANDENTRY*> m_CommandList;
CElapsedTime m_FpsLimitTimer;

pfnExecuteCommandHandler m_pfnExecuteHandler;
};
4 changes: 4 additions & 0 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include <game/CGame.h>
#include <game/CSettings.h>
#include <Accctrl.h>
#include <Aclapi.h>
#include "Userenv.h" // This will enable SharedUtil::ExpandEnvString
Expand Down Expand Up @@ -573,9 +574,12 @@ void CCore::ApplyGameSettings()
CVARS_GET("tyre_smoke_enabled", bVal);
m_pMultiplayer->SetTyreSmokeEnabled(bVal);
pGameSettings->UpdateFieldOfViewFromSettings();
pGameSettings->ResetBlurEnabled();
pGameSettings->ResetVehiclesLODDistance();
pGameSettings->ResetPedsLODDistance();
pGameSettings->ResetCoronaReflectionsEnabled();
CVARS_GET("dynamic_ped_shadows", bVal);
pGameSettings->SetDynamicPedShadowsEnabled(bVal);
pController->SetVerticalAimSensitivityRawValue(CVARS_GET_VALUE<float>("vertical_aim_sensitivity"));
CVARS_GET("mastervolume", fVal);
pGameSettings->SetRadioVolume(pGameSettings->GetRadioVolume() * fVal);
Expand Down
2 changes: 2 additions & 0 deletions Client/core/CCrashDumpWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "StdInc.h"
#include <game/CGame.h>
#include <game/CPools.h>
#include <game/CRenderWare.h>
#include <multiplayer/CMultiplayer.h>

#define LOG_EVENT_SIZE 200
Expand Down
19 changes: 16 additions & 3 deletions Client/core/CKeyBinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

#include "StdInc.h"
#include <game/CGame.h>
#include <game/CPed.h>
#include <game/CPedIntelligence.h>
#include <game/CPools.h>
#include <game/CTaskManager.h>
#include <game/Task.h>

const SBindableKey g_bkKeys[] = {{"mouse1", VK_LBUTTON, GTA_KEY_LMOUSE, DATA_NONE, 0},
{"mouse2", VK_RBUTTON, GTA_KEY_RMOUSE, DATA_NONE, 0},
Expand Down Expand Up @@ -1920,9 +1925,17 @@ void CKeyBinds::DoPostFramePulse()
{
if (!bInVehicle)
{
cs.ButtonCircle = (g_bcControls[0].bState && !bHasDetonator) ? 255 : 0; // Fire
cs.RightShoulder2 = (g_bcControls[1].bState || (bAimingWeapon && g_bcControls[7].bState)) ? 255 : 0; // Next Weapon / Zoom In
cs.LeftShoulder2 = (g_bcControls[2].bState || (bAimingWeapon && g_bcControls[8].bState)) ? 255 : 0; // Previous Weapon / Zoom Out
cs.ButtonCircle = (g_bcControls[0].bState && !bHasDetonator) ? 255 : 0; // Fire
if (bAimingWeapon)
{
cs.RightShoulder2 = g_bcControls[8].bState ? 255 : 0; // Zoom Out
cs.LeftShoulder2 = g_bcControls[7].bState ? 255 : 0; // Zoom In
}
else
{
cs.RightShoulder2 = g_bcControls[1].bState ? 255 : 0; // Next Weapon
cs.LeftShoulder2 = g_bcControls[2].bState ? 255 : 0; // Previous Weapon
}

if (!ControlForwardsBackWards(cs))
{
Expand Down
1 change: 1 addition & 0 deletions Client/core/CMemStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <StdInc.h>
#include <Psapi.h>
#include <game/CGame.h>
#include <game/CPools.h>
#include "CModelCacheManager.h"

DECLARE_ENUM(ePools);
Expand Down

0 comments on commit 493d9fb

Please sign in to comment.