Added some vars and funcs for testing. Added more fair fps counter and frame counter
This commit is contained in:
26
2DGAMELIB/_2DGAMELIB/FrameTimeCounter.cs
Normal file
26
2DGAMELIB/_2DGAMELIB/FrameTimeCounter.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace _2DGAMELIB
|
||||||
|
{
|
||||||
|
internal class FrameTimeCounter
|
||||||
|
{
|
||||||
|
private readonly Stopwatch sw = Stopwatch.StartNew();
|
||||||
|
private long lastTicks;
|
||||||
|
public double FrameMs { get; private set; }
|
||||||
|
|
||||||
|
public void Frame()
|
||||||
|
{
|
||||||
|
long now = sw.ElapsedTicks;
|
||||||
|
|
||||||
|
if (lastTicks != 0)
|
||||||
|
{
|
||||||
|
FrameMs = (now - lastTicks) * 1000.0 / Stopwatch.Frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastTicks = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -294,6 +294,10 @@ namespace _2DGAMELIB
|
|||||||
baseControl.SetTitle(UITitle);
|
baseControl.SetTitle(UITitle);
|
||||||
Modes[mode].Setting();
|
Modes[mode].Setting();
|
||||||
|
|
||||||
|
FrameTimeCounter FTC = new FrameTimeCounter();
|
||||||
|
RealFpsCounter RFC = new RealFpsCounter();
|
||||||
|
|
||||||
|
/*
|
||||||
Action action = delegate
|
Action action = delegate
|
||||||
{
|
{
|
||||||
if (FPSF.Value > 1.0)
|
if (FPSF.Value > 1.0)
|
||||||
@@ -311,6 +315,28 @@ namespace _2DGAMELIB
|
|||||||
baseControl.SetBitmap(Display);
|
baseControl.SetBitmap(Display);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Action action = () =>
|
||||||
|
{
|
||||||
|
if (FPSF.Value > 1.0)
|
||||||
|
Modes[mode].Draw(FPSF);
|
||||||
|
|
||||||
|
baseControl.SetBitmap(Display);
|
||||||
|
|
||||||
|
FTC.Frame();
|
||||||
|
RFC.Frame();
|
||||||
|
|
||||||
|
if (ShowFPS)
|
||||||
|
{
|
||||||
|
baseControl.SetTitle(
|
||||||
|
UITitle +
|
||||||
|
" - FPS: " + RFC.Value.ToString("F1") +
|
||||||
|
" | Frame: " + FTC.FrameMs.ToString("F2") + " ms"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
while (Drive)
|
while (Drive)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace _2DGAMELIB
|
namespace _2DGAMELIB
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,19 @@ namespace _2DGAMELIB
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class Par
|
public class Par
|
||||||
{
|
{
|
||||||
|
//FOR TESTS
|
||||||
|
public static long TCalc;
|
||||||
|
public static long TCalcH;
|
||||||
|
public static long TFill;
|
||||||
|
public static long TOutline;
|
||||||
|
public static long THitFill;
|
||||||
|
|
||||||
|
public static int NCalc;
|
||||||
|
public static int NCalcH;
|
||||||
|
public static int NFill;
|
||||||
|
public static int NOutline;
|
||||||
|
public static int NHitFill;
|
||||||
|
|
||||||
private Pars parent;
|
private Pars parent;
|
||||||
|
|
||||||
public string Tag = "";
|
public string Tag = "";
|
||||||
@@ -645,6 +659,10 @@ namespace _2DGAMELIB
|
|||||||
|
|
||||||
mv = Position * Unit - bp;
|
mv = Position * Unit - bp;
|
||||||
|
|
||||||
|
double a = System.Math.PI * Angle / 180.0;
|
||||||
|
M11 = System.Math.Cos(a);
|
||||||
|
M12 = System.Math.Sin(a);
|
||||||
|
|
||||||
Path.Reset();
|
Path.Reset();
|
||||||
OutlinePath.Reset();
|
OutlinePath.Reset();
|
||||||
foreach (Out item in op)
|
foreach (Out item in op)
|
||||||
@@ -654,7 +672,7 @@ namespace _2DGAMELIB
|
|||||||
{
|
{
|
||||||
p.X = item.ps[i].X * usx;
|
p.X = item.ps[i].X * usx;
|
||||||
p.Y = item.ps[i].Y * usy;
|
p.Y = item.ps[i].Y * usy;
|
||||||
p = Rotate(Angle, p) + mv;
|
p = Rotate(ref p) + mv;
|
||||||
|
|
||||||
points[i].X = (float)p.X;
|
points[i].X = (float)p.X;
|
||||||
points[i].Y = (float)p.Y;
|
points[i].Y = (float)p.Y;
|
||||||
@@ -677,11 +695,8 @@ namespace _2DGAMELIB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2D Rotate(double angle, Vector2D p)
|
private Vector2D Rotate(ref Vector2D p)
|
||||||
{
|
{
|
||||||
double M11 = System.Math.Cos(System.Math.PI * angle / 180.0);
|
|
||||||
double M12 = System.Math.Sin(System.Math.PI * angle / 180.0);
|
|
||||||
|
|
||||||
p.X -= bp.X;
|
p.X -= bp.X;
|
||||||
p.Y -= bp.Y;
|
p.Y -= bp.Y;
|
||||||
|
|
||||||
@@ -700,22 +715,34 @@ namespace _2DGAMELIB
|
|||||||
{
|
{
|
||||||
if (Edit)
|
if (Edit)
|
||||||
{
|
{
|
||||||
|
long t0 = Stopwatch.GetTimestamp();
|
||||||
Calculation(Unit);
|
Calculation(Unit);
|
||||||
|
TCalc += Stopwatch.GetTimestamp() - t0;
|
||||||
|
NCalc++;
|
||||||
Edit = false;
|
Edit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pen != null && (EditP || EditPS))
|
if (pen != null && (EditP || EditPS))
|
||||||
{
|
{
|
||||||
pen.Width = (float)(Unit * penWidth * positionSize);
|
pen.Width = (float)(Unit * penWidth * positionSize);
|
||||||
EditP = false;
|
EditP = false;
|
||||||
EditPS = false;
|
EditPS = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brush != null)
|
if (brush != null)
|
||||||
{
|
{
|
||||||
|
long t0 = Stopwatch.GetTimestamp();
|
||||||
Graphics.FillPath(brush, Path);
|
Graphics.FillPath(brush, Path);
|
||||||
|
TFill += Stopwatch.GetTimestamp() - t0;
|
||||||
|
NFill++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pen != null)
|
if (pen != null)
|
||||||
{
|
{
|
||||||
|
long t0 = Stopwatch.GetTimestamp();
|
||||||
Graphics.DrawPath(pen, OutlinePath);
|
Graphics.DrawPath(pen, OutlinePath);
|
||||||
|
TOutline += Stopwatch.GetTimestamp() - t0;
|
||||||
|
NOutline++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -792,10 +819,17 @@ namespace _2DGAMELIB
|
|||||||
{
|
{
|
||||||
if (EditH)
|
if (EditH)
|
||||||
{
|
{
|
||||||
|
long t0 = Stopwatch.GetTimestamp();
|
||||||
CalculationH(Unit);
|
CalculationH(Unit);
|
||||||
|
TCalcH += Stopwatch.GetTimestamp() - t0;
|
||||||
|
NCalcH++;
|
||||||
EditH = false;
|
EditH = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long t1 = Stopwatch.GetTimestamp();
|
||||||
Graphics.FillPath(HitBrush, gph);
|
Graphics.FillPath(HitBrush, gph);
|
||||||
|
THitFill += Stopwatch.GetTimestamp() - t1;
|
||||||
|
NHitFill++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
2DGAMELIB/_2DGAMELIB/RealFpsCounter.cs
Normal file
30
2DGAMELIB/_2DGAMELIB/RealFpsCounter.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace _2DGAMELIB
|
||||||
|
{
|
||||||
|
internal class RealFpsCounter
|
||||||
|
{
|
||||||
|
private readonly Stopwatch sw = Stopwatch.StartNew();
|
||||||
|
private int frames;
|
||||||
|
private long lastTicks;
|
||||||
|
public double Value { get; private set; }
|
||||||
|
|
||||||
|
public void Frame()
|
||||||
|
{
|
||||||
|
frames++;
|
||||||
|
|
||||||
|
long now = sw.ElapsedTicks;
|
||||||
|
long delta = now - lastTicks;
|
||||||
|
|
||||||
|
if (delta >= Stopwatch.Frequency)
|
||||||
|
{
|
||||||
|
Value = frames / (delta / (double)Stopwatch.Frequency);
|
||||||
|
frames = 0;
|
||||||
|
lastTicks = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ namespace _2DGAMELIB
|
|||||||
protected double displayUnitScale;
|
protected double displayUnitScale;
|
||||||
protected double hitUnitScale;
|
protected double hitUnitScale;
|
||||||
|
|
||||||
|
private int DrawCals = 0;
|
||||||
|
|
||||||
protected Size WH = System.Drawing.Size.Empty;
|
protected Size WH = System.Drawing.Size.Empty;
|
||||||
protected Size WHH = System.Drawing.Size.Empty;
|
protected Size WHH = System.Drawing.Size.Empty;
|
||||||
protected Size WHA = System.Drawing.Size.Empty;
|
protected Size WHA = System.Drawing.Size.Empty;
|
||||||
@@ -38,6 +40,7 @@ namespace _2DGAMELIB
|
|||||||
Setting(Unit, XRatio, YRatio, Size, DisMag, HitMag);
|
Setting(Unit, XRatio, YRatio, Size, DisMag, HitMag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RenderArea(ModeEventDispatcher Med, bool Hit)
|
public RenderArea(ModeEventDispatcher Med, bool Hit)
|
||||||
{
|
{
|
||||||
if (Hit)
|
if (Hit)
|
||||||
@@ -64,10 +67,11 @@ namespace _2DGAMELIB
|
|||||||
|
|
||||||
|
|
||||||
displayGraphics.SmoothingMode = SmoothingMode.None;
|
displayGraphics.SmoothingMode = SmoothingMode.None;
|
||||||
displayGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
|
displayGraphics.PixelOffsetMode = PixelOffsetMode.None;
|
||||||
displayGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
displayGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||||
//needed for text or smthn
|
//needed for text or smthn
|
||||||
displayGraphics.CompositingMode = CompositingMode.SourceOver;
|
displayGraphics.CompositingMode = CompositingMode.SourceOver;
|
||||||
|
displayGraphics.CompositingQuality = CompositingQuality.HighSpeed;
|
||||||
}
|
}
|
||||||
private void Setting(double Unit, double XRatio, double YRatio, double Size, double DisMag, double HitMag)
|
private void Setting(double Unit, double XRatio, double YRatio, double Size, double DisMag, double HitMag)
|
||||||
{
|
{
|
||||||
@@ -81,9 +85,10 @@ namespace _2DGAMELIB
|
|||||||
|
|
||||||
|
|
||||||
hitGraphics.SmoothingMode = SmoothingMode.None;
|
hitGraphics.SmoothingMode = SmoothingMode.None;
|
||||||
hitGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
|
hitGraphics.PixelOffsetMode = PixelOffsetMode.None;
|
||||||
hitGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
hitGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||||
hitGraphics.CompositingMode = CompositingMode.SourceOver;
|
hitGraphics.CompositingMode = CompositingMode.SourceOver;
|
||||||
|
hitGraphics.CompositingQuality = CompositingQuality.HighSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2D GetPosition()
|
public Vector2D GetPosition()
|
||||||
@@ -115,13 +120,22 @@ namespace _2DGAMELIB
|
|||||||
if (hitGraphics != null)
|
if (hitGraphics != null)
|
||||||
{
|
{
|
||||||
Pars.DrawH(hitUnitScale, hitGraphics);
|
Pars.DrawH(hitUnitScale, hitGraphics);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(RenderArea Are)
|
public void Draw(RenderArea Are)
|
||||||
{
|
{
|
||||||
Vector2D p = Are.GetPosition();
|
var p = Are.GetPosition();
|
||||||
DisplayGraphics.DrawImage(Are.DisplayLayer, (float)(p.X * Are.displayUnitScale), (float)(p.Y * Are.displayUnitScale), Are.WHA.Width, Are.WHA.Height);
|
int x = (int)(p.X * Are.displayUnitScale);
|
||||||
|
int y = (int)(p.Y * Are.displayUnitScale);
|
||||||
|
|
||||||
|
if (Are.DisplayLayer.Width == Are.WHA.Width && Are.DisplayLayer.Height == Are.WHA.Height)
|
||||||
|
DisplayGraphics.DrawImageUnscaled(Are.DisplayLayer, x, y);
|
||||||
|
else
|
||||||
|
DisplayGraphics.DrawImage(Are.DisplayLayer, x, y, Are.WHA.Width, Are.WHA.Height);
|
||||||
|
|
||||||
if (Are.hitGraphics != null && HitGraphics != null)
|
if (Are.hitGraphics != null && HitGraphics != null)
|
||||||
{
|
{
|
||||||
HitGraphics.DrawImage(Are.HitLayer, (int)(p.X * Are.hitUnitScale), (int)(p.Y * Are.hitUnitScale), Are.WHH.Width, Are.WHH.Height);
|
HitGraphics.DrawImage(Are.HitLayer, (int)(p.X * Are.hitUnitScale), (int)(p.Y * Are.hitUnitScale), Are.WHH.Width, Are.WHH.Height);
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ namespace _2DGAMELIB
|
|||||||
Glfw.SetWindowUserPointer(window, GCHandle.ToIntPtr(handle));
|
Glfw.SetWindowUserPointer(window, GCHandle.ToIntPtr(handle));
|
||||||
|
|
||||||
Glfw.MakeContextCurrent(window);
|
Glfw.MakeContextCurrent(window);
|
||||||
|
Glfw.SwapInterval(0);
|
||||||
gl = Silk.NET.OpenGL.GL.GetApi(Glfw.GetProcAddress);
|
gl = Silk.NET.OpenGL.GL.GetApi(Glfw.GetProcAddress);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user