public QuadRenderer(IRenderer renderer) { mesh = new Mesh(); var vertexFormat = new VertexFormat(); position = vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); texcoord = vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); // Some gfx cards fail to show last vertex right if texcoord is set to have 3 components vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.StaticDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBufferRange = vertexBuffer.CreateVertexBufferRange(); indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); indexWriter = new IndexBufferWriter(indexBufferRange); }
/// <summary> /// 点击创建角色 /// </summary> private void StartBtnOnClick() { RolesCreateC2S c2sMSG = new RolesCreateC2S(); c2sMSG.NickName = InputField.text; BufferFactory.CreateAndSendPackage(1201, c2sMSG); }
public void Broadcast(int teamID, int messageID, IMessage s2cMSG) { if (teamID == 0) { //A队伍 for (int i = 0; i < roomInfo.TeamA.Count; i++) { UClient client; if (clientList.TryGetValue(roomInfo.TeamA[i].RolesID, out client)) { BufferFactory.CreqateAndSendPackage(client, messageID, s2cMSG); } } } else { //B队伍 for (int i = 0; i < roomInfo.TeamB.Count; i++) { UClient client; if (clientList.TryGetValue(roomInfo.TeamB[i].RolesID, out client)) { BufferFactory.CreqateAndSendPackage(client, messageID, s2cMSG); } } } }
private static IPolygon CreateSearchBuffer( [NotNull] IGeometry geometry, double distance, [CanBeNull] ref BufferFactory bufferFactory) { // create exact buffer (not densified) to avoid slivers that result in errors if (bufferFactory == null) { bufferFactory = new BufferFactory { // NOTE: EndOption must be set FIRST, otherwise the result is not accurate // (line end points don't touch buffer in some situations, some tolerance appears to be applied) EndOption = esriBufferConstructionEndEnum.esriBufferFlat, DensifyDeviation = 0.0001, // NOTE this is required even when generating curves, otherwise the flat-end buffer is not accurate!! TODO use resolution? GenerateCurves = true, ExplodeBuffers = false, UnionOverlappingBuffers = true }; } IList <IPolygon> result = bufferFactory.Buffer(geometry, distance); // NOTE flat end buffer result list (at least) can be empty for very short input geometries if (result.Count == 0) { return(null); } Assert.AreEqual(1, result.Count, "Unexpected buffer result count"); return(result[0]); }
private void When_unlocking_bytes_in_stream_it_must_not_raise_events() { // Arrange const string directoryToWatch = @"c:\some"; string filePath = Path.Combine(directoryToWatch, "file.txt"); FakeFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingBinaryFile(filePath, BufferFactory.Create(4096)) .Build(); using (IFileStream stream = fileSystem.File.Open(filePath, FileMode.Open)) { stream.Lock(0, 256); using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch)) { watcher.NotifyFilter = TestNotifyFilters.All; watcher.IncludeSubdirectories = true; using (var listener = new FileSystemWatcherEventListener(watcher)) { // Act stream.Unlock(0, 256); watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds); // Assert listener.EventsCollected.Should().BeEmpty(); } } } }
public TextBuffer(FontStyle fontStyle) { this.fontStyle = fontStyle; mesh = new Mesh.Mesh(); var vertexFormat = new VertexFormat(); vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 3)); vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBuffer.CreateVertexBufferRange(); var indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); indexWriter = new IndexBufferWriter(indexBufferRange); }
private void When_moving_file_to_other_drive_it_must_succeed() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"D:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingVolume("D:", new FakeVolumeInfoBuilder() .OfCapacity(16384) .WithFreeSpace(6144)) .Build(); // Act fileSystem.File.Move(sourcePath, targetPath); // Assert IDriveInfo driveInfoC = fileSystem.ConstructDriveInfo("C:"); driveInfoC.AvailableFreeSpace.Should().Be(4096); IDriveInfo driveInfoD = fileSystem.ConstructDriveInfo("D:"); driveInfoD.AvailableFreeSpace.Should().Be(5376); }
private void When_increasing_file_size_using_Seek_followed_by_write_it_must_fail() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .IncludingBinaryFile(path, BufferFactory.Create(32)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { byte[] buffer = BufferFactory.Create(64); stream.Write(buffer, 0, buffer.Length); stream.Seek(1280, SeekOrigin.Begin); // Act // ReSharper disable once AccessToDisposedClosure Action action = () => stream.WriteByte(0x33); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); AssertFreeSpaceOnDrive(fileSystem, "C:", 448); } AssertFileSize(fileSystem, path, 64); }
public void MeasureBufferFactoryMappedPerformance() { const int iterations = 100; IEnumerable <IGeometry> sources = GetBufferInput(iterations); var input = new List <KeyValuePair <int, IGeometry> >(); int i = 0; foreach (IGeometry geometry in sources) { input.Add(new KeyValuePair <int, IGeometry>(i, geometry)); i++; } var factory = new BufferFactory(); var watch = new Stopwatch(); watch.Start(); var result = new List <KeyValuePair <int, IPolygon> >(factory.Buffer(input, 10)); watch.Stop(); Console.Out.WriteLine( "BufferFactory.Buffer(IEnumerable<KeyValuePair>): {0:N2} ms per geoemtry", (double)watch.ElapsedMilliseconds / iterations); Assert.AreEqual(iterations, result.Count, "Unexptected buffer output count"); }
private void When_moving_file_to_other_drive_it_must_fail() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"D:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingVolume("D:", new FakeVolumeInfoBuilder() .OfCapacity(16384) .WithFreeSpace(512)) .Build(); // Act Action action = () => fileSystem.File.Move(sourcePath, targetPath); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); // Assert AssertFreeSpaceOnDrive(fileSystem, "C:", 3328); AssertFileSize(fileSystem, sourcePath, 768); AssertFreeSpaceOnDrive(fileSystem, "D:", 512); fileSystem.File.Exists(targetPath).Should().BeFalse(); }
/// <summary> /// 注册功能 /// </summary> /// <param name="request"></param> private void HandleUserRegisterC2S(BufferEntity request) { UserRegisterC2S c2sMSG = ProtobufHelper.FromBytes <UserRegisterC2S>(request.proto); UserRegisterS2C s2cMSG = new UserRegisterS2C(); if (DBUserInfo.Instance.Select(MySqlCMD.Where("Account", c2sMSG.UserInfo.Account)) != null) { Debug.Log("帐号已被注册"); s2cMSG.Result = 3; } else { bool result = DBUserInfo.Instance.Insert(c2sMSG.UserInfo); if (result == true) { s2cMSG.Result = 0;//注册成功 } else { s2cMSG.Result = 4;//未知原因导致的失败 } } //返回结果 BufferFactory.CreqateAndSendPackage(request, s2cMSG); }
public static IPolyline GetNotEqualLine( [NotNull] IPolyline commonBorder, [NotNull] IPolyline alongBorder, [NotNull] IPolyline neighborAlongBorder, double distance, ref BufferFactory bufferFactory, double?xyTolerance = null) { IPolyline restNeighbor; if (!commonBorder.IsEmpty) { // restNeighbor = GetNearPart(commonBorder, neighborAreaBoundaryAlongBorder) ?? neighborAreaBoundaryAlongBorder; restNeighbor = GetDifference(neighborAlongBorder, commonBorder, xyTolerance); } else { restNeighbor = neighborAlongBorder; double offset = ((IProximityOperator)restNeighbor).ReturnDistance(alongBorder); if (offset > distance) { return(null); } } return(restNeighbor.IsEmpty ? null : GetNearPart(restNeighbor, alongBorder, distance, ref bufferFactory)); }
public void Broadcast(int messageID, IMessage s2cMSG) { foreach (var client in clientList.Values) { BufferFactory.CreqateAndSendPackage(client, messageID, s2cMSG); } }
async void ShowMultipleFiles(string[] files) { var openDocuments = EditorHost.GetOpenDocuments(); var searchCtx = Presenter.StartSearch($"Go to files", null, false); try { var msbuildContentType = ContentTypeRegistry.GetContentType(MSBuildContentType.Name); foreach (var file in files) { string lineText; try { if (!File.Exists(file)) { continue; } if (!openDocuments.TryGetValue(file, out var buf)) { buf = BufferFactory.CreateTextBuffer(File.OpenText(file), msbuildContentType); } lineText = buf.CurrentSnapshot.GetLineFromPosition(0).GetText(); } catch (Exception ex) { LoggingService.LogError($"Error getting text for file {file}", ex); continue; } var classifiedSpans = ImmutableArray <ClassifiedText> .Empty; classifiedSpans = classifiedSpans.Add(new ClassifiedText(lineText, PredefinedClassificationTypeNames.NaturalLanguage)); await searchCtx.OnReferenceFoundAsync(new FoundReference (file, 0, 0, ReferenceUsage.Declaration, classifiedSpans, new TextSpan(-1, 0))); } } catch (Exception ex) when(!(ex is OperationCanceledException && searchCtx.CancellationToken.IsCancellationRequested)) { LoggingService.LogError($"Error in show multiple imports", ex); } await searchCtx.OnCompletedAsync(); }
public ScalarDataBuffer(ScalarReader reader, ScalarAccessor accessor, BufferFactory bufferFactory, int numRows) { this.reader = reader; this.accessor = accessor; this.buffer = bufferFactory.newBuffer(1 + numRows); // Start with position 1 that the coordinate N cooresponds to row id N. this.position = 1; }
//private BufferRange indexBufferRange; protected override void InitializeService() { //basic = materialManager["Basic"]; basic = materialManager.MakeMaterial("Basic"); Image terrainImage = new Image("res/images/terrain.png"); // \todo support material textures basic.Textures["t_surface_color"] = materialManager.Textures["terrain"] = new TextureGL(terrainImage); blockTypes[BlockType.Grass] = new BlockType(0, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0); blockTypes[BlockType.Stone] = new BlockType(1, 0); blockTypes[BlockType.Dirt] = new BlockType(2, 0); blockTypes[BlockType.Cobblestone] = new BlockType(0, 1); blockTypes[BlockType.Bedrock] = new BlockType(1, 1); blockTypes[BlockType.Wood] = new BlockType(5, 1, 5, 1, 4, 1, 4, 1, 4, 1, 4, 1); blockTypes[BlockType.Sand] = new BlockType(2, 1); // 0, 0 grass (in gray) // 1, 0 stone // 2, 0 dirt // 3, 0 grass left, right, front, back // 4, 0 wooden planks // 5, 0 stone slab sides // 6, 0 stone slab top, bottom // 7, 0 brick // 8, 0 tnt sides // 9, 0 tnt top // 10, 0 tnt bottom // 11, 0 spider web // 12, 0 red flower // 13, 0 yellow flower // 14, 0 water? // 15, 0 sapling // 0, 1 cobble stone // 1, 1 bedrock // 2, 1 sand // 3, 1 gravel // 4, 1 log sidem // 5, 1 log top, bottom // 6, 1 iron block // 7, 1 gold block // 8, 1 diamond block // 9, 1 chest top, bottom // 10, 1 chest front, left, right // 11, 1 chest back // 12, 1 var vertexFormat = new VertexFormat(); position = vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); texcoord = vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); //color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Byte, 0, 4, true)); color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); // Some gfx cards fail to show last vertex right if texcoord is set to have 3 components vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.StaticDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); }
public NinePatch(NinePatchStyle style) { this.style = style; //mesh = new Mesh.Mesh(BufferUsageHint.DynamicDraw); mesh = new RenderStack.Mesh.Mesh(); VertexFormat vertexFormat = new VertexFormat(); vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); // \todo Allocate vertex buffers form from UI BufferPool and use double buffered Buffers // \todo Share one index buffer among all UI components that have the same index buffer //Buffer vertexBuffer = BufferPool.Instance.GetVertexBuffer(vertexFormat, BufferUsageHint.DynamicDraw); //Buffer indexBuffer = BufferPool.Instance.GetIndexBuffer(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw); vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBuffer.CreateVertexBufferRange(); IBufferRange indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); var writer = new IndexBufferWriter(indexBufferRange); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); // 12 13 14 15 // // 8 9 10 11 // // 4 5 6 7 // // 0 1 2 3 writer.BeginEdit(); writer.Quad(4, 5, 1, 0); writer.CurrentIndex += 6; writer.Quad(5, 6, 2, 1); writer.CurrentIndex += 6; writer.Quad(6, 7, 3, 2); writer.CurrentIndex += 6; writer.Quad(8, 9, 5, 4); writer.CurrentIndex += 6; writer.Quad(9, 10, 6, 5); writer.CurrentIndex += 6; writer.Quad(10, 11, 7, 6); writer.CurrentIndex += 6; writer.Quad(12, 13, 9, 8); writer.CurrentIndex += 6; writer.Quad(13, 14, 10, 9); writer.CurrentIndex += 6; writer.Quad(14, 15, 11, 10); writer.CurrentIndex += 6; writer.EndEdit(); // \bug //indexBuffer.UpdateAll(); }
public override void PacketReceived(ISessionFilterChain filterChain, IPacket packet) { if (packet == null || filterChain.Session != base._session) { base.PacketReceived(filterChain, packet); } else { lock (this) { if (_content == null) { _content = packet.Buffer; _endPoint = packet.EndPoint; } else { IBuffer content = packet.Buffer; if (_content.Remaining < content.Remaining) { IBuffer buffer = BufferFactory.GetBuffer( _content.Position + content.Remaining); buffer.Put(_content.Flip()); _content.Release(); _content = buffer; } _content.Put(content); _content.Flip(); } if (_content != null) { try { base.Recognize(_content, _endPoint); } finally { if (_content.HasRemaining) { _content.Compact(); } else { _content.Release(); _content = null; _endPoint = null; } } } } } }
public VecDataBuffer(VecReader reader, int coordsPerElem, BufferFactory bufferFactory, int numRows, int elementsPerRow) { int bufferLength = Math.Max(1, elementsPerRow); BufferWrapper buffer = bufferFactory.newBuffer((1 + numRows) * coordsPerElem * bufferLength); this.reader = reader; this.buffer = new VecBufferSequence(new VecBuffer(coordsPerElem, buffer), 1 + numRows); // Insert an empty coordinate so that the coordinate N cooresponds to row id N. this.buffer.append(VecBuffer.emptyVecBuffer(coordsPerElem)); }
public static IPolyline GetNearPart([NotNull] IPolyline toBuffer, [NotNull] IPolyline line, double distance, ref BufferFactory bufferFactory) { IPolygon buffer = CreateSearchBuffer(toBuffer, distance, ref bufferFactory); return(buffer == null ? null : GetLinearIntersection(line, buffer)); }
public IPolygon CreateBuffer(double distance) { const bool forceCreation = false; IPolyline polyLine = GetPolyline(forceCreation); IPolyline bufferInput; if (GeometryUtils.HasNonLinearSegments(polyLine)) { if (polyLine.Length > 0) { bufferInput = GeometryFactory.Clone(polyLine); double xyTolerance = GeometryUtils.GetXyTolerance(polyLine); double xyResolution = GeometryUtils.GetXyResolution(polyLine); // note: buffering a non-linear segments always results in a densified buffer // apparently, the input is first densified with a large max. densify deviation // --> the input may not be contained in the buffer for small buffer distances // --> we need to densify the input ourselves to an appropriate max. deviation value double densifyDeviation = Math.Min(xyTolerance / 2, distance / 2); double minimumAllowedDeviation = xyResolution * 2.01; if (densifyDeviation < minimumAllowedDeviation) { densifyDeviation = minimumAllowedDeviation; } bufferInput.Densify(0, densifyDeviation); } else { bufferInput = GeometryFactory.CreateLine(polyLine.FromPoint, polyLine.ToPoint); } } else { bufferInput = polyLine; } using (var factory = new BufferFactory(explodeBuffers: false, densify: false)) { IPolygon result = null; foreach (IPolygon polygon in factory.Buffer(bufferInput, distance)) { Assert.Null(result, "more than 1 buffer geometry found"); result = polygon; } return(Assert.NotNull(result, "no buffer geometry found")); } }
public static IBuffer ToBuffer(DefaultMessage message, Func <object, byte[]> messageBodyEncoder) { byte[] data = messageBodyEncoder(message.Obj); IBuffer buffer = BufferFactory.GetBuffer(data.Length + DefaultMessageHeader.HeaderLength); message.Header.Length = data.Length; message.Header.Write(buffer); System.Buffer.BlockCopy(data, 0, buffer.ByteArray, DefaultMessageHeader.HeaderLength, data.Length); return(buffer); }
static Quad() { var vertices = new float[] { 1f, -1f, 1f, 1f, -1f, -1f, -1f, 1f }; instance = new Quad { vbo = BufferFactory.Create <ArrayBuffer>(sizeof(float) * (uint)vertices.Length, vertices, BufferUsage.StaticDraw) }; }
public override void Update(float deltaTime) { base.Update(deltaTime); //回车键 if (Input.GetKeyDown(KeyCode.Return)) { BufferFactory.CreateAndSendPackage(1404, new RoomSendMsgC2S() { Text = ChatInput.text }); } }
private static void TestSend() { UserInfo userInfo = new UserInfo(); userInfo.Account = "11111"; userInfo.Password = "******"; UserRegisterC2S userRegisterC2S = new UserRegisterC2S(); userRegisterC2S.UserInfo = userInfo; BufferEntity bufferEntity = BufferFactory.CreateAndSendPackage(1001, userInfo); }
/// <summary> /// 发送选择的英雄 /// </summary> /// <param name="btn"></param> /// <param name="heroID"></param> private void SendSelectHero(Button btn, int heroID) { btn.onClick.AddListener(() => { if (isLock == false) { BufferFactory.CreateAndSendPackage(1400, new RoomSelectHeroC2S() { HeroID = heroID }); } }); }
static Triangle() { float[] vertices = { .0f, 1f, -1f, -1f, 1f, -1f }; instance = new Triangle { vbo = BufferFactory.Create <ArrayBuffer>(sizeof(float) * (uint)vertices.Length, vertices, OpenGL.BufferUsage.StaticDraw) }; }
private void SendSelectSkill(Button btn, int skillid) { btn.onClick.AddListener(() => { if (isLock == false) { BufferFactory.CreateAndSendPackage(1401, new RoomSelectHeroSkillC2S() { SkillID = skillid, GridID = grid, }); } }); }
async void SendProgeress() { BufferFactory.CreateAndSendPackage(1406, new RoomLoadProgressC2S() { LoadProgress = (int)(async.progress >= 0.89f?100:async.progress * 100) }); await Task.Delay(500); if (ct.IsCancellationRequested == true) { return; } SendProgeress(); }
/// <summary> /// Compacts the buffer list by removing and destroying all empty BufferFactories. /// </summary> internal void Compact() { // TODO this may not be entirely thread-safe lock (UpdateLock) { if (factories.Count == 0) { return; } var all = new BufferFactory[factories.Count]; var didPop = factories.TryPopRange(all); // dispose all empty entries // and put the rest back into the stack for (var i = didPop - 1; i >= 0; i--) { var current = all[i]; if (current == null) { continue; } if (current.IsEmpty) { #region debug checks #if DEBUG foreach (var tmp in knownEventArgs.Values) { if (tmp.Item1 == current) { throw new InvalidOperationException("Factory is still mapped to a SocketAsyncEventArgs"); } } #endif #endregion current.Dispose(); } else { factories.Push(current); } } } }
/// <summary> /// Compacts the buffer list by removing and destroying all empty BufferFactories. /// </summary> internal void Compact() { lock (UpdateLock) { if (factories.Count == 0) return; var all = new BufferFactory[factories.Count]; var didPop = factories.TryPopRange(all); // dispose all empty entries // and put the rest back into the stack for (var i = didPop - 1; i >= 0; i--) { var current = all[i]; Debug.Assert(current != null); if (current.IsEmpty) { #region debug checks #if DEBUG foreach (var tmp in knownEventArgs.Values) { if (tmp.Item1 == current) throw new InvalidOperationException("Factory is still mapped to a SocketAsyncEventArgs"); } #endif #endregion current.Dispose(); } else { factories.Push(current); } } } }