<commit_before>﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Delta
{
    public class EntityCollection : IDrawable, IUpdateable, ILayerable
    {
        internal static Dictionary<string, Entity> _idReferences = new Dictionary<string, Entity>();
        internal bool NeedsToSort { get; set; }

        public float Layer { get; set; }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public List<IUpdateable> _updateables = new List<IUpdateable>();
        [EditorBrowsable(EditorBrowsableState.Never)]
        public List<IDrawable> _drawables = new List<IDrawable>();

        public IComparer<ILayerable> Comparer { get; set; }

        //[ContentSerializerIgnore]
        //public Rectangle ViewingArea { get; set; }

        public EntityCollection()
            : base()
        {
            NeedsToSort = true;
            Comparer = new ILayerableComparer();
        }

        public void Add(IUpdateable updateable)
        {
            _updateables.Add(updateable);
            NeedsToSort = true;
        }

        public void Add(IDrawable drawable)
        {
            _drawables.Add(drawable);
            NeedsToSort = true;
        }

        public void Add(Entity entity)
        {
            _updateables.Add(entity);
            _drawables.Add(entity);
            NeedsToSort = true;
            entity._collectionReference = this;
            if (string.IsNullOrEmpty(entity.ID)) //if the ID is null, make it a unique.
                entity.ID = Guid.NewGuid().ToString();
            if (_idReferences.ContainsKey(entity.ID)) //if the ID already exists, append a numerical increment
            {
                for (int x = 1; x < int.MaxValue; x++)
                {
                    string newID = entity.ID + x;
                    if (!_idReferences.ContainsKey(newID))
                    {
                        entity.ID = newID;
                        break;
                    }
                }
            }
            _idReferences.Add(entity.ID.ToLower(), entity);
        }

        public void Add(EntityCollection collection)
        {
            _updateables.AddRange(collection._updateables);
            _drawables.AddRange(collection._drawables);
           NeedsToSort = true;
        }

        public void Remove(IUpdateable updateable)
        {
            _updateables.FastRemove<IUpdateable>(updateable);
            NeedsToSort = true;
        }

        public void Remove(IDrawable drawable)
        {
            _drawables.FastRemove<IDrawable>(drawable);
            NeedsToSort = true;
        }

        public void Remove(Entity entity)
        {
            _updateables.FastRemove<IUpdateable>(entity);
            _drawables.FastRemove<IDrawable>(entity);
            NeedsToSort = true;
            if (_idReferences.ContainsKey(entity.ID.ToLower()))
                _idReferences.Remove(entity.ID);
        }

        public void Remove(EntityCollection collection)
        {
            for (int x = 0; x < collection._updateables.Count; x++)
                _updateables.FastRemove<IUpdateable>(collection._updateables[x]);
            for (int x = 0; x < collection._drawables.Count; x++)
                _drawables.FastRemove<IDrawable>(collection._drawables[x]);
        }

        public virtual void LoadContent()
        {
            for (int x = 0; x < _updateables.Count; x++)
                _updateables[x].LoadContent();
        }

        public void Update(DeltaTime time)<commit_msg>Unsafe type adding is back.<commit_after>﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Delta
{
    public class EntityCollection : IDrawable, IUpdateable, ILayerable
    {
        internal static Dictionary<string, Entity> _idReferences = new Dictionary<string, Entity>();
        internal bool NeedsToSort { get; set; }

        public float Layer { get; set; }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public List<IUpdateable> _updateables = new List<IUpdateable>();
        [EditorBrowsable(EditorBrowsableState.Never)]
        public List<IDrawable> _drawables = new List<IDrawable>();

        public IComparer<ILayerable> Comparer { get; set; }

        public EntityCollection()
            : base()
        {
            NeedsToSort = true;
            Comparer = new ILayerableComparer();
        }

        public void Add(Entity entity)
        {
            _updateables.Add(entity);
            _drawables.Add(entity);
            NeedsToSort = true;
            entity._collectionReference = this;
            if (string.IsNullOrEmpty(entity.ID)) //if the ID is null, make it a unique.
                entity.ID = Guid.NewGuid().ToString();
            if (_idReferences.ContainsKey(entity.ID)) //if the ID already exists, append a numerical increment
            {
                for (int x = 1; x < int.MaxValue; x++)
                {
                    string newID = entity.ID + x;
                    if (!_idReferences.ContainsKey(newID))
                    {
                        entity.ID = newID;
                        break;
                    }
                }
            }
            _idReferences.Add(entity.ID.ToLower(), entity);
        }

        public void Add(object obj)
        {
            IUpdateable updateable = obj as IUpdateable;
            IDrawable drawable = obj as IDrawable;
            if (updateable == null && drawable == null)
                throw new Exception("The parameter 'obj' is neither an IUpdateable nor IDrawable.");
            if (updateable != null)
            {
                _updateables.Add(updateable);
                NeedsToSort = true;
            }
            if (drawable != null)
            {
                _drawables.Add(drawable);
                NeedsToSort = true;
            }
            Entity entity = obj as Entity;
            if (entity != null)
            {
                entity._collectionReference = this;
                if (string.IsNullOrEmpty(entity.ID)) //if the ID is null, make it a unique.
                    entity.ID = Guid.NewGuid().ToString();
                if (_idReferences.ContainsKey(entity.ID)) //if the ID already exists, append a numerical increment
                {
                    for (int x = 1; x < int.MaxValue; x++)
                    {
                        string newID = entity.ID + x;
                        if (!_idReferences.ContainsKey(newID))
                        {
                            entity.ID = newID;
                            break;
                        }
                    }
                }
                _idReferences.Add(entity.ID.ToLower(), entity);
            }
        }

        public void Remove(object obj)
        {
            IUpdateable updateable = obj as IUpdateable;
            if (updateable != null)
            {
                _updateables.FastRemove<IUpdateable>(updateable);
                NeedsToSort = true;
            }
            IDrawable drawable = obj as IDrawable;
            if (drawable != null)
            {
                _drawables.FastRemove<IDrawable>(drawable);
                NeedsToSort = true;
            }
            Entity entity = obj as Entity;
            if (entity != null)
            {
                if (_idReferences.ContainsKey(entity.ID.ToLower()))
                    _idReferences.Remove(entity.ID);
            }
        }

        public virtual void LoadContent()
        {
            for (int x = 0; x < _updateables.Count; x++)
                _updateables[x].LoadContent();
        }

        public void Update(DeltaTime time)
{'fraction_non_alphanumeric': 0.0900562851782364, 'fraction_numerical': 0.0008755472170106316, 'mean_word_length': 1.5743721828718609, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7365845', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1996, 'n_words': 473}