Skip to content

Commit 6c65569

Browse files
Merge pull request #37 from Timothy-Liuxf/master
publish: version v1.1.2
2 parents 716da9b + 84028ad commit 6c65569

File tree

7 files changed

+185
-86
lines changed

7 files changed

+185
-86
lines changed

CSharp/FrameRateTask/Exceptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Timothy.FrameRateTask
1414
{
1515
/// <summary>
16-
/// This exception will be throwed when the task hasn't finished but is asked to get the return value.
16+
/// This exception will be thrown when the user gets the return value without the task finished.
1717
/// </summary>
1818
public class TaskNotFinishedException : Exception
1919
{
@@ -22,7 +22,7 @@ public class TaskNotFinishedException : Exception
2222
}
2323

2424
/// <summary>
25-
/// This exception will be throwed when the time interval specified is invalid.
25+
/// This exception will be thrown when the time interval specified is invalid.
2626
/// </summary>
2727
public class IllegalTimeIntervalException : Exception
2828
{
@@ -31,7 +31,7 @@ public class IllegalTimeIntervalException : Exception
3131
}
3232

3333
/// <summary>
34-
/// This exception will be throwed when time exceeds but time exceeding is not allowed.
34+
/// This exception will be thrown when time exceeds but time exceeding is not allowed.
3535
/// </summary>
3636
public class TimeExceedException : Exception
3737
{
@@ -40,12 +40,12 @@ public class TimeExceedException : Exception
4040
}
4141

4242
/// <summary>
43-
/// This exception will be throwed when the task has been started but is asked to be started again.
43+
/// This exception will be thrown when the user trys to start a task which has started.
4444
/// </summary>
4545
public class TaskStartedMoreThanOnceException : Exception
4646
{
4747
///
48-
public override string Message => "The task has been started more than once!";
48+
public override string Message => "The task has started more than once!";
4949
}
5050

5151
}

CSharp/FrameRateTask/FrameRateTask.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ namespace Timothy.FrameRateTask
1515
{
1616

1717
/// <summary>
18-
/// The class intends to execute a task that need to be executed repeatedly every less than one second and need to be accurate.
18+
/// The class intends to execute a task which needs to be executed repeatedly every less than one second accurately.
1919
/// </summary>
2020
/// <typeparam name="TResult">The type of the return value of the task.</typeparam>
2121
public class FrameRateTaskExecutor<TResult>
2222
{
2323
/// <summary>
24-
/// The actual framerate recently.
24+
/// The current actual frame rate.
2525
/// </summary>
2626
public uint FrameRate
2727
{
@@ -62,7 +62,7 @@ private bool TrySetExecute()
6262

6363
private TResult result;
6464
/// <summary>
65-
/// Get the return value of this task.
65+
/// Get the return value of the task.
6666
/// </summary>
6767
/// <exception cref="TaskNotFinishedException">
6868
/// The task hasn't finished.
@@ -81,7 +81,7 @@ public TResult Result
8181
/// Gets or sets whether it allows time exceeding.
8282
/// </summary>
8383
/// <remarks>
84-
/// If this property is false, the task will throw a TimeExceed exception when the task cannot finish in the given time.
84+
/// If it is set false, the task will throw Timothy.FrameRateTask.TimeExceedException when the task cannot finish in the given time.
8585
/// The default value is true.
8686
/// </remarks>
8787
public bool AllowTimeExceed
@@ -95,10 +95,10 @@ public bool AllowTimeExceed
9595
} = true;
9696

9797
/// <summary>
98-
/// It will be called once time exceeds if AllowTimeExceed is set true.
98+
/// It will be called once time exceeds.
9999
/// </summary>
100100
/// <remarks>
101-
/// parameter bool: If it is called because of the number of time exceeding is greater than MaxTimeExceedCount, the argument is true; if it is called because of exceeding once, the argument is false.
101+
/// parameter bool: If it is called because of the number of time exceeding is greater than MaxTolerantTimeExceedCount, the argument is true; if it is called because of exceeding once, the argument is false.
102102
/// </remarks>
103103
public Action<bool> TimeExceedAction
104104
{
@@ -130,7 +130,7 @@ public ulong MaxTolerantTimeExceedCount
130130
/// Start this task synchronously.
131131
/// </summary>
132132
/// <exception cref="TaskStartedMoreThanOnceException">
133-
/// the task has been started.
133+
/// the task has started.
134134
/// </exception>
135135
public void Start()
136136
{
@@ -140,7 +140,7 @@ public void Start()
140140
/// Try to start this task synchronously.
141141
/// </summary>
142142
/// <returns>
143-
/// true if the task is started successfully; false if the task has been started.
143+
/// true if the task starts successfully; false if the task has started.
144144
/// </returns>
145145
public bool TryStart()
146146
{
@@ -154,11 +154,11 @@ public bool TryStart()
154154
/// <summary>
155155
/// Constructor
156156
/// </summary>
157-
/// <param name="loopCondition">If you want to continue to loop, return true; otherwise return false.</param>
157+
/// <param name="loopCondition">If you want to continue to loop, return true; otherwise, return false.</param>
158158
/// <param name="loopToDo">If you want to break out, return false; otherwise, return true.</param>
159-
/// <param name="timeInterval"></param>
160-
/// <param name="finallyReturn">The return value. It will be called after the loop.</param>
161-
/// <param name="maxTotalDuration">The maximum time for the loop to execute.</param>
159+
/// <param name="timeInterval">The time interval between two execution.</param>
160+
/// <param name="finallyReturn">Used to set the return value. It will be called after the loop.</param>
161+
/// <param name="maxTotalDuration">The maximum time for the loop to run.</param>
162162
public FrameRateTaskExecutor
163163
(
164164
Func<bool> loopCondition,
@@ -235,11 +235,11 @@ public FrameRateTaskExecutor
235235
/// <summary>
236236
/// Constructor
237237
/// </summary>
238-
/// <param name="loopCondition">If you want to continue to loop, return true; otherwise return false.</param>
238+
/// <param name="loopCondition">If you want to continue to loop, return true; otherwise, return false.</param>
239239
/// <param name="loopToDo">Loop to do.</param>
240-
/// <param name="timeInterval"></param>
241-
/// <param name="finallyReturn">The return value. It will be called after the loop.</param>
242-
/// <param name="maxTotalDuration">The maximum time for the loop to execute.</param>
240+
/// <param name="timeInterval">The time interval between two execution.</param>
241+
/// <param name="finallyReturn">Used to set the return value. It will be called after the loop.</param>
242+
/// <param name="maxTotalDuration">The maximum time for the loop to run.</param>
243243
public FrameRateTaskExecutor
244244
(
245245
Func<bool> loopCondition,

CSharp/FrameRateTask/FrameRateTask.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
5-
<FileVersion>1.1.1.0</FileVersion>
6-
<AssemblyVersion>1.1.1.0</AssemblyVersion>
7-
<VersionPrefix>1.1.1</VersionPrefix>
8-
<RepositoryUrl>https://github.com/Timothy-LiuXuefeng/FrameRateTask</RepositoryUrl>
5+
<FileVersion>1.1.2.0</FileVersion>
6+
<AssemblyVersion>1.1.2.0</AssemblyVersion>
7+
<VersionPrefix>1.1.2</VersionPrefix>
8+
<RepositoryUrl>https://github.com/Timothy-Liuxf/FrameRateTask</RepositoryUrl>
99
<PackageReadmeFile>README.md</PackageReadmeFile>
10-
<Authors>TimothyLiuXuefeng</Authors>
10+
<Authors>Timothy Liu</Authors>
1111
<Company>$(Authors)</Company>
1212
<Copyright>Copyright (C) 2022</Copyright>
1313
<RepositoryType>git</RepositoryType>
1414
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1515
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
16-
<PackageProjectUrl>https://github.com/Timothy-LiuXuefeng/FrameRateTask</PackageProjectUrl>
16+
<PackageProjectUrl>https://timothy-liuxf.github.io/FrameRateTask</PackageProjectUrl>
1717
<Nullable>disable</Nullable>
1818
<Description>Frame rate stabilizer, a task executor which executes tasks at a stable frame rate.</Description>
1919
</PropertyGroup>

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright © 2022 Timothy-LiuXuefeng
1+
Copyright © 2022 Timothy Liu
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

README.md

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,41 @@
22

33
---
44

5-
## Introduction
6-
7-
Frame rate stabilizer, a task executor which executes tasks at a stable frame rate.
5+
## Languages
86

9-
This project intends to build an engine to support to execute tasks which need to be execute repeatedly and frequently, and the time interval between two executing need 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 framerate of a game, and control the frame rate of communication through network, etc.
7+
[English](https://github.com/Timothy-LiuXuefeng/FrameRateTask/blob/master/README.md)
8+
[中文(简体)](https://github.com/Timothy-LiuXuefeng/FrameRateTask/blob/master/README.zh-CN.md)
109

11-
The source code of the dll is in the project FrameRateTask, and the example of usage is in the project Test.
10+
## Introduction
1211

13-
This project is initially written for [THUAI4](https://github.com/eesast/THUAI4) to support some functions.
12+
`FrameRateTask`, a frame rate stabilizer, a task executor which executes tasks at a stable frame rate.
1413

15-
> 帧率稳定器——以固定帧率执行任务。
16-
>
17-
> 本项目旨在构建一个可以重复、高频率执行一个任务的引擎,并且每两次执行的时间间隔有精确和稳定的需求。并且,本引擎还可以提供实时的帧率。目前本引擎仅支持的两次执行的时间间隔小于一秒钟。本引擎可以用来控制游戏帧数、网络通信帧率,等等。
18-
>
19-
> dll 的源代码在 FrameRateTask 项目中,使用示例代码在 Test 项目中。
20-
>
21-
> 本项目的编写最初是为了 [THUAI4](https://github.com/eesast/THUAI4) 来实现某些特定功能。
14+
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.
2215

16+
The source code is in the project `FrameRateTask`, and the example of usage is in the project `Test`.
2317

18+
> This project is initially written for [THUAI4](https://github.com/eesast/THUAI4) to support some functions.
2419
2520
## Get This Package
2621

27-
To get this package, please enter nuget package page: [https://www.nuget.org/packages/FrameRateTask/](https://www.nuget.org/packages/FrameRateTask/)
22+
To get this package, please enter the nuget package page: [https://www.nuget.org/packages/FrameRateTask/](https://www.nuget.org/packages/FrameRateTask/)
2823

2924
or use .NET CLI:
3025

3126
```shell
3227
$ dotnet add package FrameRateTask
3328
```
3429

35-
36-
3730
## Author
3831

3932
Autor: Timothy-LiuXuefeng
4033

41-
Job: Undergraduate in THU, major in EE
42-
4334
Copyright (C) 2022 Timothy-LiuXuefeng
4435

45-
46-
4736
## LICENSE
4837

4938
[MIT license](./LICENSE.txt)
5039

51-
52-
5340
## Interfaces
5441

5542
### CSharp
@@ -60,62 +47,64 @@ Copyright (C) 2022 Timothy-LiuXuefeng
6047

6148
+ Constructor:
6249

63-
+ `FrameRateTaskExecutor(Func<bool> loopCondition, Func<bool> loopToDo, long timeInterval, Func<TResult> finallyReturn, long maxTotalDuration = long.MaxValue)`
64-
65-
> ```c#
66-
> while (loopCondition && time <= maxTotalDuration)
67-
> {
68-
> if (!loopToDo()) break;
69-
> /*Do something to delay.*/
70-
> }
71-
> return finallyReturn;
72-
> ```
73-
>
74-
> + `loopCondition`: The condition to judge if the loop will continue. 是否继续循环的判断条件。
75-
> + `loopToDo`: The loop body. If it returns false, jump out of the loop. 循环体。如果返回 `false`,跳出循环。
76-
> + `timeInterval`: Time interval between two executing in milliseconds. 两次循环体执行的时间间隔,单位是毫秒。
77-
> + `finallyReturn`: Specify the last thing to do and the return value. 指定最后要做的事情和返回值。
78-
> + The maximum time in total for this task in milliseconds, `long.MaxValue` for default. 整个任务执行的最长时间,单位是毫秒。
50+
+ `FrameRateTaskExecutor(Func<bool> loopCondition, Func<bool> loopToDo, long timeInterval, Func<TResult> finallyReturn, long maxTotalDuration = long.MaxValue)`
51+
52+
If the object is constructed by this constructor, when calling its the `Start` or `TryStart` method, the program behaves as below:
53+
54+
```c#
55+
while (loopCondition && time <= maxTotalDuration)
56+
{
57+
if (!loopToDo()) break;
58+
/* Do something to delay until next frame comes. */
59+
}
60+
return finallyReturn;
61+
```
62+
63+
+ `loopCondition`: The condition to judge if the loop will continue.
64+
+ `loopToDo`: The loop body. If it returns false, jump out of the loop.
65+
+ `timeInterval`: Time interval between two executing in milliseconds.
66+
+ `finallyReturn`: Specify the last thing to do and the return value.
67+
+ `maxTotalDuration`:The maximum time in total for this task in milliseconds, `long.MaxValue` for default.
7968

8069
+ `FrameRateTaskExecutor(Func<bool> loopCondition, Action loopToDo, long timeInterval, Func<TResult> finallyReturn, long maxTotalDuration = long.MaxValue)`
8170

82-
> The only thing that is different from the last constructor is that `loopToDo` has no return value so you cannot jump out the loop through `loopToDo`.
83-
>
84-
> 与上一个构造函数唯一的不同是,`loopToDo` 没有返回值,因此你不能通过它跳出循环体。
71+
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`.
72+
73+
+ `public void Start()`
74+
75+
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.
76+
77+
+ `public bool TryStart()`
78+
79+
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.
8580

8681
+ `public uint FrameRate { get; }`
8782

88-
> The real-time framerate, initialized with expected framerate, changed when the task is running. 任务执行的实时帧率,初始化为期待的帧率,会在任务执行时被改变。
83+
The real-time frame rate, initialized with the expected frame rate, and will be changed when the execution of the task.
8984

9085
+ `public bool Finished { get; }`
9186

87+
Whether the task has finished.
88+
9289
+ `public bool HasExecuted { get; }`
9390

91+
Whether the task has begun to execute.
92+
9493
+ `public TResult Result { get; }`
9594

96-
> The return value of the task. It will throw an exception if the task hasn't finished.
97-
>
98-
> 任务的返回值。如果任务未执行完毕,将会抛出异常。
95+
The return value of the task. If the task has not finished, it will throw `Timothy.FrameRateTask.TaskNotFinishedException`.
9996

10097
+ `public bool AllowTimeExceed { get; init; }`
10198

102-
> Whether the engine allow time exceeding. `true` fir default. Details are under `MaxTolerantTimeExceedCount`.
103-
>
104-
> 是否允许执行超时。默认为 `true`。详情参见 `MaxTolerantTimeExceedCount`。
99+
Whether the engine allows time exceeding, `true` for default. See more details under `MaxTolerantTimeExceedCount`.
105100

106101
+ `public Action<bool> TimeExceedAction { get; init; }`
107102

108-
> It will be called when time exceeds. Details are under `MaxTolerantTimeExceedCount`.
109-
>
110-
> 将在超时后被调用。详情参见 `MaxTolerantTimeExceedCount`。
103+
It will be called when time exceeds. See more details under `MaxTolerantTimeExceedCount`.
111104

112105
+ `public ulong MaxTolerantTimeExceedCount { get; init; }`
113106

114-
> 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 (`AllowTimeExceed` is set `false`), it will throw an exception.
115-
>
116-
> Once more than `MaxTolerantTimeExceedCount`, it will automatically abandon unfinished loops, and reset the loop counter. There is an example about this in the project Test, that is, `Demo5` method.
117-
>
118-
> 允许连续超时的最大次数。默认为 `5`。一旦某次循环执行超时,如果连续超时次数不超过 `MaxTolerantTimeExceedCount`,`TimeExceedAction` 会被调用,且参数为 `false`;否则,如果 `AllowTimeExceed` 为 `true`,`TimeExceedAction` 会被调用,且参数为 `true`;如果 `AllowTimeExceed` 为 `false`,将会抛出异常。
119-
>
120-
> 一旦连续超时的次数大于 `MaxTolerantTimeExceedCount`,未完成的循环将会被舍弃,并重新进行循环计数。在 Test 项目中有一个关于本条的例子,即 `Demo5` 方法。
107+
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`.
108+
109+
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`.
121110

0 commit comments

Comments
 (0)