Skip to content

Commit

Permalink
Waiting buffer can be transferred from GameSearching to GameStarted
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongGino authored Mar 26, 2024
1 parent eb001bd commit 7a4b0ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions qhookermain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void qhookerMain::SerialInit()
}


void qhookerMain::GameSearching(QString input)
bool qhookerMain::GameSearching(QString input)
{
// Split the output in case of connecting mid-way.
buffer = input.split('\r', Qt::SkipEmptyParts);
Expand Down Expand Up @@ -196,18 +196,23 @@ void qhookerMain::GameSearching(QString input)
tempBuffer.removeFirst();
}
}
buffer.removeFirst();
return true;
} else {
gameName.clear();
}
}
buffer.removeFirst();
}
return false;
}


void qhookerMain::GameStarted(QString input)
{
buffer = input.split('\r', Qt::SkipEmptyParts);
if(buffer.isEmpty()) {
buffer = input.split('\r', Qt::SkipEmptyParts);
}
while(!buffer.isEmpty()) {
buffer[0] = buffer[0].trimmed();

Expand Down Expand Up @@ -343,7 +348,10 @@ void qhookerMain::ReadyRead()
{
buffer.clear();
if(gameName.isEmpty()) {
GameSearching(tcpSocket.readLine());
// if this returns early as true, then zip straight into the GameStarted function with the remaining buffer.
if(GameSearching(tcpSocket.readLine())) {
GameStarted("");
}
} else {
GameStarted(tcpSocket.readLine());
}
Expand Down
2 changes: 1 addition & 1 deletion qhookermain.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class qhookerMain : public QObject

void SerialInit();

void GameSearching(QString input);
bool GameSearching(QString input);

void GameStarted(QString input);

Expand Down

0 comments on commit 7a4b0ff

Please sign in to comment.