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