public static ValueEventPoller <T> Create <T>(IValueDataProvider <T> dataProvider, ISequencer sequencer, Sequence sequence, Sequence cursorSequence, params ISequence[] gatingSequences) where T : struct { var gatingSequence = SequenceGroups.CreateReadOnlySequence(cursorSequence, gatingSequences); return(new ValueEventPoller <T>(dataProvider, sequencer, sequence, gatingSequence)); }
public void Write(Stream stream) { if (!stream.CanWrite || !stream.CanSeek) { throw new InvalidDataException($"Write and seek must be supported."); } var sequenceProperties = SequenceGroups .SelectMany(x => x.Sequences) .ToList(); var header = new Header { MagicCode = MagicCodeValidator, Version = SupportedVersion, L1Count = sequenceProperties.Count, L2Count = SequenceGroups.Count, SequenceCount = SequenceItems.Count, }; stream.Position = MinimumLength; header.L1Offset = (int)stream.Position; header.L2Offset = stream.WriteList(sequenceProperties) + header.L1Offset; var oldPosition = stream.Position; var index = 0; foreach (var item in SequenceGroups) { BinaryMapping.WriteObject(stream, new RawSequenceGroup { L1Index = (short)index, L1Count = (short)item.Sequences.Count, Unknown04 = item.Unknown04, Unknown08 = item.Unknown08, Unknown0c = item.Unknown0c, Unknown10 = item.Unknown10, }); index += item.Sequences.Count; } header.SequenceOffset = (int)(stream.Position - oldPosition + header.L2Offset); WriteSequences(stream); stream.Position = 0; BinaryMapping.WriteObject(stream, header); }
/// <summary> /// Remove the specified sequence from this sequencer. /// </summary> /// <param name="sequence">to be removed.</param> /// <returns>true if this sequence was found, false otherwise.</returns> public bool RemoveGatingSequence(ISequence sequence) { return(SequenceGroups.RemoveSequence(ref _gatingSequences, sequence)); }
/// <summary> /// Add the specified gating sequences to this instance of the Disruptor. They will /// safely and atomically added to the list of gating sequences. /// </summary> /// <param name="gatingSequences">The sequences to add.</param> public void AddGatingSequences(params ISequence[] gatingSequences) { SequenceGroups.AddSequences(ref _gatingSequences, this, gatingSequences); }
private void Read(BinaryReader br, Dictionary <string, BinaryReader> sequenceGroups) { Header = new Header { ID = ID.Idst, Version = Version.Goldsource, Name = br.ReadFixedLengthString(Encoding.ASCII, 64), Size = br.ReadInt32(), EyePosition = br.ReadVector3(), HullMin = br.ReadVector3(), HullMax = br.ReadVector3(), BoundingBoxMin = br.ReadVector3(), BoundingBoxMax = br.ReadVector3(), Flags = br.ReadInt32() }; // Read all the nums/offsets from the header var sections = new int[(int)Section.NumSections][]; for (var i = 0; i < (int)Section.NumSections; i++) { var sec = (Section)i; int indexNum; if (sec == Section.Texture || sec == Section.Skin) { indexNum = 3; } else { indexNum = 2; } sections[i] = new int[indexNum]; for (var j = 0; j < indexNum; j++) { sections[i][j] = br.ReadInt32(); } } // Bones var num = SeekToSection(br, Section.Bone, sections); var numBones = num; for (var i = 0; i < num; i++) { var bone = new Bone { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Parent = br.ReadInt32(), Flags = br.ReadInt32(), Controllers = br.ReadIntArray(6), Position = br.ReadVector3(), Rotation = br.ReadVector3(), PositionScale = br.ReadVector3(), RotationScale = br.ReadVector3() }; Bones.Add(bone); } // Bone controllers num = SeekToSection(br, Section.BoneController, sections); for (var i = 0; i < num; i++) { var boneController = new BoneController { Bone = br.ReadInt32(), Type = br.ReadInt32(), Start = br.ReadSingle(), End = br.ReadSingle(), Rest = br.ReadInt32(), Index = br.ReadInt32() }; BoneControllers.Add(boneController); } // Hitboxes num = SeekToSection(br, Section.Hitbox, sections); for (var i = 0; i < num; i++) { var hitbox = new Hitbox { Bone = br.ReadInt32(), Group = br.ReadInt32(), Min = br.ReadVector3(), Max = br.ReadVector3() }; Hitboxes.Add(hitbox); } // Sequence groups num = SeekToSection(br, Section.SequenceGroup, sections); for (var i = 0; i < num; i++) { var group = new SequenceGroup { Label = br.ReadFixedLengthString(Encoding.ASCII, 32), Name = br.ReadFixedLengthString(Encoding.ASCII, 64) }; br.ReadBytes(8); // unused SequenceGroups.Add(group); } // Sequences num = SeekToSection(br, Section.Sequence, sections); for (var i = 0; i < num; i++) { var sequence = new Sequence { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Framerate = br.ReadSingle(), Flags = br.ReadInt32(), Activity = br.ReadInt32(), ActivityWeight = br.ReadInt32(), NumEvents = br.ReadInt32(), EventIndex = br.ReadInt32(), NumFrames = br.ReadInt32(), NumPivots = br.ReadInt32(), PivotIndex = br.ReadInt32(), MotionType = br.ReadInt32(), MotionBone = br.ReadInt32(), LinearMovement = br.ReadVector3(), AutoMovePositionIndex = br.ReadInt32(), AutoMoveAngleIndex = br.ReadInt32(), Min = br.ReadVector3(), Max = br.ReadVector3(), NumBlends = br.ReadInt32(), AnimationIndex = br.ReadInt32(), BlendType = br.ReadIntArray(2), BlendStart = br.ReadSingleArray(2), BlendEnd = br.ReadSingleArray(2), BlendParent = br.ReadInt32(), SequenceGroup = br.ReadInt32(), EntryNode = br.ReadInt32(), ExitNode = br.ReadInt32(), NodeFlags = br.ReadInt32(), NextSequence = br.ReadInt32() }; var seqGroup = SequenceGroups[sequence.SequenceGroup]; // Only load seqence group 0 for now (others are in other files) if (sequence.SequenceGroup == 0) { var pos = br.BaseStream.Position; sequence.Blends = LoadAnimationBlends(br, sequence, numBones); br.BaseStream.Position = pos; } else if (sequenceGroups.ContainsKey(seqGroup.Name)) { var reader = sequenceGroups[seqGroup.Name]; sequence.Blends = LoadAnimationBlends(reader, sequence, numBones); } Sequences.Add(sequence); } // Textures num = SeekToSection(br, Section.Texture, sections); var firstTextureIndex = Textures.Count; for (var i = 0; i < num; i++) { var texture = new Texture { Name = br.ReadFixedLengthString(Encoding.ASCII, 64), Flags = (TextureFlags)br.ReadInt32(), Width = br.ReadInt32(), Height = br.ReadInt32(), Index = br.ReadInt32() }; Textures.Add(texture); } // Texture data for (var i = firstTextureIndex; i < firstTextureIndex + num; i++) { var t = Textures[i]; br.BaseStream.Position = t.Index; t.Data = br.ReadBytes(t.Width * t.Height); t.Palette = br.ReadBytes(256 * 3); Textures[i] = t; } // Skins var skinSection = sections[(int)Section.Skin]; var numSkinRefs = skinSection[0]; var numSkinFamilies = skinSection[1]; br.BaseStream.Seek(skinSection[2], SeekOrigin.Begin); for (var i = 0; i < numSkinFamilies; i++) { var skin = new SkinFamily { Textures = br.ReadShortArray(numSkinRefs) }; Skins.Add(skin); } // Body parts num = SeekToSection(br, Section.BodyPart, sections); for (var i = 0; i < num; i++) { var part = new BodyPart { Name = br.ReadFixedLengthString(Encoding.ASCII, 64), NumModels = br.ReadInt32(), Base = br.ReadInt32(), ModelIndex = br.ReadInt32() }; var pos = br.BaseStream.Position; part.Models = LoadModels(br, part); br.BaseStream.Position = pos; BodyParts.Add(part); } // Attachments num = SeekToSection(br, Section.Attachment, sections); for (var i = 0; i < num; i++) { var attachment = new Attachment { Name = br.ReadFixedLengthString(Encoding.ASCII, 32), Type = br.ReadInt32(), Bone = br.ReadInt32(), Origin = br.ReadVector3(), Vectors = br.ReadVector3Array(3) }; Attachments.Add(attachment); } // Transitions // Sounds & Sound groups aren't used }
public static EventPoller <T> Create <T>(IDataProvider <T> dataProvider, ISequencer sequencer, Sequence sequence, Sequence cursorSequence, params ISequence[] gatingSequences) { var gatingSequence = SequenceGroups.CreateReadOnlySequence(cursorSequence, gatingSequences); return(new EventPoller <T>(dataProvider, sequencer, sequence, gatingSequence)); }
/// <summary> /// Adds a sequence to the sequence group after threads have started to publish to /// the Disruptor.It will set the sequences to cursor value of the ringBuffer /// just after adding them. This should prevent any nasty rewind/wrapping effects. /// </summary> /// <param name="cursored">The data structure that the owner of this sequence group will be pulling it's events from</param> /// <param name="sequence">The sequence to add</param> public void AddWhileRunning(ICursored cursored, Sequence sequence) { SequenceGroups.AddSequences(ref _sequences, cursored, sequence); }