Ejemplo n.º 1
0
        // this is a little hacky as there aren't actually any entities to process
        // probably a sign that I'm abusing the entity component system. i think the proper
        // way to do this is to create a simple entity that just has a component to hold
        // a reference to the network agent. that's roughly how it would work in unity.
        // might be best to use a TagSystem like for player input?
        protected override void ProcessEntities(IDictionary<int, Entity> entities)
        {
            List<NetIncomingMessage> messages = _networkAgent.ReadMessages();

            foreach(NetIncomingMessage netMessage in messages) {
                NetworkMessageType messageType = (NetworkMessageType)Enum.ToObject(typeof(NetworkMessageType), netMessage.ReadByte());

                if(messageType == NetworkMessageType.PlayerConnect) {
                    PlayerConnectMessage<UmbraEntityType> playerConnectMessage = new PlayerConnectMessage<UmbraEntityType>();
                    playerConnectMessage.Decode(netMessage);
                    PlayerConnect(playerConnectMessage);
                }  else if(messageType == NetworkMessageType.EntityAdd) {
                    EntityAddMessage<UmbraEntityType> addMessage = new EntityAddMessage<UmbraEntityType>();
                    addMessage.Decode(netMessage);
                    AddEntity(addMessage);
                } else if(messageType == NetworkMessageType.EntityMove) {
                    EntityMoveMessage moveMessage = new EntityMoveMessage();
                    moveMessage.Decode(netMessage);
                    MoveEntity(moveMessage);
                } else if(messageType == NetworkMessageType.EntityRemove) {
                    EntityRemoveMessage removeMessage = new EntityRemoveMessage();
                    removeMessage.Decode(netMessage);
                    RemoveEntity(removeMessage);
                }
            }
        }
Ejemplo n.º 2
0
 private void RemoveEntity(EntityRemoveMessage msg)
 {
     Entity entity = CrawEntityManager.Instance.GetEntity(msg.EntityId);
     if(entity != null) entity.Delete();
 }
Ejemplo n.º 3
0
        private void OnPlayerDisconnect(NetConnection playerConnection)
        {
            long playerEntityId = _playerEntityIds[playerConnection];
            Entity playerEntity = CrawEntityManager.Instance.GetEntity(playerEntityId);

            playerEntity.Delete();
            _playerEntityIds.Remove(playerConnection);

            EntityRemoveMessage msg = new EntityRemoveMessage(playerEntityId);
            _networkAgent.BroadcastMessage(msg);
        }