diff --git a/examples/LinkWireless_demo/src/main.cpp b/examples/LinkWireless_demo/src/main.cpp index b9c2efc..9930dab 100644 --- a/examples/LinkWireless_demo/src/main.cpp +++ b/examples/LinkWireless_demo/src/main.cpp @@ -48,7 +48,7 @@ int main() { #ifdef LINK_WIRELESS_TWO_PLAYERS_ONLY buildSettings += " + 2players\n"; #endif -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED buildSettings += " + profiler\n"; #endif @@ -286,7 +286,7 @@ void messageLoop() { bool altView = false; bool switching = false; -#ifndef PROFILING_ENABLED +#ifndef LINK_WIRELESS_PROFILING_ENABLED u32 lostPackets = 0; u32 lastLostPacketPlayerId = 0; u32 lastLostPacketExpected = 0; @@ -338,13 +338,13 @@ void messageLoop() { if (message.packetId == LINK_WIRELESS_END) break; -#ifndef PROFILING_ENABLED +#ifndef LINK_WIRELESS_PROFILING_ENABLED u32 expected = counters[message.playerId] + 1; #endif counters[message.playerId] = message.data; -#ifndef PROFILING_ENABLED +#ifndef LINK_WIRELESS_PROFILING_ENABLED // Check for packet loss if (altView && message.data != expected) { lostPackets++; @@ -364,7 +364,7 @@ void messageLoop() { // Packet loss check setting if (Common::didPress(KEY_UP, switching)) { -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED // In the profiler ROM, pressing UP will update the broadcast data if (linkWireless->getState() == LinkWireless::State::SERVING && !(keys & KEY_START)) { @@ -393,7 +393,7 @@ void messageLoop() { #endif altView = !altView; -#ifndef PROFILING_ENABLED +#ifndef LINK_WIRELESS_PROFILING_ENABLED if (!altView) { lostPackets = 0; lastLostPacketPlayerId = 0; @@ -405,7 +405,7 @@ void messageLoop() { // Normal output std::string altOptionName = "Packet loss check"; -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED altOptionName = "Show profiler"; #endif std::string output = @@ -446,9 +446,7 @@ void messageLoop() { } } if (altView) { -#ifdef PROFILING_ENABLED - output += - "\n_rejected: " + std::to_string(linkWireless->rejectedMessages); +#ifdef LINK_WIRELESS_PROFILING_ENABLED output += "\n_onVBlank: " + std::to_string(linkWireless->lastVBlankTime); output += "\n_onSerial: " + std::to_string(linkWireless->lastSerialTime); output += "\n_onTimer: " + std::to_string(linkWireless->lastTimerTime); diff --git a/examples/compile.sh b/examples/compile.sh index 3e48fa7..86f5641 100755 --- a/examples/compile.sh +++ b/examples/compile.sh @@ -116,14 +116,12 @@ compile() { cd .. # LinkWireless_demo_profiler - if [ "$1" != "multiboot" ]; then - cd LinkWireless_demo/ - mv LinkWireless_demo.gba backup.gba - make rebuild USERFLAGS="-DLINK_WIRELESS_PUT_ISR_IN_IWRAM=1 -DLINK_WIRELESS_USE_SEND_RECEIVE_LATCH=1 -DPROFILING_ENABLED=1" - cp LinkWireless_demo.gba ../LinkWireless_demo_profiler.gba - mv backup.gba LinkWireless_demo.gba - cd .. - fi + cd LinkWireless_demo/ + mv LinkWireless_demo$suffix.gba backup.gba + make rebuild $args USERFLAGS="-DLINK_WIRELESS_PUT_ISR_IN_IWRAM=1 -DLINK_WIRELESS_USE_SEND_RECEIVE_LATCH=1 -DLINK_WIRELESS_PROFILING_ENABLED=1" + cp LinkWireless_demo$suffix.gba ../$folder/LinkWireless_demo_profiler$suffix.gba + mv backup.gba LinkWireless_demo$suffix.gba + cd .. } # Cleanup diff --git a/lib/LinkWireless.hpp b/lib/LinkWireless.hpp index 970b17c..d788076 100644 --- a/lib/LinkWireless.hpp +++ b/lib/LinkWireless.hpp @@ -199,9 +199,8 @@ class LinkWireless { #endif // std::function debug; -// #define PROFILING_ENABLED -#ifdef PROFILING_ENABLED - u32 rejectedMessages = 0; +// #define LINK_WIRELESS_PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED u32 lastVBlankTime = 0; u32 lastSerialTime = 0; u32 lastTimerTime = 0; @@ -687,12 +686,6 @@ class LinkWireless { startTimer(); } - /** - * @brief Returns whether it's running an async command or not. - * \warning This is internal API! - */ - [[nodiscard]] bool _hasActiveAsyncCommand() { return asyncCommand.isActive; } - /** * @brief Returns whether there's room for sending messages or not. * \warning This is internal API! @@ -786,7 +779,7 @@ class LinkWireless { #endif #endif -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED profileStart(); #endif @@ -808,7 +801,7 @@ class LinkWireless { sessionState.acceptCalled = false; sessionState.pingSent = false; -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED lastVBlankTime = profileStop(); lastFrameSerialIRQs = serialIRQCount; lastFrameTimerIRQs = timerIRQCount; @@ -833,7 +826,7 @@ class LinkWireless { if (!isEnabled) return; -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED profileStart(); #endif @@ -860,7 +853,7 @@ class LinkWireless { } } -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED lastSerialTime = profileStop(); serialIRQCount++; #endif @@ -874,7 +867,7 @@ class LinkWireless { if (!isEnabled) return; -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED profileStart(); #endif @@ -884,7 +877,7 @@ class LinkWireless { if (!asyncCommand.isActive) acceptConnectionsOrTransferData(); -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED lastTimerTime = profileStop(); timerIRQCount++; #endif @@ -1210,14 +1203,12 @@ class LinkWireless { u32 expectedPacketId = (sessionState.lastPacketIdFromClients[message.playerId] + 1) % MAX_PACKET_IDS; + // if message.packetId > expectedPacketId = packet loss (gap) + // if message.packetId < expectedPacketId = retransmission of old packet if (config.retransmission && !isConfirmation && - message.packetId != expectedPacketId) { -#ifdef PROFILING_ENABLED - rejectedMessages++; -#endif + message.packetId != expectedPacketId) return false; - } if (!isConfirmation) message.packetId = @@ -1227,12 +1218,8 @@ class LinkWireless { (sessionState.lastPacketIdFromServer + 1) % MAX_PACKET_IDS; if (config.retransmission && !isConfirmation && - message.packetId != expectedPacketId) { -#ifdef PROFILING_ENABLED - rejectedMessages++; -#endif + message.packetId != expectedPacketId) return false; - } linkRawWireless.sessionState.playerCount = remotePlayerCount; @@ -1670,7 +1657,7 @@ class LinkWireless { u8 msB16(u16 value) { return value >> 8; } u8 lsB16(u16 value) { return value & 0xff; } -#ifdef PROFILING_ENABLED +#ifdef LINK_WIRELESS_PROFILING_ENABLED void profileStart() { Link::_REG_TM1CNT_L = 0; Link::_REG_TM2CNT_L = 0; diff --git a/lib/c_bindings/C_LinkWireless.cpp b/lib/c_bindings/C_LinkWireless.cpp index 5e665e0..395f841 100644 --- a/lib/c_bindings/C_LinkWireless.cpp +++ b/lib/c_bindings/C_LinkWireless.cpp @@ -177,42 +177,6 @@ void C_LinkWireless_setConfig(C_LinkWirelessHandle handle, static_cast(handle)->config.sendTimerId = config.sendTimerId; } -bool C_LinkWireless_hasActiveAsyncCommand(C_LinkWirelessHandle handle) { - return static_cast(handle)->_hasActiveAsyncCommand(); -} - -bool C_LinkWireless_canSend(C_LinkWirelessHandle handle) { - return static_cast(handle)->_canSend(); -} - -u32 C_LinkWireless_getPendingCount(C_LinkWirelessHandle handle) { - return static_cast(handle)->_getPendingCount(); -} - -u32 C_LinkWireless_lastPacketId(C_LinkWirelessHandle handle) { - return static_cast(handle)->_lastPacketId(); -} - -u32 C_LinkWireless_lastConfirmationFromClient1(C_LinkWirelessHandle handle) { - return static_cast(handle)->_lastConfirmationFromClient1(); -} - -u32 C_LinkWireless_lastPacketIdFromClient1(C_LinkWirelessHandle handle) { - return static_cast(handle)->_lastPacketIdFromClient1(); -} - -u32 C_LinkWireless_lastConfirmationFromServer(C_LinkWirelessHandle handle) { - return static_cast(handle)->_lastConfirmationFromServer(); -} - -u32 C_LinkWireless_lastPacketIdFromServer(C_LinkWirelessHandle handle) { - return static_cast(handle)->_lastPacketIdFromServer(); -} - -u32 C_LinkWireless_nextPendingPacketId(C_LinkWirelessHandle handle) { - return static_cast(handle)->_nextPendingPacketId(); -} - void C_LinkWireless_onVBlank(C_LinkWirelessHandle handle) { static_cast(handle)->_onVBlank(); } diff --git a/lib/c_bindings/C_LinkWireless.h b/lib/c_bindings/C_LinkWireless.h index 1304f43..a635c4a 100644 --- a/lib/c_bindings/C_LinkWireless.h +++ b/lib/c_bindings/C_LinkWireless.h @@ -125,17 +125,6 @@ C_LinkWireless_Config C_LinkWireless_getConfig(C_LinkWirelessHandle handle); void C_LinkWireless_setConfig(C_LinkWirelessHandle handle, C_LinkWireless_Config config); -bool C_LinkWireless_hasActiveAsyncCommand(C_LinkWirelessHandle handle); -bool C_LinkWireless_canSend(C_LinkWirelessHandle handle); - -u32 C_LinkWireless_getPendingCount(C_LinkWirelessHandle handle); -u32 C_LinkWireless_lastPacketId(C_LinkWirelessHandle handle); -u32 C_LinkWireless_lastConfirmationFromClient1(C_LinkWirelessHandle handle); -u32 C_LinkWireless_lastPacketIdFromClient1(C_LinkWirelessHandle handle); -u32 C_LinkWireless_lastConfirmationFromServer(C_LinkWirelessHandle handle); -u32 C_LinkWireless_lastPacketIdFromServer(C_LinkWirelessHandle handle); -u32 C_LinkWireless_nextPendingPacketId(C_LinkWirelessHandle handle); - void C_LinkWireless_onVBlank(C_LinkWirelessHandle handle); void C_LinkWireless_onSerial(C_LinkWirelessHandle handle); void C_LinkWireless_onTimer(C_LinkWirelessHandle handle);