medium sized dollop
[carveJwlIkooP6JGAAIwe30JlM.git] / steam.h
1 #ifndef STEAM_H
2 #define STEAM_H
3
4 #include "vg/vg_steam.h"
5 #include "vg/vg_steam_utils.h"
6 #include "vg/vg_steam_networking.h"
7 #include "vg/vg_steam_auth.h"
8 #include "vg/vg_steam_http.h"
9
10 /*
11 * We only want to use steamworks if building for the networked version,
12 * theres not much point otherwise. We mainly want steamworks for setting
13 * achievements etc.. so that includes our own server too.
14 *
15 * This file also wraps the functions and interfaces that we want to use to
16 * make them a bit easier to read, since they are the flat API they have very
17 * long names. in non-networked builds they will return default errors or do
18 * nothing.
19 */
20
21 static void recv_steam_warning( int severity, const char *msg )
22 {
23 if( severity == 0 )
24 vg_low( "%s\n", msg );
25 else
26 vg_info( "%s\n", msg );
27 }
28
29 static int steam_ready = 0;
30 static void *hSteamNetworkingSockets,
31 *hSteamUser;
32
33 static HSteamPipe hSteamClientPipe;
34
35 static int steam_init(void)
36 {
37 #ifdef SR_NETWORKED
38 vg_info( "Initializing steamworks\n" );
39
40 if( !SteamAPI_Init() )
41 {
42 printf("\n");
43 vg_error( "Steamworks failed to initialize\n" );
44 return 1;
45 }
46
47 steam_ready = 1;
48
49 SteamAPI_ManualDispatch_Init();
50
51 /* Connect interfaces */
52 hSteamClientPipe = SteamAPI_GetHSteamPipe();
53 hSteamNetworkingSockets = SteamAPI_SteamNetworkingSockets_SteamAPI();
54 hSteamUser = SteamAPI_SteamUser();
55
56 ISteamUtils *utils = SteamAPI_SteamUtils();
57 SteamAPI_ISteamUtils_SetWarningMessageHook( utils, recv_steam_warning );
58
59 printf("\n");
60 vg_success( "\nSteamworks API running\n" );
61 #endif
62
63 return 1;
64 }
65
66 static void steam_update(void)
67 {
68 if( steam_ready )
69 steamworks_event_loop( hSteamClientPipe );
70 }
71
72 static void steam_end(void *nothing)
73 {
74 if( steam_ready )
75 {
76 vg_info( "Shutting down\n..." );
77 SteamAPI_Shutdown();
78 }
79 }
80
81 #endif /* STEAM_H */