Here are the examples of the csharp api System.Collections.Generic.HashSet.Contains(short) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
19
Source : Optimizer.RegisterCleanup.cs
with MIT License
from JasonXuDeveloper
with MIT License
from JasonXuDeveloper
public static int CleanupRegister(List<OpCodeR> ins, int locRegStart, bool hasReturn)
{
short maxRegNum = (short)locRegStart;
HashSet<short> usedRegisters = new HashSet<short>();
//arguments can not be cleaned
for (short i = 0; i < locRegStart; i++)
usedRegisters.Add(i);
for (int i = 0; i < ins.Count; i++)
{
var X = ins[i];
short xSrc, xSrc2, xSrc3, xDst;
if(GetOpcodeSourceRegister(ref X, hasReturn, out xSrc, out xSrc2, out xSrc3))
{
if (xSrc >= 0)
{
if (xSrc > maxRegNum)
maxRegNum = xSrc;
usedRegisters.Add(xSrc);
}
if (xSrc2 >= 0)
{
if (xSrc2 > maxRegNum)
maxRegNum = xSrc2;
usedRegisters.Add(xSrc2);
}
if (xSrc3 >= 0)
{
if (xSrc3 > maxRegNum)
maxRegNum = xSrc3;
usedRegisters.Add(xSrc3);
}
}
if(GetOpcodeDestRegister(ref X, out xDst))
{
if (xDst >= 0)
{
if (xDst > maxRegNum)
maxRegNum = xDst;
usedRegisters.Add(xDst);
}
}
}
List<short> unusedRegisters = new List<short>();
for(short i = 0; i <= maxRegNum; i++)
{
if (!usedRegisters.Contains(i))
unusedRegisters.Add(i);
}
for(short i = 0; i < unusedRegisters.Count; i++)
{
short r = (short)(unusedRegisters[i] - i);
for (int j = 0; j < ins.Count; j++)
{
var X = ins[j];
short xSrc, xSrc2, xSrc3, xDst;
bool replaced = false;
if (GetOpcodeSourceRegister(ref X, hasReturn, out xSrc, out xSrc2, out xSrc3))
{
if (xSrc > r)
{
ReplaceOpcodeSource(ref X, 0, (short)(xSrc - 1));
replaced = true;
}
if (xSrc2 > r)
{
ReplaceOpcodeSource(ref X, 1, (short)(xSrc2 - 1));
replaced = true;
}
if (xSrc3 > r)
{
ReplaceOpcodeSource(ref X, 2, (short)(xSrc3 - 1));
replaced = true;
}
}
if (GetOpcodeDestRegister(ref X, out xDst))
{
if (xDst > r)
{
ReplaceOpcodeDest(ref X, (short)(xDst - 1));
replaced = true;
}
}
if (replaced)
ins[j] = X;
}
}
return maxRegNum - unusedRegisters.Count + 1;
}
19
Source : MiniILParser.cs
with GNU Lesser General Public License v3.0
from kagurazakasanae
with GNU Lesser General Public License v3.0
from kagurazakasanae
public static IEnumerable<(OpCode, long)> Decode(byte[] ilBytes)
{
int index = 0;
while (index < ilBytes.Length)
{
short currentOp = ilBytes[index++];
if (PrefixCodes.Contains(currentOp))
currentOp |= (short) (ilBytes[index++] << 8);
if (!OpCodesMap.TryGetValue(currentOp, out var opCode))
throw new NotSupportedException($"Unknown opcode {currentOp} encountered");
var argLength = GetOperandSize(opCode);
switch (argLength)
{
case 0:
yield return (opCode, 0);
break;
case 1:
yield return (opCode, ilBytes[index]);
break;
case 2:
yield return (opCode, BitConverter.ToInt16(ilBytes, index));
break;
case 4:
yield return (opCode, BitConverter.ToInt32(ilBytes, index));
break;
case 8:
yield return (opCode, BitConverter.ToInt64(ilBytes, index));
break;
default:
throw new NotSupportedException($"Unsupported opcode argument length {argLength}");
}
index += argLength;
}
}
19
Source : MiniILParser.cs
with GNU Lesser General Public License v3.0
from knah
with GNU Lesser General Public License v3.0
from knah
public static IEnumerable<(OpCode, long)> Decode(byte[] ilBytes)
{
int index = 0;
while (index < ilBytes.Length)
{
short currentOp = ilBytes[index++];
if (PrefixCodes.Contains(currentOp))
currentOp = (short) ((ushort) (currentOp << 8) | ilBytes[index++]);
if (!OpCodesMap.TryGetValue(currentOp, out var opCode))
throw new NotSupportedException($"Unknown opcode {currentOp} encountered");
var argLength = GetOperandSize(opCode);
switch (argLength)
{
case 0:
yield return (opCode, 0);
break;
case 1:
yield return (opCode, ilBytes[index]);
break;
case 2:
yield return (opCode, BitConverter.ToInt16(ilBytes, index));
break;
case 4:
yield return (opCode, BitConverter.ToInt32(ilBytes, index));
break;
case 8:
yield return (opCode, BitConverter.ToInt64(ilBytes, index));
break;
default:
throw new NotSupportedException($"Unsupported opcode argument length {argLength}");
}
index += argLength;
}
}
19
Source : JCS_PacketLostPreventer.cs
with BSD 3-Clause "New" or "Revised" License
from MapleStoryUnity
with BSD 3-Clause "New" or "Revised" License
from MapleStoryUnity
private void TrackPacket()
{
if (JCS_NetworkSettings.GetGameSocket() != null &&
!JCS_NetworkSettings.GetGameSocket().IsConnected())
return;
mResendTimer += Time.deltaTime;
if (mResendTimer < mResendTime)
return;
// reset timer.
mResendTimer = 0;
/* First check if the packet responded? Remove it if
already responded. */
{
for (int index = 0; index < mWaitingPacketIds.Count; ++index)
{
JCS_Packet packet = mWaitingPackets[index];
short packetId = mWaitingPacketIds[index];
if (mRespondPacketIds.Contains(packetId))
{
// responded, so remove it.
mWaitingPacketIds.Remove(packetId);
mWaitingPackets.Remove(packet);
}
}
}
// cleanup the respond packet id.
mRespondPacketIds.Clear();
/* Resend the packet if necessary. */
for (int index = 0; index < mWaitingPackets.Count; ++index)
{
JCS_Packet packet = mWaitingPackets[index];
// re-send the packet
JCS_NetworkSettings.GetGameSocket().SendPacket(packet.GetBytes());
}
}
19
Source : BHAVContainer.cs
with Mozilla Public License 2.0
from RHY3756547
with Mozilla Public License 2.0
from RHY3756547
public void UpdateLabelPointers(short index, HashSet<short> traversed)
{
//if we've already traversed this label, we're in a loop and don't need to update our pointers
//should probably show a warning telling the user not to do this
if (traversed.Contains(index)) return;
traversed.Add(index);
foreach (var prim in Primitives)
{
if (prim.Type == TREEBoxType.Goto && prim.TreeBox.TruePointer == index)
{
//update bhav instructions of all primitives pointing to this goto
foreach (var prim2 in Primitives)
{
if (prim2.TrueUI == prim)
{
if (prim2.Type == TREEBoxType.Label)
{
//we need to update this label too
UpdateLabelPointers(prim2.TreeBox.InternalID, traversed);
}
else if (prim2.Type == TREEBoxType.Primitive)
{
prim2.Instruction.TruePointer = prim.InstPtr;
}
}
if (prim2.FalseUI == prim)
{
if (prim2.Type == TREEBoxType.Primitive)
{
prim2.Instruction.FalsePointer = prim.InstPtr;
}
}
}
}
}
}
19
Source : TREE.cs
with Mozilla Public License 2.0
from RHY3756547
with Mozilla Public License 2.0
from RHY3756547
public byte LabelTrueID(HashSet<short> visited)
{
if (Type != TREEBoxType.Goto) return TrueID;
if (visited.Contains(InternalID)) return 253; //error
visited.Add(InternalID);
return Parent?.GetBox(Parent.GetBox(TruePointer)?.TruePointer ?? -1)?.LabelTrueID(visited) ?? 253;
}
19
Source : VMFindBestAction.cs
with Mozilla Public License 2.0
from RHY3756547
with Mozilla Public License 2.0
from RHY3756547
public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
{
//if we already have some action, do nothing
var better = context.Caller.Thread.Queue.FirstOrDefault(x => x.Priority > (context.Caller as VMAvatar).GetPersonData(VMPersonDataVariable.Priority));
if (better != null) {
context.StackObject = better.Callee;
return VMPrimitiveExitCode.GOTO_TRUE;
}
var ents = new List<VMEnreplacedy>(context.VM.Context.ObjectQueries.WithAutonomy);
var processed = new HashSet<short>();
var caller = (VMAvatar)context.Caller;
var pos1 = caller.Position;
var visitor = (caller.GetPersonData(VMPersonDataVariable.PersonType) == 1);
var child = (caller.IsChild && context.VM.TS1);
var attenTable = visitor ? TTAB.VisitorAttenuationValues : TTAB.AttenuationValues;
var global = Content.Content.Get().WorldObjectGlobals;
var interactionCurve = child ? global.InteractionScoreChild : global.InteractionScore;
var happyCurve = child ? global.HappyWeightChild : global.HappyWeight;
var isStray = caller.IsPet && context.VM.TS1 && caller.GetPersonData(VMPersonDataVariable.GreetStatus) == 0 && caller.GetPersonData(VMPersonDataVariable.PersonType) == 1;
// === HAPPY CALCULATION ===
var newStyle = false;
// TODO: new style
var weights = newStyle ? new float[9] : new float[9] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //TODO: weights from curves for new
var totalWeight = weights.Sum();
for (int i = 0; i < 9; i++) weights[i] /= totalWeight;
var minScore = (caller.GetPersonData(VMPersonDataVariable.Posture) > 0) ? 1e-6 : 1e-7;
var motives = WeightMotives.Select(x => caller.GetMotiveData(x));
var happyParts = motives
.Zip(interactionCurve, (motive, curve) => curve.GetPoint(motive))
.Zip(weights, (motive, weight) => motive * weight)
.ToArray();
float baseHappy = happyParts.Sum();
List<VMPieMenuInteraction> validActions = new List<VMPieMenuInteraction>();
foreach (var iobj in ents)
{
if (iobj.Position == LotTilePos.OUT_OF_WORLD) continue;
var obj = iobj.MulreplacedileGroup.GetInteractionGroupLeader(iobj);
if (processed.Contains(obj.ObjectID) || (obj is VMGameObject && ((VMGameObject)obj).Disabled > 0)) continue;
processed.Add(obj.ObjectID);
if (isStray)
{
if (obj is VMGameObject) continue;
//determine if the object is indoors
var roomID = context.VM.Context.GetObjectRoom(obj);
roomID = (ushort)Math.Max(0, Math.Min(context.VM.Context.RoomInfo.Length - 1, roomID));
var room = context.VM.Context.RoomInfo[roomID];
var outside = room.Room.IsOutside;
if (!outside) continue;
}
var pos2 = obj.Position;
var distance = (float)Math.Sqrt(Math.Pow(pos1.x - pos2.x, 2) + Math.Pow(pos1.y - pos2.y, 2) + Math.Pow((pos1.Level - pos2.Level) * 320, 2.0)) / 16.0f;
var inUse = obj.GetFlag(VMEnreplacedyFlags.Occupied);
if (obj.TreeTable == null) continue;
foreach (var entry in obj.TreeTable.AutoInteractions)
{
var id = entry.TTAIndex;
if (inUse && !obj.TreeTable.Interactions.Any(x => x.JoiningIndex == id)) continue;
var advertisements = entry.ActiveMotiveEntries; //TODO: cache this
if (advertisements.Length == 0) continue; //no ads on this object.
var action = obj.GetAction((int)id, caller, context.VM.Context, false);
TTAs ttas = obj.TreeTableStrings;
caller.ObjectData[(int)VMStackObjectVariable.HideInteraction] = 0;
var actionStrings = caller.Thread.CheckAction(action, true);
var pie = new List<VMPieMenuInteraction>();
if (actionStrings != null)
{
if (actionStrings.Count > 0)
{
foreach (var actionS in actionStrings)
{
if (actionS.Name == null) actionS.Name = ttas?.GetString((int)id) ?? "***MISSING***";
actionS.ID = (byte)id;
actionS.Entry = entry;
actionS.Global = false;
pie.Add(actionS);
}
}
else
{
if (ttas != null)
{
pie.Add(new VMPieMenuInteraction()
{
Name = ttas.GetString((int)id),
ID = (byte)id,
Entry = entry,
Global = false,
});
}
}
}
var first = pie.FirstOrDefault();
if (first != null)
{
// calculate score for this tree.
// start with the base happy value, and modify it for each motive changed.
float score = baseHappy;
for (int i = 0; i < advertisements.Length; i++)
{
var motiveI = advertisements[i].MotiveIndex;
var motiveScore = entry.MotiveEntries[motiveI];
short min = motiveScore.EffectRangeMinimum;
short max = motiveScore.EffectRangeDelta;
short personality = (short)motiveScore.PersonalityModifier;
if (first.MotiveAdChanges != null)
{
first.MotiveAdChanges.TryGetValue((0 << 16) | motiveI, out min);
first.MotiveAdChanges.TryGetValue((1 << 16) | motiveI, out max);
first.MotiveAdChanges.TryGetValue((2 << 16) | motiveI, out personality);
}
if (max == 0 && min > 0)
{
//invalid delta. do from 0..delta instead (fix child-talk preference?)
max = min;
min = 0;
}
max += min; //it's a delta, add min to it
var myMotive = caller.GetMotiveData((VMMotive)motiveI);
if (min != 0 && myMotive > min) continue;
// subtract the base contribution for this motive from happy
var weightInd = MotiveToWeight[motiveI];
if (weightInd == -1) continue;
score -= happyParts[weightInd];
float personalityMul = 1;
if (personality > 0 && personality < VaryByTypes.Length)
{
personalityMul = caller.GetPersonData(VaryByTypes[personality]);
personalityMul /= 1000f;
if (personality < 13)
{
if ((personality & 1) == 0)
{
personalityMul = 1 - personalityMul;
}
} else
{
personalityMul *= 2;
}
}
// then add the new contribution for this motive.
score += interactionCurve[weightInd].GetPoint(myMotive + (max * personalityMul) / 1000f) * weights[weightInd];
}
// score relative to base
score -= baseHappy;
// modify score using attenuation
float atten = (entry.AttenuationCode == 0 || entry.AttenuationCode >= attenTable.Length) ?
entry.AttenuationValue : attenTable[entry.AttenuationCode];
score = score / (1 + atten * distance);
if (score > minScore)
{
foreach (var item in pie)
{
item.Score = score;
item.Callee = obj;
validActions.Add(first);
}
}
}
//if (attenScore != 0) attenScore += (int)context.VM.Context.NextRandom(31) - 15;
//TODO: Lockout interactions that have been used before for a few sim hours (in ts1 ticks. same # of ticks for tso probably)
//TODO: special logic for socials?
}
}
List<VMPieMenuInteraction> sorted = validActions.OrderByDescending(x => x.Score).ToList();
sorted = TakeTopActions(sorted, 4);
var selection = sorted.FirstOrDefault();
if (selection == null) return VMPrimitiveExitCode.GOTO_FALSE;
if (!selection.Entry.AutoFirst)
{
// weighted random selection
//var slice = sorted.Take(Math.Min(4, sorted.Count)).ToList();
var totalScore = sorted.Sum(x => x.Score);
var random = context.VM.Context.NextRandom(10000);
float randomTotal = 0;
for (int i=0; i < sorted.Count; i++)
{
var action = sorted[i];
randomTotal += (sorted[i].Score / totalScore) * 10000;
if (random <= randomTotal)
{
selection = action;
break;
}
}
}
var qaction = selection.Callee.GetAction(selection.ID, context.Caller, context.VM.Context, false, new short[] { selection.Param0, 0, 0, 0 });
if (qaction != null)
{
qaction.Priority = (short)VMQueuePriority.Autonomous;
context.Caller.Thread.EnqueueAction(qaction);
context.StackObject = selection.Callee;
return VMPrimitiveExitCode.GOTO_TRUE;
} else
{
return VMPrimitiveExitCode.GOTO_FALSE;
}
}