Beispiel #1
0
        internal void RemovePlayer(Player player)
        {
            if (player.Id != 0)
            {
                //first need to inform the room, if there is one, of the player's disconnect.
                //Otherwise a new player might obtain the id and send that to a new room before this message gets there
                player.DisconnectOnRoom();

                //this will clean up the player whether or not they actually finished being added.
                lock (_players)
                {
                    _players.Remove(player.Id);
                    PlayerCount--;
                }

                Room.MovePlayerCount(this, player.CurrentRoomGuid, Guid.Empty);
            }

            //it is necessary that we still raise the event, in case users are doing something during verification
            try
            {
                PlayerRemoved?.Invoke(player);
            }
            catch (Exception e) { Debug.LogException(e); }
        }
Beispiel #2
0
        private void RemovePlayer(Player player)
        {
            if (player.Id == 0)
            {
                return;
            }

            //first need to inform the room, if there is one, of the player's disconnect.
            //Otherwise a new player might obtain the id and send that to a new room before this message gets there
            player.DisconnectOnRoom();

            //this will clean up the player whether or not they actually finished being added.
            lock (_players)
                _players.Remove(player.Id);

            Room.MovePlayerCount(this, player.CurrentRoomGuid, Guid.Empty);

            //todo: anything else? this is run on disconnect

            try
            {
                PlayerRemoved?.Invoke(player);
            }
            catch (Exception e) { Debug.LogException(e); }
        }
        /// <summary>
        /// run a single step
        /// </summary>
        public void Update(float?newTime = null)
        {
            if (newTime == null)
            {
                Time.Update((float)_watch.Elapsed.TotalSeconds);
            }
            else
            {
                Time.Update(newTime.Value);
            }


            //TODO: call update on everything
            _keysToRemove.Clear();

            for (int i = 0; i < _gameObjects.Capacity; i++)
            {
                GameObject gobj;
                if (_gameObjects.TryGetValue(i, out gobj))
                {
                    if (Object.IsNull(gobj))
                    {
                        _gameObjects.Remove(i);
                    }
                    else
                    {
                        gobj.RunComponentUpdates();
                    }
                }
            }

            foreach (var go in _gameObjects)
            {
                if (go)
                {
                    go.RunCoroutines();
                }
            }
            foreach (var go in _gameObjects)
            {
                if (go)
                {
                    go.RunComponentLateUpdates();
                }
            }
            foreach (var go in _gameObjects)
            {
                if (go)
                {
                    go.RunEndOfFrameCoroutines();
                }
            }

            //clear out destroyed objects
            foreach (var key in _keysToRemove)
            {
                _gameObjects.Remove(key);
            }
            _keysToRemove.Clear();
        }
Beispiel #4
0
        public void RemoveAddTest()
        {
            var add = new MockObject();

            for (int i = 0; i < 10; i++)
            {
                _target.Add(add);
            }

            _target.Remove(3);

            int expected = 3;
            int actual   = _target.Add(add);

            Assert.AreEqual(expected, actual);

            _target.Remove(0);
            expected = 0;
            actual   = _target.Add(add);
            Assert.AreEqual(expected, actual);


            //make sure out of bounds doesn't throw
            _target.Remove(int.MaxValue);
        }
Beispiel #5
0
 internal void RemoveView(NetworkView view)
 {
     if (view.Manager == this)
     {
         _allViews.Remove(view.ViewID.guid);
         RecycleNetworkView(view);
     }
 }
Beispiel #6
0
 async Task RemoveRegistration(Registration registration)
 {
     _registrationLookup.Remove(registration.UserId);
     _registrations.Remove(registration);
     foreach (var groupId in await _groupsClient.GetUsersGroups(registration.UserId))
     {
         _registeredGroupMembersLookup[groupId].Remove(registration.EndPoint);
     }
 }
Beispiel #7
0
 internal static void RemoveObject(GameObject gobj)
 {
     //
     if (gobj.Id == -1)
     {
         Debug.LogError("Attempted to remove a gameobject with an Id of -1. This happens only if the gameobject has not fully registered with the gamestate before being destroyed. This should never happen. Throwing.");
         throw new Exception("Attempted to remove a gameobject with an Id of -1. This would be due to a gameobject not fully registering itself with the gamestate before being destroyed. This should never happen");
     }
     GameObjects.Remove(gobj.Id);
 }
Beispiel #8
0
 internal static void RemoveView(NetworkView view)
 {
     lock (ViewsLock)
     {
         var findView = Views[view.viewID.guid];
         if (findView != null)
         {
             if (findView == view)
             {
                 Views.Remove(view.viewID.guid);
             }
         }
     }
 }
Beispiel #9
0
        internal static void DestroyAllViews()
        {
            var cap = allViews.Capacity;

            for (int i = 0; i < cap; i++)
            {
                NetworkView view;
                if (allViews.TryGetValue(i, out view))
                {
                    Destroy(view.gameObject);
                }

                allViews.Remove(i);
            }
        }
Beispiel #10
0
        ///////////////////////////////////////////////////////////////////////

        private static void UnsetTraceCategories(
            IEnumerable <string> categories
            )
        {
            lock (syncRoot) /* TRANSACTIONAL */
            {
                //
                // NOTE: If the dictionary of "allowed" trace categories has
                //       not been created yet, do so now.
                //
                if (traceCategories == null)
                {
                    traceCategories = new IntDictionary();
                }

                //
                // NOTE: If there are no trace categories specified, the trace
                //       category dictionary may be created; however, it will
                //       not be removed from.
                //
                if (categories != null)
                {
                    foreach (string category in categories)
                    {
                        //
                        // NOTE: Skip null categories.
                        //
                        if (category == null)
                        {
                            continue;
                        }

                        //
                        // NOTE: Remove the trace category.
                        //
                        traceCategories.Remove(category);
                    }
                }
            }
        }
Beispiel #11
0
 internal void UnsubscribeSynchronizedField(int fieldId)
 {
     FieldProcessors.Remove(fieldId);
 }
Beispiel #12
0
 internal static void RemoveObject(GameObject gobj)
 {
     GameObjects.Remove(gobj.Id);
 }
Beispiel #13
0
        public void IntDictionaryComparisonTest()
        {
            const int TestSize = 10000000;
            var intDic = new IntDictionary<MockObject>(32);
            var dic = new Dictionary<int, MockObject>(32);

            //jit shit.
            var add = new MockObject();
            add.Id = intDic.Add(add);
            foreach (var kvp in intDic)
            {
                kvp.DoNothing();
            }
            intDic.Remove(add.Id);

            add.Id = 0;
            dic.Add(add.Id, add);
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            dic.Remove(add.Id);

            Stopwatch watch = new Stopwatch();
            watch.Reset();

            //the real tests
            watch.Start();
            for (int i = 0; i < TestSize; i++)
            {
                var foo = new MockObject();
                foo.Id = intDic.Add(foo);
            }
            watch.Stop();

            Debug.WriteLine("IntDic add: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < TestSize; i++)
            {
                var foo = new MockObject();
                foo.Id = i;
                dic.Add(i, foo);
            }
            watch.Stop();

            Debug.WriteLine("Dic add: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in intDic)
            {
                if (kvp != null)
                    kvp.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("Intdic foreach: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("Dic foreach: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < intDic.Capacity; i++)
            {
                MockObject value;
                if (intDic.TryGetValue(i, out value))
                    value.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("Intdic for: {0}", watch.Elapsed);
            watch.Reset();

            const int halfSize = TestSize / 2;

            watch.Start();
            for (int i = 0; i < halfSize; i++)
            {
                intDic.Remove(i);
            }
            watch.Stop();

            Debug.WriteLine("Intdic remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < halfSize; i++)
            {
                dic.Remove(i);
            }
            watch.Stop();

            Debug.WriteLine("dic remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in intDic)
            {
                if (kvp != null)
                    kvp.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("intdic foreach after remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("dic foreach after remove: {0}", watch.Elapsed);
            watch.Reset();
        }
 internal void Remove(int value)
 {
     _ReplaceFieldValueIntToDocId.Remove(value);
 }
Beispiel #15
0
 /// <summary>
 /// remove the network view. This does not verify that the object in the slot was the same thing. Use contains to check that.
 /// </summary>
 /// <param name="view"></param>
 internal void Remove(NetworkView view)
 {
     _networkViews.Remove(view.Id);
 }
Beispiel #16
0
        public void IntDictionaryComparisonTest()
        {
            const int TestSize = 10000000;
            var       intDic   = new IntDictionary <MockObject>(32);
            var       dic      = new Dictionary <int, MockObject>(32);

            //jit shit.
            var add = new MockObject();

            add.Id = intDic.Add(add);
            foreach (var kvp in intDic)
            {
                kvp.DoNothing();
            }
            intDic.Remove(add.Id);

            add.Id = 0;
            dic.Add(add.Id, add);
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            dic.Remove(add.Id);

            Stopwatch watch = new Stopwatch();

            watch.Reset();

            //the real tests
            watch.Start();
            for (int i = 0; i < TestSize; i++)
            {
                var foo = new MockObject();
                foo.Id = intDic.Add(foo);
            }
            watch.Stop();

            Debug.WriteLine("IntDic add: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < TestSize; i++)
            {
                var foo = new MockObject();
                foo.Id = i;
                dic.Add(i, foo);
            }
            watch.Stop();

            Debug.WriteLine("Dic add: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in intDic)
            {
                if (kvp != null)
                {
                    kvp.DoNothing();
                }
            }
            watch.Stop();

            Debug.WriteLine("Intdic foreach: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("Dic foreach: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < intDic.Capacity; i++)
            {
                MockObject value;
                if (intDic.TryGetValue(i, out value))
                {
                    value.DoNothing();
                }
            }
            watch.Stop();

            Debug.WriteLine("Intdic for: {0}", watch.Elapsed);
            watch.Reset();

            const int halfSize = TestSize / 2;

            watch.Start();
            for (int i = 0; i < halfSize; i++)
            {
                intDic.Remove(i);
            }
            watch.Stop();

            Debug.WriteLine("Intdic remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            for (int i = 0; i < halfSize; i++)
            {
                dic.Remove(i);
            }
            watch.Stop();

            Debug.WriteLine("dic remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in intDic)
            {
                if (kvp != null)
                {
                    kvp.DoNothing();
                }
            }
            watch.Stop();

            Debug.WriteLine("intdic foreach after remove: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();
            foreach (var kvp in dic)
            {
                kvp.Value.DoNothing();
            }
            watch.Stop();

            Debug.WriteLine("dic foreach after remove: {0}", watch.Elapsed);
            watch.Reset();
        }