/// <summary> /// Gets a content of buffers on current buffering level converted to string regardless of its type. /// </summary> /// <returns> /// The content converted to a string. Binary data are converted using <see cref="Encoding"/>. /// </returns> public string GetContentAsString() { if (level == null) { return(null); } StringBuilder result = new StringBuilder(level.size, level.size); for (int i = 0; i < level.buffers.Count; i++) { BufferElement element = (BufferElement)level.buffers[i]; byte[] bytes = element.data as byte[]; if (bytes != null) { result.Append(encoding.GetString(bytes, 0, element.size)); } else { result.Append((char[])element.data, 0, element.size); } } return(result.ToString()); }
/// <summary> /// Loads the configuration properties from the application /// configuration. /// </summary> public static void Load() { ConfigSection section = (ConfigSection) ConfigurationManager.GetSection("x2net"); TraceLevel = section.Trace.Level; HeartbeatInterval = section.Heartbeat.Interval; FlowLoggingElement logging = section.Flow.Logging; Flow.Logging.SlowHandler.TraceLevel = logging.SlowHandler.TraceLevel; Flow.Logging.SlowHandler.Threshold = logging.SlowHandler.Threshold; Flow.Logging.LongQueue.TraceLevel = logging.LongQueue.TraceLevel; Flow.Logging.LongQueue.Threshold = logging.LongQueue.Threshold; MaxLinkHandles = section.Link.MaxHandles; BufferElement buffer = section.Buffer; Buffer.SizeExponent.Chunk = buffer.SizeExponent.Chunk; Buffer.SizeExponent.Segment = buffer.SizeExponent.Segment; Buffer.RoomFactor.MinLevel = buffer.RoomFactor.MinLevel; Buffer.RoomFactor.MaxLevel = buffer.RoomFactor.MaxLevel; Coroutine.MaxWaitHandles = section.Coroutine.MaxWaitHandles; Coroutine.DefaultTimeout = section.Coroutine.DefaultTimeout; }
public void CreateBufferElement(ShaderDataType type, int size) { var bufferElement = new BufferElement(type, "Test"); Assert.Equal(size, bufferElement.Size); Assert.Equal("Test", bufferElement.Name); Assert.False(bufferElement.Normalized); }
public override void SetLayout(BufferLayout bufferLayout) { this.layout = bufferLayout; List <BufferElement> layout = bufferLayout.GetLayout(); for (int i = 0; i < layout.Count; i++) { BufferElement element = layout[i]; Gl.EnableVertexAttribArray(i); Gl.VertexAttribPointer((uint)i, (int)element.count, (VertexAttribPointerType)element.type, element.normalized, (int)bufferLayout.GetStride(), new IntPtr(element.offset)); } }
private void TransformPoints(float scale, Vector2 add) { for (var i = 0; i < _points.Length; i++) { var f = (_points[i].Vertex.X / scale) + add.X; if (f < -1) { f += 2; } _points[i] = new BufferElement(new Vector2(f, (_points[i].Vertex.Y / scale) + add.Y), _points[i].Color); } }
public void CreateBufferLayout(int count) { const ShaderDataType type = ShaderDataType.Float; var typeSize = BufferElement.ShaderDataTypeSize(type); var bufferElements = new BufferElement[count]; for (int i = 0; i < count; i++) { bufferElements[i] = new BufferElement(ShaderDataType.Float, "Test"); } IBufferLayout bufferLayout = new OpenGLBufferLayout(bufferElements); Assert.NotNull(bufferLayout.Elements); Assert.Equal(count, bufferLayout.Elements.Count()); Assert.Equal(count * typeSize, bufferLayout.Stride); }
/// <summary> /// Gets a content of buffers on current buffering level. /// </summary> /// <returns>The content as <see cref="string"/> or <see cref="PhpBytes"/> or a /// <b>null</b> reference if output buffering is disable.</returns> /// <remarks> /// Character data are returned unchanged, binary data are converted to string by /// the <see cref="System.Text.Encoding.GetString"/> method of the current encoding. /// </remarks> public object GetContent() { if (level == null) { return(null); } if (level.size == 0) { return(String.Empty); } // contains characters only: if (!level.containsByteData) { StringBuilder result = new StringBuilder(level.size, level.size); for (int i = 0; i < level.buffers.Count; i++) { BufferElement element = (BufferElement)level.buffers[i]; result.Append((char[])element.data, 0, element.size); } return(result.ToString()); } else // contains bytes only: if (!level.containsCharData) { var result = new byte[level.size]; for (int i = 0, k = 0; i < level.buffers.Count; i++) { BufferElement element = (BufferElement)level.buffers[i]; Array.Copy(element.data, 0, result, k, element.size); k += element.size; } return(new PhpBytes(result)); } else // contains both bytes and characters: { return(GetContentAsString()); } }
/// <summary> /// Flushes data on current level of buffering to the sinks or to the previous level. /// The current level clean up MUST follow this method's call. /// </summary> internal void InternalFlush() { Debug.Assert(_level != null); if (_level.filter == null) { if (_level.Index == 0) { // TODO: PhpString buffers // writes top-level data to sinks: for (int i = 0; i < _level.buffers.Count; i++) { BufferElement element = _level.buffers[i]; byte[] bytes = element.data as byte[]; if (bytes != null) { _byteSink.Write(bytes, 0, element.size); } else { _charSink.Write((char[])element.data, 0, element.size); } } } else { // joins levels (data are not copied => the current level MUST be cleaned up after the return from this method): if (_level.size > 0) { var lower_level = _levels[_level.Index - 1]; lower_level.buffers.AddRange(_level.buffers); lower_level.size += _level.size; lower_level.freeSpace = _level.freeSpace; // free space in the last buffer of the level lower_level.containsByteData |= _level.containsByteData; lower_level.containsCharData |= _level.containsCharData; } } } else { // gets data from user's callback: var data = _level.filter.DynamicInvoke(GetContent(), ChunkPosition.First | ChunkPosition.Middle | ChunkPosition.Last); if (data != null) { var bindata = data as byte[]; // writes data to the current level of buffering or to sinks depending on the level count: if (_level.Index == 0) { // checks whether the filtered data are binary at first; if not so, converts them to a string: if (bindata != null) { _byteSink.Write(bindata, 0, bindata.Length); } else { // TODO: PhpString containing both string and byte[] _charSink.Write(data.ToString()); } } else { // temporarily decreases the level of buffering toredirect writes to the lower level: var old_level = _level; _level = _levels[_level.Index - 1]; // checks whether the filtered data are binary at first; if not so, converts them to a string: if (bindata != null) { _stream.Write(bindata, 0, bindata.Length); } else { // TODO: PhpString containing both string and byte[] this.Write(data.ToString()); } // restore the level of buffering: _level = old_level; } } } }
///// <summary> ///// Creates an instance of <see cref="BufferedOutput"/> having enabled buffering and with sinks set to null sinks. ///// </summary> //public BufferedOutput() // : this(true, TextWriter.Null, System.IO.Stream.Null, Configuration.Application.Globalization.PageEncoding) //{ //} #endregion #region Buffer allocation, level changing /// <summary> /// Gets a buffer where data of requested size and type can be stored. /// </summary> /// <param name="sizeNeeded">The number of characters or bytes to be allocated.</param> /// <param name="binary">Whether allocated data are bytes or chars.</param> /// <param name="buffer">Returns the buffer where data can be written to.</param> /// <param name="position">Returns the position where data can be written on.</param> /// <returns>The number of allocated characters or bytes.</returns> /// <remarks> /// The buffer may already exist or new one may be created. /// Works on the current level of buffering. /// </remarks> private int AllocateBuffer(int sizeNeeded, bool binary, out System.Array buffer, out int position) { Debug.Assert(_level != null); BufferElement element; int chunk; int kind = binary ? 1 : 0; // close binary buffer: _level.freeSpace[1 - kind] = 0; if (binary) { _level.containsByteData = true; } else { _level.containsCharData = true; } // no free space for characters found (no buffer exists, the top buffer isn't a character buffer // or the top buffer is full character buffer): if (_level.freeSpace[kind] == 0) { // computes the size of buffer to be allocated as min{sizeNeeded,dafaultBufferSize}: int size = sizeNeeded; if (size < _minBufferSize[kind]) { size = _minBufferSize[kind]; _level.freeSpace[kind] = size - sizeNeeded; } else { _level.freeSpace[kind] = 0; // all space in allocated buffer will be occupied } // allocates a new buffer element for data: element = new BufferElement(); if (binary) { buffer = new byte[size]; } else { buffer = new char[size]; } element.data = buffer; element.size = sizeNeeded; //sizeNeeded <= (buffer size) _level.buffers.Add(element); position = 0; chunk = sizeNeeded; } else // some free space found: { Debug.Assert(_level.buffers.Count > 0); // available space: chunk = (_level.freeSpace[kind] < sizeNeeded) ? _level.freeSpace[kind] : sizeNeeded; element = _level.buffers[_level.buffers.Count - 1]; buffer = element.data; position = element.data.Length - _level.freeSpace[kind]; element.size += chunk; _level.freeSpace[kind] -= chunk; } _level.size += chunk; return(chunk); }
/// <summary> /// Gets a buffer where data of requested size and type can be stored. /// </summary> /// <param name="sizeNeeded">The number of characters or bytes to be allocated.</param> /// <param name="binary">Whether allocated data are bytes or chars.</param> /// <param name="buffer">Returns the buffer where data can be written to.</param> /// <param name="position">Returns the position where data can be written on.</param> /// <returns>The number of allocated characters or bytes.</returns> /// <remarks> /// The buffer may already exist or new one may be created. /// Works on the current level of buffering. /// </remarks> private int AllocateBuffer(int sizeNeeded, bool binary, out System.Array buffer, out int position) { Debug.Assert(level != null); BufferElement element; int chunk; int kind = binary ? 1 : 0; // close binary buffer: level.freeSpace[1 - kind] = 0; if (binary) level.containsByteData = true; else level.containsCharData = true; // no free space for characters found (no buffer exists, the top buffer isn't a character buffer // or the top buffer is full character buffer): if (level.freeSpace[kind] == 0) { // computes the size of buffer to be allocated as min{sizeNeeded,dafaultBufferSize}: int size = sizeNeeded; if (size < minBufferSize[kind]) { size = minBufferSize[kind]; level.freeSpace[kind] = size - sizeNeeded; } else level.freeSpace[kind] = 0; // all space in allocated buffer will be occupied // allocates a new buffer element for data: element = new BufferElement(); if (binary) buffer = new byte[size]; else buffer = new char[size]; element.data = buffer; element.size = sizeNeeded; //sizeNeeded <= (buffer size) level.buffers.Add(element); position = 0; chunk = sizeNeeded; } else // some free space found: { Debug.Assert(level.buffers.Count > 0); // available space: chunk = (level.freeSpace[kind] < sizeNeeded) ? level.freeSpace[kind] : sizeNeeded; element = (BufferElement)level.buffers[level.buffers.Count - 1]; buffer = element.data; position = element.data.Length - level.freeSpace[kind]; element.size += chunk; level.freeSpace[kind] -= chunk; } level.size += chunk; return chunk; }
/// <summary> /// Flushes data on current level of buffering to the sinks or to the previous level. /// The current level clean up MUST follow this method's call. /// </summary> internal void InternalFlush() { Debug.Assert(level != null); if (level.filter != null) { ChunkPosition chunk_position = ChunkPosition.First | ChunkPosition.Middle | ChunkPosition.Last; // writes data to the current level of buffering or to sinks depending on the level count: if (level.index > 0) { // gets data from user's callback: object data = level.filter.Invoke(GetContent(), chunk_position); // store level to allow its restore: LevelElement old_level = level; // temporarily decreases the level of buffering toredirect writes to the lower level: level = (LevelElement)levels[level.index - 1]; // checks whether the filtered data are binary at first; if not so, converts them to a string: PhpBytes bin = data as PhpBytes; if (bin != null) { stream.Write(bin.ReadonlyData, 0, bin.Length); } else { this.Write(PHP.Core.Convert.ObjectToString(data)); } // restore the level of buffering: level = old_level; } else { // gets data from user's callback: object data = level.filter.Invoke(GetContent(), chunk_position); // checks whether the filtered data are binary at first; if not so, converts them to a string: PhpBytes bin = data as PhpBytes; if (bin != null) { if (bin.Length > 0) { byteSink.Write(bin.ReadonlyData, 0, bin.Length); } } else { charSink.Write(PHP.Core.Convert.ObjectToString(data)); } } } else { if (level.index > 0) { // joins levels (data are not copied => the current level MUST be cleaned up after the return from this method): if (level.size > 0) { LevelElement lower_level = (LevelElement)levels[level.index - 1]; lower_level.buffers.AddRange(level.buffers); lower_level.size += level.size; lower_level.freeSpace = level.freeSpace; // free space in the last buffer of the level lower_level.containsByteData |= level.containsByteData; lower_level.containsCharData |= level.containsCharData; } } else { // writes top-level data to sinks: for (int i = 0; i < level.buffers.Count; i++) { BufferElement element = (BufferElement)level.buffers[i]; byte[] bytes = element.data as byte[]; if (bytes != null) { byteSink.Write(bytes, 0, element.size); } else { charSink.Write((char[])element.data, 0, element.size); } } } } }
public VisitStatus Visit <TContainer>(Property <TContainer, BufferElement> property, ref TContainer container, ref BufferElement data) { if (!Category.HasFlag(Category.BufferData)) { return(VisitStatus.Stop); } if (Read) { Assert.That(data.FloatValue, Is.EqualTo(Value * (property as IListElementProperty).Index)); } else { data.FloatValue = Value * (property as IListElementProperty).Index; } return(VisitStatus.Stop); }
public VisitStatus Visit <TContainer>(Property <TContainer, BufferElement> property, ref TContainer container, ref BufferElement data) { Assert.That(data.Category, Is.EqualTo(Category.BufferData)); return(VisitStatus.Stop); }
public void GetBufferDataCount(ShaderDataType type, int count) { var result = new BufferElement(type, "Test").GetCount(); Assert.Equal(count, result); }
public void GetShaderDataTypeSize(ShaderDataType type, int size) { var result = BufferElement.ShaderDataTypeSize(type); Assert.Equal(size, result); }
private void UpdatePath(TickItem sender, GameWindow game, FrameEventArgs e) { _selectedCountry = _countries.RandomSubset(2).ToArray(); var pathingCities = new[] { _selectedCountry?[0].Cities.RandomSubset(1).First(), _selectedCountry?[1].Cities.RandomSubset(1).First() }; var connected = _selectedCountry[0].BorderCountries.Any( o => o == _selectedCountry[1] || o.BorderCountries.Contains(_selectedCountry[1])); if (connected) { var middleC = _selectedCountry[0].BorderCountries.Contains(_selectedCountry[1]) ? null : _selectedCountry[0].BorderCountries.FirstOrDefault( o => o.BorderCountries.Contains(_selectedCountry[1])); if (_selectedCountry == null) { return; } if (middleC != null) { var path = new[] { AStar.FindPath(pathingCities[0], _selectedCountry[0].Outbound[middleC], Distance, Distance), AStar.FindPath(middleC.Outbound[_selectedCountry[0]], middleC.Outbound[_selectedCountry[1]], Distance, Distance), AStar.FindPath(_selectedCountry[1].Outbound[middleC], pathingCities[1], Distance, Distance) }; path[2].FirstPath.PreviousSteps = path[1]; path[1].FirstPath.PreviousSteps = path[0]; pathingCities = path[2].ToArray(); _path = path[2]; } else { var path = new[] { AStar.FindPath(pathingCities[0], _selectedCountry[0].Outbound[_selectedCountry[1]], Distance, Distance), AStar.FindPath(_selectedCountry[1].Outbound[_selectedCountry[0]], pathingCities[1], Distance, Distance) }; path[1].FirstPath.PreviousSteps = path[0]; pathingCities = path[1].ToArray(); _path = path[1]; } } else { var path = new[] { AStar.FindPath(pathingCities[0], _selectedCountry[0].Cities[0], Distance, Distance), new Path <City>(_selectedCountry[1].Cities[0]) { PreviousSteps = new Path <City>(_selectedCountry[0].Cities[0]) }, AStar.FindPath(_selectedCountry[1].Cities[0], pathingCities[1], Distance, Distance) }; path[2].FirstPath.PreviousSteps = path[1]; path[1].FirstPath.PreviousSteps = path[0]; pathingCities = path[2].ToArray(); _path = path[2]; } _paths = new BufferElement[(pathingCities.Length - 1) * 2]; for (var i = 0; i < pathingCities.Length - 1; i++) { var d = (float)((pathingCities[i].Longitude / _scale) + _add.X); if (d < -1) { d += 2; } var d2 = (float)((pathingCities[i + 1].Longitude / _scale) + _add.X); if (d2 < -1) { d2 += 2; } var color = pathingCities[i].Country == pathingCities[i + 1].Country || pathingCities[i].Country.BorderCountries.Contains(pathingCities[i + 1].Country) ? new Vector4(1f, 0f, 0f, 1f) : new Vector4(0f, 0f, 1f, 1f); _paths[i * 2] = new BufferElement(new Vector2(d, (float)((pathingCities[i].Latitude / _scale) + _add.Y)), color); _paths[(i * 2) + 1] = new BufferElement(new Vector2(d2, (float)((pathingCities[i + 1].Latitude / _scale) + _add.Y)), color); } PathBuffer?.Dispose(); PathBuffer = new VertexBuffer <BufferElement>(_paths, () => { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.VertexPointer(2, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0)); GL.ColorPointer(4, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector2.SizeInBytes)); }); _pathText.Text = _path.ToString(); }