Beispiel #1
0
        public IClientDistributedObject CreateDistributedObject(DistributedObjectId distributedObjectId, List <object> messageData)
        {
            DistributedObjectTypes type = CheckType.TryAssignType <DistributedObjectTypes>(messageData[0]);

            IClientDistributedObject clientDistributedObject = null;

            switch (type)
            {
            case DistributedObjectTypes.Avatar:
                Guid localSessionId = CheckType.TryAssignType <Guid>(messageData[2]);
                if (mLocalSessionId == localSessionId)
                {
                    clientDistributedObject = BuildLocalAvatarDistributedObject(distributedObjectId, messageData);
                }
                else
                {
                    clientDistributedObject = BuildForeignAvatarDistributedObject(distributedObjectId, messageData);
                }
                break;

            case DistributedObjectTypes.Room:
                clientDistributedObject = BuildRoomDistributedObject(distributedObjectId, messageData);
                break;

            case DistributedObjectTypes.MockObject:
                clientDistributedObject = BuildMockDistributedObject(distributedObjectId, messageData);
                break;

            default:
                throw new NotImplementedException(type.ToString());
            }
            return(clientDistributedObject);
        }
Beispiel #2
0
        /*******************************/
        // IMessageRouter Functions
        /*******************************/
        public void ReceiveMessage(Message message)
        {
            switch (message.MessageType)
            {
            case MessageType.Create:
                IClientDistributedObject distributedObject = mDistributedObjectFactory.CreateDistributedObject(message.DistributedObjectId, message.Data);
                if (distributedObject != null)
                {
                    this.AddObject(distributedObject);
                    List <System.Action <IClientDistributedObject> > requestedObjectCallbacks = null;
                    if (mAnticipatedDistributedObjectIdsToCallbacks.TryGetValue(distributedObject.DistributedObjectId, out requestedObjectCallbacks))
                    {
                        foreach (System.Action <IClientDistributedObject> requestedObjectCallback in requestedObjectCallbacks)
                        {
                            requestedObjectCallback(distributedObject);
                        }
                        mAnticipatedDistributedObjectIdsToCallbacks.Remove(distributedObject.DistributedObjectId);
                    }
                }
                break;

            case MessageType.Update:
                DistributedObjectId doId         = message.DistributedObjectId;
                IDistributedObject  updateObject = null;
                if (mObjectIds.TryGetValue(doId, out updateObject))
                {
                    updateObject.ProcessMessage(message);
                }
                else
                {
                    Console.LogError("Message update but objectId " + doId + " not found in repository");
                }
                break;

            case MessageType.Delete:
                DistributedObjectId deletedoId = message.DistributedObjectId;
                IDistributedObject  deleteObject;

                if (mObjectIds.TryGetValue(deletedoId, out deleteObject))
                {
                    if (deleteObject is ClientDistributedObject)
                    {
                        ClientDistributedObject deleteClientObject = deleteObject as ClientDistributedObject;
                        if (deleteClientObject != null)
                        {
                            deleteClientObject.Dispose();
                        }
                    }
                    this.RemoveObject(deleteObject);
                }
                else
                {
                    Console.LogError("Message delete but objectId " + deletedoId.ToString() + " not found in repository");
                }
                break;
            }
        }
Beispiel #3
0
        private void GetDistributedObjectReference(DistributedObjectId requestedDistributedObjectId, System.Action <IClientDistributedObject> retrieveDistributedObjectCallback)
        {
            IClientDistributedObject clientDistributedObject = this.GetObject(requestedDistributedObjectId) as IClientDistributedObject;

            //if the resulting object is null, we need to cache this request for when the object is eventually downloaded
            if (clientDistributedObject == null)
            {
                if (!mAnticipatedDistributedObjectIdsToCallbacks.ContainsKey(requestedDistributedObjectId))
                {
                    mAnticipatedDistributedObjectIdsToCallbacks.Add(requestedDistributedObjectId, new List <System.Action <IClientDistributedObject> >());
                }
                mAnticipatedDistributedObjectIdsToCallbacks[requestedDistributedObjectId].Add(retrieveDistributedObjectCallback);
            }
            else
            {
                retrieveDistributedObjectCallback(clientDistributedObject);
            }
        }