/// <summary> /// Checks if the specified receiver exists, and is within influence range of <paramref name="senderPosition"/>. /// If so, the message is relayed to the receiver, and the method returns true. /// </summary> /// <param name="senderPosition"></param> /// <param name="receiver"></param> /// <param name="message"></param> /// <returns>True if the entity was found, in range, and the message index was not yet used by the receiver-sender-tuple</returns> public bool RelayMessage(Vec3 senderPosition, Guid receiver, OrderedEntityMessage message) { Container rs; if (!guidMap.TryGetValue(receiver, out rs)) { return(false); } if (!ctx.CheckT("Message", senderPosition, rs.entity)) { return(false); } return(rs.messages.GetOrAdd(message.Message.Sender.Guid, guid => new Container.BySender()).Add(message)); }
public int BroadcastMessage(Vec3 senderPosition, float maxRange, OrderedEntityMessage message) { int counter = 0; foreach (var p in tree.RadialSearch(senderPosition.ToArray(), Math.Min(maxRange, ctx.Ranges.R))) { //if (Vec3.GetChebyshevDistance(p.Item2.entity.ID.Position, senderPosition) > ctx.Ranges.R) // throw new IntegrityViolation("Sender range exceeded during broadcast. Tree is out of date"); if (p.Item2.entity.ID.Guid != message.Message.Sender.Guid) // && Simulation.GetDistance(senderPosition, p.Key.Position) <= Simulation.Ranges.R) { p.Item2.messages.GetOrAdd(message.Message.Sender.Guid, guid => new Container.BySender()).Add(message); counter++; } } return(counter); }
private static ICollection <OrderedEntityMessage> Combine(ConcurrentBag <OrderedEntityMessage> a, ConcurrentBag <OrderedEntityMessage> b) { if (b == null || b.Count == 0) { return(a?.ToArray()); } if (a == null || a.Count == 0) { return(b.ToArray()); } OrderedEntityMessage[] rs = new OrderedEntityMessage[a.Count + b.Count]; int at = 0; foreach (var msg in a) { rs[at++] = msg; } foreach (var msg in b) { rs[at++] = msg; } return(rs); }
public bool Add(OrderedEntityMessage msg) { return(inMessages.TryAdd(new MessageKey(msg), msg.Message)); }
public MessageKey(OrderedEntityMessage msg) : this() { orderID = msg.OrderID; senderID = new EntityID(msg.Message.Sender.Guid, msg.Message.Sender.Position); }