Пример #1
0
    static GWorld()
    {
        world = new WorldStates();

        people = new ResourceQueue("", "", world);
        resources.Add("people", people);

        cubicles = new ResourceQueue("Cubicle", "FreeCubicle", world);
        resources.Add("cubicles", cubicles);

        offices = new ResourceQueue("Office", "FreeOffice", world);
        resources.Add("offices", offices);

        toilets = new ResourceQueue("Toilet", "FreeToilet", world);
        resources.Add("toilets", toilets);

        puddles = new ResourceQueue("Puddle", "FreePuddle", world);
        resources.Add("puddles", puddles);

        foods = new ResourceQueue("Food", "FreeFood", world);
        resources.Add("foods", foods);

        waters = new ResourceQueue("Water", "FreeWater", world);
        resources.Add("waters", waters);

        seats = new ResourceQueue("Seat", "FreeSeat", world);
        resources.Add("seats", seats);

        //Time.timeScale = 5;    //Speeds up time
    }
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();
            int x = 0;
            ResourceQueue<string> queue = new ResourceQueue<string>(() => (x++).ToString(), 3, 4);

            x = 10;

            Assert.AreEqual(queue.Dequeue(), "0");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "10");
            Assert.AreEqual(queue.Dequeue(), "11");

            queue.Enqueue("0");
            queue.Enqueue("1");
            Assert.AreEqual(queue.Dequeue(), "0");
            queue.Enqueue("3");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "12");

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");
            queue.Enqueue("4");
            queue.Enqueue("5");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "4");
            Assert.AreEqual(queue.Dequeue(), "13");
            MemoryPoolTest.TestMemoryLeak();
        }
Пример #3
0
        /// <summary>
        /// Creates a new CustomFileStream
        /// </summary>
        /// <param name="stream">The filestream to use as the base stream</param>
        /// <param name="ioSize">The size of a buffer pool entry</param>
        /// <param name="fileStructureBlockSize">The size of an individual block</param>
        /// <param name="fileName">The filename</param>
        /// <param name="isReadOnly">If the file is read only</param>
        /// <param name="isSharingEnabled">if the file is exclusively opened</param>
        private CustomFileStream(FileStream stream, int ioSize, int fileStructureBlockSize, string fileName, bool isReadOnly, bool isSharingEnabled)
        {
            if (ioSize < 4096)
            {
                throw new ArgumentOutOfRangeException("ioSize", "Cannot be less than 4096");
            }
            if (fileStructureBlockSize > ioSize)
            {
                throw new ArgumentOutOfRangeException("fileStructureBlockSize", "Must not be greater than BufferPoolSize");
            }
            if (!BitMath.IsPowerOfTwo(ioSize))
            {
                throw new ArgumentException("Must be a power of 2", "ioSize");
            }
            if (!BitMath.IsPowerOfTwo(fileStructureBlockSize))
            {
                throw new ArgumentException("Must be a power of 2", "fileStructureBlockSize");
            }

            m_ioSize                 = ioSize;
            m_fileName               = fileName;
            m_isReadOnly             = isReadOnly;
            m_isSharingEnabled       = isSharingEnabled;
            m_fileStructureBlockSize = fileStructureBlockSize;
            m_bufferQueue            = ResourceList.GetResourceQueue(ioSize);
            m_syncRoot               = new object();
            m_stream                 = stream;
            m_length.Value           = m_stream.Length;
        }
Пример #4
0
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();
            int x = 0;
            ResourceQueue <string> queue = new ResourceQueue <string>(() => (x++).ToString(), 3, 4);

            x = 10;

            Assert.AreEqual(queue.Dequeue(), "0");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "10");
            Assert.AreEqual(queue.Dequeue(), "11");

            queue.Enqueue("0");
            queue.Enqueue("1");
            Assert.AreEqual(queue.Dequeue(), "0");
            queue.Enqueue("3");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "12");

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");
            queue.Enqueue("4");
            queue.Enqueue("5");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "4");
            Assert.AreEqual(queue.Dequeue(), "13");
            MemoryPoolTest.TestMemoryLeak();
        }
Пример #5
0
 public void DeQUEUE()
 {
     _ = ResourceQueue.Instance().PushItem(new DefaultResourceItem());
     ResourceQueue.Instance().Fetch <DefaultResourceItem>(item =>
     {
         return(true);
     }).Wait();
 }
Пример #6
0
 public int Allocate(bool isSource, Uri url)
 {
     var key = Key(isSource, url);
     if (!url.IsFile) {
         Queue[key] = new ResourceQueue<FtpClient>();
         var n = Connections(url) ?? 10;
         var i = n;
         while (i-- > 0) Queue[key].Enqueue(null);
         return n;
     }
     return 1;
 }
Пример #7
0
 public void MutipleMessage_100_000()
 {
     for (int i = 0; i < 100_000; i++)
     {
         _ = ResourceQueue.Instance().PushItem(new DefaultResourceItem());
     }
     for (int i = 0; i < 100_000; i++)
     {
         ResourceQueue.Instance().Fetch <DefaultResourceItem>(item =>
         {
             return(true);
         }).Wait();
     }
 }
Пример #8
0
    static GWorld()
    {
        world    = new WorldStates();
        patients = new ResourceQueue("", "", world);
        resources.Add("patients", patients);
        cubicles = new ResourceQueue("Cubicle", "FreeCubicle", world);
        resources.Add("cubicles", cubicles);
        offices = new ResourceQueue("Office", "FreeOffice", world);
        resources.Add("offices", offices);
        toilets = new ResourceQueue("Toilet", "FreeToilet", world);
        resources.Add("toilets", toilets);
        puddles = new ResourceQueue("Puddle", "FreePuddle", world);
        resources.Add("puddles", puddles);

        Time.timeScale = 5;
    }
Пример #9
0
    static GWorld()
    {
        // Create our world
        world = new WorldStates();

        //New Resources
        // Create Cover array
        covers = new ResourceQueue("Cover", "FreeCover", world);
        // Add to the resources Dictionary
        resources.Add("covers", covers);

        weapons = new ResourceQueue("Weapon", "FreeWeapon", world);
        // Add to the resources Dictionary
        resources.Add("weapons", weapons);
        Ammo = new ResourceQueue("Ammo", "FreeAmmo", world);
        // Add to the resources Dictionary
        resources.Add("Ammo", Ammo);
    }
    static GWorld()
    {
        // Create our world
        world = new WorldStates();

        patients = new ResourceQueue(ResourceTypes.Patient, ResourceStates.nullState, world);
        _resources.Add(ResourceQueueEnum.Patients.ToString(), patients);
        cubicles = new ResourceQueue(ResourceTypes.Cubicle, ResourceStates.freeCubicle, world);
        _resources.Add(ResourceQueueEnum.Cubicles.ToString(), cubicles);
        _offices = new ResourceQueue(ResourceTypes.Office, ResourceStates.freeOffice, world);
        _resources.Add(ResourceQueueEnum.Offices.ToString(), _offices);
        _toilets = new ResourceQueue(ResourceTypes.Toilet, ResourceStates.freeToilet, world);
        _resources.Add(ResourceQueueEnum.Toilets.ToString(), _toilets);
        _puddles = new ResourceQueue(ResourceTypes.Puddle, ResourceStates.puddles, world);
        _resources.Add(ResourceQueueEnum.Puddles.ToString(), _puddles);
        // Set the time scale in Unity
        Time.timeScale = 5.0f;
    }
Пример #11
0
    static GWorld()
    {
        world    = new WorldStates();
        patients = new ResourceQueue("", "", world);
        resources.Add(ResourceType.Patients, patients);

        cubicles = new ResourceQueue(ObjectTag.Cubicle, WorldStateName.FreeCubicle, world);
        resources.Add(ResourceType.Cubicles, cubicles);

        offices = new ResourceQueue(ObjectTag.Office, WorldStateName.FreeOffice, world);
        resources.Add(ResourceType.Offices, offices);

        toilets = new ResourceQueue(ObjectTag.Toilet, WorldStateName.FreeToilet, world);
        resources.Add(ResourceType.Toilets, toilets);

        puddles = new ResourceQueue(ObjectTag.Puddle, WorldStateName.FreePuddle, world);
        resources.Add(ResourceType.Puddles, puddles);

        Time.timeScale = 5;
    }
Пример #12
0
    static GWorld()
    {
        // Create our world
        world = new WorldStates();
        // Create custoemrs array
        customers = new ResourceQueue("", "", world);
        // Add to the resources Dictionary
        resources.Add("customers", customers);
        // Create customers array
        requirements = new ResourceQueue("", "", world);
        // Add to the resources Dictionary
        resources.Add("requirements", requirements);
        // Create tasks array
        tasks = new ResourceQueue("", "", world);
        // Add to the resources Dictionary
        resources.Add("tasks", tasks);
        // Create deliverables array
        deliverables = new ResourceQueue("", "", world);
        // Add to the deliverables Dictionary
        resources.Add("deliverables", deliverables);

        // Set the time scale in Unity
        Time.timeScale = 5.0f;
    }
        /// <summary>
        /// Creates a new CustomFileStream
        /// </summary>
        /// <param name="stream">The filestream to use as the base stream</param>
        /// <param name="ioSize">The size of a buffer pool entry</param>
        /// <param name="fileStructureBlockSize">The size of an individual block</param>
        /// <param name="fileName">The filename</param>
        /// <param name="isReadOnly">If the file is read only</param>
        /// <param name="isSharingEnabled">if the file is exclusively opened</param>
        private CustomFileStream(FileStream stream, int ioSize, int fileStructureBlockSize, string fileName, bool isReadOnly, bool isSharingEnabled)
        {
            if (ioSize < 4096)
                throw new ArgumentOutOfRangeException("ioSize", "Cannot be less than 4096");
            if (fileStructureBlockSize > ioSize)
                throw new ArgumentOutOfRangeException("fileStructureBlockSize", "Must not be greater than BufferPoolSize");
            if (!BitMath.IsPowerOfTwo(ioSize))
                throw new ArgumentException("Must be a power of 2", "ioSize");
            if (!BitMath.IsPowerOfTwo(fileStructureBlockSize))
                throw new ArgumentException("Must be a power of 2", "fileStructureBlockSize");

            m_ioSize = ioSize;
            m_fileName = fileName;
            m_isReadOnly = isReadOnly;
            m_isSharingEnabled = isSharingEnabled;
            m_fileStructureBlockSize = fileStructureBlockSize;
            m_bufferQueue = ResourceList.GetResourceQueue(ioSize);
            m_syncRoot = new object();
            m_stream = stream;
            m_length.Value = m_stream.Length;
        }
Пример #14
0
 public void PushItem()
 {
     _ = ResourceQueue.Instance().PushItem(new DefaultResourceItem());
 }