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
2 changes: 1 addition & 1 deletion Game.Server/SceneEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ public void UnloadScene() {
actor = FindNamedActor(choreoActor.GetName());

if (actor != null) {
ActorList[index] = new EHANDLE().Set(actor);
ActorList[index] = actor.GetRefEHandle();
NetworkProp().NetworkStateForceUpdate();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Game.Server/Soundscape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ public void DelegateStartTouch(BaseEntity ent) {

// Just in case.. we shouldn't already be in the player's list because it should have
// called DelegateEndTouch, but this seems to happen when they're noclipping.
player.TriggerSoundscapeList.Remove(new EHANDLE().Set(this));
player.TriggerSoundscapeList.Remove(GetRefEHandle());

// Add us to the player's list of soundscapes and
player.TriggerSoundscapeList.Insert(0, new EHANDLE().Set(this));
player.TriggerSoundscapeList.Insert(0, GetRefEHandle());
WriteAudioParamsTo(ref player.GetAudioParams());
}

Expand All @@ -354,7 +354,7 @@ public void DelegateEndTouch(BaseEntity ent) {
return;

// Remove us from the ent's list of soundscapes.
player.TriggerSoundscapeList.Remove(new EHANDLE().Set(this));
player.TriggerSoundscapeList.Remove(GetRefEHandle());
while (player.TriggerSoundscapeList.Count > 0) {
if (player.TriggerSoundscapeList[0].Get() is EnvSoundscapeTriggerable ss) {
// Make this one current.
Expand Down
2 changes: 1 addition & 1 deletion Game.Shared/BaseCombatWeaponShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private static void RecvProxy_WeaponState(ref readonly RecvProxyData data, objec
public virtual bool CanBePickedUpByNPCs() => true;

TimeUnit_t UnlockTime;
readonly EHANDLE Locker = new();
EHANDLE Locker = new();

public void Lock(TimeUnit_t lockTime, BaseEntity? locker) {
UnlockTime = gpGlobals.CurTime + lockTime;
Expand Down
91 changes: 48 additions & 43 deletions Source.Common/BaseHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,32 @@
/// </summary>
public struct BaseHandle : IEquatable<BaseHandle>, IBaseHandle
{
public bool Equals(BaseHandle otherHandle) => Index == otherHandle.Index;
public readonly bool Equals(BaseHandle otherHandle) => Index == otherHandle.Index;
public uint Index;

public uint Unpack() => Index;
public readonly uint Unpack() => Index;


public void Invalidate() => Index = (uint)Constants.INVALID_EHANDLE_INDEX;
public BaseHandle() => Invalidate();
public BaseHandle() => Index = (uint)Constants.INVALID_EHANDLE_INDEX;
public BaseHandle(uint value) => Index = value;
public BaseHandle(in BaseHandle handle) => Index = handle.Index;
public BaseHandle(int entry, int serial) => Init(entry, serial);
public BaseHandle(int entry, int serial) => Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));

public void Init(in BaseHandle otherHandle) => Index = otherHandle.Index;
public void Init(uint entindex) => Index = entindex;
public void Init(ulong entindex) => Index = (uint)entindex;
public void Init(int entry, int serial) => Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));

public int GetEntryIndex() => (int)(Index & Constants.ENT_ENTRY_MASK);
public int GetSerialNumber() => (int)(Index >> Constants.NUM_ENT_ENTRY_BITS);
public readonly int GetEntryIndex() => (int)(Index & Constants.ENT_ENTRY_MASK);
public readonly int GetSerialNumber() => (int)(Index >> Constants.NUM_ENT_ENTRY_BITS);

public static bool operator ==(BaseHandle a, BaseHandle b) => a.Index == b.Index;
public static bool operator !=(BaseHandle a, BaseHandle b) => a.Index != b.Index;
public static bool operator <(BaseHandle a, BaseHandle b) => a.Index < b.Index;
public static bool operator >(BaseHandle a, BaseHandle b) => a.Index > b.Index;
public override bool Equals(object? obj) {
public override readonly bool Equals(object? obj) {
return obj switch {
BaseHandle b => Index == b.Index,
_ => false
};
}
public override int GetHashCode() => (int)Index;
public bool IsValid() => Index != Constants.INVALID_EHANDLE_INDEX;

public BaseHandle Set(IHandleEntity? entity) {
if (entity != null)
this.Index = entity.GetRefEHandle().Index;
else
Index = Constants.INVALID_EHANDLE_INDEX;
return this;
}
public override readonly int GetHashCode() => (int)Index;
public readonly bool IsValid() => Index != Constants.INVALID_EHANDLE_INDEX;
}


Expand All @@ -54,25 +40,19 @@ public BaseHandle Set(IHandleEntity? entity) {
/// <typeparam name="T"></typeparam>
public struct Handle<T> : IEquatable<Handle<T>>, IEquatable<BaseHandle>, IBaseHandle
{
public uint Unpack() => Index;
public readonly uint Unpack() => Index;

public bool Equals(Handle<T> otherHandle) => Index == otherHandle.Index;
public bool Equals(BaseHandle otherHandle) => Index == otherHandle.Index;
public readonly bool Equals(Handle<T> otherHandle) => Index == otherHandle.Index;
public readonly bool Equals(BaseHandle otherHandle) => Index == otherHandle.Index;
public uint Index;

public void Invalidate() => Index = (uint)Constants.INVALID_EHANDLE_INDEX;
public Handle() => Invalidate();
public Handle() => Index = (uint)Constants.INVALID_EHANDLE_INDEX;
public Handle(uint value) => Index = value;
public Handle(in BaseHandle handle) => Index = handle.Index;
public Handle(int entry, int serial) => Init(entry, serial);

public void Init(in BaseHandle otherHandle) => Index = otherHandle.Index;
public void Init(uint entindex) => Index = entindex;
public void Init(ulong entindex) => Index = (uint)entindex;
public void Init(int entry, int serial) => Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));
public Handle(int entry, int serial) => Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));

public int GetEntryIndex() => (int)(Index & Constants.ENT_ENTRY_MASK);
public int GetSerialNumber() => (int)(Index >> Constants.NUM_ENT_ENTRY_BITS);
public readonly int GetEntryIndex() => (int)(Index & Constants.ENT_ENTRY_MASK);
public readonly int GetSerialNumber() => (int)(Index >> Constants.NUM_ENT_ENTRY_BITS);

public static bool operator ==(BaseHandle a, Handle<T> b) => a.Index == b.Index;
public static bool operator !=(BaseHandle a, Handle<T> b) => a.Index != b.Index;
Expand All @@ -89,7 +69,7 @@ public struct Handle<T> : IEquatable<Handle<T>>, IEquatable<BaseHandle>, IBaseHa
public static bool operator <(Handle<T> a, Handle<T> b) => a.Index < b.Index;
public static bool operator >(Handle<T> a, Handle<T> b) => a.Index > b.Index;

public override bool Equals(object? obj) {
public override readonly bool Equals(object? obj) {
return obj switch {
BaseHandle b => Index == b.Index,
Handle<T> b => Index == b.Index,
Expand All @@ -101,14 +81,39 @@ public override bool Equals(object? obj) {
public static implicit operator Handle<T>(BaseHandle handle) => new(handle.Index);
public static implicit operator BaseHandle(Handle<T> handle) => new(handle.Index);

public override int GetHashCode() => (int)Index;
public bool IsValid() => Index != Constants.INVALID_EHANDLE_INDEX;
public override readonly int GetHashCode() => (int)Index;
public readonly bool IsValid() => Index != Constants.INVALID_EHANDLE_INDEX;
}

public static class BaseHandleExts
{
public static void Invalidate(ref this BaseHandle handle) => handle.Index = (uint)Constants.INVALID_EHANDLE_INDEX;

public static void Init(ref this BaseHandle handle, in BaseHandle otherHandle) => handle.Index = otherHandle.Index;
public static void Init(ref this BaseHandle handle, uint entindex) => handle.Index = entindex;
public static void Init(ref this BaseHandle handle, ulong entindex) => handle.Index = (uint)entindex;
public static void Init(ref this BaseHandle handle, int entry, int serial) => handle.Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));

public static BaseHandle Set(ref this BaseHandle handle, IHandleEntity? entity) {
if (entity != null)
handle.Index = entity.GetRefEHandle().Index;
else
handle.Index = Constants.INVALID_EHANDLE_INDEX;
return handle;
}

public static void Invalidate<T>(ref this Handle<T> handle) => handle.Index = (uint)Constants.INVALID_EHANDLE_INDEX;

public static void Init<T>(ref this Handle<T> handle, in BaseHandle otherHandle) => handle.Index = otherHandle.Index;
public static void Init<T>(ref this Handle<T> handle, uint entindex) => handle.Index = entindex;
public static void Init<T>(ref this Handle<T> handle, ulong entindex) => handle.Index = (uint)entindex;
public static void Init<T>(ref this Handle<T> handle, int entry, int serial) => handle.Index = (uint)(entry | (serial << Constants.NUM_ENT_ENTRY_BITS));

public Handle<T> Set(IHandleEntity? entity) {
public static Handle<T> Set<T>(ref this Handle<T> handle, IHandleEntity? entity) {
if (entity != null)
this.Index = entity.GetRefEHandle().Index;
handle.Index = entity.GetRefEHandle().Index;
else
Index = Constants.INVALID_EHANDLE_INDEX;
return this;
handle.Index = Constants.INVALID_EHANDLE_INDEX;
return handle;
}
}
5 changes: 0 additions & 5 deletions Source.Common/IBaseHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ public interface IBaseHandle
int GetEntryIndex();
int GetHashCode();
int GetSerialNumber();
void Init(in BaseHandle otherHandle);
void Init(int entry, int serial);
void Init(uint entindex);
void Init(ulong entindex);
void Invalidate();
bool IsValid();
}
1 change: 1 addition & 0 deletions Usings/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
global using static Source.Common.DataMapConstants;
global using static Source.Common.PartitionConstants;
global using static Source.Common.DispCollCommon;
global using static Source.Common.BaseHandleExts;
global using CRC32_t = uint;
global using HCursor = nint;
global using UtlSymId_t = ulong;
Expand Down
Loading