[Voice] Use largelocal for speed/+cred/respect? (#448)

This commit is contained in:
Edo 2022-08-22 16:06:00 +02:00 committed by GitHub
parent ba34f1ea7c
commit 92ed9afae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 145 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include <STDInclude.hpp>
#include "Game/Engine/LargeLocal.hpp"
namespace Components
{
@ -36,15 +37,17 @@ namespace Components
void Voice::SV_SendClientVoiceData(Game::client_t* client)
{
const auto msg_buf = std::make_unique<unsigned char[]>(0x10000);
Game::msg_t msg{};
const auto clientNum = client - Game::svs_clients;
const Game::Engine::LargeLocal msg_buf_large_local(0x10000);
auto* msg_buf = static_cast<unsigned char*>(msg_buf_large_local.GetBuf());
assert(VoicePacketCount[clientNum] >= 0);
if (client->header.state == Game::CS_ACTIVE && VoicePacketCount[clientNum])
{
Game::MSG_Init(&msg, msg_buf.get(), 0x10000);
Game::MSG_Init(&msg, msg_buf, 0x10000);
assert(msg.cursize == 0);
assert(msg.bit == 0);

View File

@ -0,0 +1,93 @@
#include <STDInclude.hpp>
#include "LargeLocal.hpp"
namespace Game::Engine
{
#define PAGE_SIZE 128
#define CanUseServerLargeLocal() (SV_GetServerThreadOwnsGame() ? Sys_IsServerThread() : Sys_IsRenderThread())
LargeLocal::LargeLocal(int sizeParam)
{
assert(sizeParam);
assert(Sys_IsMainThread() || CanUseServerLargeLocal());
sizeParam = ((sizeParam + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1));
if (Sys_IsMainThread())
{
this->startPos = LargeLocalBegin(sizeParam);
}
else
{
this->startPos = LargeLocalBeginRight(sizeParam);
}
this->size = sizeParam;
}
LargeLocal::~LargeLocal()
{
if (this->size)
{
this->PopBuf();
}
}
void LargeLocal::PopBuf()
{
assert(this->size);
assert(Sys_IsMainThread() || CanUseServerLargeLocal());
if (Sys_IsMainThread())
{
LargeLocalEnd(this->startPos);
}
else
{
LargeLocalEndRight(this->startPos);
}
this->size = 0;
}
void* LargeLocal::GetBuf() const
{
assert(this->size);
assert(Sys_IsMainThread() || CanUseServerLargeLocal());
return LargeLocalGetBuf(this->startPos, this->size);
}
void LargeLocalEnd(int startPos)
{
assert(Sys_IsMainThread());
assert(g_largeLocalBuf);
*g_largeLocalPos = startPos;
}
void LargeLocalEndRight(int startPos)
{
assert(CanUseServerLargeLocal());
assert(g_largeLocalBuf);
*g_largeLocalRightPos = startPos;
}
void* LargeLocalGetBuf(int startPos, int size)
{
assert(Sys_IsMainThread() || CanUseServerLargeLocal());
assert(g_largeLocalBuf);
assert(!(size & (PAGE_SIZE - 1)));
if (Sys_IsMainThread())
{
return &g_largeLocalBuf[startPos];
}
const auto startIndex = startPos - size;
assert(startIndex >= 0);
return &g_largeLocalBuf[startIndex];
}
}

View File

@ -0,0 +1,29 @@
#pragma once
namespace Game::Engine
{
class LargeLocal
{
public:
explicit LargeLocal(int sizeParam);
~LargeLocal();
LargeLocal(LargeLocal&&) = delete;
LargeLocal(const LargeLocal&) = delete;
LargeLocal& operator=(LargeLocal&&) = delete;
LargeLocal& operator=(const LargeLocal&) = delete;
void* GetBuf() const;
private:
void PopBuf();
int startPos;
int size;
};
extern void LargeLocalEnd(int startPos);
extern void LargeLocalEndRight(int startPos);
extern void* LargeLocalGetBuf(int startPos, int size);
}

View File

@ -493,6 +493,9 @@ namespace Game
Voice_IncomingVoiceData_t Voice_IncomingVoiceData = Voice_IncomingVoiceData_t(0x5001A0);
Voice_IsClientTalking_t Voice_IsClientTalking = Voice_IsClientTalking_t(0x4D9D20);
LargeLocalBegin_t LargeLocalBegin = LargeLocalBegin_t(0x4127A0);
LargeLocalBeginRight_t LargeLocalBeginRight = LargeLocalBeginRight_t(0x644140);
XAssetHeader* DB_XAssetPool = reinterpret_cast<XAssetHeader*>(0x7998A8);
unsigned int* g_poolSize = reinterpret_cast<unsigned int*>(0x7995E8);
@ -664,6 +667,10 @@ namespace Game
volatile long* sv_thread_owns_game = reinterpret_cast<volatile long*>(0x2089DB8);
unsigned char* g_largeLocalBuf = reinterpret_cast<unsigned char*>(0x63D9790);
int* g_largeLocalPos = reinterpret_cast<int*>(0x63D97B4);
int* g_largeLocalRightPos = reinterpret_cast<int*>(0x63D9780);
void Sys_LockRead(FastCriticalSection* critSect)
{
InterlockedIncrement(&critSect->readCount);

View File

@ -1188,6 +1188,12 @@ namespace Game
typedef bool(__cdecl * Voice_IsClientTalking_t)(int clientNum);
extern Voice_IsClientTalking_t Voice_IsClientTalking;
typedef int(__cdecl * LargeLocalBegin_t)(int size);
extern LargeLocalBegin_t LargeLocalBegin;
typedef int(__cdecl* LargeLocalBeginRight_t)(int size);
extern LargeLocalBeginRight_t LargeLocalBeginRight;
constexpr std::size_t STATIC_MAX_LOCAL_CLIENTS = 1;
constexpr std::size_t MAX_LOCAL_CLIENTS = 1;
constexpr std::size_t MAX_CLIENTS = 18;
@ -1269,7 +1275,7 @@ namespace Game
extern FxEffectDef*** varFxEffectDefHandle;
extern PhysCollmap*** varPhysCollmapPtr;
extern PhysPreset*** varPhysPresetPtr;
extern Game::MaterialPass** varMaterialPass;
extern MaterialPass** varMaterialPass;
extern snd_alias_list_t*** varsnd_alias_list_name;
extern FxElemField* s_elemFields;
@ -1370,6 +1376,10 @@ namespace Game
extern volatile long* sv_thread_owns_game;
extern unsigned char* g_largeLocalBuf;
extern int* g_largeLocalPos;
extern int* g_largeLocalRightPos;
void Sys_LockRead(FastCriticalSection* critSect);
void Sys_UnlockRead(FastCriticalSection* critSect);