Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ jobs:

- name: Build
run: dotnet build Source.NET.slnx -c ${{ matrix.configuration }}

- name: Test
run: dotnet test --project Source.Common.Tests/Source.Common.Tests.csproj -c ${{ matrix.configuration }} --no-build
2 changes: 1 addition & 1 deletion Game.Client/C_RecipientFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void UsePredictionRules() {

public bool IgnorePredictionCull() => bIgnorePredictionCull;
public void SetIgnorePredictionCull(bool ignore) => bIgnorePredictionCull = ignore;
public void AddPlayersFromBitMask(in AbsolutePlayerLimitBitVec playerbits) {
public void AddPlayersFromBitMask(in PlayerBitSet playerbits) {
C_BasePlayer? player = C_BasePlayer.GetLocalPlayer();

if (player == null)
Expand Down
1 change: 1 addition & 0 deletions Game.Client/Game.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<ProjectReference Include="../Source.CodeAnalysis/Source.CodeAnalysis/Source.CodeAnalysis.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="../Source.CodeAnalysis.Lua/Source.CodeAnalysis.Lua.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="../Source.CodeAnalysis.NetworkVars/Source.CodeAnalysis.NetworkVars.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="../Source.CodeAnalysis.BitVec/Source.CodeAnalysis.BitVec.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.5" />
Expand Down
30 changes: 15 additions & 15 deletions Game.Client/VoiceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ public class VoiceStatus
int ServerModEnable; // What we've sent to the server about our "voice_modenable" cvar.

IPanel? ParentPanel;
PlayerBitVec VoicePlayers; // Who is currently talking. Indexed by client index.
PlayerBitSet VoicePlayers; // Who is currently talking. Indexed by client index.

// This is the gamerules-defined list of players that you can hear. It is based on what teams people are on
// and is totally separate from the ban list. Indexed by client index.
PlayerBitVec AudiblePlayers;
PlayerBitSet AudiblePlayers;

// Players who have spoken at least once in the game so far
PlayerBitVec VoiceEnabledPlayers;
PlayerBitSet VoiceEnabledPlayers;

// This is who the server THINKS we have banned (it can become incorrect when a new player arrives on the server).
// It is checked periodically, and the server is told to squelch or unsquelch the appropriate players.
PlayerBitVec ServerBannedPlayers;
PlayerBitSet ServerBannedPlayers;

IVoiceStatusHelper? Helper; // Each mod provides an implementation of this.

Expand Down Expand Up @@ -211,7 +211,7 @@ public void DrawHeadLabels() {
using MatRenderContextPtr renderContext = new(materials);

for (int i = 0; i < VOICE_MAX_PLAYERS; i++) {
if (!VoicePlayers[i])
if (!VoicePlayers.IsBitSet(i))
continue;

C_BaseEntity? client = cl_entitylist.GetEnt(i + 1);
Expand Down Expand Up @@ -300,11 +300,11 @@ public void UpdateSpeakerStatus(int entindex, bool talking) {
return;

if (talking) {
VoicePlayers[iClient] = true;
VoiceEnabledPlayers[iClient] = true;
VoicePlayers.Set(iClient, true);
VoiceEnabledPlayers.Set(iClient, true);
}
else
VoicePlayers[iClient] = false;
VoicePlayers.Set(iClient, false);
}
}

Expand Down Expand Up @@ -345,7 +345,7 @@ void UpdateServerState(bool force) {
if (BanMgr.GetPlayerBan(pi.GUID))
banMask |= 1u << (int)i;

if (ServerBannedPlayers[playerIndex])
if (ServerBannedPlayers.IsBitSet(playerIndex))
serverBanMask |= 1u << (int)i;
}

Expand Down Expand Up @@ -374,13 +374,13 @@ void UpdateServerState(bool force) {
public void HandleVoiceMaskMsg(bf_read msg) {
uint dw;
for (dw = 0; dw < VOICE_MAX_PLAYERS_DW; dw++) {
AudiblePlayers.SetDWord((int)dw, (uint)msg.ReadLong());
ServerBannedPlayers.SetDWord((int)dw, (uint)msg.ReadLong());
AudiblePlayers.SetWord((int)dw, (uint)msg.ReadLong());
ServerBannedPlayers.SetWord((int)dw, (uint)msg.ReadLong());

if (voice_clientdebug.GetInt() != 0) {
Msg("CVoiceStatus::HandleVoiceMaskMsg\n");
Msg($" - m_AudiblePlayers[{dw}] = {AudiblePlayers.GetDWord((int)dw)}\n");
Msg($" - m_ServerBannedPlayers[{dw}] = {ServerBannedPlayers.GetDWord((int)dw)}\n");
Msg($" - m_AudiblePlayers[{dw}] = {AudiblePlayers.GetWord((int)dw)}\n");
Msg($" - m_ServerBannedPlayers[{dw}] = {ServerBannedPlayers.GetWord((int)dw)}\n");
}
}

Expand Down Expand Up @@ -424,12 +424,12 @@ public bool IsPlayerBlocked(int player) {

// returns false if the player can't hear the other client due to game rules (eg. the other team)
public bool IsPlayerAudible(int player) {
return AudiblePlayers[player - 1];
return AudiblePlayers.IsBitSet(player - 1);
}

// returns true if the player is currently speaking
public bool IsPlayerSpeaking(int playerIndex) {
return VoicePlayers[playerIndex - 1];
return VoicePlayers.IsBitSet(playerIndex - 1);
}

// returns true if the local player is attempting to speak
Expand Down
4 changes: 2 additions & 2 deletions Game.Server/AI_BaseNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3200,7 +3200,7 @@ public bool IsScheduleValid() {

SetCustomInterruptCondition((int)SCOND_t.COND_NPC_FREEZE);

CustomInterruptConditions.And(Conditions, out AI_ScheduleBits testBits);
AI_ScheduleBits testBits = CustomInterruptConditions.And(Conditions);

if (!testBits.IsAllClear()) {
if (developer.GetInt() != 0) {
Expand Down Expand Up @@ -4710,7 +4710,7 @@ public virtual bool CanBeAnEnemyOf(BaseEntity enemy) {

public void RemoveIgnoredConditions() {
ConditionsPreIgnore = Conditions;
Conditions.And(InverseIgnoreConditions, out Conditions);
Conditions = Conditions.And(InverseIgnoreConditions);

if (NPCState == NPCState.Script && Cine.Get() != null)
Cine.Get()!.RemoveIgnoredConditions();
Expand Down
22 changes: 2 additions & 20 deletions Game.Server/AI_Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,5 @@ public enum SCOND_t
LAST_SHARED_CONDITION
}

[InlineArray(MAX_CONDITIONS >> 3)]
public struct AI_ScheduleBits
{
public byte bytes;
public void ClearAll() => BitVecBase.ClearAll(this);
public void SetAll() => ((Span<byte>)this).Fill(0xff);
public void Set(int bit) => BitVecBase.Set(this, bit);
public void Clear(int bit) => BitVecBase.Clear(this, bit);
public bool IsBitSet(int bit) => BitVecBase.IsBitSet(this, bit);
public bool IsAllClear() => ((ReadOnlySpan<byte>)this).IndexOfAnyExcept((byte)0) < 0;
public void And(in AI_ScheduleBits other, out AI_ScheduleBits result) {
AI_ScheduleBits temp = default;
ReadOnlySpan<byte> a = this;
ReadOnlySpan<byte> b = other;
Span<byte> r = temp;
for (int i = 0; i < r.Length; i++)
r[i] = (byte)(a[i] & b[i]);
result = temp;
}
}
[BitVec<byte>(MAX_CONDITIONS)]
public partial struct AI_ScheduleBits;
2 changes: 2 additions & 0 deletions Game.Server/Game.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Source.CodeAnalysis.Lua\Source.CodeAnalysis.Lua.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Source.CodeAnalysis.BitVec\Source.CodeAnalysis.BitVec.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Game.Shared\*.cs" Link="Shared\%(Filename)%(Extension)" />
Expand Down
2 changes: 1 addition & 1 deletion Game.Server/HL2MP/HL2MP_Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void FireBullets(FireBulletsInfo info) { }

void NoteWeaponFired() { }

public override bool WantsLagCompensationOnEntity(BaseEntity entity, in UserCmd cmd, ref readonly MaxEdictsBitVec entityTransmitBits) {
public override bool WantsLagCompensationOnEntity(BaseEntity entity, in UserCmd cmd, ref readonly MaxEdictsBitSet entityTransmitBits) {
return base.WantsLagCompensationOnEntity(entity, in cmd, in entityTransmitBits);
}

Expand Down
2 changes: 1 addition & 1 deletion Game.Server/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ public override EdictFlags ShouldTransmit(CheckTransmitInfo info) {
return base.ShouldTransmit(info);
}

public virtual bool WantsLagCompensationOnEntity(BaseEntity entity, in UserCmd cmd, ref readonly MaxEdictsBitVec entityTransmitBits) {
public virtual bool WantsLagCompensationOnEntity(BaseEntity entity, in UserCmd cmd, ref readonly MaxEdictsBitSet entityTransmitBits) {
if (!Unsafe.IsNullRef(in entityTransmitBits) && !entityTransmitBits.IsBitSet(entity.EntIndex()))
return false;

Expand Down
2 changes: 1 addition & 1 deletion Game.Server/PlayerLagCompensation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void StartLagCompensation(BasePlayer player, in Vector3 weaponPos = defau
WeaponAngles = weaponAngles;
WeaponRange = weaponRange;

ref readonly MaxEdictsBitVec entityTransmitBits = ref engine.GetEntityTransmitBitsForClient(player.EntIndex() - 1);
ref readonly MaxEdictsBitSet entityTransmitBits = ref engine.GetEntityTransmitBitsForClient(player.EntIndex() - 1);

foreach (KeyValuePair<EHANDLE, EntityLagData> kvp in CompensatedEntities) {
EntityLagData ld = kvp.Value;
Expand Down
6 changes: 3 additions & 3 deletions Game.Server/RecipientFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void AddAllPlayers() {
AddRecipient(player);
}
}
public void AddPlayersFromBitMask(ref AbsolutePlayerLimitBitVec playerbits) {
public void AddPlayersFromBitMask(ref PlayerBitSet playerbits) {
int index = playerbits.FindNextSetBit(0);

while (index > -1) {
Expand All @@ -81,7 +81,7 @@ public void AddRecipientsByPVS(in Vector3 origin) {
if (gpGlobals.MaxClients == 1)
AddAllPlayers();
else {
AbsolutePlayerLimitBitVec playerbits = default;
PlayerBitSet playerbits = default;
engine.Message_DetermineMulticastRecipients(false, origin, ref playerbits);
AddPlayersFromBitMask(ref playerbits);
}
Expand All @@ -91,7 +91,7 @@ public void AddRecipientsByPAS(in Vector3 origin) {
if (gpGlobals.MaxClients == 1)
AddAllPlayers();
else {
AbsolutePlayerLimitBitVec playerbits = default;
PlayerBitSet playerbits = default;
engine.Message_DetermineMulticastRecipients(true, origin, ref playerbits);
AddPlayersFromBitMask(ref playerbits);
}
Expand Down
49 changes: 25 additions & 24 deletions Game.Server/VoiceGameMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Game.Shared;

using Source;
using Source.Common;
using Source.Common.Commands;
using Source.Common.Engine;
Expand All @@ -25,17 +26,17 @@ public static class VoiceGameMgrGlobals
public const double UPDATE_INTERVAL = 0.3;

// These are stored off as VoiceGameMgr is created and deleted.
public static PlayerBitVec g_PlayerModEnable; // Set to 1 for each player if the player wants to use voice in this mod.
public static PlayerBitSet g_PlayerModEnable; // Set to 1 for each player if the player wants to use voice in this mod.
// (If it's zero, then the server reports that the game rules are saying the
// player can't hear anyone).

public static readonly PlayerBitVec[] g_BanMasks = new PlayerBitVec[VOICE_MAX_PLAYERS]; // Tells which players don't want to hear each other.
public static readonly PlayerBitSet[] g_BanMasks = new PlayerBitSet[VOICE_MAX_PLAYERS]; // Tells which players don't want to hear each other.
// These are indexed as clients and each bit represents a client
// (so player entity is bit+1).

public static readonly PlayerBitVec[] g_SentGameRulesMasks = new PlayerBitVec[VOICE_MAX_PLAYERS]; // These store the masks we last sent to each client so we can determine if
public static readonly PlayerBitVec[] g_SentBanMasks = new PlayerBitVec[VOICE_MAX_PLAYERS]; // we need to resend them.
public static PlayerBitVec g_bWantModEnable;
public static readonly PlayerBitSet[] g_SentGameRulesMasks = new PlayerBitSet[VOICE_MAX_PLAYERS]; // These store the masks we last sent to each client so we can determine if
public static readonly PlayerBitSet[] g_SentBanMasks = new PlayerBitSet[VOICE_MAX_PLAYERS]; // we need to resend them.
public static PlayerBitSet g_bWantModEnable;

public static readonly ConVar voice_serverdebug = new("voice_serverdebug", "0");

Expand Down Expand Up @@ -106,9 +107,9 @@ public void ClientConnected(Edict edict) {
int index = edict.EdictIndex - 1;

// Clear out everything we use for deltas on this guy.
g_bWantModEnable[index] = true;
g_SentGameRulesMasks[index].Init(0);
g_SentBanMasks[index].Init(0);
g_bWantModEnable.Set(index, true);
g_SentGameRulesMasks[index].ClearAll();
g_SentBanMasks[index].ClearAll();
}

// Called on ClientCommand. Checks for the squelch and unsquelch commands.
Expand All @@ -127,7 +128,7 @@ public bool ClientCommand(BasePlayer player, in TokenizedCommand args) {

if (i <= VOICE_MAX_PLAYERS_DW) {
VoiceServerDebug($"CVoiceGameMgr::ClientCommand: vban (0x{mask:x}) from {playerClientIndex}\n");
g_BanMasks[playerClientIndex].SetDWord(i - 1, mask);
g_BanMasks[playerClientIndex].SetWord(i - 1, mask);
}
else
VoiceServerDebug($"CVoiceGameMgr::ClientCommand: invalid index ({i})\n");
Expand All @@ -139,8 +140,8 @@ public bool ClientCommand(BasePlayer player, in TokenizedCommand args) {
}
else if (args[0].Equals("VModEnable", StringComparison.OrdinalIgnoreCase) && args.ArgC() >= 2) {
VoiceServerDebug($"CVoiceGameMgr::ClientCommand: VModEnable ({(atoi(args[1]) != 0 ? 1 : 0)})\n");
g_PlayerModEnable[playerClientIndex] = atoi(args[1]) != 0;
g_bWantModEnable[playerClientIndex] = false;
g_PlayerModEnable.Set(playerClientIndex, atoi(args[1]) != 0);
g_bWantModEnable.Set(playerClientIndex, false);
//UpdateMasks();
return true;
}
Expand All @@ -160,7 +161,7 @@ public void SetProximityDistance(int distance) {
}

public bool IsPlayerIgnoringPlayer(int talker, int listener) {
return g_BanMasks[listener - 1][talker - 1];
return g_BanMasks[listener - 1].IsBitSet(talker - 1);
}

// Force it to update the client masks.
Expand All @@ -179,24 +180,24 @@ void UpdateMasks() {
SingleUserRecipientFilter user = new(player);

// Request the state of their "VModEnable" cvar.
if (g_bWantModEnable[iClient]) {
if (g_bWantModEnable.IsBitSet(iClient)) {
UserMessageBegin(user, "RequestState");
MessageEnd();
// Since this is reliable, only send it once
g_bWantModEnable[iClient] = false;
g_bWantModEnable.Set(iClient, false);
}

PlayerBitVec gameRulesMask = default;
PlayerBitVec proximityMask = default;
PlayerBitSet gameRulesMask = default;
PlayerBitSet proximityMask = default;
bool proximity = false;
if (g_PlayerModEnable[iClient]) {
if (g_PlayerModEnable.IsBitSet(iClient)) {
// Build a mask of who they can hear based on the game rules.
for (int iOtherClient = 0; iOtherClient < MaxPlayers; iOtherClient++) {
BaseEntity? otherEnt = Util.PlayerByIndex(iOtherClient + 1);
if (otherEnt != null && otherEnt.IsPlayer() &&
(allTalk || Helper!.CanPlayerHearPlayer(player, (BasePlayer)otherEnt, ref proximity))) {
gameRulesMask[iOtherClient] = true;
proximityMask[iOtherClient] = proximity;
gameRulesMask.Set(iOtherClient, true);
proximityMask.Set(iOtherClient, proximity);
}
}
}
Expand All @@ -210,20 +211,20 @@ void UpdateMasks() {
UserMessageBegin(user, "VoiceMask");
int dw;
for (dw = 0; dw < VOICE_MAX_PLAYERS_DW; dw++) {
MessageWriteLong((int)gameRulesMask.GetDWord(dw));
MessageWriteLong((int)g_BanMasks[iClient].GetDWord(dw));
MessageWriteLong((int)gameRulesMask.GetWord(dw));
MessageWriteLong((int)g_BanMasks[iClient].GetWord(dw));
}
MessageWriteByte(g_PlayerModEnable[iClient] ? 1 : 0);
MessageWriteByte(g_PlayerModEnable.IsBitSet(iClient) ? 1 : 0);
MessageEnd();
}

// Tell the engine.
for (int iOtherClient = 0; iOtherClient < MaxPlayers; iOtherClient++) {
bool canHear = gameRulesMask[iOtherClient] && !g_BanMasks[iClient][iOtherClient];
bool canHear = gameRulesMask.IsBitSet(iOtherClient) && !g_BanMasks[iClient].IsBitSet(iOtherClient);
g_pVoiceServer.SetClientListening(iClient + 1, iOtherClient + 1, canHear);

if (canHear)
g_pVoiceServer.SetClientProximity(iClient + 1, iOtherClient + 1, proximityMask[iOtherClient]);
g_pVoiceServer.SetClientProximity(iClient + 1, iOtherClient + 1, proximityMask.IsBitSet(iOtherClient));
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions Game.Shared/ChoreoScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ public static bool IsBufferBinaryVCD(ReadOnlySpan<byte> buffer) {
}
}

[InlineArray(((int)ChoreoEvent.EventType.NumTypes + 31) / 32 * 4)]
public struct ChoreoEventTypeBitVec
{
public byte bytes;
public bool IsBitSet(int bit) => BitVecBase.IsBitSet(this, bit);
public void Set(int bit, bool newVal) => BitVecBase.Set(this, bit, newVal);
public void ClearAll() => BitVecBase.ClearAll(this);
}
[BitVec<byte>((int)ChoreoEvent.EventType.NumTypes)]
public partial struct ChoreoEventTypeBitSet;

public class ChoreoScene : ICurveDataAccessor
{
Expand Down Expand Up @@ -111,7 +105,7 @@ enum TimeRange
readonly SortedList<string, int> TimeZoomLookup = new(Comparer<string>.Create(static (a, b) => stricmp(a, b)));
string FileName = "";

ChoreoEventTypeBitVec BitvecHasEventOfType;
ChoreoEventTypeBitSet BitvecHasEventOfType;

bool IsBackgroundValue;
bool IgnorePhonemesValue;
Expand Down
1 change: 1 addition & 0 deletions Game.Shared/Game.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ItemGroup>
<ProjectReference Include="..\Source.Common\Source.Common.csproj" />
<ProjectReference Include="..\Source.Engine\Source.Engine.csproj" />
<ProjectReference Include="..\Source.CodeAnalysis.BitVec\Source.CodeAnalysis.BitVec.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Usings\GlobalUsings.cs" Link="Usings/GlobalUsings.cs" />
Expand Down
Loading
Loading