daily update on 20231214 by nitload youmu
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using StgSharp;
|
||||
using StgSharp.Logic;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
@@ -6,13 +7,63 @@ 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.glfw.GetTime() - 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
|
||||
{
|
||||
private Form timeProvider;
|
||||
internal readonly uint bornTick;
|
||||
private Form timeProvider;
|
||||
|
||||
public FrameTimer(Form provaider)
|
||||
{
|
||||
timeProvider = provaider;
|
||||
bornTick = timeProvider.timer.totalFrame;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Frames after this timer created.
|
||||
@@ -22,12 +73,6 @@ namespace StgSharp.Graphics
|
||||
get { return timeProvider.timer.totalFrame - bornTick; }
|
||||
}
|
||||
|
||||
public FrameTimer(Form provaider)
|
||||
{
|
||||
timeProvider = provaider;
|
||||
bornTick = timeProvider.timer.totalFrame;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a <see cref="FrameTimer"/> into uint value.
|
||||
/// this will get total frames since the timer was created.
|
||||
@@ -39,94 +84,4 @@ namespace StgSharp.Graphics
|
||||
return timer.Time;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Form
|
||||
{
|
||||
|
||||
internal class FrameUpdateTimer
|
||||
{
|
||||
private Counter<uint> tickCounter;
|
||||
private float frameLength;
|
||||
private double frameTime;
|
||||
private bool refreshed;
|
||||
private SemaphoreSlim pong;
|
||||
private bool isOnceFulFrame = false;
|
||||
|
||||
public uint totalFrame
|
||||
{
|
||||
get { return tickCounter; }
|
||||
}
|
||||
|
||||
public double timeAfterFrame
|
||||
{
|
||||
get { return InternalIO.glfw.GetTime() - frameTime; }
|
||||
}
|
||||
|
||||
internal bool IsOnceFullFrame
|
||||
{
|
||||
get { return isOnceFulFrame; }
|
||||
set
|
||||
{
|
||||
if (!isOnceFulFrame)
|
||||
{
|
||||
isOnceFulFrame = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Init(SemaphoreSlim semaphore)
|
||||
{
|
||||
pong = semaphore;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
refreshed = false;
|
||||
}
|
||||
|
||||
internal bool GoNextFrame()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (refreshed) { }
|
||||
refreshed = true;
|
||||
return refreshed;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isFullyRendered = false;
|
||||
|
||||
/// <summary>
|
||||
/// Wait until the next frame of a certain <see cref="Form"/> started,
|
||||
/// all GL function after this method will be blocked until the next frame started.
|
||||
/// When a frame refreshed before
|
||||
/// It should be noticed that do not use this method too often to avoid unexpected performance problem
|
||||
/// </summary>
|
||||
/// <param name="form">The <see cref="Form"/> that can provide a frame refresh benchmark</param>
|
||||
/// <param name="action"><see cref="Action"/> to be done and aligned.</param>
|
||||
/// <returns>
|
||||
/// A bool value indicating if the <see cref="Form"/> successfully refresh the frame.
|
||||
/// If the retur value is false, please set a new <see cref="Form"/> as benchmark.
|
||||
/// </returns>
|
||||
protected bool AlignFrame(Form form, Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isAligned = form.timer.GoNextFrame();
|
||||
action();
|
||||
return isAligned;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user