internal void TakeSnapshot() { //hacked together queue int snapIdx = ++currentSnapshot % snapMemoryCount; LinkedList <TransformProfile> profiles = new LinkedList <TransformProfile>(); savedGameObjectStates[snapIdx].Clear(); //snapshot all the network transforms LinkedListNode <NetworkTransform> node = objectsToWatch.First; while (node != null) { LinkedListNode <NetworkTransform> next = node.Next; NetworkTransform transform = node.Value; //clear out any "destroyed" nodes if (transform == null) { objectsToWatch.Remove(node); } else { //snapshot the transform savedGameObjectStates [snapIdx] [transform.gameObjectId] = new TransformProfile(transform.gameObject); //iterate through every collider foreach (Collider collider in transform.watchedColliders) { profiles.AddFirst(TransformProfile.ProfileFromCollider(collider)); } } node = next; } //clear linkedlist in O(1) time while s******g on the garbage collector savedColliderStates[snapIdx] = profiles; if (currentSnapshot == 0) { //figure out what 0 time is zeroTickTime = Utils.Timestamp; } }
/// <summary> /// Adds a NetworkTransform to the list of objects to take physics samples of /// </summary> /// <param name="nt">The network transform</param> public static void WatchObject(NetworkTransform nt) { SnapShotter.objectsToWatch.AddLast(nt); }