RemoveAt() public method

public RemoveAt ( int index ) : void
index int
return void
コード例 #1
0
 public override void ClearRecordAt(int frame)
 {
     for (int i = 0; i < m_record.Count; i++)
     {
         if (m_record[i].Frame == frame)
         {
             m_record.RemoveAt(i);
             i--;
         }
     }
 }
コード例 #2
0
    /*
     * 插入功能:
     *  - 如果当前节点[ 存在 ]子节点,则检查物体到底属于哪个子节点,如果能匹配到子节点,则将该物体插入到该子节点中
     *  - 如果当前节点[ 不存在 ]子节点,将该物体存储在当前节点。随后,检查当前节点的存储数量,
     *  - 如果超过了最大存储数量,则对当前节点进行划分,划分完成后,将当前节点存储的物体重新分配到四个子节点中。
     */
    public void Insert(CollisionComponent coll)
    {
        //如果存在子节点,则插入子节点
        if (m_childListCount > 0)
        {
            int index = GetIndex(coll.area);

            //Debug.Log("index " + index + " depth " + m_depth);

            //如果都不包含则存储在父节点内
            if (index == -1)
            {
                m_objectList.Add(coll);
                m_objectListCount++;
            }
            else
            {
                m_childList[index].Insert(coll);
            }
        }

        //否则则存储在当前节点
        else
        {
            m_objectList.Add(coll);
            m_objectListCount++;

            //如果当前节点储存的数量超过了上限,则分裂
            if (m_objectListCount > MAX_OBJECTS &&
                m_depth < MAX_DEPTH)
            {
                Split();

                //把当前节点下对象的放入子节点内
                for (int i = 0; i < m_objectListCount; i++)
                {
                    int index = GetIndex(m_objectList[i].area);

                    if (index != -1)
                    {
                        CollisionComponent tmp = m_objectList[i];
                        m_objectList.RemoveAt(i);
                        i--;

                        m_childList[index].Insert(tmp);
                        m_objectListCount--;
                    }
                }
            }
        }
    }
コード例 #3
0
ファイル: MiniMap.cs プロジェクト: yuri410/lrvbsvnicg
        public override void Update(GameTime time)
        {
            //const float StdRot = 0;
            //if (state == AnimState.Out)
            //{
            //    rot += (StdRot - rot + PopBaseSpeed) * time.ElapsedGameTimeSeconds * 2;
            //    if (rot >= StdRot)
            //    {
            //        rot = StdRot;
            //        state = AnimState.Outside;
            //    }

            //}
            //else if (state == AnimState.In)
            //{
            //    rot -= (StdRot - rot + PopBaseSpeed) * time.ElapsedGameTimeSeconds * 2;
            //    if (rot < RotIn)
            //    {
            //        rot = RotIn;
            //        state = AnimState.Inside;
            //    }
            //}
            for (int i = marks.Count - 1; i >= 0; i--)
            {
                if (marks[i].IsFinished)
                {
                    marks.RemoveAt(i);
                }
                else
                {
                    marks[i].Update(time);
                }
            }
        }
コード例 #4
0
ファイル: Managers.cs プロジェクト: vvvv/VL.Stride
        public Entity Update(Spread <EntityComponent> components)
        {
            // Quick change check
            if (components != this.components)
            {
                this.components = components;
            }
            else
            {
                return(entity);
            }

            // Synchronize our entity links
            var @array = components._array;

            for (int i = 0; i < array.Length; i++)
            {
                var link = links.ElementAtOrDefault(i);
                if (link == null)
                {
                    link = new ComponentLink(entity);
                    links.Add(link);
                }
                link.Component = array[i];
            }
            for (int i = links.Count - 1; i >= array.Length; i--)
            {
                var link = links[i];
                link.Dispose();
                links.RemoveAt(i);
            }

            return(entity);
        }
コード例 #5
0
        public static void SmoothPath(FastList <GridNode> nodePath, Vector2d End, FastList <Vector2d> outputVectorPath, int unitHalfSize)
        {
            //nodePath should include the start and end nodes

            outputVectorPath.FastClear();
            length = nodePath.Count - 1;
            //culling out unneded nodes


            var StartNode = nodePath[0];
            //outputVectorPath.Add(StartNode.WorldPos);
            GridNode oldNode = StartNode;
            long     oldX    = 0;
            long     oldY    = 0;
            long     newX    = 0;
            long     newY    = 0;

            for (i = 1; i < length; i++)
            {
                GridNode node = nodePath[i];

                bool important = false;
                //Anyone who's somebody is near an unwalkable node
                important = node.GetClearanceDegree() <= unitHalfSize + 1;
                if (important)
                {
                    newX = node.gridX - oldNode.gridX;
                    newY = node.gridY - oldNode.gridY;
                    if (
                        (newX <= 1 && newX >= -1) &&
                        (newY <= 1 && newY >= -1)
                        )
                    {
                        if (newX == oldX && newY == oldY)
                        {
                            if (oldX != 0 || oldY != 0)
                            {
                                outputVectorPath.RemoveAt(outputVectorPath.Count - 1);
                            }
                        }
                        else
                        {
                            oldX = newX;
                            oldY = newY;
                        }
                    }
                    else
                    {
                        oldX = 0;
                        oldY = 0;
                    }
                    outputVectorPath.Add(node.WorldPos);

                    oldNode = node;
                }
            }
            outputVectorPath.Add(End);
        }
コード例 #6
0
    public override void RevertToFrame(int frame)
    {
        //Debug.Log("RevertToFrame " + frame + " count " + m_record.Count);

        for (int i = 0; i < m_record.Count; i++)
        {
            T record = m_record[i];

            //Debug.Log("record.Frame " + record.Frame);

            if (record.Frame == frame)
            {
                if (m_world.GetEntityIsExist(record.ID))
                {
                    EntityBase entity = m_world.GetEntity(record.ID);
                    entity.ChangeComp(hashCode, (T)record.DeepCopy());
                    //if (SyncDebugSystem.isDebug && SyncDebugSystem.IsFilter(typeof(T).Name))
                    //{
                    //    Debug.Log("RevertToFrame " + frame + " ->> " + Serializer.Serialize((T)record.DeepCopy()));
                    //}
                }
                else if (m_world.GetIsExistDispatchDestroyCache(record.ID))
                {
                    EntityBase entity = m_world.GetDispatchDestroyCache(record.ID);
                    entity.ChangeComp(hashCode, (T)record.DeepCopy());
                }
                else if (m_world.GetIsExistDispatchCreateCache(record.ID))
                {
                    EntityBase entity = m_world.GetDispatchCreateCache(record.ID);
                    entity.ChangeComp(hashCode, (T)record.DeepCopy());
                }
                else
                {
                    Debug.Log("没有找到回滚对象 ! " + record.ID);
                }

                m_record.RemoveAt(i);
                i--;

                m_world.heapComponentPool.PutObject(hashCode, record);
            }
        }
    }
コード例 #7
0
        public override void Update(GameTime time)
        {
            base.Update(time);

            float distance = Vector3.Distance(this.Position, SoundManager.Instance.ListenerPosition);

            if (distance < float.Epsilon)
            {
                return;
            }

            bool action = false;

            float r = radius * 4;

            if (distance <= r)
            {
                if (lastDistance > r)
                {
                    AddToPlayList(SoundEffectPart.Fadein);
                    action = true;
                    // just in
                }
            }
            else
            {
                if (lastDistance <= r)
                {
                    AddToPlayList(SoundEffectPart.Fadeout);
                    action = true;
                    // just out
                }
            }

            if (!action && distance <= r)
            {
                if (playList.Count == 0)
                {
                    AddToPlayList(SoundEffectPart.Medium);
                }
            }


            if (currentInstance == null)
            {
                if (playList.Count > 0)
                {
                    currentInstance = soundEffectGame.Play(playList[0].Part, this);

                    playList.RemoveAt(0);
                }
            }

            lastDistance = distance;
        }
コード例 #8
0
 public override void Update(GameTime dt)
 {
     for (int i = 0; i < instance.Count; i++)
     {
         if (instance[i].State == SoundState.Stopped)
         {
             instance.RemoveAt(i);
         }
         else
         {
             soundEffectGame.Update(this, instance[i]);
         }
     }
 }
コード例 #9
0
            void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
            {
                _networkSystem.DebugWriteLine($"Svr OnPeerDisconnected: {disconnectInfo.Reason}");

                var  networkEntityProcessor = _networkSystem._networkEntityProcessor;
                bool wasRemoved             = false;

                int clientIndex = FindClientDetailsIndex(peer);

                if (clientIndex >= 0)
                {
                    var clientDetails = _activeClients.Items[clientIndex];
                    _activeClients.RemoveAt(clientIndex);

                    var  playerId            = clientDetails.PlayerId;
                    var  serverPlayerManager = networkEntityProcessor.GetServerPlayerManager();
                    bool wasActivePlayer     = serverPlayerManager.RemoveRemotePlayer(playerId);
                    if (wasActivePlayer)
                    {
                        // Need to notify all active players of this player's removal
                        var gameClockManager = _networkSystem._gameClockManager;
                        var despawnPlayer    = new DespawnRemotePlayerMessage
                        {
                            PlayerId             = playerId,
                            SimulationTickNumber = gameClockManager.SimulationClock.SimulationTickNumber
                        };
                        _networkMessageWriter.Reset();
                        despawnPlayer.WriteTo(_networkMessageWriter);
                        for (int playerIdx = 0; playerIdx < _activeClients.Count; playerIdx++)
                        {
                            ref var otherClientDetails = ref _activeClients.Items[playerIdx];
                            if (!otherClientDetails.IsInGame)
                            {
                                continue;
                            }
                            otherClientDetails.Connection.Send(_networkMessageWriter, SendNetworkMessageType.ReliableOrdered);   // Use Ordered to ensure a player's joined & dropped events are in sequence
                        }
                    }
                    _networkSystem.DebugWriteLine($"Svr Player disconnected: { clientDetails.PlayerName}");
                    wasRemoved = true;
                }
コード例 #10
0
ファイル: DebugRenderSystem.cs プロジェクト: CriDos/xenko
 private void PushMessage(ref DebugRenderable msg)
 {
     if (msg.Lifetime > 0.0f)
     {
         renderMessagesWithLifetime.Add(msg);
         // drop one old message if the tail size has been reached
         if (renderMessagesWithLifetime.Count > MaxPrimitivesWithLifetime)
         {
             renderMessagesWithLifetime.RemoveAt(renderMessagesWithLifetime.Count - 1);
         }
     }
     else
     {
         renderMessages.Add(msg);
         // drop one old message if the tail size has been reached
         if (renderMessages.Count > MaxPrimitives)
         {
             renderMessages.RemoveAt(renderMessages.Count - 1);
         }
     }
 }
コード例 #11
0
    /// <summary>
    /// Update the fog of war's visibility.
    /// </summary>

    void UpdateBuffer()
    {
        // Add all items scheduled to be added
        if (mAdded.size > 0)
        {
            lock (mAdded)
            {
                while (mAdded.size > 0)
                {
                    int index = mAdded.size - 1;
                    mRevealers.Add(mAdded.buffer[index]);
                    mAdded.RemoveAt(index);
                }
            }
        }

        // Remove all items scheduled for removal
        if (mRemoved.size > 0)
        {
            lock (mRemoved)
            {
                while (mRemoved.size > 0)
                {
                    int index = mRemoved.size - 1;
                    mRevealers.Remove(mRemoved.buffer[index]);
                    mRemoved.RemoveAt(index);
                }
            }
        }

        // Use the texture blend time, thus estimating the time this update will finish
        // Doing so helps avoid visible changes in blending caused by the blended result being X milliseconds behind.
        float factor = (map.fow.textureBlendTime > 0f) ? Mathf.Clamp01(mBlendFactor + map.elapsed / map.fow.textureBlendTime) : 1f;

        // Clear the buffer's red channel (channel used for current visibility -- it's updated right after)
        if (mBuffer0 != null)
        {
            for (int i = 0, imax = mBuffer0.Length; i < imax; ++i)
            {
                mBuffer0[i]   = Color32.Lerp(mBuffer0[i], mBuffer1[i], factor);
                mBuffer0[i].r = 0;
            }
        }

        // For conversion from world coordinates to texture coordinates
        float worldToTex = (float)(map.fow.textureSize / map.fow.textureSize);

        // Update the visibility buffer, one revealer at a time
        for (int i = 0; i != mRevealers.size; ++i)
        {
            Revealer rev = mRevealers[i];

            if (!rev.isActive)
            {
                continue;
            }

            RevealAtPosition(rev, worldToTex);
        }

        // Blur the final visibility data
        for (int i = 0; i != map.fow.blurIterations; ++i)
        {
            BlurVisibility();
        }

        // Reveal the map based on what's currently visible
        RevealMap();
    }
コード例 #12
0
    /*
     * -----------------------
     * DrawCategories()
     * -----------------------
     */
    void DrawCategories(Event e)
    {
        // do any housework before we start drawing
        if (moveQueued)
        {
            // make a temp copy
            List <SoundFX> origSoundList   = new List <SoundFX>(audioManager.soundGroupings[origGroup].soundList);
            SoundFX        temp            = origSoundList[origIndex];
            List <SoundFX> moveToSoundList = new List <SoundFX>(audioManager.soundGroupings[moveToGroup].soundList);
            // add it to the move to group
            moveToSoundList.Add(temp);
            audioManager.soundGroupings[moveToGroup].soundList = moveToSoundList.ToArray();
            // and finally, remove it from the original group
            origSoundList.RemoveAt(origIndex);
            audioManager.soundGroupings[origGroup].soundList = origSoundList.ToArray();
            Debug.Log("> Moved '" + temp.name + "' from " + "'" + audioManager.soundGroupings[origGroup].name + "' to '" + audioManager.soundGroupings[moveToGroup].name);
            MarkDirty();
            moveQueued = false;
        }
        // switch to the next group
        if (nextGroup > -1)
        {
            selectedGroup = nextGroup;
            nextGroup     = -1;
        }
        // add a sound
        if (addSound)
        {
            List <SoundFX> soundList = new List <SoundFX>(audioManager.soundGroupings[selectedGroup].soundList);
            SoundFX        soundFX   = new SoundFX();
            soundFX.name = audioManager.soundGroupings[selectedGroup].name.ToLower() + "_new_unnamed_sound_fx";
            soundList.Add(soundFX);
            audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
            MarkDirty();
            addSound = false;
        }
        // sort the sounds
        if (sortSounds)
        {
            List <SoundFX> soundList = new List <SoundFX>(audioManager.soundGroupings[selectedGroup].soundList);
            soundList.Sort(delegate(SoundFX sfx1, SoundFX sfx2) { return(string.Compare(sfx1.name, sfx2.name)); });
            audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
            MarkDirty();
            sortSounds = false;
        }
        // delete a sound
        if (deleteSoundIdx > -1)
        {
            List <SoundFX> soundList = new List <SoundFX>(audioManager.soundGroupings[selectedGroup].soundList);
            soundList.RemoveAt(deleteSoundIdx);
            audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
            MarkDirty();
            deleteSoundIdx = -1;
        }
        // duplicate a sound
        if (dupeSoundIdx > -1)
        {
            List <SoundFX> soundList   = new List <SoundFX>(audioManager.soundGroupings[selectedGroup].soundList);
            SoundFX        origSoundFX = soundList[dupeSoundIdx];
            // clone this soundFX
            string  json    = JsonUtility.ToJson(origSoundFX);
            SoundFX soundFX = JsonUtility.FromJson <SoundFX>(json);
            soundFX.name += "_duplicated";
            soundList.Insert(dupeSoundIdx + 1, soundFX);
            audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
            MarkDirty();
            dupeSoundIdx = -1;
        }

        if (e.type == EventType.Repaint)
        {
            groups.Clear();
        }

        GUILayout.Space(6f);

        Color defaultColor = GUI.contentColor;

        BeginContents();

        if (DrawHeader("Sound FX Groups", true))
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            soundGroups.Clear();
            for (int i = 0; i < audioManager.soundGroupings.Length; i++)
            {
                soundGroups.Add(audioManager.soundGroupings[i]);
            }
            for (int i = 0; i < soundGroups.size; i++)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    if (i == selectedGroup)
                    {
                        GUI.contentColor = (i == editGroup) ? Color.white : Color.yellow;
                    }
                    else
                    {
                        GUI.contentColor = defaultColor;
                    }
                    if ((e.type == EventType.KeyDown) && ((e.keyCode == KeyCode.Return) || (e.keyCode == KeyCode.KeypadEnter)))
                    {
                        // toggle editing
                        if (editGroup >= 0)
                        {
                            editGroup = -1;
                        }
                        Event.current.Use();
                    }
                    if (i == editGroup)
                    {
                        soundGroups[i].name = GUILayout.TextField(soundGroups[i].name, GUILayout.MinWidth(Screen.width - 80f));
                    }
                    else
                    {
                        GUILayout.Label(soundGroups[i].name, (i == selectedGroup) ? EditorStyles.whiteLabel : EditorStyles.label, GUILayout.ExpandWidth(true));
                    }
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button(GUIContent.none, "OL Minus", GUILayout.Width(17f)))                            // minus button
                    {
                        if (EditorUtility.DisplayDialog("Delete '" + soundGroups[i].name + "'", "Are you sure you want to delete the selected sound group?", "Continue", "Cancel"))
                        {
                            soundGroups.RemoveAt(i);
                            MarkDirty();
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                // build a list of items
                Rect lastRect = GUILayoutUtility.GetLastRect();
                if (e.type == EventType.Repaint)
                {
                    groups.Add(new ItemRect(i, lastRect, null));
                }
                if ((e.type == EventType.MouseDown) && lastRect.Contains(e.mousePosition))
                {
                    if ((i != selectedGroup) || (e.clickCount == 2))
                    {
                        nextGroup = i;
                        if (e.clickCount == 2)
                        {
                            editGroup = i;
                        }
                        else if (editGroup != nextGroup)
                        {
                            editGroup = -1;
                        }
                        Repaint();
                    }
                }
            }
            // add the final plus button
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GUIContent.none, "OL Plus", GUILayout.Width(17f)))                     // plus button
            {
                soundGroups.Add(new SoundGroup("unnamed sound group"));
                selectedGroup = editGroup = soundGroups.size - 1;
                MarkDirty();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // reset the color
            GUI.contentColor = defaultColor;

            // the sort and import buttons
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Sort", GUILayout.Width(70f)))
            {
                soundGroups.Sort(delegate(SoundGroup sg1, SoundGroup sg2) { return(string.Compare(sg1.name, sg2.name)); });
                MarkDirty();
            }
            EditorGUILayout.EndHorizontal();

            // draw a rect around the selected item
            if ((selectedGroup >= 0) && (selectedGroup < groups.size))
            {
                EditorGUI.DrawRect(groups[selectedGroup].rect, new Color(1f, 1f, 1f, 0.06f));
            }

            // finally move the sound groups back into the audio manager
            if (soundGroups.size > 0)
            {
                audioManager.soundGroupings = soundGroups.ToArray();
            }

            // calculate the drop area rect
            if ((e.type == EventType.Repaint) && (groups.size > 0))
            {
                dropArea.x      = groups[0].rect.x;
                dropArea.y      = groups[0].rect.y;
                dropArea.width  = groups[0].rect.width;
                dropArea.height = (groups[groups.size - 1].rect.y - groups[0].rect.y) + groups[groups.size - 1].rect.height;
            }
        }
        // draw the sound group properties now
        DrawSoundGroupProperties();

        EndContents();

        EditorGUILayout.HelpBox("Create and delete sound groups by clicking + and - respectively.  Double click to rename sound groups.  Drag and drop sounds from below to the groups above to move them.", MessageType.Info);
    }
コード例 #13
0
        public static void SmoothPath(FastList <GridNode> nodePath, Vector2d End, FastList <Vector2d> outputVectorPath, int unitSize)
        {
            outputVectorPath.FastClear();
            length = nodePath.Count - 1;
            //culling out unneded nodes


            var StartNode = nodePath[0];

            outputVectorPath.Add(StartNode.WorldPos);
            GridNode oldNode = StartNode;
            long     oldX    = 0;
            long     oldY    = 0;
            long     newX    = 0;
            long     newY    = 0;

            for (i = 1; i < length; i++)
            {
                GridNode node = nodePath[i];

                bool important = false;
                if (unitSize <= SmallSize)
                {
                    important = !node.Clearance;
                }
                else if (unitSize <= MediumSize)
                {
                    important = !node.ExtraClearance;
                }
                else
                {
                    important = true;
                }
                //important = true;
                if (important)
                {
                    newX = node.gridX - oldNode.gridX;
                    newY = node.gridY - oldNode.gridY;
                    if (
                        (newX <= 1 && newX >= -1) &&
                        (newY <= 1 && newY >= -1)
                        )
                    {
                        if (newX == oldX && newY == oldY)
                        {
                            if (oldX != 0 || oldY != 0)
                            {
                                outputVectorPath.RemoveAt(outputVectorPath.Count - 1);
                            }
                        }
                        else
                        {
                            oldX = newX;
                            oldY = newY;
                        }
                    }
                    else
                    {
                        oldX = 0;
                        oldY = 0;
                    }
                    outputVectorPath.Add(node.WorldPos);

                    oldNode = node;
                }
            }
            outputVectorPath.Add(End);
        }
コード例 #14
0
        private void UnlikelySortProperties(FastList <BlittableJsonDocumentBuilder.PropertyTag> properties)
        {
            _hasDuplicates = false;

            var index = GetPropertiesHashedIndex(properties);

            if (_cachedSorts[index] == null)
            {
                _cachedSorts[index] = new CachedSort();
            }

            _cachedSorts[index].Sorting.Clear();

            for (int i = 0; i < properties.Count; i++)
            {
                _cachedSorts[index].Sorting.Add(new PropertyPosition
                {
                    Property       = properties[i].Property,
                    SortedPosition = -1
                });
            }

            _cachedSorts[index].FinalCount = properties.Count;

            properties.Sort(ref _sorter);

            // The item comparison method has a side effect, which can modify the _hasDuplicates field.
            // This can either be true or false at any given time.
            if (_hasDuplicates)
            {
                // leave just the latest
                for (int i = 0; i < properties.Count - 1; i++)
                {
                    if (properties[i].Property.Equals(properties[i + 1].Property))
                    {
                        _cachedSorts[index].FinalCount--;
                        _cachedSorts[index].Sorting[i + 1] = new PropertyPosition
                        {
                            Property = properties[i + 1].Property,
                            // set it to the previous value, so it'll just overwrite
                            // this saves us a check and more complex code
                            SortedPosition = i
                        };

                        properties.RemoveAt(i + 1);

                        i--;
                    }
                }
            }

            for (int i = 0; i < _cachedSorts[index].Sorting.Count; i++)
            {
                var propPos = _cachedSorts[index].Sorting[i];
                propPos.SortedPosition = -1;
                for (int j = 0; j < properties.Count; j++)
                {
                    if (properties[j].Property == propPos.Property)
                    {
                        propPos.SortedPosition = j;
                        break;
                    }
                }
            }
        }
コード例 #15
0
        private void Add(Scene scene)
        {
            if (scene.Entities.Count > 0)
            {
                var entitiesToAdd = new FastList <Entity>();
                // Reverse order, we're adding and removing from the tail to
                // avoid forcing the list to move all items when removing at [0]
                for (int i = scene.Entities.Count - 1; i >= 0; i--)
                {
                    entitiesToAdd.Add(scene.Entities[i]);
                }

                scene.Entities.CollectionChanged += DealWithTempChanges;
                while (entitiesToAdd.Count > 0)
                {
                    int i      = entitiesToAdd.Count - 1;
                    var entity = entitiesToAdd[i];
                    entitiesToAdd.RemoveAt(i);
                    Add(entity);
                }
                scene.Entities.CollectionChanged -= DealWithTempChanges;

                void DealWithTempChanges(object sender, TrackingCollectionChangedEventArgs e)
                {
                    Entity entity = (Entity)e.Item;

                    if (e.Action == NotifyCollectionChangedAction.Remove)
                    {
                        if (entitiesToAdd.Remove(entity) == false)
                        {
                            Remove(entity);
                        }
                    }
                    else if (e.Action == NotifyCollectionChangedAction.Add)
                    {
                        entitiesToAdd.Add(entity);
                    }
                }
            }

            if (scene.Children.Count > 0)
            {
                var scenesToAdd = new FastList <Scene>();
                // Reverse order, we're adding and removing from the tail to
                // avoid forcing the list to move all items when removing at [0]
                for (int i = scene.Children.Count - 1; i >= 0; i--)
                {
                    scenesToAdd.Add(scene.Children[i]);
                }

                scene.Children.CollectionChanged += DealWithTempChanges;
                while (scenesToAdd.Count > 0)
                {
                    int i      = scenesToAdd.Count - 1;
                    var entity = scenesToAdd[i];
                    scenesToAdd.RemoveAt(i);
                    Add(entity);
                }
                scene.Children.CollectionChanged -= DealWithTempChanges;

                void DealWithTempChanges(object sender, TrackingCollectionChangedEventArgs e)
                {
                    Scene subScene = (Scene)e.Item;

                    if (e.Action == NotifyCollectionChangedAction.Remove)
                    {
                        if (scenesToAdd.Remove(subScene) == false)
                        {
                            Remove(subScene);
                        }
                    }
                    else if (e.Action == NotifyCollectionChangedAction.Add)
                    {
                        scenesToAdd.Add(subScene);
                    }
                }
            }

            // Listen to future changes in entities and child scenes
            scene.Children.CollectionChanged += Children_CollectionChanged;
            scene.Entities.CollectionChanged += Entities_CollectionChanged;
        }
コード例 #16
0
        public void FreeScratchPagesOlderThan(LowLevelTransaction tx, long lastSyncedTransactionId)
        {
            var unusedPages   = _scratchPagesPositionsPool.Allocate();
            var unusedAndFree = _scratchPagesPositionsPool.Allocate();

            using (_locker2.Lock())
            {
                int count         = _unusedPages.Count;
                int originalCount = count;

                for (int i = 0; i < count; i++)
                {
                    var page = _unusedPages[i];
                    if (page.TransactionId <= lastSyncedTransactionId)
                    {
                        unusedAndFree.Add(page);

                        count--;

                        if (i < count)
                        {
                            _unusedPages[i] = _unusedPages[count];
                        }

                        _unusedPages.RemoveAt(count);

                        i--;
                    }
                }

                // This must hold true, if not we have leakage of memory and disk.
                Debug.Assert(_unusedPages.Count + unusedAndFree.Count == originalCount);

                _pageTranslationTable.RemoveKeysWhereAllPagesOlderThan(lastSyncedTransactionId, unusedPages);
            }

            // use current write tx id to prevent from overriding a scratch page by write tx
            // while there might be old read tx looking at it by using PTT from the journal snapshot
            var availableForAllocationAfterTx = tx.Id;

            int length = unusedPages.Count;

            for (int i = 0; i < length; i++)
            {
                var page = unusedPages[i];

                if (page.IsFreedPageMarker)
                {
                    continue;
                }

                if (page.UnusedInPTT) // to prevent freeing a page that was already freed as unused and free
                {
                    // the page could be either freed in the current run, then just skip it to avoid freeing an unallocated page, or
                    // it could be released in an earlier run, but it still resided in PTT because a under a relevant page number of PTT
                    // there were overwrites by newer transactions (> lastSyncedTransactionId) and we didn't remove it from there
                    continue;
                }

                unusedAndFree.Add(page);
            }

            length = unusedAndFree.Count;
            for (int i = 0; i < length; i++)
            {
                var unusedPage = unusedAndFree[i];
                if (unusedPage.IsFreedPageMarker)
                {
                    continue;
                }

                _env.ScratchBufferPool.Free(tx, unusedPage.ScratchNumber, unusedPage.ScratchPage, availableForAllocationAfterTx);
            }

            _scratchPagesPositionsPool.Free(unusedPages);
            _scratchPagesPositionsPool.Free(unusedAndFree);
        }
コード例 #17
0
        private void AppendRenderResult(RenderFinishedEventArgs result)
        {
            if (result != null)
            {
                CanvasElement.style.width  = result.TotalWidth + "px";
                CanvasElement.style.height = result.TotalHeight + "px";
            }


            if (result == null || result.RenderResult != null)
            {
                // the queue/dequeue like mechanism used here is to maintain the order within the setTimeout.
                // setTimeout allows to decouple the rendering from the JS processing a bit which makes the overall display faster.
                _renderResults.Add(result);

                setTimeout(() =>
                {
                    while (_renderResults.Count > 0)
                    {
                        var renderResult = _renderResults[0];
                        _renderResults.RemoveAt(0);

                        // null result indicates that the rendering finished
                        if (renderResult == null)
                        {
                            // so we remove elements that might be from a previous render session
                            while (CanvasElement.childElementCount > _totalResultCount)
                            {
                                CanvasElement.removeChild(CanvasElement.lastChild);
                            }
                        }
                        // NOTE: here we try to replace existing children
                        else
                        {
                            var body = renderResult.RenderResult;
                            if (@typeof(body) == "string")
                            {
                                HtmlElement placeholder;
                                if (_totalResultCount < CanvasElement.childElementCount)
                                {
                                    placeholder = CanvasElement.children[_totalResultCount].As <HtmlElement>();
                                }
                                else
                                {
                                    placeholder = document.createElement("div").As <HtmlElement>();
                                    CanvasElement.appendChild(placeholder);
                                }

                                placeholder.style.width   = renderResult.Width + "px";
                                placeholder.style.height  = renderResult.Height + "px";
                                placeholder.style.display = "inline-block";

                                if (IsElementInViewPort(placeholder) || Settings.DisableLazyLoading)
                                {
                                    placeholder.outerHTML = body.As <string>();
                                }
                                else
                                {
                                    placeholder.As <dynamic>().svg = body;
                                    placeholder.setAttribute("data-lazy", "true");
                                }
                            }
                            else
                            {
                                if (_totalResultCount < CanvasElement.childElementCount)
                                {
                                    CanvasElement.replaceChild(renderResult.RenderResult.As <Node>(), CanvasElement.children[_totalResultCount]);
                                }
                                else
                                {
                                    CanvasElement.appendChild(renderResult.RenderResult.As <Node>());
                                }
                            }
                            _totalResultCount++;
                        }
                    }
                }, 1);
            }
        }