88 lines
2.2 KiB
C#
88 lines
2.2 KiB
C#
using StgSharp;
|
|
using StgSharp.Logic;
|
|
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
public partial class Form
|
|
{
|
|
private bool isFullyRendered = false;
|
|
|
|
internal class FrameUpdateTimer
|
|
{
|
|
internal Bool2 alignSign;
|
|
private float frameLength;
|
|
private double frameBegin;
|
|
private bool refreshed;
|
|
private Counter<uint> tickCounter;
|
|
|
|
public double timeAfterFrame
|
|
{
|
|
get { return InternalIO.glfwGetTime() - frameBegin; }
|
|
}
|
|
|
|
public uint totalFrame
|
|
{
|
|
get { return tickCounter; }
|
|
}
|
|
|
|
internal void Refresh()
|
|
{
|
|
refreshed = false;
|
|
}
|
|
|
|
internal bool WaitNextFrame()
|
|
{
|
|
try
|
|
{
|
|
while (refreshed) { }
|
|
refreshed = true;
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A timer counting frames after its construction.
|
|
/// </summary>
|
|
public class FrameTimer
|
|
{
|
|
internal readonly uint bornTick;
|
|
private Form timeProvider;
|
|
|
|
public FrameTimer(Form provaider)
|
|
{
|
|
timeProvider = provaider;
|
|
bornTick = timeProvider.timer.totalFrame;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Frames after this timer created.
|
|
/// </summary>
|
|
public uint Time
|
|
{
|
|
get { return timeProvider.timer.totalFrame - bornTick; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a <see cref="FrameTimer"/> into uint value.
|
|
/// this will get total frames since the timer was created.
|
|
/// </summary>
|
|
/// <param name="timer"><see cref="FrameTimer"/> to be converted</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static implicit operator uint(FrameTimer timer)
|
|
{
|
|
return timer.Time;
|
|
}
|
|
}
|
|
} |