public NetworkView Get(ushort id) { NetworkView view; _networkViews.TryGetValue(id, out view); return(view); }
/// <summary> /// get a gameobject from its id /// </summary> /// <param name="gameObjectId"></param> /// <returns>null if that id does not exist</returns> public static GameObject GetGameObject(int gameObjectId) { GameObject value; if (GameObjects.TryGetValue(gameObjectId, out value)) { return(value); } return(null); }
/// <summary> /// get the player associated with the specified id. /// </summary> /// <param name="id"></param> /// <returns></returns> public Player GetPlayer(ushort id) { Player player; _players.TryGetValue(id, out player); return(player); }
/// <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(); }
public bool UpdateRegistration(uint userId) { _semaphoreSlim.Wait(); try { if (_registrationLookup.TryGetValue(userId, out var registration)) { registration?.Renew(); return(true); } return(false); //not registered } finally { _semaphoreSlim.Release(); } }
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); } }
internal void Update() { try { for (int i = 0; i < _roomBehaviours.Count; ++i) { _roomBehaviours[i].Update(); } for (int i = 0; i < _gameObjects.Capacity; ++i) { GameObject gobj; if (_gameObjects.TryGetValue(i, out gobj)) { gobj.Update(); } } } catch (Exception e) { Debug.LogError("[Room Update] {0}: {1}", Name, e); } }
static void Update() { PreviousFrameTime = TimeSinceStartup; TimeSinceStartup = Watch.Elapsed.TotalSeconds; if (_starteds.Count > 0) { List <Action> startsToRun = _starteds; _starteds = new List <Action>(); startsToRun.ForEach(a => { try { a(); } catch (Exception e) { Debug.LogError("[Start] ", e.ToString()); } }); } for (int i = 0; i < GameObjects.Capacity; i++) { GameObject get; if (!GameObjects.TryGetValue(i, out get)) { continue; } try { get.Update(); } catch (Exception e) { Debug.LogError("[Update Loop] {0}", e.ToString()); } } if (RoomUpdates != null) { RoomUpdates(); } try { update(); } catch (Exception e) { Debug.LogError("[Server Update] {0}", e.ToString()); } LoopRoutines(); for (int i = 0; i < GameObjects.Capacity; i++) { GameObject get; if (!GameObjects.TryGetValue(i, out get)) { continue; } try { get.LateUpdate(); } catch (Exception e) { Debug.LogError("[Late Update] {0}", e.ToString()); } } if (DestroyDelays == null) { return; } try { var frameDestructions = DestroyDelays; DestroyDelays = null; frameDestructions(); } catch (Exception e) { Debug.LogError("[Destruction] {0}", e.ToString()); } }
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(); }
/////////////////////////////////////////////////////////////////////// // // HACK: This is part of a hack that solves a chicken-and-egg problem // with the diagnostic tracing method used by this library. We // allow tracing to be disabled via an environment variable // and/or the shell command line. Unfortunately, by the time we // disable tracing, many messages will have typically already // been written to the trace listeners. To prevent this noise // (that the user wishes to suppress), we internalize the check // (i.e. we do it from inside the core trace method itself) and // initialize this variable [once] with the result of checking // the environment variable. // private static bool IsTraceEnabled( TracePriority priority, params string[] categories ) { bool result; lock (syncRoot) /* TRANSACTIONAL */ { if (isTraceEnabled == null) { // // NOTE: Cannot use the GlobalConfiguration.GetValue // method at this point because that method may // call into the DebugTrace method (below), which // calls this method. // if (CommonOps.Environment.DoesVariableExist( EnvVars.NoTrace)) { isTraceEnabled = false; } else if (CommonOps.Environment.DoesVariableExist( EnvVars.Trace)) { isTraceEnabled = true; } else { isTraceEnabled = isTraceEnabledByDefault; } } // // NOTE: Determine if tracing is globally enabled or disabled. // result = (bool)isTraceEnabled; // // NOTE: If tracing has been globally disabled, do not bother // checking any categories. // if (result) { // // NOTE: The priority flags specified by the caller must // all be present in the configured trace priority // flags. // if (!FlagOps.HasFlags(tracePriorities, priority, true)) { result = false; } else { // // NOTE: If the caller specified a null category -OR- // there are no trace categories specifically // enabled (i.e. all trace categories are // allowed), always allow the message through. // if ((categories != null) && (categories.Length > 0) && (traceCategories != null) && (traceCategories.Count > 0)) { // // NOTE: At this point, at least one of the // specified trace categories, if any, // must exist in the dictionary and its // associated value must be non-zero; // otherwise, the trace message is not // allowed through. // bool found = false; foreach (string category in categories) { if (category == null) { continue; } int value; if (traceCategories.TryGetValue( category, out value) && (value != 0)) { found = true; break; } } if (!found) { result = false; } } } } } return(result); }
internal bool TryGetValue(int key, out int docId) { return(_ReplaceFieldValueIntToDocId.TryGetValue(key, out docId)); }
internal bool InnerTryGetRank(int docid, out UInt16 rank) { return(_DocIdToRank.TryGetValue(docid, out rank)); }
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(); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="view"></param> /// <returns></returns> public bool Find(NetworkViewId id, out NetworkView view) { return(_allViews.TryGetValue(id.guid, out view)); }
public NetworkView Get(NetworkViewId id) { _networkViews.TryGetValue(id.Id, out var view); return(view); }