FrameRateTask 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package FrameRateTask --version 1.1.2
                    
NuGet\Install-Package FrameRateTask -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FrameRateTask" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FrameRateTask" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="FrameRateTask" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FrameRateTask --version 1.1.2
                    
#r "nuget: FrameRateTask, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FrameRateTask@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FrameRateTask&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=FrameRateTask&version=1.1.2
                    
Install as a Cake Tool

FrameRateTask


Languages

English
中文(简体)

Introduction

FrameRateTask, a frame rate stabilizer, a task executor which executes tasks at a stable frame rate.

This project intends to build an engine to support executing tasks which need to be executed repeatedly and frequently in a single thread, and the time interval between two execution needs to be accurately stable. And this engine can also provide the real-time frame rate. Up to now, this time interval should be no more than 1 second. It can be used to control the frame rate of a game, or communication through network, etc.

The source code is in the project FrameRateTask, and the example of usage is in the project Test.

This project is initially written for THUAI4 to support some functions.

Get This Package

To get this package, please enter the nuget package page: https://www.nuget.org/packages/FrameRateTask/

or use .NET CLI:

$ dotnet add package FrameRateTask

Author

Autor: Timothy-LiuXuefeng

Copyright (C) 2022 Timothy-LiuXuefeng

LICENSE

MIT license

Interfaces

CSharp

class FrameRateTaskExecutor<TResult>

TResult: The return value of the task.

  • Constructor:

    • FrameRateTaskExecutor(Func<bool> loopCondition, Func<bool> loopToDo, long timeInterval, Func<TResult> finallyReturn, long maxTotalDuration = long.MaxValue)

      If the object is constructed by this constructor, when calling its the Start or TryStart method, the program behaves as below:

      while (loopCondition && time <= maxTotalDuration)
      {
      if (!loopToDo()) break;
      /* Do something to delay until next frame comes. */
      }
      return finallyReturn;
      
      • loopCondition: The condition to judge if the loop will continue.
      • loopToDo: The loop body. If it returns false, jump out of the loop.
      • timeInterval: Time interval between two executing in milliseconds.
      • finallyReturn: Specify the last thing to do and the return value.
      • maxTotalDuration:The maximum time in total for this task in milliseconds, long.MaxValue for default.
    • FrameRateTaskExecutor(Func<bool> loopCondition, Action loopToDo, long timeInterval, Func<TResult> finallyReturn, long maxTotalDuration = long.MaxValue)

      The only thing different from the last constructor is that loopToDo has no return value so that you cannot jump out of the loop through loopToDo.

  • public void Start()

    Start executing the task. If the task has started, it will throw Timothy.FrameRateTask.TaskStartedMoreThanOnceException. Otherwise, it will execute the task and return after the task finishes.

  • public bool TryStart()

    Try to start executing the task. If the task has started, it will return false. Otherwise, it will execute the task and return true after the task finishes.

  • public uint FrameRate { get; }

    The real-time frame rate, initialized with the expected frame rate, and will be changed when the execution of the task.

  • public bool Finished { get; }

    Whether the task has finished.

  • public bool HasExecuted { get; }

    Whether the task has begun to execute.

  • public TResult Result { get; }

    The return value of the task. If the task has not finished, it will throw Timothy.FrameRateTask.TaskNotFinishedException.

  • public bool AllowTimeExceed { get; init; }

    Whether the engine allows time exceeding, true for default. See more details under MaxTolerantTimeExceedCount.

  • public Action<bool> TimeExceedAction { get; init; }

    It will be called when time exceeds. See more details under MaxTolerantTimeExceedCount.

  • public ulong MaxTolerantTimeExceedCount { get; init; }

    The maximum number of time exceeding in a series, 5 for default. Once time exceeds, if the number of time exceeding in a series is no more than MaxTolerantTimeExceedCount, TimeExceedAction will be called with argument false。Otherwise, if AllowTimeExceed is set true, TimeExceedAction will be called with argument true, otherwise, that is, AllowTimeExceed is set false, it will throw Timothy.FrameRateTask.TimeExceedException.

    Once more than MaxTolerantTimeExceedCount, it will automatically abandon unfinished loops, and reset the loop counter. There is an example about this, which is the Demo5 method in the project Test.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 18,973 12/4/2022
1.1.2 686 7/18/2022
1.1.1 1,148 3/27/2022
1.1.0 588 3/25/2022
1.0.0 758 3/7/2022 1.0.0 is deprecated because it has critical bugs.