mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-04-26 02:02:25 -05:00
Updating error checking, canSend is not reliable anymore
This commit is contained in:
parent
b1196edfa6
commit
1197883f7a
|
|
@ -240,22 +240,30 @@ void messageLoop() {
|
|||
u16 keys = ~REG_KEYS & KEY_ANY;
|
||||
|
||||
// (6) Send data
|
||||
if (linkWireless->canSend() &&
|
||||
((keys & KEY_B) || (!sending && (keys & KEY_A)))) {
|
||||
if ((keys & KEY_B) || (!sending && (keys & KEY_A))) {
|
||||
bool doubleSend = false;
|
||||
sending = true;
|
||||
|
||||
again:
|
||||
counters[linkWireless->currentPlayerId()]++;
|
||||
linkWireless->send(
|
||||
std::vector<u32>{counters[linkWireless->currentPlayerId()]});
|
||||
CHECK_ERRORS("Send failed :(")
|
||||
u32 newValue = counters[linkWireless->currentPlayerId()] + 1;
|
||||
bool success = linkWireless->send(std::vector<u32>{newValue});
|
||||
|
||||
if (!doubleSend && (keys & KEY_LEFT) && linkWireless->canSend()) {
|
||||
if (success) {
|
||||
counters[linkWireless->currentPlayerId()] = newValue;
|
||||
} else {
|
||||
if (linkWireless->getLastError(false) == LinkWireless::BUFFER_IS_FULL) {
|
||||
linkWireless->getLastError();
|
||||
goto sendEnd;
|
||||
}
|
||||
CHECK_ERRORS("Send failed :(")
|
||||
}
|
||||
|
||||
if (!doubleSend && (keys & KEY_LEFT)) {
|
||||
doubleSend = true;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
sendEnd:
|
||||
if (sending && (!(keys & KEY_A)))
|
||||
sending = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -429,9 +429,10 @@ class LinkWireless {
|
|||
u8 currentPlayerId() { return sessionState.currentPlayerId; }
|
||||
bool canSend() { return !sessionState.outgoingMessages.isFull(); }
|
||||
u32 getPendingCount() { return sessionState.outgoingMessages.size(); }
|
||||
Error getLastError() {
|
||||
Error getLastError(bool clear = true) {
|
||||
Error error = lastError;
|
||||
lastError = NONE;
|
||||
if (clear)
|
||||
lastError = NONE;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user