Compare commits

...

5 Commits

Author SHA1 Message Date
Mr_Goldberg b1206b0fa2
Add a longer delay to P2PSessionRequest_t callback.
Don't fire it if packet is sent before it is fired.
2020-01-26 17:25:41 -05:00
Mr_Goldberg 39d1d8dcdf
Add a notifications mutex to the overlay. 2020-01-26 17:24:16 -05:00
Mr_Goldberg 92218b08c6
Build overlay in steamclient debug build. 2020-01-26 09:47:19 -05:00
Mr_Goldberg eace15df47
Thread related overlay improvements. 2020-01-26 09:46:57 -05:00
Mr_Goldberg 6d96784af1
Fix menu buttons not working in Aoe2DE. 2020-01-26 09:45:54 -05:00
5 changed files with 113 additions and 69 deletions

View File

@ -270,8 +270,8 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; }
if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; }
if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; }
if (!ImGui::IsAnyMouseDown() && ::GetCapture() == NULL)
::SetCapture(hwnd);
// if (!ImGui::IsAnyMouseDown() && ::GetCapture() == NULL)
// ::SetCapture(hwnd);
io.MouseDown[button] = true;
return 0;
}
@ -286,8 +286,8 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
if (msg == WM_MBUTTONUP) { button = 2; }
if (msg == WM_XBUTTONUP) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; }
io.MouseDown[button] = false;
if (!ImGui::IsAnyMouseDown() && ::GetCapture() == hwnd)
::ReleaseCapture();
// if (!ImGui::IsAnyMouseDown() && ::GetCapture() == hwnd)
// ::ReleaseCapture();
return 0;
}
case WM_MOUSEWHEEL:

View File

@ -3,9 +3,9 @@ call build_set_protobuf_directories.bat
"%PROTOC_X86_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto
call build_env_x86.bat
cl dll/rtlgenrandom.c dll/rtlgenrandom.def
cl /LD /I%PROTOBUF_X86_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c "%PROTOBUF_X86_LIBRARY%" Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib /EHsc /MP12 /link /OUT:steamclient.dll
cl /LD /IImGui /Iglew\include /I%PROTOBUF_X86_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X86_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient.dll
cl /LD steamnetworkingsockets.cpp /EHsc /MP12 /link /OUT:steamnetworkingsockets.dll
call build_env_x64.bat
cl dll/rtlgenrandom.c dll/rtlgenrandom.def
cl /LD /I%PROTOBUF_X64_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c "%PROTOBUF_X64_LIBRARY%" Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib /EHsc /MP12 /link /OUT:steamclient64.dll
cl /LD /IImGui /Iglew\include /I%PROTOBUF_X64_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X64_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient64.dll
cl /LD steamnetworkingsockets.cpp /EHsc /MP12 /link /OUT:steamnetworkingsockets64.dll

View File

@ -21,6 +21,9 @@
#define ORPHANED_PACKET_TIMEOUT (20)
#define NEW_CONNECTION_TIMEOUT (20.0)
//kingdom 2 crowns doesn't work with a 0.3 delay or lower
#define NEW_CONNECTION_DELAY (0.4)
#define OLD_CHANNEL_NUMBER 1
struct Steam_Networking_Connection {
@ -78,6 +81,7 @@ public ISteamNetworking
std::vector<struct steam_connection_socket> connection_sockets;
std::map<CSteamID, std::chrono::high_resolution_clock::time_point> new_connection_times;
std::queue<CSteamID> new_connections_to_call_cb;
bool connection_exists(CSteamID id)
{
@ -819,10 +823,7 @@ void RunCallbacks()
if (!msg.network().processed()) {
if (!connection_exists(source_id)) {
if (new_connection_times.find(source_id) == new_connection_times.end()) {
P2PSessionRequest_t data;
memset(&data, 0, sizeof(data));
data.m_steamIDRemote = CSteamID(source_id);
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), 0.1);
new_connections_to_call_cb.push(source_id);
new_connection_times[source_id] = std::chrono::high_resolution_clock::now();
}
} else {
@ -855,6 +856,25 @@ void RunCallbacks()
}
while (!new_connections_to_call_cb.empty()) {
CSteamID source_id = new_connections_to_call_cb.front();
auto t = new_connection_times.find(source_id);
if (t == new_connection_times.end()) {
new_connections_to_call_cb.pop();
continue;
}
if (!check_timedout(t->second, NEW_CONNECTION_DELAY)) {
break;
}
P2PSessionRequest_t data;
memset(&data, 0, sizeof(data));
data.m_steamIDRemote = source_id;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
new_connections_to_call_cb.pop();
}
//TODO: not sure if sockets should be wiped right away
remove_killed_connection_sockets();

View File

@ -89,7 +89,8 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu
notif_position(ENotificationPosition::k_EPositionBottomLeft),
h_inset(0),
v_inset(0),
overlay_state_changed(false)
overlay_state_changed(false),
i_have_lobby(false)
{
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::steam_overlay_callback, this);
@ -283,6 +284,7 @@ void Steam_Overlay::FriendConnect(Friend _friend)
item.window_state = window_state_none;
item.id = id;
memset(item.chat_input, 0, max_chat_len);
item.has_lobby = false;
}
else
PRINT_DEBUG("No more free id to create a friend window\n");
@ -298,7 +300,7 @@ void Steam_Overlay::FriendDisconnect(Friend _friend)
void Steam_Overlay::AddMessageNotification(std::string const& message)
{
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications);
if (id != 0)
{
@ -315,7 +317,7 @@ void Steam_Overlay::AddMessageNotification(std::string const& message)
void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
{
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications);
if (id != 0)
{
@ -333,7 +335,7 @@ void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_state>& wnd_state)
{
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications);
if (id != 0)
{
@ -390,13 +392,13 @@ void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& sta
// If we have the same appid, activate the invite/join buttons
if (settings->get_local_game_id().AppID() == frd.appid())
{
if (IHaveLobby() && ImGui::Button("Invite###PopupInvite"))
if (i_have_lobby && ImGui::Button("Invite###PopupInvite"))
{
state.window_state |= window_state_invite;
has_friend_action.push(frd);
close_popup = true;
}
if (FriendHasLobby(frd.id()) && ImGui::Button("Join###PopupJoin"))
if (state.has_lobby && ImGui::Button("Join###PopupJoin"))
{
state.window_state |= window_state_join;
has_friend_action.push(frd);
@ -520,6 +522,11 @@ void Steam_Overlay::BuildNotifications(int width, int height)
int font_size = ImGui::GetFontSize();
std::queue<Friend> friend_actions_temp;
{
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
for (auto it = notifications.begin(); it != notifications.end(); ++it, ++i)
{
auto elapsed_notif = now - it->start_time;
@ -560,7 +567,7 @@ void Steam_Overlay::BuildNotifications(int width, int height)
ImGui::TextWrapped("%s", it->message.c_str());
if (ImGui::Button("Join"))
{
has_friend_action.push(it->frd->first);
friend_actions_temp.push(it->frd->first);
it->start_time = std::chrono::seconds(0);
}
}
@ -578,6 +585,15 @@ void Steam_Overlay::BuildNotifications(int width, int height)
}), notifications.end());
}
if (!friend_actions_temp.empty()) {
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
while (!friend_actions_temp.empty()) {
has_friend_action.push(friend_actions_temp.front());
friend_actions_temp.pop();
}
}
}
void Steam_Overlay::CreateFonts()
{
ImGuiIO& io = ImGui::GetIO();
@ -606,16 +622,11 @@ void Steam_Overlay::OverlayProc()
ImGuiIO& io = ImGui::GetIO();
ImGui::PushFont(font_notif);
overlay_mutex.lock();
BuildNotifications(io.DisplaySize.x, io.DisplaySize.y);
overlay_mutex.unlock();
ImGui::PopFont();
if (show_overlay)
{
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
int friend_size = friends.size();
// Set the overlay windows to the size of the game window
ImGui::SetNextWindowPos({ 0,0 });
ImGui::SetNextWindowSize({ static_cast<float>(io.DisplaySize.x),
@ -640,9 +651,11 @@ void Steam_Overlay::OverlayProc()
ImGui::Spacing();
ImGui::LabelText("##label", "Friends");
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
if (!friends.empty())
{
ImGui::ListBoxHeader("##label", friend_size);
ImGui::ListBoxHeader("##label", friends.size());
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
{
ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id);
@ -707,7 +720,13 @@ void Steam_Overlay::RunCallbacks()
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
i_have_lobby = IHaveLobby();
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
{
i.second.has_lobby = FriendHasLobby(i.first.id());
});
while (!has_friend_action.empty())
{
auto friend_info = friends.find(has_friend_action.front());

View File

@ -31,6 +31,8 @@ struct friend_window_state
};
std::string chat_history;
char chat_input[max_chat_len];
bool has_lobby;
};
struct Friend_Less
@ -90,9 +92,12 @@ class Steam_Overlay
// Callback infos
std::queue<Friend> has_friend_action;
std::vector<Notification> notifications;
std::recursive_mutex notifications_mutex;
bool overlay_state_changed;
std::recursive_mutex overlay_mutex;
std::atomic<bool> i_have_lobby;
Steam_Overlay(Steam_Overlay const&) = delete;
Steam_Overlay(Steam_Overlay&&) = delete;