Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Common/Cpp/Sockets/ClientSocket_WinSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ size_t ClientSocket_WinSocket::send(const void* data, size_t bytes, std::chrono:
int current = (int)std::min<size_t>(bytes, BLOCK_SIZE);
int current_sent = ::send(socket, ptr, current, 0);
if (current_sent != SOCKET_ERROR){
// A partial send is not an error: advance and keep looping
// until everything is written or the deadline/state ends
// the send, the same way the POSIX and Qt backends do.
sent += current_sent;
if (current_sent != current){
return sent;
}
ptr += current_sent;
bytes -= current_sent;
continue;
Expand Down
8 changes: 7 additions & 1 deletion Common/Cpp/Sockets/ServerSocket_WinSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <chrono>
#include <thread>
#include <iostream>
#include <algorithm>
#include <winsock2.h>
#include "Common/Cpp/Concurrency/ThreadPool.h"
#include "ServerSocket_WinSocket.h"
Expand Down Expand Up @@ -157,7 +158,7 @@
}
}

size_t ServerSocket_WinSocket::send(const void* data, size_t bytes, std::chrono::milliseconds timeout){

Check failure on line 161 in Common/Cpp/Sockets/ServerSocket_WinSocket.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::ServerSocket_WinSocket::send( const * data , size_t bytes , std :: chrono :: milliseconds timeout): function_lines=60, limit=50, allowed 55
SOCKET socket;
{
std::lock_guard<Mutex> lg(m_lock);
Expand Down Expand Up @@ -191,7 +192,12 @@
return sent;
}

int current_sent = ::send(socket, ptr, (int)bytes, 0);
// "::send" takes an "int" length, so chunk the send the same
// way the WinSocket client does; sending a payload larger than
// 2 GiB in one call would wrap the length negative.
constexpr size_t BLOCK_SIZE = (size_t)1 << 30;
const int current = (int)std::min<size_t>(bytes, BLOCK_SIZE);
int current_sent = ::send(socket, ptr, current, 0);
if (current_sent != SOCKET_ERROR){
sent += (size_t)current_sent;
ptr += current_sent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/ImageFilter.h"
#include "VideoGames/PokemonSV/Inference/PokemonSV_BlueberryQuestReader.h"
#include "Tests/ImageUnitTest.h"
#include "PokemonSV_BlueberryQuestDetector.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -108,8 +109,73 @@ bool BlueberryQuestWatcher::process_frame(const ImageViewRGB32& screen, WallCloc
}


// One quest slot on a full frame of the quest panel.
struct BlueberryQuestScenario{
std::string image;
BlueberryQuestDetector::QuestPosition position;
std::string expected_slug;
size_t width;
size_t height;
};

class Test_BlueberryQuestDetector : public ImageUnitTest{
public:
Test_BlueberryQuestDetector(BlueberryQuestScenario scenario)
: ImageUnitTest(
"PokemonSV::BlueberryQuestDetector - " + scenario.image
+ " - slot " + std::to_string((int)scenario.position + 1)
+ " - " + std::to_string(scenario.width),
{scenario.image}
)
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run_on_images(
Logger& logger, CancellableScope&,
const std::vector<ImageRGB32>& images
) const override{
ImageRGB32 image = images[0].scale_to(m_scenario.width, m_scenario.height);
BlueberryQuestDetector detector(logger, COLOR_RED, Language::ChineseTraditional, m_scenario.position);
const std::string actual = detector.detect_quest(image);
if (actual != m_scenario.expected_slug){
return "Expected quest \"" + m_scenario.expected_slug + "\", read \"" + actual + "\"";
}
return true;
}

private:
const BlueberryQuestScenario m_scenario;
};

// Every slot of one Traditional Chinese quest panel frame, at 1080p and 720p.
static void add_tests_BlueberryQuestPanel(
UnitTestDatabase& database,
const std::string& image, const std::string (&slugs)[4]
){
using enum BlueberryQuestDetector::QuestPosition;
const BlueberryQuestDetector::QuestPosition positions[] = {FIRST, SECOND, THIRD, FOURTH};
const std::pair<size_t, size_t> sizes[] = {{1920, 1080}, {1280, 720}};
for (size_t slot = 0; slot < 4; slot++){
for (const auto& [width, height] : sizes){
database.add<Test_BlueberryQuestDetector>(BlueberryQuestScenario{
.image = image,
.position = positions[slot],
.expected_slug = slugs[slot],
.width = width,
.height = height,
});
}
}
}

void add_tests_BlueberryQuestDetector(UnitTestDatabase& database){
// Singleplayer without a red quest shows 3 quests, so the fourth slot reads
// as nothing. "catch-any" reads "捕捉1隻..." on screen where the dictionary
// has "捕捉一隻...".
add_tests_BlueberryQuestPanel(database, "PokemonSV/BlueberryPoints/6750.png", {"catch-any", "sneak-up", "auto-10", ""});
// The first frame after rerolling the first quest.
add_tests_BlueberryQuestPanel(database, "PokemonSV/BlueberryPoints/6740.png", {"photo-swim", "sneak-up", "auto-10", ""});
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Common/Cpp/Color.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonFramework/Language.h"
Expand Down Expand Up @@ -75,6 +76,9 @@ class BlueberryQuestWatcher : public VisualInferenceCallback{
};


void add_tests_BlueberryQuestDetector(UnitTestDatabase& database);




}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Tests/ImageUnitTest.h"
#include "Inference/PokemonSV_BlueberryPointsReader.h"
#include "Inference/PokemonSV_BlueberryQuestDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -148,7 +149,7 @@

}

void add_tests(UnitTestDatabase& database){

Check warning on line 152 in SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::add_tests( UnitTestDatabase & database): function_lines=34 (advisory above 25, limit 50)
database.add<Test_BBQuestsSlugs>();

// Full-frame references, in the CommandLineTests repo: they exercise the production
Expand Down Expand Up @@ -180,6 +181,7 @@
add_tests_NormalBattleMenus(database);
add_tests_LetsGoKillDetector(database);
add_tests_TeraEncounterAction(database);
add_tests_BlueberryQuestDetector(database);
}


Expand Down
Loading