/// <summary> /// Event Handler for EntityRemoved event fired by the entity registry. Once an entity is removed from the registry, /// its entry is also deleted from the database (including cascaded deletion of its component instances) /// </summary> /// <param name="sender">Sender of the event (the EntityRegistry)</param> /// <param name="e">Event Arguments</param> internal void OnEntityRemoved(Object sender, EntityEventArgs e) { RemoveEntityFromDatabase (e.Entity); }
private void HandleOnEntityAdded(object sender, EntityEventArgs e) { // FIXME: This is not very efficient. Would be nice to be triggered only when anything in "scripting" // component is changed, but without the need to create one. Essentially we need an event // OnComponentCreated. e.Entity.ChangedAttribute += HandleOnAttributeInComponentChanged; InitEntityContext(e.Entity); }
/// <summary> /// Event Handler for EntityAdded event fired by the EntityRegistry. A new entity will be persisted to the database, /// unless the entity to be added was just queried from the database (e.g. upon initialization) /// </summary> /// <param name="sender">Sender of the event (the EntityRegistry)</param> /// <param name="e">Event arguments</param> internal void OnEntityAdded(Object sender, EntityEventArgs e) { Entity addedEntity = e.Entity; // Only persist entities if they are not added during intialization on Startup if (!EntitiesToInitialize.Contains (addedEntity.Guid)) { AddEntityToPersisted (addedEntity); } else { EntitiesToInitialize.Remove(addedEntity.Guid); } addedEntity.ChangedAttribute += new EventHandler<ChangedAttributeEventArgs>(OnAttributeChanged); addedEntity.CreatedComponent += new EventHandler<ComponentEventArgs>(HandleComponentCreated); }
/// <summary> /// Handler for the event AddedEntity event in the World. Invokes addEntity method on the connected sync nodes /// to notify them about new entity. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> internal void HandleLocalAddedEntity(object sender, EntityEventArgs e) { e.Entity.ChangedAttribute += HandleLocalChangedAttribute; // Ignore this change if it was caused by the scalability plugin itself. lock (ignoredEntityAdditions) { if (ignoredEntityAdditions.Remove(e.Entity.Guid)) return; } lock (syncInfo) { // Local sync info may already be present if this new entity was added in response to a sync message // from remote sync node. if (!syncInfo.ContainsKey(e.Entity.Guid)) { var newSyncInfo = CreateSyncInfoForNewEntity(e.Entity); syncInfo.Add(e.Entity.Guid, newSyncInfo); } // This must be inside the lock to prevent concurrent changes to entity's sync info. foreach (IRemoteServer server in ServerSync.RemoteServers) if (server.DoI.IsInterestedInEntity(e.Entity)) server.Connection["serverSync.addEntity"](e.Entity.Guid, syncInfo[e.Entity.Guid]); } }
void HandleAddedEntity(object sender, EntityEventArgs e) { if (!CheckAndRegisterAvatarEntity(e.Entity)) e.Entity.CreatedComponent += HandleCreatedComponent; }
/// <summary> /// Handler for the event RemovedEntity event in the World. Invokes removeEntity method on the connected sync /// nodes to notify them about removed entity. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> internal void HandleLocalRemovedEntity(object sender, EntityEventArgs e) { // Ignore this change if it was caused by the scalability plugin itself. lock (ignoredEntityRemovals) { if (ignoredEntityRemovals.Remove(e.Entity.Guid)) return; } lock (syncInfo) { // Local sync info may already have been removed if this new entity was removed in response to a sync // message from remote sync node. if (syncInfo.ContainsKey(e.Entity.Guid)) syncInfo.Remove(e.Entity.Guid); } foreach (IRemoteServer server in ServerSync.RemoteServers) if (server.DoI.IsInterestedInEntity(e.Entity)) server.Connection["serverSync.removeEntity"](e.Entity.Guid); }
private void HandleEntityRemoved(object sender, EntityEventArgs e) { foreach (KeyValuePair<Connection, ClientFunction> clientHandler in onRemovedEntityHandlers) { if(e.Entity.Owner != clientHandler.Key.SessionID) clientHandler.Value(e.Entity.Guid.ToString()); } }
private void HandleEntityAdded(object sender, EntityEventArgs e) { foreach (KeyValuePair<Connection, ClientFunction> clientHandler in onNewEntityHandlers) { if(e.Entity.Owner != clientHandler.Key.SessionID) clientHandler.Value(ConstructEntityInfo(e.Entity)); } }
/// <summary> /// Sets initial ground level of an entity to its y-attribute. This is as when just added the entity the /// client may not yet have determined the ground level (as no ray was cast). To avoid setting the entity /// to a wrong level, it is just kept where it is until the first ray is cast /// </summary> /// <param name="sender">The World</param> /// <param name="e">Entity Added event arguments</param> private void HandleEntityAdded(Object sender, EntityEventArgs e) { if (e.Entity.ContainsComponent("avatar")) { // Initialise entities without gravity float initialGroundlevel = ((Vector)e.Entity["location"]["position"].Value).y; e.Entity["avatarCollision"]["groundLevel"].Suggest(initialGroundlevel); } }
private void HandleEntityRemoved(object sender, EntityEventArgs e) { foreach (ClientFunction clientHandler in onRemovedEntityHandlers.Values) { clientHandler(ConstructEntityInfo(e.Entity)); } }