public override void Draw(IDrawingGraphics drawingGraphics) { if (drawingGraphics == null) return; if ((_needRepaint) && (!FreezeUpdate)) { var newbuffer = CreateBuffer(); RepaintBuffer(newbuffer); _buffer = newbuffer; _needRepaint = false; } // buffer may be null when staring if (_buffer != null) DrawBuffer(drawingGraphics); }
public LexicalAnalyzer(ITextSource source) { _source = source ?? throw new ArgumentNullException("source"); _reader = _source.CreateReader(); _buffer = new DoubleBuffer(_reader); }
public void DoAll() { "多线程随机延迟一边加入元素一边执行,可以执行所有元素".Test(() => { var mock = new Mock <IFoo>(); mock.Setup(foo => foo.Foo()); var random = new Random(); const int n = 100; var doubleBuffer = new DoubleBuffer <IFoo>(); var t1 = Task.Run(async() => { for (int i = 0; i < n; i++) { doubleBuffer.Add(mock.Object); await Task.Delay(random.Next(100)); } }); var t2 = Task.Run(async() => { await Task.Delay(300); await doubleBuffer.DoAllAsync(async list => { foreach (var foo in list) { await Task.Delay(random.Next(50)); foo.Foo(); } }); }); Task.WaitAll(t1, t2); doubleBuffer.DoAllAsync(async list => { foreach (var foo in list) { await Task.Delay(random.Next(50)); foo.Foo(); } }).Wait(); mock.Verify(foo => foo.Foo(), Times.Exactly(n)); }); "多线程一边加入元素一边执行,可以执行所有元素".Test(() => { var mock = new Mock <IFoo>(); mock.Setup(foo => foo.Foo()); const int n = 10000; var doubleBuffer = new DoubleBuffer <IFoo>(); for (int i = 0; i < n; i++) { doubleBuffer.Add(mock.Object); } var t1 = Task.Run(() => { for (int i = 0; i < n; i++) { doubleBuffer.Add(mock.Object); } }); var t2 = Task.Run(() => { doubleBuffer.DoAll(list => list.ForEach(foo => foo.Foo())); }); Task.WaitAll(t1, t2); // 没有执行一次 mock.Verify(foo => foo.Foo(), Times.Exactly(n * 2)); }); "给定10次元素,执行 DoAll 元素执行10次".Test(() => { var mock = new Mock <IFoo>(); mock.Setup(foo => foo.Foo()); const int n = 10; var doubleBuffer = new DoubleBuffer <IFoo>(); for (int i = 0; i < n; i++) { doubleBuffer.Add(mock.Object); } doubleBuffer.DoAll(list => list.ForEach(foo => foo.Foo())); // 没有执行一次 mock.Verify(foo => foo.Foo(), Times.Exactly(n)); }); "没有给定缓存内容,执行 DoAll 啥都不做".Test(() => { var mock = new Mock <IFoo>(); mock.Setup(foo => foo.Foo()); var doubleBuffer = new DoubleBuffer <IFoo>(); doubleBuffer.DoAll(list => list.ForEach(foo => foo.Foo())); // 没有执行一次 mock.Verify(foo => foo.Foo(), Times.Never); }); }
private void DisposeBackBuffer () { if (backbuffer != null) { backbuffer.Dispose (); backbuffer = null; } }
private DoubleBuffer GetBackBuffer () { if (backbuffer == null) backbuffer = new DoubleBuffer (this); return backbuffer; }
// Create the buffer object for the widget. private void CreateBuffer(int width, int height) { DeleteBuffer(); buffer = new DoubleBuffer(widget); }
public override DoubleBuffer put(DoubleBuffer prm1) { return(default(DoubleBuffer)); }
private void RepaintBuffer(DoubleBuffer buffer) { if (buffer == null) return; ClearBuffer(buffer, new Rectangle(0, 0, buffer.Image.Width, buffer.Image.Height)); Children .ToList() .ForEach(element => { //!! todo не порождать дочерние графики рисовать прямо на одном //_buffer.DrawingGraphics.MoveRel(e.Location.X, e.Location.Y); //e.Draw(_buffer.DrawingGraphics); //_buffer.DrawingGraphics.MoveRel(- e.Location.X, - e.Location.Y); element.Draw(buffer.DrawingGraphics.CreateChild(element.Location, element.TransformationScaling, element.TransformationCenter)); }); }
private static DoubleBuffer createRoundedRectangleWithLeaderBuffer(double width, double height, Point leaderOffset, double leaderGapWidth, int cornerRadius, DoubleBuffer buffer) { int numVertices = 12 + (cornerRadius < 1 ? 0 : 4 * (cornerSteps - 2)); buffer = allocateVertexBuffer(numVertices, buffer); int idx = 0; // Drawing counter clockwise from right leader connection at the bottom // so as to accommodate GL_TRIANGLE_FAN and GL_LINE_STRIP (inside and border) // Bottom right buffer.put(idx++, width / 2 + leaderGapWidth / 2); buffer.put(idx++, 0d); buffer.put(idx++, width - cornerRadius); buffer.put(idx++, 0d); idx = drawCorner(width - cornerRadius, cornerRadius, cornerRadius, -Math.PI / 2, 0, cornerSteps, buffer, idx); // Right buffer.put(idx++, width); buffer.put(idx++, (double)cornerRadius); buffer.put(idx++, width); buffer.put(idx++, height - cornerRadius); idx = drawCorner(width - cornerRadius, height - cornerRadius, cornerRadius, 0, Math.PI / 2, cornerSteps, buffer, idx); // Top buffer.put(idx++, width - cornerRadius); buffer.put(idx++, height); buffer.put(idx++, (double)cornerRadius); buffer.put(idx++, height); idx = drawCorner(cornerRadius, height - cornerRadius, cornerRadius, Math.PI / 2, Math.PI, cornerSteps, buffer, idx); // Left buffer.put(idx++, 0d); buffer.put(idx++, height - cornerRadius); buffer.put(idx++, 0d); buffer.put(idx++, (double)cornerRadius); idx = drawCorner(cornerRadius, cornerRadius, cornerRadius, Math.PI, Math.PI * 1.5, cornerSteps, buffer, idx); // Bottom left buffer.put(idx++, (double)cornerRadius); buffer.put(idx++, 0d); buffer.put(idx++, width / 2 - leaderGapWidth / 2); buffer.put(idx++, 0d); // Draw leader buffer.put(idx++, leaderOffset.x); buffer.put(idx++, leaderOffset.y); buffer.put(idx++, width / 2 + leaderGapWidth / 2); buffer.put(idx++, 0d); buffer.limit(idx); return(buffer); }
/** * Draw a vertex buffer with texture coordinates in a given gl mode. Vertex buffers coming from the * createShapeBuffer() methods support both <code>GL.GL_TRIANGLE_FAN</code> and <code>GL.LINE_STRIP</code>. * * @param dc the current DrawContext. * @param mode the desired drawing GL mode. * @param count the number of vertices to draw. * @param verts the vertex buffer to draw. * @param coords the buffer containing the shape texture coordinates. */ public static void drawBuffer(DrawContext dc, int mode, int count, DoubleBuffer verts, DoubleBuffer coords) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (verts == null || coords == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. // Set up gl.glPushClientAttrib(GL2.GL_CLIENT_VERTEX_ARRAY_BIT); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(2, GL2.GL_DOUBLE, 0, verts); gl.glTexCoordPointer(2, GL2.GL_DOUBLE, 0, coords); // Draw gl.glDrawArrays(mode, 0, count); // Restore gl.glPopClientAttrib(); }
/** * Create a vertex buffer for a shape with the specified width, height and corner radius. The shape includes a * leader triangle pointing to a specified point. Corner radius only apply to <code>SHAPE_RECTANGLE</code> - set to * zero for square corners. * * @param shape the shape - can be one of <code>SHAPE_RECTANGLE</code> or <code>SHAPE_ELLIPSE</code>. * @param width the width of the overall shape. * @param height the height of the shape excluding the leader. * @param leaderOffset the coordinates of the point to which the leader leads. * @param leaderGapWidth the starting width of the leader shape. * @param cornerRadius the rounded corners radius. Set to zero for square corners. * @param buffer the buffer to store shape vertices, or null to allocate a new buffer. * * @return the vertex buffer. */ public static DoubleBuffer createShapeWithLeaderBuffer(String shape, double width, double height, Point leaderOffset, double leaderGapWidth, int cornerRadius, DoubleBuffer buffer) { if (shape.Equals(AVKey.SHAPE_RECTANGLE)) { return(createRoundedRectangleWithLeaderBuffer(width, height, leaderOffset, leaderGapWidth, cornerRadius, buffer)); } else if (shape.Equals(AVKey.SHAPE_ELLIPSE)) { return(createEllipseWithLeaderBuffer(width, height, leaderOffset, leaderGapWidth, circleSteps, buffer)); } else if (shape.Equals(AVKey.SHAPE_NONE)) { return(null); } else { // default to rectangle if shape unknown return(createRoundedRectangleWithLeaderBuffer(width, height, leaderOffset, leaderGapWidth, cornerRadius, buffer)); } }
public LocalLog() { mLogBufferList = new DoubleBuffer <string>(); mWriteLogThread = new CustomThread("WriteLocalLog"); mLogFilePath = CommonDefine.F_ASSETS_PATH + "log.txt"; }
public override void Setup(ScriptableRenderContext context, ref MyRenderingData renderingData) { if (needUpdate) { if (!computeShader || !material || !mesh) { return; } if (boidBuffer != null) { boidBuffer.Current.Release(); boidBuffer.Next.Release(); } if (argsBuffer != null) { argsBuffer.Release(); } boidBuffer = new DoubleBuffer <ComputeBuffer>((i) => new ComputeBuffer(count, EntityData.Size)); var data = new EntityData[count]; for (var i = 0; i < count; i++) { data[i] = new EntityData() { position = Random.insideUnitSphere * distributeRadius + spawnPoint.position, velocity = Random.insideUnitSphere, }; data[i].velocity = data[i].velocity.normalized * (data[i].velocity.magnitude * (maxSpeed - minSpeed) + minSpeed); var up = Random.onUnitSphere; var right = Vector3.Cross(data[i].velocity, up); if (Mathf.Approximately(right.magnitude, 0)) { var v = data[i].velocity; float x = Mathf.Abs(v.x); float y = Mathf.Abs(v.y); float z = Mathf.Abs(v.z); if (x < y && x < z) { right = Vector3.right; } else if (y < x && y < z) { right = Vector3.up; } else { right = Vector3.forward; } } up = Vector3.Cross(right, data[i].velocity); data[i].up = up.normalized; } boidBuffer.Current.SetData(data); boidBuffer.Next.SetData(data); //要绘制多少个实例的参数来自bufferWithArgs //Buffer with arguments, bufferWithArgs, has to have five integer numbers at given argsOffset offset: index count per instance, instance count, start index location, base vertex location, start instance location. //2是 ebo 3 是 vbo //带参数的bufferWithArgs,在给定的argsOffset偏移量处必须有五个整数:每个实例的索引计数、实例计数、起始索引位置、基顶点位置、开始实例的偏移。 args[0] = mesh.GetIndexCount(0); args[1] = (uint)count; args[2] = mesh.GetIndexStart(0); args[3] = mesh.GetBaseVertex(0); argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments); argsBuffer.SetData(args); needUpdate = false; } }
public FastRenderer(Game game) { this.game = game; this.buffer = DoubleBuffer.GetInstance(); }
private void ClearBuffer(DoubleBuffer buffer, Rectangle rect) { buffer.Graphics.FillRectangle(new SolidBrush(MetroTheme.PhoneBackgroundBrush), rect); }
private DoubleBuffer CreateBuffer() { // create new buffer with new size var buffer = new DoubleBuffer(Size); _needRepaint = true; return buffer; }
//-- Circle / Ellipse ----------------------------------------------------------- private static DoubleBuffer createEllipseBuffer(double width, double height, int steps, DoubleBuffer buffer) { int numVertices = steps + 1; buffer = allocateVertexBuffer(numVertices, buffer); // Drawing counter clockwise from bottom-left double halfWidth = width / 2; double halfHeight = height / 2; double halfPI = Math.PI / 2; double x0 = halfWidth; double y0 = halfHeight; double step = Math.PI * 2 / steps; int idx = 0; for (int i = 0; i <= steps; i++) { double a = step * i - halfPI; double x = x0 + Math.Cos(a) * halfWidth; double y = y0 + Math.Sin(a) * halfHeight; buffer.put(idx++, x); buffer.put(idx++, y); } buffer.limit(idx); return(buffer); }
private static DoubleBuffer createEllipseWithLeaderBuffer(double width, double height, Point leaderOffset, double leaderGapWidth, int steps, DoubleBuffer buffer) { int numVertices = steps + 3; buffer = allocateVertexBuffer(numVertices, buffer); // Drawing counter clockwise from right leader connection at the bottom // so as to accomodate GL_TRIANGLE_FAN and GL_LINE_STRIP (inside and border) double halfWidth = width / 2; double halfHeight = height / 2; double halfPI = Math.PI / 2; double x0 = halfWidth; double y0 = halfHeight; double step = Math.PI * 2 / steps; double halfGap = leaderGapWidth / 2 / halfWidth; int idx = 0; for (int i = 0; i <= steps; i++) { double a = step * i - halfPI; if (i == 0) { a += halfGap; } if (i == steps) { a -= halfGap; } double x = x0 + Math.Cos(a) * halfWidth; double y = y0 + Math.Sin(a) * halfHeight; buffer.put(idx++, x); buffer.put(idx++, y); } // Draw leader buffer.put(idx++, leaderOffset.x); buffer.put(idx++, leaderOffset.y); buffer.put(idx++, x0 + Math.Cos(halfGap - halfPI) * halfWidth); buffer.put(idx++, y0 + Math.Sin(halfGap - halfPI) * halfHeight); buffer.limit(idx); return(buffer); }
public override DoubleBuffer Put(DoubleBuffer buffer) { throw new ReadOnlyBufferException(); }
public static void Encrypt(string EncryptedFilePath, Key key) { string EFName = Path.GetFileNameWithoutExtension(EncryptedFilePath); string EFNameExt = Path.GetFileName(EncryptedFilePath); string EFNameDir = Path.GetDirectoryName(EncryptedFilePath); File.Copy(EncryptedFilePath, temp + @"\" + EFName + "def.sketemp", true); string PreviousFilePath = temp + @"\" + EFName + "def.sketemp"; string CurrentFilePath = null; CurrentFilePath = temp + @"\" + EFName + "enc.sketemp"; FileStream Previous = new FileStream(PreviousFilePath, FileMode.Open); FileStream Current = new FileStream(CurrentFilePath, FileMode.Create); FileInfo PreviousFile = new FileInfo(PreviousFilePath); FileInfo CurrentFile = new FileInfo(CurrentFilePath); Current.SetLength(PreviousFile.Length); long Pos = key.Start; DoubleBuffer db = null; for (long o = 0; o < PreviousFile.Length; o++) { Pos = Misc.Mod(Pos, PreviousFile.Length); if (o % 67108864 == 0) { } //Previous.Seek(Pos, SeekOrigin.Begin); //int First = Previous.ReadByte(); /*int Second; * long SPos = Misc.Mod((BigInteger)Pos - key.Start, PreviousFile.Length); * long SJump = Misc.Mod((BigInteger)Pos + key.Jump - key.Start, PreviousFile.Length); * if (SJump >= SPos) * { * //Previous.Seek(Misc.Mod((BigInteger)Pos + key.Jump, PreviousFile.Length), SeekOrigin.Begin); * //Second = Previous.ReadByte(); * } * else * { * //Current.Seek(Misc.Mod((BigInteger)Pos + key.Jump, PreviousFile.Length), SeekOrigin.Begin); * //Second = Current.ReadByte(); * }*/ int First = db.Get(Pos); int Second = db.Get(Misc.Mod((BigInteger)Pos + key.Jump, PreviousFile.Length)); byte New; byte[] Operations = new byte[8]; byte[] Multipliers = new byte[8]; for (int p = 0; p < 8; p++) { Operations[p] = Convert.ToByte(key.Operations.ToString("X").Split(2)[p], 16); } for (int p = 0; p < 8; p++) { Multipliers[p] = Convert.ToByte(key.Multipliers.ToString("X").Split(2)[p], 16); } if (new BitArray(Operations).Get((int)(o % 64))) { New = (byte)Misc.Mod(First + (Second * Multipliers[o % 8] + 5), 256); } else { New = (byte)Misc.Mod(First - (Second * Multipliers[o % 8] + 5), 256); } /*Current.Seek(Pos, SeekOrigin.Begin); * Current.WriteByte(New);*/ db.Set(Pos, New); Pos++; } Previous.Close(); Current.Close(); File.Delete(PreviousFilePath); PreviousFilePath = CurrentFilePath; File.Copy(PreviousFilePath, EFNameDir + "\\" + EFNameExt + ".ske", true); }
public void init() { myDoubleBuffer = new DoubleBuffer(this); BackImage = new Bitmap(@"media/graphic/field.png"); }