Exemple #1
0
        private void SaveAlphaBinAs_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the bin
            SaveFileDialog saveBin = new SaveFileDialog();

            saveBin.Filter = "BT Alpha Bin File|*.bin|BK Alpha Bin File|*.bin";
            saveBin.Title  = "Save a new bin file.";
            saveBin.ShowDialog();
            if (saveBin.FileName != "") // If the file name is not an empty string open it for saving.
            {
                switch (saveBin.FilterIndex)
                {
                case 1:
                    BinManager.ConvertBKtoBT(BinManager.AlphaBin);
                    File.WriteAllBytes(saveBin.FileName, BinManager.AlphaBin.getCurrentBin());
                    ReloadMainBin();    //BK was converted to BT, must convert back or renderer can't read it!
                    if (BinManager.AlphaBin != null)
                    {
                        ReloadAlphaBin();
                    }
                    break;

                case 2:
                    BinManager.ConvertBTtoBK(BinManager.AlphaBin);
                    File.WriteAllBytes(saveBin.FileName, BinManager.AlphaBin.getCurrentBin());
                    break;
                }
            }
        }
Exemple #2
0
        private void ValidateBalanced(BinManager manager, List <MachineId> locations)
        {
            var expectedLocationsPerBin = locations.Count > manager.LocationsPerBin
                ? manager.LocationsPerBin
                : locations.Count;

            var expectedBinsPerLocation = locations.Count >= manager.LocationsPerBin
                ? BinManager.NumberOfBins / locations.Count * manager.LocationsPerBin
                : BinManager.NumberOfBins;

            var binMappings = manager.GetBins();
            var counts      = new Dictionary <int, int>();

            foreach (var location in locations)
            {
                counts[location.Index] = 0;
            }

            foreach (var bin in binMappings)
            {
                bin.Length.Should().Be(expectedLocationsPerBin);

                foreach (var mapping in bin)
                {
                    counts[mapping.Index]++;
                }
            }

            foreach (var count in counts.Values)
            {
                count.Should().BeInRange((int)(expectedBinsPerLocation * .9), (int)(expectedBinsPerLocation * 1.1));
            }
        }
Exemple #3
0
        private void OpenAlphaBin(object sender, EventArgs e)//LoadAlphaBin
        {
            OpenFileDialog OpenAlphaBIN = OFD();

            OpenAlphaBIN.Filter = "BIN Files|*.bin";
            OpenAlphaBIN.Title  = "Select an Alpha BIN File";
            if (OpenAlphaBIN.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bool isAlphaBinFile = false;
                using (FileStream fs = new FileStream(OpenAlphaBIN.FileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] Header = new byte[4]; fs.Read(Header, 0, 4); //Load header into bytearray
                    if (Header[3] == 0x0B && Header[0] == 0x00)
                    {
                        isAlphaBinFile = true;
                    }                                                                      //Check if header is correct
                    fs.Close();
                }
                if (isAlphaBinFile)
                {
                    BinManager.LoadAlphaBIN(OpenAlphaBIN.FileName);
                    Renderer.Render(ClientRectangle, Width, Height, RenderPanel);
                    SaveAlphaBinAs.Enabled = true;
                    currentAlphaBinPath    = OpenAlphaBIN.FileName;
                    UpdateStatusText();
                }
                else
                {
                    MessageBox.Show("Alpha File is not a BK Model Bin! Please try again.", "Invalid File!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #4
0
        private void RemoveLocationsAndValidate(BinManager manager, List <MachineId> locations, int locationsToRemove)
        {
            for (var i = 0; i < locationsToRemove; i++)
            {
                var locationToRemove = locations[0];

                var binsWithMachineAssigned = manager.GetBins(force: true)
                                              .Select((machines, bin) => (machines, bin))
                                              .Where(t => t.machines.Contains(locationToRemove))
                                              .Select(t => (uint)t.bin)
                                              .ToHashSet();

                var chain = manager.EnumeratePreviousBins(0).Take(30).Select(b => (b, binsWithMachineAssigned.Contains(b))).ToList();

                locations.Remove(locationToRemove);
                manager.RemoveLocation(locationToRemove);

                ValidateBalanced(manager, locations);

                foreach (var binWithMachineAssigned in binsWithMachineAssigned)
                {
                    var assignedMachines            = manager.GetDesignatedLocations(binWithMachineAssigned, includeExpired: false);
                    var assignedMachinesWithExpired = manager.GetDesignatedLocations(binWithMachineAssigned, includeExpired: true);

                    assignedMachines.Should().NotContain(locationToRemove);
                    assignedMachinesWithExpired.Should().Contain(locationToRemove);
                }
            }
        }
Exemple #5
0
        private void VerifyMappingsAreEqual(BinManager x, BinManager y)
        {
            var xBins = x.GetBins();
            var yBins = y.GetBins();

            var xExpired = x.GetExpiredAssignments();
            var yExpired = y.GetExpiredAssignments();

            xBins.Length.Should().Be(yBins.Length);
            for (var bin = 0; bin < xBins.Length; bin++)
            {
                xBins[bin].Length.Should().Be(yBins[bin].Length);
                for (var mapping = 0; mapping < xBins[bin].Length; mapping++)
                {
                    xBins[bin][mapping].Index.Should().Be(yBins[bin][mapping].Index);
                }
            }

            xExpired.Count.Should().Be(yExpired.Count);
            foreach (var bin in xExpired.Keys)
            {
                var xBinExpired = xExpired[bin];
                var yBinExpired = yExpired[bin];
                xBinExpired.Count.Should().Be(yBinExpired.Count);

                foreach (var machine in xBinExpired.Keys)
                {
                    xBinExpired[machine].Should().Be(yBinExpired[machine]);
                }
            }
        }
Exemple #6
0
 // Use this for initialization
 void Start()
 {
     // Initiate a BIN manger
     binManager = new BinManager();
     // Initiate a map manger
     mapManager = new MapManager();
 }
Exemple #7
0
        private void BaseCoatButton_Click(object sender, EventArgs e)
        {
            for (uint j = 29; j >= 1 && j <= 29; j--) //Shift all mem back one
            {
                Vertex.OriginalVertexMem[j] = Vertex.OriginalVertexMem[j - 1];
            }
            Vertex.OriginalVertexMem[0] = new UInt32[Vertex.CurrentVertexList.Length][]; //Set up new undo level with all combos
            for (uint i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                Vertex.OriginalVertexMem[0][i] = new UInt32[2];
                uint currentVTX = Vertex.CurrentVertexList[i];
                Vertex.OriginalVertexMem[0][i][0] = currentVTX + 12;
                var BinAndAddr = BinManager.AttainCorrectBin(currentVTX);
                Vertex.OriginalVertexMem[0][i][1] = BinAndAddr.Item1.ReadFourBytes(BinAndAddr.Item2 + 12); //Initial RGBA
            }
            byte   R      = (byte)Math.Round(RedNum.Value * ((decimal)Brightness.Value / 100));
            byte   G      = (byte)Math.Round(GreenNum.Value * ((decimal)Brightness.Value / 100));
            byte   B      = (byte)Math.Round(BlueNum.Value * ((decimal)Brightness.Value / 100));
            byte   A      = (byte)AlphaNum.Value;
            UInt32 colour = (uint)((R << 24) | (G << 16) | (B << 8) | A);

            for (int i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                var BinAndAddr = BinManager.AttainCorrectBin(Vertex.CurrentVertexList[i]);
                BinManager.SetVertRGBA(BinAndAddr.Item1, BinAndAddr.Item2, colour, AlphaOnlyCheckbox.Checked);
            }
        }
Exemple #8
0
        [InlineData(3, 0, 3)]    // We have 0 locations
        public void BinManagerFromOther(int prevLocationsPerBin, int amountOfLocations, int currLocationsPerBin)
        {
            var(manager, locations) = CreateAndValidate(prevLocationsPerBin, amountOfLocations);
            var bytes = manager.Serialize();
            var deserializedManager = BinManager.CreateFromSerialized(bytes, currLocationsPerBin, _clock, TimeSpan.FromHours(1));

            ValidateBalanced(deserializedManager, locations);
        }
Exemple #9
0
        private (BinManager manager, List <MachineId> locations) CreateAndValidate(int locationsPerBin, int amountOfLocations)
        {
            var locations = Enumerable.Range(0, amountOfLocations).Select(num => new MachineId(num)).ToList();
            var manager   = new BinManager(locationsPerBin, startLocations: locations, _clock, TimeSpan.FromHours(1));

            ValidateBalanced(manager, locations);

            return(manager, locations);
        }
Exemple #10
0
        [InlineData(3, 1000, 10)] // Start with large amount of machines
        public void BinManagerSerializeDeserialize(int locationsPerBin, int initialAmountOfLocations, int locationsToAdd)
        {
            var(manager, locations) = CreateAndValidate(locationsPerBin, initialAmountOfLocations);
            AddLocationsAndValidate(manager, locations, locationsToAdd);

            var bytes = manager.Serialize();
            var deserializedManager = BinManager.CreateFromSerialized(bytes, locationsPerBin, _clock, TimeSpan.FromHours(1));

            VerifyMappingsAreEqual(manager, deserializedManager);
        }
Exemple #11
0
 /// <summary>
 /// Constructor por defecto
 /// </summary>
 public FrmVacunatorio()
 {
     InitializeComponent();
     bin       = new BinManager <CentroDeVacunacion>();
     xml       = new XmlManager <CentroDeVacunacion>();
     txt       = new TxTManager();
     dao       = new DAO();
     pacientes = new List <Paciente>();
     salita    = new CentroDeVacunacion();
 }
Exemple #12
0
        public void UpdateAllShouldNotBreakWithCollectionWasModified()
        {
            var startLocations = Enumerable.Range(1, 10).Select(i => new MachineId(i)).ToArray();
            var manager        = new BinManager(locationsPerBin: 3, startLocations, _clock, expiryTime: TimeSpan.FromSeconds(1));

            var activeMachines   = new MachineId[] { new MachineId(3), new MachineId(12), };
            var inactiveMachines = new MachineId[] { new MachineId(1), new MachineId(11), };

            // The original implementation was causing a runtime failure.
            manager.UpdateAll(activeMachines, inactiveMachines).ThrowIfFailure();
        }
Exemple #13
0
        public void BinManagerGetNextBinReturnsAllValues()
        {
            HashSet <uint> results = new HashSet <uint>();

            for (uint i = 0; i < BinManager.NumberOfBins; i++)
            {
                var  nextBin = BinManager.GetNextBin(i);
                bool added   = results.Add(nextBin);
                added.Should().BeTrue();
            }
        }
Exemple #14
0
    void SetNewMeshMaterial(BinManager mainBox)
    {
        var walls = mainBox.BinWalls;

        Material material = new Material(walls[0].material);
        Color    color    = material.color;

        for (int i = 0; i < walls.Count; i++)
        {
            // mainBox.BinWalls[i].material.color = material.color+ new Color(1,1,1,0)  * (  Mathf.Pow(2.0f,(currentBox+1f)/maxBox));
        }
    }
Exemple #15
0
        private void AddLocationsAndValidate(BinManager manager, List <MachineId> locations, int locationsToAdd)
        {
            var newLocations = Enumerable.Range(locations.Count, locationsToAdd).Select(num => new MachineId(num));

            foreach (var location in newLocations)
            {
                locations.Add(location);
                manager.AddLocation(location);

                ValidateBalanced(manager, locations);
            }
        }
Exemple #16
0
        public async Task StressTestForSerializationAsync()
        {
            var startLocations    = Enumerable.Range(1, 10).Select(i => new MachineId(i)).ToArray();
            var locationsToRemove = Enumerable.Range(1, 5).Select(i => new MachineId(i)).ToArray();

            for (var repetition = 0; repetition < 10; repetition++)
            {
                var manager = new BinManager(locationsPerBin: 3, startLocations, _clock, expiryTime: TimeSpan.FromSeconds(1));

                var tasks      = locationsToRemove.Select(i => Task.Run(() => manager.RemoveLocation(i))).ToArray();
                var serialized = manager.Serialize();
                BinManager.CreateFromSerialized(serialized, locationsPerBin: 3, _clock, TimeSpan.FromSeconds(1)); // We want to make sure that deserialization does not fail.
                await Task.WhenAll(tasks);
            }
        }
Exemple #17
0
        private void OpenMainBin(object sender, EventArgs e)//LoadMainBin
        {
            // Displays an OpenFileDialog so the user can select a Cursor.
            OpenFileDialog OpenBIN = OFD();

            OpenBIN.Filter = "BIN Files|*.bin";
            OpenBIN.Title  = "Select a BIN File";
            if (OpenBIN.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bool isBinFile = false;
                using (FileStream fs = new FileStream(OpenBIN.FileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] Header = new byte[16]; fs.Read(Header, 0, 16); //Load header into bytearray
                    if (Header[3] == 0x0B && Header[0] == 0x00)
                    {
                        isBinFile = true;
                    }                                                                 //Check if header is correct
                    if (Header[9] == 0x50)
                    {
                        isBTBin = true;
                    }
                    else
                    {
                        isBTBin = false;
                    }
                    fs.Close();
                }
                if (isBinFile)
                {
                    if (isBTBin)
                    {
                        DisplayBTBinMessage(); return;
                    }                                               //BT Not supported YET
                    BinManager.LoadBIN(OpenBIN.FileName);
                    SaveBinMenu.Enabled    = true; SaveBinAs.Enabled = true;
                    LoadBKAlphaBin.Enabled = true;
                    Renderer.Render(ClientRectangle, Width, Height, RenderPanel);
                    currentMainBinPath = OpenBIN.FileName;
                    UpdateStatusText();
                    ControlPanel.Visible          = true;
                    viewToolStripMenuItem.Visible = true;
                }
                else
                {
                    MessageBox.Show("File is not a BK Model Bin! Please try again.", "Invalid File!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #18
0
    public static void EditVertex(Rectangle ClientRectangle, int Width, int Height, GLControl RenderPanel, Point pt, byte R, byte G, byte B, byte A, bool AlphaOnly)
    {
        byte[] color = new byte[4];
        Renderer.RenderColourBuffer(ClientRectangle, Width, Height, RenderPanel);
        GL.ReadPixels(pt.X, RenderPanel.Height - pt.Y - 1, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, color);
        UInt32 Addr = (UInt32)((color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3]);

        if (Addr != 0)
        {
            for (uint i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                bool alphabin = false;
                if (Addr > 0x80000000)
                {
                    alphabin = true;                    //remove the alpha addr flag
                }
                uint[]    list    = Vertex.CurrentVertexList;
                uint      rawAddr = Addr & 0x7FFFFFFF;
                BTBinFile currentbin;
                if (!alphabin)
                {
                    currentbin = BinManager.MainBin;
                }
                else
                {
                    currentbin = BinManager.AlphaBin;
                }
                if (Addr == Vertex.CurrentVertexList[i])
                {
                    UInt32 colour = (uint)((R << 24) | (G << 16) | (B << 8) | A);
                    if (colour == currentbin.ReadFourBytes(rawAddr + 12))
                    {
                        return;                               //If it's the same, don't do anything
                    }
                    for (uint j = 29; j >= 1 && j <= 29; j--) //Shift all mem back one
                    {
                        Vertex.OriginalVertexMem[j] = Vertex.OriginalVertexMem[j - 1];
                    }
                    Vertex.OriginalVertexMem[0]       = new UInt32[1][]; //Set up new undo level with one combo
                    Vertex.OriginalVertexMem[0][0]    = new UInt32[2];
                    Vertex.OriginalVertexMem[0][0][0] = Addr + 12;
                    Vertex.OriginalVertexMem[0][0][1] = currentbin.ReadFourBytes(rawAddr + 12); //Initial RGBA
                    BinManager.SetVertRGBA(currentbin, rawAddr, colour, AlphaOnly);
                    break;
                }
            }
        }
    }
Exemple #19
0
    IEnumerator BombSpawner()
    {
        while (_levelInProgress)
        {
            if (_objectState != State.PAUSED)
            {
                if (_freeBins.Count > 0)
                {
                    int        randomBinIndex   = UnityEngine.Random.Range(0, _freeBins.Count);
                    GameObject randomBinObject  = (GameObject)_freeBins[randomBinIndex];
                    BinManager randomBinManager = randomBinObject.GetComponent <BinManager>();
                    randomBinManager.CreateBomb();
                }
            }

            yield return(new WaitForSeconds(_BombSpawnTimer / BoardManager.DifficultyLevel));
        }
    }
Exemple #20
0
 void SetBinMembers(BinManager bin)
 {
     bin._ScoreManager = _ScoreManager;
     bin._LifeManager  = _LifeManager;
 }
 // Start is called before the first frame update
 void Start()
 {
     binManager   = FindObjectOfType <BinManager>();
     levelManager = FindObjectOfType <LevelManager>();
     levelManager.GameOverEvent += OnGameOver;
 }
Exemple #22
0
        void RenderPanel_KeyDown(object sender, KeyEventArgs e)
        {
            keystate = Keyboard.GetState();
            switch (e.KeyCode)
            {
            case Keys.Z:
                if (!keystate[Key.ControlLeft] || Vertex.OriginalVertexMem[0] == null)
                {
                    break;
                }
                for (int j = 29; j > 0; j--)
                {
                    Vertex.EditedVertexMem[j] = Vertex.EditedVertexMem[j - 1];
                }                                                                                               //shift all mem back one (make room for redo)
                Vertex.EditedVertexMem[0] = new UInt32[Vertex.OriginalVertexMem[0].Length][];
                for (int i = 0; i < Vertex.EditedVertexMem[0].Length; i++)
                {
                    Vertex.EditedVertexMem[0][i] = new UInt32[2];
                }                                                                                                               //set new space to this undo
                for (uint i = 0; i < Vertex.OriginalVertexMem[0].Length; i++)
                {
                    uint OriginalVTXValue = Vertex.OriginalVertexMem[0][i][0];
                    Vertex.EditedVertexMem[0][i][0] = OriginalVTXValue;
                    var BinAndAddr = BinManager.AttainCorrectBin(OriginalVTXValue);
                    Vertex.EditedVertexMem[0][i][1] = BinAndAddr.Item1.ReadFourBytes(BinAndAddr.Item2);     //Write @ addr this colour for all addr+rgba in collection
                }
                for (uint i = 0; i < Vertex.OriginalVertexMem[0].Length; i++)
                {
                    var BinAndAddr = BinManager.AttainCorrectBin(Vertex.OriginalVertexMem[0][i][0]);
                    BinAndAddr.Item1.WriteFourBytes(BinAndAddr.Item2, Vertex.OriginalVertexMem[0][i][1]);     //Write @ addr this colour for all addr+rgba in collection
                }
                for (uint i = 0; i < 29; i++)
                {
                    Vertex.OriginalVertexMem[i] = Vertex.OriginalVertexMem[i + 1];
                }                                                                                                    //Shift all mem forward one (forget the undo)
                break;

            case Keys.Y:
                if (!keystate[Key.ControlLeft] || Vertex.EditedVertexMem[0] == null)
                {
                    break;
                }
                for (int j = 29; j > 0; j--)
                {
                    Vertex.OriginalVertexMem[j] = Vertex.OriginalVertexMem[j - 1];
                }                                                                                                   //Shift all mem back one (make room for undo)
                Vertex.OriginalVertexMem[0] = new UInt32[Vertex.EditedVertexMem[0].Length][];
                for (int i = 0; i < Vertex.OriginalVertexMem[0].Length; i++)
                {
                    Vertex.OriginalVertexMem[0][i] = new UInt32[2];
                }                                                                                                                   //set new space to this undo
                for (uint i = 0; i < Vertex.EditedVertexMem[0].Length; i++)
                {
                    uint EditedVTXAddr = Vertex.EditedVertexMem[0][i][0];
                    Vertex.OriginalVertexMem[0][i][0] = EditedVTXAddr;
                    var BinAndAddr = BinManager.AttainCorrectBin(EditedVTXAddr);
                    Vertex.OriginalVertexMem[0][i][1] = BinAndAddr.Item1.ReadFourBytes(BinAndAddr.Item2);     //Write @ addr this colour for all addr+rgba in collection
                }
                for (uint i = 0; i < Vertex.EditedVertexMem[0].Length; i++)
                {
                    var BinAndAddr = BinManager.AttainCorrectBin(Vertex.EditedVertexMem[0][i][0]);
                    BinAndAddr.Item1.WriteFourBytes(BinAndAddr.Item2, Vertex.EditedVertexMem[0][i][1]);     //Write @ addr this colour for all addr+rgba in collection
                }
                for (uint i = 0; i < 29; i++)
                {
                    Vertex.EditedVertexMem[i] = Vertex.EditedVertexMem[i + 1];
                }                                                                                                //Shift all mem forward one (forget the redo)
                break;

            case Keys.S:
                if (!keystate[Key.ControlLeft] || BinNullCheck())
                {
                    break;
                }
                Cursor.Current = Cursors.WaitCursor;
                File.WriteAllBytes(currentMainBinPath, BinManager.MainBin.getCurrentBin());     //Ctrl+S to save
                if (!AlphaBinNullCheck())
                {
                    File.WriteAllBytes(currentMainBinPath, BinManager.MainBin.getCurrentBin());                         //Ctrl+S to save
                }
                StatusLabel.Text = "ROM Saved to " + currentMainBinPath;
                Cursor.Current   = Cursors.Default;
                break;

            case Keys.O:
                if (!keystate[Key.ControlLeft])
                {
                    break;
                }
                if (!keystate[Key.LShift])
                {
                    OpenMainBin(sender, e);                            //Ctrl+O to open
                }
                else if (!BinNullCheck())
                {
                    OpenAlphaBin(sender, e);                          //if ctrl shift is held, it will open alpha bin
                }
                break;

            case Keys.R:
                if (!keystate[Key.ControlLeft] || BinNullCheck())
                {
                    break;
                }
                ReloadMainBin();     //Ctrl+O to open
                if (!AlphaBinNullCheck())
                {
                    ReloadAlphaBin();
                }
                break;
            }
        }
Exemple #23
0
 void SetBinMembers(BinManager bin)
 {
     bin._ScoreManager = _ScoreManager;
     bin._LifeManager = _LifeManager;
 }
Exemple #24
0
 private void ReloadAlphaBin()
 {
     BinManager.LoadAlphaBIN(currentAlphaBinPath);
     Renderer.Render(ClientRectangle, Width, Height, RenderPanel);
     UpdateStatusText();
 }
Exemple #25
0
 // Start is called before the first frame update
 void Start()
 {
     Life       = GameObject.Find("Lives Manager");
     binManager = GameObject.Find("Recycling Bin Manager").GetComponent <BinManager>();
 }