Adding Link::perFrame(...) helper

This commit is contained in:
Rodrigo Alfonso
2024-08-23 05:53:34 -03:00
parent e1ae8cfba2
commit 2c7234ff18
4 changed files with 11 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ Name | Type | Default | Description
--- | --- | --- | ---
`baudRate` | **BaudRate** | `BAUD_RATE_1` | Sets a specific baud rate.
`timeout` | **u32** | `3` | Maximum number of *frames* without receiving data from other player before marking them as disconnected or resetting the connection.
`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU.
`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. You can use `Link::perFrame(...)` to convert from *packets per frame* to *interval values*.
`sendTimerId` | **u8** *(0~3)* | `3` | GBA Timer to use for sending.
You can update these values at any time without creating a new instance:
@@ -171,7 +171,7 @@ Name | Type | Default | Description
`retransmission` | **bool** | `true` | If `true`, the library handles retransmission for you, so there should be no packet loss.
`maxPlayers` | **u8** *(2~5)* | `5` | Maximum number of allowed players. If your game only supports -for example- two players, set this to `2` as it will make transfers faster.
`timeout` | **u32** | `10` | Maximum number of *frames* without receiving data from other player before resetting the connection.
`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU.
`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. You can use `Link::perFrame(...)` to convert from *packets per frame* to *interval values*.
`sendTimerId` | **u8** *(0~3)* | `3` | GBA Timer to use for sending.
`asyncACKTimerId` | **s8** *(0~3 or -1)* | `-1` | GBA Timer to use for ACKs. If you have free timers, use one here to reduce CPU usage.

View File

@@ -106,6 +106,8 @@ class LinkCable {
* *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values
* will transfer faster but also consume more CPU.
* @param sendTimerId `(0~3)` GBA Timer to use for sending.
* \warning You can use `Link::perFrame(...)` to convert from *packets per
* frame* to *interval values*.
*/
explicit LinkCable(BaudRate baudRate = BAUD_RATE_1,
u32 timeout = LINK_CABLE_DEFAULT_TIMEOUT,

View File

@@ -258,6 +258,8 @@ class LinkWireless {
* @param sendTimerId GBA Timer to use for sending.
* @param asyncACKTimerId GBA Timer to use for ACKs. If you have free timers,
* use one here to reduce CPU usage.
* \warning You can use `Link::perFrame(...)` to convert from *packets per
* frame* to *interval values*.
*/
explicit LinkWireless(
bool forwarding = true,

View File

@@ -239,6 +239,11 @@ class Queue {
volatile bool _needsClear = false;
};
// Packets per frame -> Timer interval
static inline u16 perFrame(u16 packets) {
return (1667 * 1024) / (packets * 6104);
}
// mGBA Logging
#if LINK_ENABLE_DEBUG_LOGS != 0