public void WriteAndReadTest() { Span <byte> span = new byte[Constants.PAGE_SIZE]; span.Clear(); var pos = SlotEntry.GetEntryPosition(1); SlotEntry slotEntry = new SlotEntry(1, 324); slotEntry.ToBuffer(span, pos); var res = SlotEntry.FromBuffer(span, pos); res.DataLength.ShouldBe(slotEntry.DataLength); res.DataOffset.ShouldBe(slotEntry.DataOffset); pos = SlotEntry.GetEntryPosition(7); slotEntry = new SlotEntry(7, 324); slotEntry.ToBuffer(span, pos); res = SlotEntry.FromBuffer(span, pos); res.DataLength.ShouldBe(slotEntry.DataLength); res.DataOffset.ShouldBe(slotEntry.DataOffset); }
public override void Update() { for (int i = 0; i < slots.Length; i++) { SlotEntry slotEntry = slots[i]; AssignableSlotInstance slot = slotEntry.slot; if (slot.IsAssigned()) { bool flag = slot.assignable.GetNavigationCost(navigator) != -1; Operational component = slot.assignable.GetComponent <Operational>(); if ((Object)component != (Object)null) { flag = (flag && component.IsOperational); } if (flag != slotEntry.isReachable) { slotEntry.isReachable = flag; slots[i] = slotEntry; Trigger(334784980, slotEntry); } } else if (slotEntry.isReachable) { slotEntry.isReachable = false; slots[i] = slotEntry; Trigger(334784980, slotEntry); } } }
public void Assign(PowerEntry iPe) { Level = iPe.Level; NIDPowerset = iPe.NIDPowerset; IDXPower = iPe.IDXPower; NIDPower = iPe.NIDPower; Tag = iPe.Tag; StatInclude = iPe.StatInclude; VariableValue = iPe.VariableValue; if (iPe.Slots != null) { Slots = new SlotEntry[iPe.Slots.Length]; for (int index = 0; index <= Slots.Length - 1; ++index) { Slots[index].Assign(iPe.Slots[index]); } } else { Slots = new SlotEntry[0]; } if (iPe.SubPowers != null) { SubPowers = new PowerSubEntry[iPe.SubPowers.Length]; for (int index = 0; index <= SubPowers.Length - 1; ++index) { SubPowers[index].Assign(iPe.SubPowers[index]); } } else { SubPowers = new PowerSubEntry[0]; } }
public void EndPositionOfDataTest() { Span <byte> span = new byte[Constants.PAGE_SIZE]; span.Clear(); SlotEntry slotEntry = new SlotEntry(1, 324); slotEntry.EndPositionOfData().ShouldBe((ushort)(1 + 324)); }
public PowerEntry(int iLevel = -1, IPower power = null, bool chosen = false) { StatInclude = false; Level = iLevel; Chosen = chosen; if (power != null) { NIDPowerset = power.PowerSetID; IDXPower = power.PowerSetIndex; NIDPower = power.PowerIndex; if (power.NIDSubPower.Length > 0) { SubPowers = new PowerSubEntry[power.NIDSubPower.Length]; for (int index = 0; index <= SubPowers.Length - 1; ++index) { SubPowers[index] = new PowerSubEntry { nIDPower = power.NIDSubPower[index] }; SubPowers[index].Powerset = DatabaseAPI.Database.Power[SubPowers[index].nIDPower].PowerSetID; SubPowers[index].Power = DatabaseAPI.Database.Power[SubPowers[index].nIDPower].PowerSetIndex; } } else { SubPowers = new PowerSubEntry[0]; } if (power.Slottable & power.GetPowerSet().GroupName != "Incarnate") { Slots = new SlotEntry[1]; Slots[0].Enhancement = new I9Slot(); Slots[0].FlippedEnhancement = new I9Slot(); Slots[0].Level = iLevel; } else { Slots = new SlotEntry[0]; } if (power.AlwaysToggle | power.PowerType == Enums.ePowerType.Auto_) { StatInclude = true; } } else { IDXPower = -1; NIDPowerset = -1; NIDPower = -1; Slots = new SlotEntry[0]; SubPowers = new PowerSubEntry[0]; } Tag = false; VariableValue = 0; }
public int AddSlot(int iLevel) { int num1; if (Slots.Length > 5 | !DatabaseAPI.Database.Power[NIDPower].Slottable) { num1 = -1; } else { int index1; if (Slots.Length == 0) { Slots = new SlotEntry[1]; index1 = 0; } else { int num2 = 0; for (int index2 = 1; index2 < Slots.Length; ++index2) { if (Slots[index2].Level <= iLevel) { num2 = index2; } } index1 = num2 + 1; SlotEntry[] slotEntryArray = new SlotEntry[Slots.Length + 1]; int index3 = -1; for (int index2 = 0; index2 < slotEntryArray.Length; ++index2) { if (index2 == index1) { continue; } ++index3; slotEntryArray[index2].Assign(Slots[index3]); } Slots = new SlotEntry[slotEntryArray.Length]; for (int index2 = 0; index2 < Slots.Length; ++index2) { if (index2 != index1) { Slots[index2].Assign(slotEntryArray[index2]); } } } Slots[index1].Enhancement = new I9Slot(); Slots[index1].FlippedEnhancement = new I9Slot(); Slots[index1].Level = iLevel; num1 = index1; } return(num1); }
public int AddSlot(int iLevel) { int num; if (this.Slots.Length > 5 | !DatabaseAPI.Database.Power[this.NIDPower].Slottable) { num = -1; } else { int index; if (this.Slots.Length == 0) { this.Slots = new SlotEntry[1]; index = 0; } else { index = 0; for (int index2 = 1; index2 < this.Slots.Length; index2++) { if (this.Slots[index2].Level <= iLevel) { index = index2; } } index++; SlotEntry[] slotEntryArray = new SlotEntry[this.Slots.Length + 1]; int index3 = -1; for (int index4 = 0; index4 < slotEntryArray.Length; index4++) { if (index4 != index) { index3++; slotEntryArray[index4].Assign(this.Slots[index3]); } } this.Slots = new SlotEntry[slotEntryArray.Length]; for (int index5 = 0; index5 < this.Slots.Length; index5++) { if (index5 != index) { this.Slots[index5].Assign(slotEntryArray[index5]); } } } this.Slots[index].Enhancement = new I9Slot(); this.Slots[index].FlippedEnhancement = new I9Slot(); this.Slots[index].Level = iLevel; num = index; } return(num); }
public void Reset() { NIDPowerset = -1; IDXPower = -1; NIDPower = -1; Tag = false; StatInclude = false; SubPowers = new PowerSubEntry[0]; if (Slots.Length != 1 || Slots[0].Enhancement.Enh != -1) { return; } Slots = new SlotEntry[0]; }
public void IsEmptyTest() { Span <byte> span = new byte[Constants.PAGE_SIZE]; span.Clear(); var pos = SlotEntry.GetEntryPosition(1); SlotEntry.IsEmpty(span, pos).ShouldBeTrue(); SlotEntry slotEntry = new SlotEntry(1, 324); slotEntry.ToBuffer(span, pos); SlotEntry.IsEmpty(span, pos).ShouldBeFalse(); }
public void FindFreeSpaceBetweenTest_EmptySpaceOnStart() { using BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); bufferSegment.Span.Clear(); PageHeader header = new PageHeader(1, PageType.Data, 0, 0, 5000, 0, 7032, 2000, 2); SlotEntry directoryEntry = new SlotEntry(2032, 5000); directoryEntry.ToBuffer(bufferSegment.Span, SlotEntry.GetEntryPosition(2)); header.ToBuffer(bufferSegment.Span); DataPage dataPage = new DataPage(bufferSegment); // Empty space should be between header and 2 entry var res = dataPage.FindFreeSpaceBetween(1000); res.Index1.ShouldBe((byte)0); res.Index2.ShouldBe((byte)2); }
public PowerEntry(IPower power) { StatInclude = false; Level = -1; if (power == null) { IDXPower = -1; NIDPowerset = -1; NIDPower = -1; } else { IDXPower = power.PowerSetIndex; NIDPower = power.PowerIndex; NIDPowerset = power.PowerSetID; } Tag = false; Slots = new SlotEntry[0]; SubPowers = new PowerSubEntry[0]; VariableValue = 0; }
private List <SlotEntry> GetCurrentSlotEntries() { List <SlotEntry> slotEntries = new List <SlotEntry>(); int count = 1; foreach (RuneItem rune in RedListBox.Items) { SlotEntry slotEntry = new SlotEntry(); slotEntry.RuneId = ((runes)rune.Tag).id; slotEntry.RuneSlotId = count++; slotEntries.Add(slotEntry); } count = 10; foreach (RuneItem rune in YellowListBox.Items) { SlotEntry slotEntry = new SlotEntry(); slotEntry.RuneId = ((runes)rune.Tag).id; slotEntry.RuneSlotId = count++; slotEntries.Add(slotEntry); } count = 19; foreach (RuneItem rune in BlueListBox.Items) { SlotEntry slotEntry = new SlotEntry(); slotEntry.RuneId = ((runes)rune.Tag).id; slotEntry.RuneSlotId = count++; slotEntries.Add(slotEntry); } count = 28; foreach (RuneItem rune in BlackListBox.Items) { SlotEntry slotEntry = new SlotEntry(); slotEntry.RuneId = ((runes)rune.Tag).id; slotEntry.RuneSlotId = count++; slotEntries.Add(slotEntry); } return(slotEntries); }
public void DeleteTest() { var bogus = new Bogus.Randomizer(); const int insertLength = 20; using BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); PageHeader header = new PageHeader(1, PageType.Data); header.ToBuffer(bufferSegment.Span, 0); byte[] toInsert = TestHelper.GenerateByteArray(insertLength, 0xFF); DataPage dataPage = new DataPage(bufferSegment); dataPage.IsFull.ShouldBeFalse(); byte index = 0; for (int i = 0; i < 10; i++) { var ins = dataPage.Insert(insertLength, out index); ins.WriteBytes(0, toInsert); } // Highest index should be 10 index.ShouldBe((byte)10); dataPage.PageHeader.HighestSlotId.ShouldBe(index); var before = dataPage.PageHeader.UsedBytes; var unaligned = dataPage.PageHeader.UnalignedFreeBytes; unaligned.ShouldBe((ushort)0); // delete entry 3 var dirEntryPosition = SlotEntry.GetEntryPosition(3); var dirEntry = SlotEntry.FromBuffer(bufferSegment.Span, dirEntryPosition); dirEntry.DataLength.ShouldBe((ushort)insertLength); dataPage.Delete(3); // data should be gone var data = bufferSegment.Span.Slice(dirEntry.DataOffset, dirEntry.DataLength); data.ToArray().ShouldAllBe(b => b == 0x00); dataPage.PageHeader.UsedBytes.ShouldBe((ushort)(before - insertLength)); // delete entry 7 dirEntryPosition = SlotEntry.GetEntryPosition(7); dirEntry = SlotEntry.FromBuffer(bufferSegment.Span, dirEntryPosition); dirEntry.DataLength.ShouldBe((ushort)insertLength); dataPage.Delete(7); // data should be gone data = bufferSegment.Span.Slice(dirEntry.DataOffset, dirEntry.DataLength); data.ToArray().ShouldAllBe(b => b == 0x00); // delete entry 10 dirEntryPosition = SlotEntry.GetEntryPosition(10); dirEntry = SlotEntry.FromBuffer(bufferSegment.Span, dirEntryPosition); dirEntry.DataLength.ShouldBe((ushort)insertLength); dataPage.Delete(10); // data should be gone data = bufferSegment.Span.Slice(dirEntry.DataOffset, dirEntry.DataLength); data.ToArray().ShouldAllBe(b => b == 0x00); dataPage.PageHeader.HighestSlotId.ShouldBe((byte)9); dataPage.PageHeader.UnalignedFreeBytes.ShouldBe((ushort)40); var s = dataPage.ToString(); }
private static SpellBookPageDTO ToSpellBookPage(InventoryHelper.RuneSetup setup) { List<SlotEntry> slotEntries = new List<SlotEntry>(); IGrouping<RuneType, InventoryHelper.Rune>[] array = ( from x in (IEnumerable<InventoryHelper.Rune>)setup.Runes group x by InventoryHelper.GetRuneType(x.Id) into x orderby x.Key select x).ToArray<IGrouping<RuneType, InventoryHelper.Rune>>(); for (int i = 0; i < (int)array.Length; i++) { IGrouping<RuneType, InventoryHelper.Rune> runeTypes = array[i]; RuneType key = runeTypes.Key; InventoryHelper.Rune[] runeArray = runeTypes.ToArray<InventoryHelper.Rune>(); int num = (byte)key * 9 + (byte)RuneType.Yellow; for (int j = 0; j < (int)runeArray.Length; j++) { InventoryHelper.Rune rune = runeArray[j]; for (int k = 0; k < rune.Count; k++) { SlotEntry slotEntry = new SlotEntry() { RuneId = rune.Id, RuneSlotId = num }; slotEntries.Add(slotEntry); num++; } } } SpellBookPageDTO spellBookPageDTO = new SpellBookPageDTO() { PageId = setup.Id, Name = setup.Name, SlotEntries = slotEntries.ToList<SlotEntry>(), Current = true }; return spellBookPageDTO; }
public void GetEntryPositionTest() { SlotEntry.GetEntryPosition(1).ShouldBe((ushort)(Constants.PAGE_SIZE - Constants.PAGE_DIRECTORY_ENTRY_SIZE)); SlotEntry.GetEntryPosition(10).ShouldBe((ushort)(Constants.PAGE_SIZE - Constants.PAGE_DIRECTORY_ENTRY_SIZE * 10)); SlotEntry.GetEntryPosition(3).ShouldBe((ushort)(Constants.PAGE_SIZE - Constants.PAGE_DIRECTORY_ENTRY_SIZE * 3)); }
public void Assign(SlotEntry slotEntry) { this.Level = slotEntry.Level; this.Enhancement = (slotEntry.Enhancement.Clone() as I9Slot); this.FlippedEnhancement = (slotEntry.FlippedEnhancement.Clone() as I9Slot); }
private void ComputeSpilling() { // Just a stupid greedy algorithm... int scount = _tempRegs.Length; _regIndices = new int[scount]; var lifeList = new SortedSet <SlotEntry>(new SlotComparer()); for (int i = 0; i < scount; i++) { _regIndices[i] = int.MinValue; lifeList.Add(new SlotEntry(i, _lifeStart[i])); } SlotEntry inf = new SlotEntry(-1, int.MaxValue); int nextReg = 0; while (lifeList.Any()) { var node = lifeList.First(); int cur = node.Slot; int slotIndex; if (IsUnused(cur)) { _regIndices[cur] = -1; lifeList.Remove(node); continue; } else { slotIndex = nextReg++; _regIndices[cur] = slotIndex; lifeList.Remove(node); } var type = _tempRegTypes[cur]; long end = _lifeEnd[cur]; var nextView = lifeList.GetViewBetween(new SlotEntry(-1, end), inf); bool found; do { found = false; foreach (var nextSlot in nextView) { int next = nextSlot.Slot; var nextType = _tempRegTypes[next]; if (IsUnused(next) || type.Equals(nextType)) { if (IsUnused(next)) { _regIndices[next] = -1; lifeList.Remove(nextSlot); } else if (type.Equals(nextType)) { _regIndices[next] = slotIndex; lifeList.Remove(nextSlot); end = _lifeEnd[next]; } nextView = lifeList.GetViewBetween(new SlotEntry(-1, end), inf); found = true; break; } } } while (found); } _regsCur = new SignalBase[nextReg]; _regsNext = new SignalBase[nextReg]; }
public void Assign(SlotEntry slotEntry) { Level = slotEntry.Level; Enhancement = slotEntry.Enhancement.Clone() as I9Slot; FlippedEnhancement = slotEntry.FlippedEnhancement.Clone() as I9Slot; }