new build method
authorhgn <hgodden00@gmail.com>
Mon, 8 Aug 2022 20:55:11 +0000 (21:55 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 8 Aug 2022 20:55:11 +0000 (21:55 +0100)
src/tools.sh [new file with mode: 0644]
src/vg/vg_m.h
src/vg/vg_steam.h
src/vg/vg_steam_auth.h
src/vg/vg_steam_networking.h
src/vg/vg_ui.h
vg_build.sh [new file with mode: 0644]

diff --git a/src/tools.sh b/src/tools.sh
new file mode 100644 (file)
index 0000000..e5a428a
--- /dev/null
@@ -0,0 +1,32 @@
+mkdir $_folder/tools -p
+
+_link="-lm"
+
+tool_shader(){
+   _src="vg/src/shader.c"
+   _dst="tools/shader"
+   compile_x
+}
+
+tool_fontcomp(){
+   _src="vg/src/fontcomp.c"
+   _dst="tools/fontcomp"
+   compile_x
+}
+
+tool_qoiconv(){
+   _src="vg/src/qoiconv.c"
+   _dst="tools/qoiconv"
+   compile_x
+}
+
+tool_texsheet(){
+   _src="vg/src/texsheet.c"
+   _dst="tools/texsheet"
+   compile_x
+}
+
+tool_shader
+tool_fontcomp
+tool_qoiconv
+tool_texsheet
index 7e827a531ca74db784c2a86620306af5fd97af35..a97101e6d0ac94b5012cd69f93f8dcf67d7a3eba 100644 (file)
@@ -902,29 +902,29 @@ static inline void m4x3_lookat( m4x3f m, v3f pos, v3f target, v3f up )
                                                                { 0.0f, 0.0f, 0.0f, 0.0f }}
 
 static void m4x4_projection( m4x4f m, float angle,
-      float ratio, float near, float far )
+      float ratio, float fnear, float ffar )
 {
-   float scale = tanf( angle * 0.5f * VG_PIf / 180.0f ) * near,
+   float scale = tanf( angle * 0.5f * VG_PIf / 180.0f ) * fnear,
          r = ratio * scale,
          l = -r,
          t = scale,
          b = -t;
 
-   m[0][0] =  2.0f * near / (r - l); 
+   m[0][0] =  2.0f * fnear / (r - l); 
    m[0][1] =  0.0f; 
    m[0][2] =  0.0f; 
    m[0][3] =  0.0f; 
    m[1][0] =  0.0f; 
-   m[1][1] =  2.0f * near / (t - b); 
+   m[1][1] =  2.0f * fnear / (t - b); 
    m[1][2] =  0.0f; 
    m[1][3] =  0.0f; 
    m[2][0] =  (r + l) / (r - l); 
    m[2][1] =  (t + b) / (t - b); 
-   m[2][2] = -(far + near) / (far - near); 
+   m[2][2] = -(ffar + fnear) / (ffar - fnear); 
    m[2][3] = -1.0f; 
    m[3][0] =  0.0f; 
    m[3][1] =  0.0f; 
-   m[3][2] = -2.0f * far * near / (far - near); 
+   m[3][2] = -2.0f * ffar * fnear / (ffar - fnear); 
    m[3][3] =  0.0f;
 } 
 
index b503d0bde228a7c8846a9abc1797fbe178093ec4..604dcdfa1d7f2a88adce79210c669d69b0eac8d1 100644 (file)
@@ -27,6 +27,14 @@ typedef int E_iCallBack_t;
 typedef u64    u64_steamid;
 typedef u64 SteamAPICall_t;
 
+typedef u32 AppId_t;
+const AppId_t k_uAppIdInvalid = 0x0;
+
+typedef u32 DepotId_t;
+const DepotId_t k_uDepotIdInvalid = 0x0;
+
+typedef u32 RTime32;
+
 enum { k_iSteamUserCallbacks = 100 };
 enum { k_iSteamGameServerCallbacks = 200 };
 enum { k_iSteamFriendsCallbacks = 300 };
@@ -576,4 +584,15 @@ static void steamworks_event_loop( HSteamPipe pipe,
        }
 }
 
+/*
+ * This is required to run the server outside of steamcmd environment.
+ * It can be any appid but idealy the one that is actually your game
+ */
+static void steamworks_ensure_txt( const char *appid_str )
+{
+   FILE *txt = fopen("steam_appid.txt", "w");
+   fputs( appid_str, txt );
+   fclose( txt );
+}
+
 #endif /* VG_STEAM_H */
index dec590a43757c8b3bbb1a51c0a3adf01075662b4..9d06c9c852c1bdac329cc16d97b469dc90cbc709 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef VG_STEAM_AUTH_H
 #define VG_STEAM_AUTH_H
 
+typedef u32 HAuthTicket;
+enum{ k_HAuthTicketInvalid = 0 };
+
 #include "vg_steam.h"
 #if defined( VALVE_CALLBACK_PACK_SMALL )
  #pragma pack( push, 4 )
  #pragma pack( push, 8 )
 #endif 
 
+typedef struct EncryptedAppTicketResponse_t EncryptedAppTicketResponse_t;
+struct EncryptedAppTicketResponse_t
+{
+       EResult m_eResult;
+};
+enum{ k_iEncryptedAppTicketResponse = k_iSteamUserCallbacks + 54 };
+
+typedef struct GetAuthSessionTicketResponse_t GetAuthSessionTicketResponse_t;
+struct GetAuthSessionTicketResponse_t
+{
+       HAuthTicket m_hAuthTicket;
+       EResult m_eResult;
+};
+enum{ k_iGetAuthSessionTicketResponse = k_iSteamUserCallbacks + 63 };
+
 #pragma pack(pop)
 
-typedef u32 HAuthTicket;
-enum{ k_HAuthTicketInvalid = 0 };
+/*
+ * Regular authentication
+ */
 
-void *SteamAPI_SteamUser_v021(void);
-void *SteamAPI_SteamUser(void) 
+typedef void ISteamUser;
+ISteamUser *SteamAPI_SteamUser_v021(void);
+ISteamUser *SteamAPI_SteamUser(void) 
 { 
    return SteamAPI_SteamUser_v021();
 }
 
 HAuthTicket SteamAPI_ISteamUser_GetAuthSessionTicket( 
-                  void *self, void *pTicket, 
+                  ISteamUser *self, void *pTicket, 
                   int cbMaxTicket, u32 *pcbTicket );
 
+/*
+ * Application symetric-key ticket (Client)
+ */
+
+SteamAPICall_t SteamAPI_ISteamUser_RequestEncryptedAppTicket( 
+      ISteamUser *self, void *pDataToInclude, int cbDataToInclude );
+
+int SteamAPI_ISteamUser_GetEncryptedAppTicket( 
+      ISteamUser *self, void *pTicket, 
+      int cbMaxTicket, u32 *pcbTicket );
+
+
+/* 
+ * Application symetric-key ticket method (Server)
+ */
+
+enum { k_nSteamEncryptedAppTicketSymmetricKeyLen = 32 };
+
+int SteamEncryptedAppTicket_BDecryptTicket( u8 *rgubTicketEncrypted, 
+         u32 cubTicketEncrypted, u8 *rgubTicketDecrypted, 
+         u32 *pcubTicketDecrypted, 
+         u8 rgubKey[k_nSteamEncryptedAppTicketSymmetricKeyLen], 
+         int cubKey );
+
+int SteamEncryptedAppTicket_BIsTicketForApp( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted, AppId_t nAppID );
+
+RTime32 SteamEncryptedAppTicket_GetTicketIssueTime( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted );
+
+void SteamEncryptedAppTicket_GetTicketSteamID( 
+      u8 *rgubTicketDecrypted, u32 cubTicketDecrypted, CSteamID *psteamID );
+
+AppId_t SteamEncryptedAppTicket_GetTicketAppID( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted );
+
+int SteamEncryptedAppTicket_BUserOwnsAppInTicket( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted, AppId_t nAppID );
+
+int SteamEncryptedAppTicket_BUserIsVacBanned( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted );
+
+int SteamEncryptedAppTicket_BGetAppDefinedValue( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted, u32 *pValue );
+
+u8 *SteamEncryptedAppTicket_GetUserVariableData( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted, u32 *pcubUserData );
+
+int SteamEncryptedAppTicket_BIsTicketSigned( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted, u8 *pubRSAKey, u32 cubRSAKey );
+
+int SteamEncryptedAppTicket_BIsLicenseBorrowed( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted );
+
+int SteamEncryptedAppTicket_BIsLicenseTemporary( u8 *rgubTicketDecrypted, 
+      u32 cubTicketDecrypted );
+
+static u8 vg_char_base16( char c )
+{
+   if( c >= '0' && c <= '9' )
+      return c-'0';
+   if( c >= 'a' && c <= 'f' )
+      return (c-'a') + 10;
+
+   return 0;
+}
+
+static int vg_load_steam_symetric_key( const char *path, u8 *buf )
+{
+   i64 len;
+   char *text_src = vg_textasset_read_s( path, &len );
+
+   if( text_src )
+   {
+      if( len < k_nSteamEncryptedAppTicketSymmetricKeyLen )
+      {
+         vg_error( "Application key was invalid size\n" );
+         free( text_src );
+         return 0;
+      }
+      
+      for( int i=0; i<k_nSteamEncryptedAppTicketSymmetricKeyLen; i++ )
+      {
+         buf[i] = (vg_char_base16( text_src[i*2+0] ) << 4) |
+                   vg_char_base16( text_src[i*2+1] );
+      }
+
+      free( text_src );
+      return 1;
+   }
+   else
+   {
+      vg_error( "Application key path was invalid\n" );
+      return 0;
+   }
+}
+
+
 #endif /* VG_STEAM_AUTH_H */
index c5c053626b7bb83306503e6d495c9fc57be917cd..874bc9e6464e353c8c27583befad3f975c8b3799 100644 (file)
@@ -193,10 +193,7 @@ typedef u32 HSteamListenSocket;
 HSteamListenSocket const k_HSteamListenSocket_Invalid = 0;
 
 typedef u32 SteamNetworkingPOPID;
-
-#define k_cchSteamNetworkingMaxConnectionCloseReason 128
-#define k_cchSteamNetworkingMaxConnectionDescription 128
-#define k_cchSteamNetworkingMaxConnectionAppName 32
+typedef i64 SteamNetworkingMicroseconds;
 
 #pragma pack(push,1)
 /* Store an IP and port. IPv6 is always used; IPv4 is represented using
@@ -328,69 +325,6 @@ ESteamNetworkingFakeIPType SteamAPI_SteamNetworkingIPAddr_GetFakeIPType(
 /* Return true if we are a FakeIP */
 int SteamAPI_SteamNetworkingIPAddr_IsFakeIP( SteamNetworkingIPAddr* self );
 
-
-/* Describe the state of a connection. */
-typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t;
-struct SteamNetConnectionInfo_t
-{
-       SteamNetworkingIdentity m_identityRemote;
-
-       /* Arbitrary user data set by the local application code */
-       i64 m_nUserData;
-
-       /* Handle to listen socket this was connected on, or 
-    * k_HSteamListenSocket_Invalid if we initiated the connection */
-       HSteamListenSocket m_hListenSocket;
-
-       /* Remote address.  Might be all 0's if we don't know it, or if this is N/A.
-    * (E.g. Basically everything except direct UDP connection.) */
-       SteamNetworkingIPAddr m_addrRemote;
-       u16 m__pad1;
-
-       /* What data center is the remote host in?  (0 if we don't know.) */
-       SteamNetworkingPOPID m_idPOPRemote;
-
-       /* What relay are we using to communicate with the remote host? 
-    * (0 if not applicable.) */
-       SteamNetworkingPOPID m_idPOPRelay;
-
-       /* High level state of the connection */
-       ESteamNetworkingConnectionState m_eState;
-
-       /* Basic cause of the connection termination or problem.
-    * See ESteamNetConnectionEnd for the values used */
-       int m_eEndReason;
-
-       /* 
-    * Human-readable, but non-localized explanation for connection
-    * termination or problem.  This is intended for debugging /
-        * diagnostic purposes only, not to display to users.  It might
-        * have some details specific to the issue.
-    */
-       char m_szEndDebug[ 128 ];
-
-       /* 
-    * Debug description.  This includes the internal connection ID,
-    * connection type (and peer information), and any name
-        * given to the connection by the app.  This string is used in various
-        * internal logging messages.
-        * 
-        * Note that the connection ID *usually* matches the HSteamNetConnection
-        * handle, but in certain cases with symmetric connections it might not.
-    */
-       char m_szConnectionDescription[ 128 ];
-
-       /* 
-    * Misc flags.  Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx
-    */
-       int m_nFlags;
-
-       /* 
-    * Internal stuff, room to change API easily
-    */
-       u32 reserved[63];
-};
-
 /* 
  * In a few places we need to set configuration options on listen sockets and 
  * connections, and have them take effect *before* the listen socket or 
@@ -446,6 +380,11 @@ void SteamAPI_SteamNetworkingConfigValue_t_SetString(
       SteamNetworkingConfigValue_t* self, ESteamNetworkingConfigValue eVal, 
       const char * data );
 
+typedef void ISteamNetworkingSockets;
+typedef struct SteamNetworkingMessage_t SteamNetworkingMessage_t;
+typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t;
+
+
 /*
  * Handle used to identify a poll group, used to query many
  * connections at once efficiently.
@@ -453,46 +392,384 @@ void SteamAPI_SteamNetworkingConfigValue_t_SetString(
 typedef u32 HSteamNetPollGroup;
 HSteamNetPollGroup const k_HSteamNetPollGroup_Invalid = 0;
 
-void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void);
-void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void) 
+ISteamNetworkingSockets 
+*SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void);
+
+ISteamNetworkingSockets 
+*SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void) 
 { 
    return SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(); 
 }
 
 
-void *SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
-void *SteamAPI_SteamNetworkingSockets_SteamAPI() 
+ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
+ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI() 
 { 
    return SteamAPI_SteamNetworkingSockets_SteamAPI_v012(); 
 }
 
+
+/* 
+ * Send the message unreliably. Can be lost.  Messages *can* be larger than a
+ * single MTU (UDP packet), but there is no retransmission, so if any piece
+ * of the message is lost, the entire message will be dropped.
+
+ * The sending API does have some knowledge of the underlying connection, so
+ * if there is no NAT-traversal accomplished or there is a recognized adjustment
+ * happening on the connection, the packet will be batched until the connection
+ * is open again.
+
+ * Migration note: This is not exactly the same as k_EP2PSendUnreliable!  You
+ * probably want k_ESteamNetworkingSendType_UnreliableNoNagle
+ */
+const int k_nSteamNetworkingSend_Unreliable = 0;
+
+/* 
+ * Disable Nagle's algorithm.
+ * By default, Nagle's algorithm is applied to all outbound messages. This means
+ * that the message will NOT be sent immediately, in case further messages are
+ * sent soon after you send this, which can be grouped together.  Any time there
+ * is enough buffered data to fill a packet, the packets will be pushed out 
+ * immediately, but partially-full packets not be sent until the Nagle timer 
+ * expires. See ISteamNetworkingSockets::FlushMessagesOnConnection, 
+ * ISteamNetworkingMessages::FlushMessagesToUser
+ *
+ * NOTE: Don't just send every message without Nagle because you want packets to
+ * get there quicker.  Make sure you understand the problem that Nagle is 
+ * solving before disabling it. If you are sending small messages, often many at
+ * the same time, then it is very likely that it will be more efficient to leave
+ * Nagle enabled.  A typical proper use of this flag is when you are sending 
+ * what you know will be the last message sent for a while (e.g. the last in the
+ * server simulation tick to a particular client), and you use this flag to
+ * flush all messages.
+ */
+const int k_nSteamNetworkingSend_NoNagle = 1;
+
+/* 
+ * Send a message unreliably, bypassing Nagle's algorithm for this message and 
+ * any messages currently pending on the Nagle timer. This is equivalent to 
+ * using k_ESteamNetworkingSend_Unreliable and then immediately flushing the 
+ * messages using ISteamNetworkingSockets::FlushMessagesOnConnection or 
+ * ISteamNetworkingMessages::FlushMessagesToUser. (But using this flag is more 
+ * efficient since you only make one API call.)
+ */
+const int k_nSteamNetworkingSend_UnreliableNoNagle = 
+            k_nSteamNetworkingSend_Unreliable | 
+            k_nSteamNetworkingSend_NoNagle;
+/*
+ * If the message cannot be sent very soon (because the connection is still 
+ * doing some initial handshaking, route negotiations, etc), then just drop it.
+ * This is only applicable for unreliable messages. Using this flag on reliable 
+ * messages is invalid.
+ */
+const int k_nSteamNetworkingSend_NoDelay = 4;
+
+/* 
+ * Send an unreliable message, but if it cannot be sent relatively quickly, just
+ * drop it instead of queuing it. This is useful for messages that are not 
+ * useful if they are excessively delayed, such as voice data.
+ * NOTE: The Nagle algorithm is not used, and if the message is not dropped, any
+ * messages waiting on the Nagle timer are immediately flushed.
+ *
+ * A message will be dropped under the following circumstances:
+ * - the connection is not fully connected.  (E.g. the "Connecting" or 
+ *                                                     "FindingRoute" states)
+ * - there is a sufficiently large number of messages queued up already such 
+ *   that the current message will not be placed on the wire in the next 
+ *   ~200ms or so.
+ *
+ * If a message is dropped for these reasons, k_EResultIgnored will be returned.
+ */
+const int k_nSteamNetworkingSend_UnreliableNoDelay = 
+            k_nSteamNetworkingSend_Unreliable |
+            k_nSteamNetworkingSend_NoDelay | 
+            k_nSteamNetworkingSend_NoNagle;
+
+/* 
+ * Reliable message send. Can send up to 
+ * k_cbMaxSteamNetworkingSocketsMessageSizeSend bytes in a single message. 
+ * Does fragmentation/re-assembly of messages under the hood, as well as a 
+ * sliding window for efficient sends of large chunks of data.
+ * The Nagle algorithm is used. See notes on 
+ * k_ESteamNetworkingSendType_Unreliable for more details.
+ * See k_ESteamNetworkingSendType_ReliableNoNagle, 
+ *     ISteamNetworkingSockets::FlushMessagesOnConnection,
+ *     ISteamNetworkingMessages::FlushMessagesToUser
+ *
+ * Migration note: This is NOT the same as k_EP2PSendReliable, it's more like 
+ * k_EP2PSendReliableWithBuffering
+ */
+const int k_nSteamNetworkingSend_Reliable = 8;
+
+/* 
+ * Send a message reliably, but bypass Nagle's algorithm.
+ *
+ * Migration note: This is equivalent to k_EP2PSendReliable
+ */
+const int k_nSteamNetworkingSend_ReliableNoNagle = 
+            k_nSteamNetworkingSend_Reliable | 
+            k_nSteamNetworkingSend_NoNagle;
+
+
 HSteamListenSocket SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP( 
-      void *self, SteamNetworkingIPAddr *localAddress, int nOptions, 
+      ISteamNetworkingSockets *self, 
+      SteamNetworkingIPAddr *localAddress, int nOptions, 
       SteamNetworkingConfigValue_t *pOptions );
 
 HSteamNetConnection SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress( 
-      void *self, 
+      ISteamNetworkingSockets *self, 
       SteamNetworkingIPAddr *address, int nOptions, 
       SteamNetworkingConfigValue_t *pOptions );
 
 
 EResult SteamAPI_ISteamNetworkingSockets_AcceptConnection( 
-      void *self, HSteamNetConnection hConn );
+      ISteamNetworkingSockets *self, 
+      HSteamNetConnection hConn );
 
 int SteamAPI_ISteamNetworkingSockets_CloseConnection( 
-      void *self, HSteamNetConnection hPeer, int nReason, const char *pszDebug, 
+      ISteamNetworkingSockets *self, 
+      HSteamNetConnection hPeer, int nReason, const char *pszDebug, 
       int bEnableLinger );
 
 int SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress( 
-      void *self, HSteamListenSocket hSocket, 
+      ISteamNetworkingSockets *self, HSteamListenSocket hSocket, 
       SteamNetworkingIPAddr *address );
 
 int SteamAPI_ISteamNetworkingSockets_CloseConnection( 
-      void *self, HSteamNetConnection hPeer, int nReason, const char *pszDebug, 
+      ISteamNetworkingSockets *self, 
+      HSteamNetConnection hPeer, int nReason, const char *pszDebug, 
       int bEnableLinger );
 
 int SteamAPI_ISteamNetworkingSockets_CloseListenSocket( 
-      void *self, HSteamListenSocket hSocket );
+      ISteamNetworkingSockets *self, HSteamListenSocket hSocket );
+
+EResult SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( 
+      ISteamNetworkingSockets* self, 
+      HSteamNetConnection hConn, const void *pData, u32 cbData, int nSendFlags, 
+      i64 * pOutMessageNumber );
+
+void SteamAPI_ISteamNetworkingSockets_SendMessages( 
+      ISteamNetworkingSockets* self, 
+      int nMessages, SteamNetworkingMessage_t *const *pMessages, 
+      i64 *pOutMessageNumberOrResult );
+
+EResult SteamAPI_ISteamNetworkingSockets_FlushMessagesOnConnection( 
+      ISteamNetworkingSockets* self, 
+      HSteamNetConnection hConn );
+
+int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnConnection( 
+      ISteamNetworkingSockets* self, 
+      HSteamNetConnection hConn, 
+      SteamNetworkingMessage_t **ppOutMessages, 
+      int nMaxMessages );
+
+/* 
+ * Poll Groups
+ */
+
+HSteamNetPollGroup SteamAPI_ISteamNetworkingSockets_CreatePollGroup( 
+      ISteamNetworkingSockets *self );
+
+int SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( 
+      ISteamNetworkingSockets *self, 
+      HSteamNetPollGroup hPollGroup );
+
+int SteamAPI_ISteamNetworkingSockets_SetConnectionPollGroup( 
+      ISteamNetworkingSockets *self, 
+      HSteamNetConnection hConn, HSteamNetPollGroup hPollGroup );
+
+int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup( 
+      ISteamNetworkingSockets *self, 
+      HSteamNetPollGroup hPollGroup, SteamNetworkingMessage_t **ppOutMessages, 
+      int nMaxMessages );
+/*
+ * Returns basic information about the high-level state of the connection.
+ * Returns false if the connection handle is invalid.
+ */
+int SteamAPI_ISteamNetworkingSockets_GetConnectionInfo( 
+      ISteamNetworkingSockets* self, 
+      HSteamNetConnection hConn, SteamNetConnectionInfo_t * pInfo );
+
+int SteamAPI_ISteamNetworkingSockets_GetDetailedConnectionStatus( 
+      ISteamNetworkingSockets* self, 
+      HSteamNetConnection hConn, char *pszBuf, int cbBuf );
+
+int SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress( 
+      ISteamNetworkingSockets* self, 
+      HSteamListenSocket hSocket, SteamNetworkingIPAddr *address );
+
+enum{ k_cchSteamNetworkingMaxConnectionCloseReason = 128 };
+enum{ k_cchSteamNetworkingMaxConnectionDescription = 128 };
+enum{ k_cchSteamNetworkingMaxConnectionAppName = 32 };
+enum{ k_nSteamNetworkConnectionInfoFlags_Unauthenticated = 1 };
+enum{ k_nSteamNetworkConnectionInfoFlags_Unencrypted = 2 };
+enum{ k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers = 4 };
+enum{ k_nSteamNetworkConnectionInfoFlags_Fast = 8 };
+enum{ k_nSteamNetworkConnectionInfoFlags_Relayed = 16 };
+enum{ k_nSteamNetworkConnectionInfoFlags_DualWifi = 32 };
+
+/* Describe the state of a connection. */
+typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t;
+struct SteamNetConnectionInfo_t
+{
+       /* 
+    * Who is on the other end? Depending on the connection type and phase of the
+    * connection, we might not know
+    */
+       SteamNetworkingIdentity m_identityRemote;
+
+       /* Arbitrary user data set by the local application code */
+       i64 m_nUserData;
+
+       /* 
+    * Handle to listen socket this was connected on, or 
+    * k_HSteamListenSocket_Invalid if we initiated the connection
+    */
+       HSteamListenSocket m_hListenSocket;
+
+       /*
+    * Remote address.  Might be all 0's if we don't know it, or if this is N/A.
+        * (E.g. Basically everything except direct UDP connection.)
+    */
+       SteamNetworkingIPAddr m_addrRemote;
+       u16 m__pad1;
+
+       /* What data center is the remote host in?  (0 if we don't know.) */
+       SteamNetworkingPOPID m_idPOPRemote;
+
+       /* 
+    * What relay are we using to communicate with the remote host?
+    * (0 if not applicable.)
+    */
+       SteamNetworkingPOPID m_idPOPRelay;
+
+       /* High level state of the connection */
+       ESteamNetworkingConnectionState m_eState;
+
+       /*
+    * Basic cause of the connection termination or problem.
+        * See ESteamNetConnectionEnd for the values used
+    */
+       int m_eEndReason;
+
+       /* 
+    * Human-readable, but non-localized explanation for connection
+        * termination or problem.  This is intended for debugging /
+        * diagnostic purposes only, not to display to users.  It might
+        * have some details specific to the issue.
+    */
+       char m_szEndDebug[ k_cchSteamNetworkingMaxConnectionCloseReason ];
+
+       /*
+    * Debug description.  This includes the internal connection ID,
+        * connection type (and peer information), and any name
+        * given to the connection by the app.  This string is used in various
+        * internal logging messages.
+        * 
+        * Note that the connection ID *usually* matches the HSteamNetConnection
+        * handle, but in certain cases with symmetric connections it might not.
+    */
+       char m_szConnectionDescription
+      [ k_cchSteamNetworkingMaxConnectionDescription ];
+
+       /* Misc flags.  Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx */
+       int m_nFlags;
+
+       /* Internal stuff, room to change API easily */
+       u32 reserved[63];
+};
+
+/* 
+ * Quick connection state, pared down to something you could call
+ * more frequently without it being too big of a perf hit.
+ */
+struct SteamNetConnectionRealTimeStatus_t
+{
+       /* High level state of the connection */
+       ESteamNetworkingConnectionState m_eState;
+
+       /* Current ping (ms) */
+       int m_nPing;
+
+       /* 
+    * Connection quality measured locally, 0...1.  
+    * (Percentage of packets delivered end-to-end in order). 
+    */
+       float m_flConnectionQualityLocal;
+
+       /* Packet delivery success rate as observed from remote host */
+       float m_flConnectionQualityRemote;
+
+       /* Current data rates from recent history. */
+       float m_flOutPacketsPerSec;
+       float m_flOutBytesPerSec;
+       float m_flInPacketsPerSec;
+       float m_flInBytesPerSec;
+
+       /* 
+    * Estimate rate that we believe that we can send data to our peer.
+        * Note that this could be significantly higher than m_flOutBytesPerSec,
+        * meaning the capacity of the channel is higher than you are sending data.
+        * (That's OK!)
+    */
+       int m_nSendRateBytesPerSecond;
+
+       /*
+    * Number of bytes pending to be sent.  This is data that you have recently
+        * requested to be sent but has not yet actually been put on the wire.  The
+        * reliable number ALSO includes data that was previously placed on the wire,
+        * but has now been scheduled for re-transmission.  Thus, it's possible to
+        * observe m_cbPendingReliable increasing between two checks, even if no
+        * calls were made to send reliable data between the checks.  Data that is
+        * awaiting the Nagle delay will appear in these numbers.
+    */
+       int m_cbPendingUnreliable;
+       int m_cbPendingReliable;
+
+       /*
+    * Number of bytes of reliable data that has been placed the wire, but
+        * for which we have not yet received an acknowledgment, and thus we may
+        * have to re-transmit.
+    */
+       int m_cbSentUnackedReliable;
+
+       /* 
+    * If you queued a message right now, approximately how long would that 
+    * message wait in the queue before we actually started putting its data on 
+    * the wire in a packet?
+        *
+        * In general, data that is sent by the application is limited by the 
+    * bandwidth of the channel.  If you send data faster than this, it must be 
+    * queued and put on the wire at a metered rate.  Even sending a small amount
+    * of data (e.g. a few MTU, say ~3k) will require some of the data to be 
+    * delayed a bit.
+        * 
+        * Ignoring multiple lanes,the estimated delay will be approximately equal to
+        *
+        *              ( m_cbPendingUnreliable+m_cbPendingReliable ) / 
+    *             m_nSendRateBytesPerSecond
+        *
+        * plus or minus one MTU.  It depends on how much time has elapsed since the 
+    * last packet was put on the wire.  For example, the queue might have *just*
+    * been emptied, and the last packet placed on the wire, and we are exactly 
+    * up against the send rate limit.  In that case we might need to wait for 
+    * one packet's worth of time to elapse before we can send again. On the 
+    * other extreme, the queue might have data in it waiting for Nagle. (This 
+    * will always be less than one packet, because as soon as we have a complete
+    * packet we would send it.)  In that case, we might be ready to send data 
+    * now, and this value will be 0.
+        *
+        * This value is only valid if multiple lanes are not used. If multiple lanes
+    * are in use, then the queue time will be different for each lane, and you 
+    * must use the value in SteamNetConnectionRealTimeLaneStatus_t.
+        * 
+        * Nagle delay is ignored for the purposes of this calculation.
+    */
+       SteamNetworkingMicroseconds m_usecQueueTime;
+
+       // Internal stuff, room to change API easily
+       u32 reserved[16];
+};
 
 /*
  * Callbacks
@@ -530,4 +807,198 @@ struct SteamNetAuthenticationStatus_t
 };
 
 #pragma pack(pop)
+
+/* This does not have packing specified in the steamnetworkingtypes.h, it seems
+ * to use default */
+struct SteamNetworkingMessage_t
+{
+       /*
+    * Message payload
+    */
+       void *m_pData;
+
+       /*
+    * Size of the payload.
+    */
+       int m_cbSize;
+
+       HSteamNetConnection m_conn;
+
+       /* 
+    * For inbound messages: Who sent this to us?
+        * For outbound messages on connections: not used.
+        * For outbound messages on the ad-hoc ISteamNetworkingMessages interface: 
+    *    who should we send this to?
+    */
+       SteamNetworkingIdentity m_identityPeer;
+
+       /* 
+    * For messages received on connections, this is the user data
+        * associated with the connection.
+        *
+        * This is *usually* the same as calling GetConnection() and then
+        * fetching the user data associated with that connection, but for
+        * the following subtle differences:
+        *
+        * - This user data will match the connection's user data at the time
+        *   is captured at the time the message is returned by the API.
+        *   If you subsequently change the userdata on the connection,
+        *   this won't be updated.
+        * - This is an inline call, so it's *much* faster.
+        * - You might have closed the connection, so fetching the user data
+        *   would not be possible.
+        *
+        * Not used when sending messages.
+    */
+       i64 m_nConnUserData;
+
+       /*
+    * Local timestamp when the message was received
+        * Not used for outbound messages.
+    */
+       SteamNetworkingMicroseconds m_usecTimeReceived;
+
+       /* 
+    * Message number assigned by the sender.  This is not used for outbound
+        * messages.  Note that if multiple lanes are used, each lane has its own
+        * message numbers, which are assigned sequentially, so messages from
+        * different lanes will share the same numbers.
+    */
+       i64 m_nMessageNumber;
+
+       /* 
+    * Function used to free up m_pData.  This mechanism exists so that
+        * apps can create messages with buffers allocated from their own
+        * heap, and pass them into the library.  This function will
+        * usually be something like:
+    *
+        * free( pMsg->m_pData );
+    */
+       void (*m_pfnFreeData)( SteamNetworkingMessage_t *pMsg );
+
+       /*
+    * Function to used to decrement the internal reference count and, if
+        * it's zero, release the message.  You should not set this function pointer,
+        * or need to access this directly!  Use the Release() function instead!
+    */
+       void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg );
+
+       /* 
+    * When using ISteamNetworkingMessages, the channel number the message was 
+    * received on (Not used for messages sent or received on "connections")
+    */
+       int m_nChannel;
+
+       /* 
+    * Bitmask of k_nSteamNetworkingSend_xxx flags.
+        * For received messages, only the k_nSteamNetworkingSend_Reliable bit is 
+    *    valid.
+        * For outbound messages, all bits are relevant
+    */
+       int m_nFlags;
+
+       /* 
+    * Arbitrary user data that you can use when sending messages using
+        * ISteamNetworkingUtils::AllocateMessage and 
+    *    ISteamNetworkingSockets::SendMessage.
+        * (The callback you set in m_pfnFreeData might use this field.)
+        *
+        * Not used for received messages.
+    */
+       i64 m_nUserData;
+
+       /* 
+    * For outbound messages, which lane to use? See 
+    *    ISteamNetworkingSockets::ConfigureConnectionLanes.
+        * For inbound messages, what lane was the message received on?
+    */
+       u16 m_idxLane;
+       u16 _pad1__;
+};
+
+void SteamAPI_SteamNetworkingMessage_t_Release(SteamNetworkingMessage_t* self);
+
+
+
+
+/*
+ * Utility
+ */
+
+static const char *string_ESteamNetworkingConnectionState( 
+      ESteamNetworkingConnectionState s )
+{
+   switch(s)
+   {
+      case k_ESteamNetworkingConnectionState_None:       return "None"; break;
+      case k_ESteamNetworkingConnectionState_Connecting: 
+         return "Connecting";
+      break;
+      case k_ESteamNetworkingConnectionState_FindingRoute:
+         return "Finding route";
+      break;
+      case k_ESteamNetworkingConnectionState_Connected:
+         return "Connected";
+      break;
+      case k_ESteamNetworkingConnectionState_ClosedByPeer:
+         return "Closed By Peer";
+      break;
+      case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
+         return "Problem detected locally";
+      break;
+      case k_ESteamNetworkingConnectionState_FinWait:
+         return "Finwait";
+      break;
+      case k_ESteamNetworkingConnectionState_Linger:
+         return "Linger";
+      break;
+      case k_ESteamNetworkingConnectionState_Dead:
+         return "Dead";
+      break;
+      case k_ESteamNetworkingConnectionState__Force32Bit:
+         return "Force 32 Bit";
+      break;
+   }
+
+   return "Error";
+}
+
+static const char *string_ESteamNetworkingAvailability( 
+      ESteamNetworkingAvailability s )
+{
+   switch(s)
+   {
+      case k_ESteamNetworkingAvailability_CannotTry:
+         return "Cannot Try";
+      break;
+      case k_ESteamNetworkingAvailability_Failed:
+         return "Failed";
+      break;
+      case k_ESteamNetworkingAvailability_Previously:
+         return "Previously";
+      break;
+      case k_ESteamNetworkingAvailability_Retrying:
+         return "Retrying";
+      break;
+      case k_ESteamNetworkingAvailability_NeverTried:
+         return "Never tried";
+      break;
+      case k_ESteamNetworkingAvailability_Waiting:
+         return "Waiting";
+      break;
+      case k_ESteamNetworkingAvailability_Attempting:
+         return "Attempting";
+      break;
+      case k_ESteamNetworkingAvailability_Current:
+         return "Current";
+      break;
+      case k_ESteamNetworkingAvailability_Unknown:
+         return "Unknown";
+      break;
+      default:
+         return "Error";
+      break;
+   }
+}
+
 #endif /* VG_STEAM_NETWORKING_H */
index 5b97133b3b1ceebe096300d0de8a9bdc0563a83d..917b5e657c3c3b9611335a4b830fead767040bcd 100644 (file)
@@ -123,6 +123,8 @@ struct ui_ctx
        }
        *verts;
        #pragma pack(pop)
+
+   u32 control_id;
        
        u32 num_verts;
        u16 *indices;
@@ -133,8 +135,7 @@ struct ui_ctx
        u32 stack_count;
        u32 capture_mouse_id;
        int capture_lock;
-       u32 id_base;
-       int glyph_base;
+
        
        /* User input */
        ui_px mouse[2];
@@ -463,21 +464,14 @@ static void ui_clamp_rect( ui_rect parent, ui_rect dest )
        dest[1] = vg_max( parent[1], dest[1] );
 }
 
-static u32 ui_group_id( ui_ctx *ctx, u32 lesser_unique )
-{
-       return ctx->id_base | lesser_unique;
-}
-
 static void ui_capture_mouse( ui_ctx *ctx, u32 id )
 {
-       u32 group_uid = ui_group_id(ctx,id);
-
        struct ui_qnode *node = &ctx->stack[ ctx->stack_count-1 ];
-       node->capture_id = group_uid;
+       node->capture_id = id;
        
        if( !ctx->capture_lock && node->mouse_over )
        {
-               ctx->capture_mouse_id = group_uid;
+               ctx->capture_mouse_id = id;
        }
 }
 
@@ -728,11 +722,13 @@ enum button_state
        k_button_hold
 };
 
-static int ui_button( ui_ctx *ctx, u32 id )
+static int ui_button( ui_ctx *ctx )
 {
+   u32 uid = ctx->control_id ++;
+
        ui_new_node( ctx );
        {
-               ui_capture_mouse( ctx, id );
+               ui_capture_mouse( ctx, uid );
                
                if( ui_hasmouse(ctx) )
                {
@@ -757,8 +753,6 @@ static int ui_button( ui_ctx *ctx, u32 id )
 
 static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
 {
-       ctx->id_base = control_group << 16;
-
        if( window->drag )
        {
                window->transform[0] = ctx->mouse[0]+window->drag_offset[0];
@@ -776,13 +770,13 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
        
        ui_new_node( ctx );
        {
-               ui_capture_mouse( ctx, __COUNTER__ );
+               ui_capture_mouse( ctx, ctx->control_id ++ );
                
                /* Drag bar */
                ctx->cursor[3] = 25;            
                ui_new_node( ctx );
                {
-                       ui_capture_mouse( ctx, __COUNTER__ );
+                       ui_capture_mouse( ctx, ctx->control_id ++ );
                        
                        struct ui_vert *drag_bar = ui_fill_rect( ctx, ctx->cursor, 0xff555555 );
                        
@@ -798,7 +792,7 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
                        ui_align_top( ctx );
                        ui_rect_pad( ctx->cursor, 4 );
                        
-                       if( ui_button( ctx, __COUNTER__ ) )
+                       if( ui_button( ctx ) )
                        {
                                vg_info( "Click clacked\n" );
                        }
@@ -870,12 +864,9 @@ static void ui_slider( ui_ctx *ctx, struct ui_slider *slider )
    ctx->cursor[2] = fwidth;
    ctx->cursor[0] = slider_start + fpos * fmove;
    
-   /* TODO.. */
-   u32 uid = (u32)(u64)slider->data;
-   int status = ui_button( ctx, uid );
-   
-   if( ctx->capture_lock && 
-         (ctx->capture_mouse_id == ui_group_id( ctx, uid )))
+   u32 uid = ctx->control_id ++;
+   int status = ui_button( ctx );
+   if( ctx->capture_lock && (ctx->capture_mouse_id == uid))
    {
       float ui_new = ctx->mouse[0],
             local  = ui_new - (slider_start + fstart),
@@ -891,7 +882,6 @@ static void ui_slider( ui_ctx *ctx, struct ui_slider *slider )
    snprintf( buf, 12, "%.2f", *slider->data );
    ui_text( ctx, ctx->cursor, buf, 1, 0 );
    ui_end_down( ctx );
-
    ui_end_down( ctx );
 }
 
@@ -908,8 +898,7 @@ static void ui_slider_vector( ui_ctx *ctx, struct ui_slider_vector *slider )
 
 static void ui_checkbox( ui_ctx *ctx, struct ui_checkbox *cb )
 {
-   u32 uid = (u32)(u64)cb->data;
-   if( ui_button(ctx,uid) == k_button_click )
+   if( ui_button(ctx) == k_button_click )
       *cb->data ^= 0x1;
    
    ui_new_node(ctx);
@@ -938,7 +927,6 @@ static void ui_checkbox( ui_ctx *ctx, struct ui_checkbox *cb )
 #define gui_align_top() ui_align_top( &ui_global_ctx )
 #define gui_align_left() ui_align_left( &ui_global_ctx )
 #define gui_clamp_rect(...) ui_clamp_rect( &ui_global_ctx, __VA_ARGS__)
-#define gui_group_id(...) ui_group_id( &ui_global_ctx, __VA_ARGS__)
 #define gui_capture_mouse(...) ui_capture_mouse( &ui_global_ctx, __VA_ARGS__)
 #define gui_set_clip(...) ui_set_clip( &ui_global_ctx, __VA_ARGS__)
 #define gui_release_clip() ui_release_clip( &ui_global_ctx )
diff --git a/vg_build.sh b/vg_build.sh
new file mode 100644 (file)
index 0000000..9ea7867
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+# Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved
+
+# Util
+# ==============================================================================
+error(){
+    echo -e "\033[1;31mError:\e[0m $@"
+    exit 1
+}
+
+warning(){
+    echo -e "\033[1;33mWarning:\e[0m $@"
+}
+
+success(){
+   echo -e "\033[1;32mSuccess:\e[0m $@"
+}
+
+logit(){
+   echo -e "\033[0;37m$@\e[0m"
+}
+
+titleit(){
+   echo ""
+   echo -e "\033[1;35m$@\e[0m"
+   echo "================================================================"
+   echo ""
+}
+
+titleit "      vg_build.sh ver: 2.0\n"
+
+# Compile shit
+# ==============================================================================
+
+compiler_cache="ccache"
+
+# Autodetect ccache unavailible
+if ! [ -x "$( command -v $compiler_cache )" ]; then
+   compiler_cache=""
+fi
+
+compile_x(){
+   mkdir $_folder -p
+
+   cmd="$compiler_cache $_compiler 
+        $_options
+        $_warnings
+        $_include
+        $_library
+        $_src
+        -o $_folder/$_dst$_ext
+        $_link
+        $_epilogue"
+
+   logit "    $cmd\n"
+   $cmd
+
+       if [ $? -ne 0 ]; then
+               error "compiler failed"
+       fi
+
+   success "Compiled item\n"
+}
+
+# Tools scripts
+# ==============================================================================
+enable_tools=false
+
+vg_compile_tools() {
+   if [ $enable_tools = true ]; then source vg/src/tools.sh; fi
+}
+
+tools() {
+   enable_tools=true
+}
+
+$1
+$2
+$3
+$4
+$5
+$6
+$7
+$8
+$9