From 6195cb8a0a0e4edfdae14c8e46a03f2374cb3bbf Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Thu, 30 May 2019 10:28:09 -0500 Subject: [PATCH] lsteamclient: Add a manual override for the cpp side of the new networking API --- ...rkingSockets_SteamNetworkingSockets002.cpp | 18 ----------- lsteamclient/gen_wrapper.py | 27 +++++++++++----- lsteamclient/steamclient_manual_144.cpp | 32 +++++++++++++++---- lsteamclient/struct_converters.h | 2 -- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/lsteamclient/cppISteamNetworkingSockets_SteamNetworkingSockets002.cpp b/lsteamclient/cppISteamNetworkingSockets_SteamNetworkingSockets002.cpp index ab858dae..1f302bb4 100644 --- a/lsteamclient/cppISteamNetworkingSockets_SteamNetworkingSockets002.cpp +++ b/lsteamclient/cppISteamNetworkingSockets_SteamNetworkingSockets002.cpp @@ -74,24 +74,6 @@ EResult cppISteamNetworkingSockets_SteamNetworkingSockets002_FlushMessagesOnConn return ((ISteamNetworkingSockets*)linux_side)->FlushMessagesOnConnection((HSteamNetConnection)hConn); } -int cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection(void *linux_side, HSteamNetConnection hConn, winSteamNetworkingMessage_t_144 ** ppOutMessages, int nMaxMessages) -{ - SteamNetworkingMessage_t * lin_ppOutMessages; - win_to_lin_struct_SteamNetworkingMessage_t_144(ppOutMessages, &lin_ppOutMessages); - int retval = ((ISteamNetworkingSockets*)linux_side)->ReceiveMessagesOnConnection((HSteamNetConnection)hConn, &lin_ppOutMessages, (int)nMaxMessages); - lin_to_win_struct_SteamNetworkingMessage_t_144(retval, &lin_ppOutMessages, ppOutMessages); - return retval; -} - -int cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket(void *linux_side, HSteamListenSocket hSocket, winSteamNetworkingMessage_t_144 ** ppOutMessages, int nMaxMessages) -{ - SteamNetworkingMessage_t * lin_ppOutMessages; - win_to_lin_struct_SteamNetworkingMessage_t_144(ppOutMessages, &lin_ppOutMessages); - int retval = ((ISteamNetworkingSockets*)linux_side)->ReceiveMessagesOnListenSocket((HSteamListenSocket)hSocket, &lin_ppOutMessages, (int)nMaxMessages); - lin_to_win_struct_SteamNetworkingMessage_t_144(retval, &lin_ppOutMessages, ppOutMessages); - return retval; -} - bool cppISteamNetworkingSockets_SteamNetworkingSockets002_GetConnectionInfo(void *linux_side, HSteamNetConnection hConn, SteamNetConnectionInfo_t * pInfo) { return ((ISteamNetworkingSockets*)linux_side)->GetConnectionInfo((HSteamNetConnection)hConn, (SteamNetConnectionInfo_t *)pInfo); diff --git a/lsteamclient/gen_wrapper.py b/lsteamclient/gen_wrapper.py index ecafd9eb..c6130f06 100755 --- a/lsteamclient/gen_wrapper.py +++ b/lsteamclient/gen_wrapper.py @@ -169,6 +169,13 @@ manually_handled_structs = [ "SteamNetworkingMessage_t" ] +manually_handled_methods = { + "cppISteamNetworkingSockets_SteamNetworkingSockets002": [ + "ReceiveMessagesOnConnection", + "ReceiveMessagesOnListenSocket" + ] +} + # manual converters for simple types (function pointers) manual_type_converters = [ "FSteamNetworkingSocketsDebugOutput" @@ -432,6 +439,13 @@ def get_path_converter(parent): return conv return None +class DummyWriter(object): + def write(self, s): + #noop + pass + +dummy_writer = DummyWriter() + def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, existing_methods): used_name = method.spelling if used_name in existing_methods: @@ -451,6 +465,10 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e for param in list(method.get_children()): if param.kind == clang.cindex.CursorKind.PARM_DECL: parambytes += int(math.ceil(param.type.get_size()/4.0) * 4) + if cppname in manually_handled_methods and \ + used_name in manually_handled_methods[cppname]: + #just don't write the cpp function + cpp = dummy_writer cfile.write("DEFINE_THISCALL_WRAPPER(%s_%s, %s)\n" % (winclassname, used_name, parambytes)) cpp_h.write("extern ") if method.result_type.spelling.startswith("ISteam"): @@ -629,11 +647,7 @@ def handle_method(cfile, classname, winclassname, cppname, method, cpp, cpp_h, e real_type = param.type; while real_type.kind == clang.cindex.TypeKind.POINTER: real_type = real_type.get_pointee() - if strip_const(real_type.spelling) in manually_handled_structs: - #this is clumsy - cpp.write(" lin_to_win_struct_%s_%s(retval, &lin_%s, %s);\n" % (real_type.spelling, sdkver, param.spelling, param.spelling)) - else: - cpp.write(" lin_to_win_struct_%s_%s(&lin_%s, %s);\n" % (real_type.spelling, sdkver, param.spelling, param.spelling)) + cpp.write(" lin_to_win_struct_%s_%s(&lin_%s, %s);\n" % (real_type.spelling, sdkver, param.spelling, param.spelling)) else: cpp.write(" lin_to_win_struct_%s_%s(&lin_%s, &%s);\n" % (param.type.spelling, sdkver, param.spelling, param.spelling)) if method.result_type.kind != clang.cindex.TypeKind.VOID and \ @@ -814,9 +828,6 @@ def handle_struct(sdkver, struct): hfile.write("struct %s;\n" % struct.displayname); if strip_const(struct.spelling) in manually_handled_structs: - #this is clumsy - hfile.write("extern void %s(struct win%s **w, struct %s **l);\n" % (w2l_handler_name, struct_name, struct.displayname)) - hfile.write("extern void %s(int retval, struct %s **l, struct win%s **w);\n" % (l2w_handler_name, struct.displayname, struct_name)) hfile.write("#endif\n\n") return diff --git a/lsteamclient/steamclient_manual_144.cpp b/lsteamclient/steamclient_manual_144.cpp index 0acd31f2..8eba5a6d 100644 --- a/lsteamclient/steamclient_manual_144.cpp +++ b/lsteamclient/steamclient_manual_144.cpp @@ -1,5 +1,6 @@ #include "steam_defs.h" #include "steamworks_sdk_144/steam_api.h" +#include "steamworks_sdk_144/isteamnetworkingsockets.h" #include "steamworks_sdk_144/steamnetworkingtypes.h" #include "steamclient_private.h" extern "C" { @@ -58,13 +59,7 @@ void lin_FreeData(struct SteamNetworkingMessage_t *lin_msg) ((void (__attribute__((ms_abi))*)(struct winSteamNetworkingMessage_t_144 *))msg->win_msg.m_pfnFreeData)(&msg->win_msg); } -void win_to_lin_struct_SteamNetworkingMessage_t_144(struct winSteamNetworkingMessage_t_144 **w, struct SteamNetworkingMessage_t **l) -{ - TRACE("\n"); - /* it's an output param, do nothing. */ -} - -void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct SteamNetworkingMessage_t **l, struct winSteamNetworkingMessage_t_144 **w) +void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct SteamNetworkingMessage_t **l, struct winSteamNetworkingMessage_t_144 **w, int max_messages) { int i; @@ -114,6 +109,29 @@ void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct Steam w[i] = &msg->win_msg; TRACE("done with %u, returned wrapper %p\n", i, msg); } + + for(; i < max_messages; ++i) + w[i] = NULL; +} + +int cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( + void *linux_side, HSteamNetConnection hConn, + winSteamNetworkingMessage_t_144 **ppOutMessages, int nMaxMessages) +{ + SteamNetworkingMessage_t *lin_ppOutMessages[nMaxMessages]; + int retval = ((ISteamNetworkingSockets*)linux_side)->ReceiveMessagesOnConnection(hConn, lin_ppOutMessages, nMaxMessages); + lin_to_win_struct_SteamNetworkingMessage_t_144(retval, lin_ppOutMessages, ppOutMessages, nMaxMessages); + return retval; +} + +int cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( + void *linux_side, HSteamListenSocket hSocket, + winSteamNetworkingMessage_t_144 **ppOutMessages, int nMaxMessages) +{ + SteamNetworkingMessage_t *lin_ppOutMessages[nMaxMessages]; + int retval = ((ISteamNetworkingSockets*)linux_side)->ReceiveMessagesOnListenSocket(hSocket, lin_ppOutMessages, nMaxMessages); + lin_to_win_struct_SteamNetworkingMessage_t_144(retval, lin_ppOutMessages, ppOutMessages, nMaxMessages); + return retval; } } diff --git a/lsteamclient/struct_converters.h b/lsteamclient/struct_converters.h index 50b380ff..78eb165b 100644 --- a/lsteamclient/struct_converters.h +++ b/lsteamclient/struct_converters.h @@ -82,8 +82,6 @@ struct winSteamNetworkingMessage_t_144 { #pragma pack( pop ) typedef struct winSteamNetworkingMessage_t_144 winSteamNetworkingMessage_t_144; struct SteamNetworkingMessage_t; -extern void win_to_lin_struct_SteamNetworkingMessage_t_144(struct winSteamNetworkingMessage_t_144 **w, struct SteamNetworkingMessage_t **l); -extern void lin_to_win_struct_SteamNetworkingMessage_t_144(int retval, struct SteamNetworkingMessage_t **l, struct winSteamNetworkingMessage_t_144 **w); #endif #if defined(SDKVER_143y) || !defined(__cplusplus)