now thats a lot of damage!
[vg.git] / src / vg / vg_steam.h
index ab135bcc675ea02d434d66f8ae8c323d28a0330a..740ffdaa076aef8f8b4864be8473eedb5ba2676f 100644 (file)
@@ -3,6 +3,10 @@
 
 #include "vg.h"
 
+/* 
+ * TODO: Combine interfaces and stuff here instead of having them in client code
+ */
+
 #if defined(__linux__) || defined(__APPLE__) 
 /* 
  * The 32-bit version of gcc has the alignment requirement for u64 and double 
@@ -522,6 +526,78 @@ int        SteamAPI_ManualDispatch_GetAPICallResult( HSteamPipe hSteamPipe,
 
 void   SteamAPI_ReleaseCurrentThreadMemory(void);
 
+static void steamworks_process_api_call( HSteamPipe pipe, 
+                                         CallbackMsg_t *callback )
+{
+   SteamAPICallCompleted_t *pCallCompleted = 
+      (SteamAPICallCompleted_t *)callback->m_pubParam;
+
+   int bFailed;
+
+   void *temp = alloca( pCallCompleted->m_cubParam );
+   
+   if( SteamAPI_ManualDispatch_GetAPICallResult( 
+      pipe,
+      pCallCompleted->m_hAsyncCall, 
+      temp,
+      pCallCompleted->m_cubParam, 
+      pCallCompleted->m_iCallback, 
+      &bFailed ) 
+   )
+   {
+      /* 
+       * Dispatch the call result to the registered handler(s) for the
+       * call identified by pCallCompleted->m_hAsyncCall 
+       */
+      
+      vg_info( "steamworks_event::api_call_completed( %lu )\n", 
+            pCallCompleted->m_hAsyncCall );
+      
+      int j=0;
+      for( int i=0; i<steam_async_track_count; i++ )
+      {
+         if( steam_async_trackers[j].id != pCallCompleted->m_hAsyncCall )
+         {
+            steam_async_trackers[j ++] = steam_async_trackers[i];
+         }
+         else
+         {
+            steam_async *pasync = &steam_async_trackers[j];
+            pasync->p_handler( temp, pasync->data );
+         }
+      }
+
+      if( steam_async_track_count == j )
+      {
+         vg_error( "No tracker was register for API call\n" );
+      }
+
+      steam_async_track_count = j;
+   } 
+   else 
+   { 
+#if 0
+      typedef enum ESteamAPICallFailure
+      {
+         k_ESteamAPICallFailureNone = -1,
+         k_ESteamAPICallFailureSteamGone = 0, 
+         k_ESteamAPICallFailureNetworkFailure = 1,     
+         k_ESteamAPICallFailureInvalidHandle = 2,
+         k_ESteamAPICallFailureMismatchedCallback = 3,
+      } 
+
+      ESteamAPICallFailure;
+      ESteamAPICallFailure fail_why = 
+      SteamAPI_ISteamUtils_GetAPICallFailureReason( 
+            steam_api_classes.utils, pCallCompleted->m_hAsyncCall );
+   
+      vg_error( "steamworks_event: error getting call result on"
+                "%lu (code %d)\n", 
+                pCallCompleted->m_hAsyncCall, fail_why );
+#endif
+   }
+}
+
 static void steamworks_event_loop( HSteamPipe pipe )
 {
        SteamAPI_ManualDispatch_RunFrame( pipe );
@@ -534,74 +610,7 @@ static void steamworks_event_loop( HSteamPipe pipe )
                /* Check for dispatching API call results */
                if( callback.m_iCallback == k_iSteamAPICallCompleted )
       {
-                       SteamAPICallCompleted_t *pCallCompleted = 
-            (SteamAPICallCompleted_t *)callback.m_pubParam;
-
-                       void *pTmpCallResult = vg_alloc( pCallCompleted->m_cubParam );
-                       int bFailed;
-                       
-                       if( SteamAPI_ManualDispatch_GetAPICallResult( 
-                               pipe,
-                               pCallCompleted->m_hAsyncCall, 
-                               pTmpCallResult,
-                               pCallCompleted->m_cubParam, 
-                               pCallCompleted->m_iCallback, 
-                               &bFailed ) 
-                       )
-                       {
-                               /* 
-             * Dispatch the call result to the registered handler(s) for the
-                                * call identified by pCallCompleted->m_hAsyncCall 
-             */
-                               
-                               vg_info( "steamworks_event::api_call_completed( %lu )\n", 
-                  pCallCompleted->m_hAsyncCall );
-            
-            int j=0;
-            for( int i=0; i<steam_async_track_count; i++ )
-            {
-               if( steam_async_trackers[j].id != pCallCompleted->m_hAsyncCall )
-               {
-                  steam_async_trackers[j ++] = steam_async_trackers[i];
-               }
-               else
-               {
-                  steam_async *pasync = &steam_async_trackers[j];
-                  pasync->p_handler( pTmpCallResult, pasync->data );
-               }
-            }
-
-            if( steam_async_track_count == j )
-            {
-               vg_error( "No tracker was register for API call\n" );
-            }
-
-            steam_async_track_count = j;
-                       } 
-                       else 
-                       { 
-#if 0
-                               typedef enum ESteamAPICallFailure
-                               {
-                                       k_ESteamAPICallFailureNone = -1,
-                                       k_ESteamAPICallFailureSteamGone = 0, 
-                                       k_ESteamAPICallFailureNetworkFailure = 1,       
-                                       k_ESteamAPICallFailureInvalidHandle = 2,
-                                       k_ESteamAPICallFailureMismatchedCallback = 3,
-                               } 
-
-            ESteamAPICallFailure;
-                               ESteamAPICallFailure fail_why = 
-                               SteamAPI_ISteamUtils_GetAPICallFailureReason( 
-                  steam_api_classes.utils, pCallCompleted->m_hAsyncCall );
-                       
-                               vg_error( "steamworks_event: error getting call result on"
-                      "%lu (code %d)\n", 
-                      pCallCompleted->m_hAsyncCall, fail_why );
-#endif
-                       }
-                       
-                       vg_free( pTmpCallResult );
+         steamworks_process_api_call( pipe, &callback );
                } 
                else 
                {