From ad7c3e616fdc6f13812ec52675d226a19351494a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Dec 2024 15:40:19 -0500 Subject: Added getting player position from IPC --- src/ap_state.cpp | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/ap_state.cpp') diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 32ae8f0..80d96a1 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp @@ -22,6 +22,7 @@ #include #include "game_data.h" +#include "ipc_state.h" #include "logger.h" #include "tracker_frame.h" #include "tracker_state.h" @@ -43,6 +44,7 @@ struct APState { TrackerFrame* tracker_frame = nullptr; bool client_active = false; + std::string status_message = "Not connected to Archipelago."; std::mutex client_mutex; bool connected = false; @@ -113,7 +115,10 @@ struct APState { initialized = true; } - tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); + { + std::lock_guard client_guard(client_mutex); + SetStatusMessage("Connecting to Archipelago server...."); + } TrackerLog(fmt::format("Connecting to Archipelago server ({})...", server)); { @@ -169,8 +174,7 @@ struct APState { "Connected to Archipelago server. Authenticating as {} {}", player, (password.empty() ? "without password" : "with password " + password))); - tracker_frame->SetStatusMessage( - "Connected to Archipelago server. Authenticating..."); + SetStatusMessage("Connected to Archipelago server. Authenticating..."); apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, {AP_MAJOR, AP_MINOR, AP_REVISION}); @@ -187,14 +191,14 @@ struct APState { }); apclient->set_slot_disconnected_handler([this]() { - tracker_frame->SetStatusMessage( + SetStatusMessage( "Disconnected from Archipelago. Attempting to reconnect..."); TrackerLog( "Slot disconnected from Archipelago. Attempting to reconnect..."); }); apclient->set_socket_disconnected_handler([this]() { - tracker_frame->SetStatusMessage( + SetStatusMessage( "Disconnected from Archipelago. Attempting to reconnect..."); TrackerLog( "Socket disconnected from Archipelago. Attempting to reconnect..."); @@ -229,10 +233,12 @@ struct APState { apclient->set_slot_connected_handler([this, player, server, &connection_mutex]( const nlohmann::json& slot_data) { - tracker_frame->SetStatusMessage( - fmt::format("Connected to Archipelago! ({}@{})", player, server)); + SetStatusMessage( + fmt::format("Connected to Archipelago! ({}@{}).", player, server)); TrackerLog("Connected to Archipelago!"); + IPC_SetTrackerSlot(server, player); + save_name = fmt::format("zzAP_{}_{}.save", apclient->get_seed(), apclient->get_player_number()); data_storage_prefix = @@ -328,7 +334,7 @@ struct APState { has_connection_result = true; } - tracker_frame->SetStatusMessage("Disconnected from Archipelago."); + SetStatusMessage("Disconnected from Archipelago."); std::vector error_messages; error_messages.push_back("Could not connect to Archipelago."); @@ -376,7 +382,10 @@ struct APState { if (interval == 0) { DestroyClient(); - tracker_frame->SetStatusMessage("Disconnected from Archipelago."); + { + std::lock_guard client_guard(client_mutex); + SetStatusMessage("Disconnected from Archipelago."); + } TrackerLog("Timeout while connecting to Archipelago server."); wxMessageBox("Timeout while connecting to Archipelago server.", "Connection failed", wxOK | wxICON_ERROR); @@ -400,6 +409,17 @@ struct APState { } } + std::string GetStatusMessage() { + std::lock_guard client_guard(client_mutex); + return status_message; + } + + void SetStatusMessage(std::string msg) { + status_message = std::move(msg); + + tracker_frame->UpdateStatusMessage(); + } + void HandleDataStorage(const std::string& key, const nlohmann::json& value) { if (value.is_boolean()) { data_storage[key] = value.get(); @@ -527,6 +547,8 @@ void AP_Connect(std::string server, std::string player, std::string password) { GetState().Connect(server, player, password); } +std::string AP_GetStatusMessage() { return GetState().GetStatusMessage(); } + std::string AP_GetSaveName() { return GetState().save_name; } bool AP_HasCheckedGameLocation(int location_id) { @@ -590,7 +612,8 @@ bool AP_IsLocationVisible(int classification) { return false; } - if (GetState().door_shuffle_mode == kDOORS_MODE && !GetState().early_color_hallways) { + if (GetState().door_shuffle_mode == kDOORS_MODE && + !GetState().early_color_hallways) { world_state |= kLOCATION_SMALL_SPHERE_ONE; } -- cgit 1.4.1