mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* Add support for struct directed events. - Turn transform events into readonly structs * TransformComponent events have readonly fields. * Reduce boxing allocations, add DirectedRegistration readonly struct. * Use typeof in a few places instead of GetType * Add overloads to allow passing directed events by ref. * Raise transform events by ref. * Fix occluder AnchorStateChangedEvent subscription * Fix broadphase subscriptions * Fix bug oops * Fix transform system raising moveevents by value * Don't reflect the test entity systems. * Directed EventBus uses ref everywhere, internally Deduplicates a bunch of code. Whoo! * Add broadcast by-ref events * Fix by-ref events bug using Unsafe, add new tests for sorted by-ref events. * Port broadcast events to by-ref. * Speed, more correctness, reduce generics bloat. * Clean up subscription code some. * Remove bad test. Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using System;
|
|
using Robust.Shared.Players;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
public interface IEntityEventSubscriber { }
|
|
|
|
public delegate void EntityEventHandler<in T>(T ev);
|
|
public delegate void EntityEventRefHandler<T>(ref T ev);
|
|
public delegate void EntitySessionEventHandler<in T>(T msg, EntitySessionEventArgs args);
|
|
|
|
[Serializable, NetSerializable]
|
|
public abstract class EntityEventArgs { }
|
|
|
|
[Serializable, NetSerializable]
|
|
public abstract class HandledEntityEventArgs : EntityEventArgs
|
|
{
|
|
/// <summary>
|
|
/// If this message has already been "handled" by a previous system.
|
|
/// </summary>
|
|
public bool Handled { get; set; }
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public abstract class CancellableEntityEventArgs : EntityEventArgs
|
|
{
|
|
/// <summary>
|
|
/// Whether this even has been cancelled.
|
|
/// </summary>
|
|
public bool Cancelled { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Cancels the event.
|
|
/// </summary>
|
|
public void Cancel() => Cancelled = true;
|
|
|
|
/// <summary>
|
|
/// Uncancels the event. Don't call this unless you know what you're doing.
|
|
/// </summary>
|
|
public void Uncancel() => Cancelled = false;
|
|
}
|
|
|
|
public readonly struct EntitySessionEventArgs
|
|
{
|
|
public EntitySessionEventArgs(ICommonSession senderSession)
|
|
{
|
|
SenderSession = senderSession;
|
|
}
|
|
|
|
public ICommonSession SenderSession { get; }
|
|
}
|
|
|
|
internal readonly struct EntitySessionMessage<T>
|
|
{
|
|
public EntitySessionMessage(EntitySessionEventArgs eventArgs, T message)
|
|
{
|
|
EventArgs = eventArgs;
|
|
Message = message;
|
|
}
|
|
|
|
public EntitySessionEventArgs EventArgs { get; }
|
|
public T Message { get; }
|
|
|
|
public void Deconstruct(out EntitySessionEventArgs eventArgs, out T message)
|
|
{
|
|
eventArgs = EventArgs;
|
|
message = Message;
|
|
}
|
|
}
|
|
}
|