Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
steam_api_common.h
Go to the documentation of this file.
1
//====== Copyright Valve Corporation, All rights reserved. ====================
2
//
3
// Steamworks SDK minimal include
4
//
5
// Defines the minimal set of things we need to use any single interface
6
// or register for any callback.
7
//
8
//=============================================================================
9
10
#ifndef STEAM_API_COMMON_H
11
#define STEAM_API_COMMON_H
12
13
#include "
steamtypes.h
"
14
#include "
steamclientpublic.h
"
15
16
// S_API defines the linkage and calling conventions for steam_api.dll exports
17
#if defined( _WIN32 ) && !defined( _X360 )
18
#if defined( STEAM_API_EXPORTS )
19
#define S_API extern "C" __declspec( dllexport )
20
#elif defined( STEAM_API_NODLL )
21
#define S_API extern "C"
22
#else
23
#define S_API extern "C" __declspec( dllimport )
24
#endif
// STEAM_API_EXPORTS
25
#elif defined( __GNUC__ )
26
#if defined( STEAM_API_EXPORTS )
27
#define S_API extern "C" __attribute__ ((visibility("default")))
28
#else
29
#define S_API extern "C"
30
#endif
// STEAM_API_EXPORTS
31
#else
// !WIN32
32
#if defined( STEAM_API_EXPORTS )
33
#define S_API extern "C"
34
#else
35
#define S_API extern "C"
36
#endif
// STEAM_API_EXPORTS
37
#endif
38
39
#if defined( __cplusplus ) && ( __cplusplus >= 201103L )
40
#define S_OVERRIDE override
41
#else
42
#define S_OVERRIDE
43
#endif
44
45
#if ( defined(STEAM_API_EXPORTS) || defined(STEAM_API_NODLL) ) && !defined(API_GEN)
46
#define STEAM_PRIVATE_API( ... ) __VA_ARGS__
47
#elif defined(STEAM_API_EXPORTS) && defined(API_GEN)
48
#define STEAM_PRIVATE_API( ... )
49
#else
50
#define STEAM_PRIVATE_API( ... ) protected: __VA_ARGS__ public:
51
#endif
52
53
// handle to a communication pipe to the Steam client
54
typedef
int32
HSteamPipe
;
55
// handle to single instance of a steam user
56
typedef
int32
HSteamUser
;
57
58
// A fixed size buffer to receive an error message that is returned by some API
59
// calls.
60
const
int
k_cchMaxSteamErrMsg
= 1024;
61
typedef
char
SteamErrMsg
[
k_cchMaxSteamErrMsg
];
62
63
// #define away __cdecl on posix.
64
// This is really, really bad. We're sorry. But it's been this way for
65
// a long time now and it's scary to change it, as there may be others that
66
// depend on it.
67
#ifndef _WIN32
68
#define __cdecl
69
#endif
70
71
// function prototype
72
extern
"C"
typedef
void
(
S_CALLTYPE
*SteamAPIWarningMessageHook_t )(
int
,
const
char
* );
73
extern
"C"
typedef
uint32
(
S_CALLTYPE
*SteamAPI_CheckCallbackRegistered_t )(
int
iCallbackNum );
74
#if defined( __SNC__ )
75
#pragma diag_suppress=1700
// warning 1700: class "%s" has virtual functions but non-virtual destructor
76
#endif
77
78
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
79
// steam callback and call-result helpers
80
//
81
// The following macros and classes are used to register your application for
82
// callbacks and call-results, which are delivered in a predictable manner.
83
//
84
// STEAM_CALLBACK macros are meant for use inside of a C++ class definition.
85
// They map a Steam notification callback directly to a class member function
86
// which is automatically prototyped as "void func( callback_type *pParam )".
87
//
88
// CCallResult is used with specific Steam APIs that return "result handles".
89
// The handle can be passed to a CCallResult object's Set function, along with
90
// an object pointer and member-function pointer. The member function will
91
// be executed once the results of the Steam API call are available.
92
//
93
// CCallback and CCallbackManual classes can be used instead of STEAM_CALLBACK
94
// macros if you require finer control over registration and unregistration.
95
//
96
// Callbacks and call-results are queued automatically and are only
97
// delivered/executed when your application calls SteamAPI_RunCallbacks().
98
//
99
// Note that there is an alternative, lower level callback dispatch mechanism.
100
// See SteamAPI_ManualDispatch_Init
101
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
102
103
// Dispatch all queued Steamworks callbacks.
104
//
105
// This is safe to call from multiple threads simultaneously,
106
// but if you choose to do this, callback code could be executed on any thread.
107
// One alternative is to call SteamAPI_RunCallbacks from the main thread only,
108
// and call SteamAPI_ReleaseCurrentThreadMemory regularly on other threads.
109
S_API
void
S_CALLTYPE
SteamAPI_RunCallbacks
();
110
111
// Declares a callback member function plus a helper member variable which
112
// registers the callback on object creation and unregisters on destruction.
113
// The optional fourth 'var' param exists only for backwards-compatibility
114
// and can be ignored.
115
#define STEAM_CALLBACK( thisclass, func, ...
/*callback_type, [deprecated] var*/
) \
116
_STEAM_CALLBACK_SELECT( ( __VA_ARGS__, 4, 3 ), (
/**/
, thisclass, func, __VA_ARGS__ ) )
117
118
// Declares a callback function and a named CCallbackManual variable which
119
// has Register and Unregister functions instead of automatic registration.
120
#define STEAM_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
121
CCallbackManual< thisclass, callback_type > var; void func( callback_type *pParam )
122
123
// Dispatch callbacks relevant to the gameserver client and interfaces.
124
// To register for these, you need to use STEAM_GAMESERVER_CALLBACK.
125
// (Or call SetGameserverFlag on your CCallbackBase object.)
126
S_API
void
S_CALLTYPE
SteamGameServer_RunCallbacks
();
127
128
// Same as STEAM_CALLBACK, but for callbacks on the gameserver interface.
129
// These will be dispatched during SteamGameServer_RunCallbacks
130
#define STEAM_GAMESERVER_CALLBACK( thisclass, func,
/*callback_type, [deprecated] var*/
... ) \
131
_STEAM_CALLBACK_SELECT( ( __VA_ARGS__, GS, 3 ), ( this->SetGameserverFlag();, thisclass, func, __VA_ARGS__ ) )
132
#define STEAM_GAMESERVER_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
133
CCallbackManual< thisclass, callback_type, true > var; void func( callback_type *pParam )
134
135
//-----------------------------------------------------------------------------
136
// Purpose: base for callbacks and call results - internal implementation detail
137
//-----------------------------------------------------------------------------
138
class
CCallbackBase
139
{
140
public
:
141
CCallbackBase
() {
m_nCallbackFlags
= 0;
m_iCallback
= 0; }
142
// don't add a virtual destructor because we export this binary interface across dll's
143
virtual
void
Run
(
void
*pvParam ) = 0;
144
virtual
void
Run
(
void
*pvParam,
bool
bIOFailure,
SteamAPICall_t
hSteamAPICall ) = 0;
145
int
GetICallback
() {
return
m_iCallback
; }
146
virtual
int
GetCallbackSizeBytes
() = 0;
147
148
protected
:
149
enum
{
k_ECallbackFlagsRegistered
= 0x01,
k_ECallbackFlagsGameServer
= 0x02 };
150
uint8
m_nCallbackFlags
;
151
int
m_iCallback
;
152
friend
class
CCallbackMgr
;
153
154
private
:
155
CCallbackBase
(
const
CCallbackBase
& );
156
CCallbackBase
&
operator=
(
const
CCallbackBase
& );
157
};
158
159
//-----------------------------------------------------------------------------
160
// Purpose: templated base for callbacks - internal implementation detail
161
//-----------------------------------------------------------------------------
162
template
<
int
sizeof_P >
163
class
CCallbackImpl
:
protected
CCallbackBase
164
{
165
public
:
166
virtual
~CCallbackImpl
() {
if
(
m_nCallbackFlags
&
k_ECallbackFlagsRegistered
)
SteamAPI_UnregisterCallback
(
this
); }
167
void
SetGameserverFlag
() {
m_nCallbackFlags
|=
k_ECallbackFlagsGameServer
; }
168
169
protected
:
170
friend
class
CCallbackMgr
;
171
virtual
void
Run
(
void
*pvParam )
S_OVERRIDE
= 0;
172
virtual
void
Run
(
void
*pvParam,
bool
/*bIOFailure*/
,
SteamAPICall_t
/*hSteamAPICall*/
)
S_OVERRIDE
{
Run
( pvParam ); }
173
virtual
int
GetCallbackSizeBytes
()
S_OVERRIDE
{
return
sizeof_P; }
174
};
175
176
177
//-----------------------------------------------------------------------------
178
// Purpose: maps a steam async call result to a class member function
179
// template params: T = local class, P = parameter struct
180
//-----------------------------------------------------------------------------
181
template
<
class
T,
class
P >
182
class
CCallResult
:
private
CCallbackBase
183
{
184
public
:
185
typedef
void
(T::*
func_t
)( P*, bool );
186
187
CCallResult
();
188
~CCallResult
();
189
190
void
Set
(
SteamAPICall_t
hAPICall, T *p,
func_t
func );
191
bool
IsActive
()
const
;
192
void
Cancel
();
193
194
void
SetGameserverFlag
() {
m_nCallbackFlags
|=
k_ECallbackFlagsGameServer
; }
195
private
:
196
virtual
void
Run
(
void
*pvParam )
S_OVERRIDE
;
197
virtual
void
Run
(
void
*pvParam,
bool
bIOFailure,
SteamAPICall_t
hSteamAPICall )
S_OVERRIDE
;
198
virtual
int
GetCallbackSizeBytes
()
S_OVERRIDE
{
return
sizeof
( P ); }
199
200
SteamAPICall_t
m_hAPICall
;
201
T *
m_pObj
;
202
func_t
m_Func
;
203
};
204
205
206
207
//-----------------------------------------------------------------------------
208
// Purpose: maps a steam callback to a class member function
209
// template params: T = local class, P = parameter struct,
210
// bGameserver = listen for gameserver callbacks instead of client callbacks
211
//-----------------------------------------------------------------------------
212
template
<
class
T,
class
P,
bool
bGameserver = false >
213
class
CCallback
:
public
CCallbackImpl
< sizeof( P ) >
214
{
215
public
:
216
typedef
void
(T::*
func_t
)(P*);
217
218
// NOTE: If you can't provide the correct parameters at construction time, you should
219
// use the CCallbackManual callback object (STEAM_CALLBACK_MANUAL macro) instead.
220
CCallback
( T *pObj,
func_t
func );
221
222
void
Register
( T *pObj,
func_t
func );
223
void
Unregister
();
224
225
protected
:
226
virtual
void
Run
(
void
*pvParam )
S_OVERRIDE
;
227
228
T *
m_pObj
;
229
func_t
m_Func
;
230
};
231
232
233
//-----------------------------------------------------------------------------
234
// Purpose: subclass of CCallback which allows default-construction in
235
// an unregistered state; you must call Register manually
236
//-----------------------------------------------------------------------------
237
template
<
class
T,
class
P,
bool
bGameServer = false >
238
class
CCallbackManual
:
public
CCallback
< T, P, bGameServer >
239
{
240
public
:
241
CCallbackManual
() :
CCallback
< T, P, bGameServer >( nullptr, nullptr ) {}
242
243
// Inherits public Register and Unregister functions from base class
244
};
245
246
// Internal implementation details for all of the above
247
#include "
steam_api_internal.h
"
248
249
#endif
// STEAM_API_COMMON_H
int
SCRIPT_CONTROL SCRIPT_STATE const void int
Definition
Controls.cpp:5032
CCallResult::m_Func
func_t m_Func
Definition
steam_api_common.h:202
CCallResult::func_t
void(T::*) func_t(P *, bool)
Definition
steam_api_common.h:185
CCallResult::Cancel
void Cancel()
Definition
steam_api_internal.h:108
CCallResult::CCallResult
CCallResult()
Definition
steam_api_internal.h:79
CCallResult::GetCallbackSizeBytes
virtual int GetCallbackSizeBytes() S_OVERRIDE
Definition
steam_api_common.h:198
CCallResult::m_pObj
T * m_pObj
Definition
steam_api_common.h:201
CCallResult::SetGameserverFlag
void SetGameserverFlag()
Definition
steam_api_common.h:194
CCallResult::Run
virtual void Run(void *pvParam) S_OVERRIDE
Definition
steam_api_internal.h:124
CCallResult::m_hAPICall
SteamAPICall_t m_hAPICall
Definition
steam_api_common.h:200
CCallResult::Set
void Set(SteamAPICall_t hAPICall, T *p, func_t func)
Definition
steam_api_internal.h:88
CCallResult::IsActive
bool IsActive() const
Definition
steam_api_internal.h:102
CCallbackBase::m_iCallback
int m_iCallback
Definition
steam_api_common.h:151
CCallbackBase::CCallbackMgr
friend class CCallbackMgr
Definition
steam_api_common.h:152
CCallbackBase::CCallbackBase
CCallbackBase()
Definition
steam_api_common.h:141
CCallbackBase::operator=
CCallbackBase & operator=(const CCallbackBase &)
CCallbackBase::Run
virtual void Run(void *pvParam)=0
CCallbackBase::Run
virtual void Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall)=0
CCallbackBase::m_nCallbackFlags
uint8 m_nCallbackFlags
Definition
steam_api_common.h:150
CCallbackBase::CCallbackBase
CCallbackBase(const CCallbackBase &)
CCallbackBase::k_ECallbackFlagsGameServer
@ k_ECallbackFlagsGameServer
Definition
steam_api_common.h:149
CCallbackBase::k_ECallbackFlagsRegistered
@ k_ECallbackFlagsRegistered
Definition
steam_api_common.h:149
CCallbackBase::GetICallback
int GetICallback()
Definition
steam_api_common.h:145
CCallbackBase::GetCallbackSizeBytes
virtual int GetCallbackSizeBytes()=0
CCallback::CCallback
CCallback(T *pObj, func_t func)
Definition
steam_api_internal.h:141
CCallback::Unregister
void Unregister()
Definition
steam_api_internal.h:167
CCallback::m_Func
func_t m_Func
Definition
steam_api_common.h:229
CCallback::Register
void Register(T *pObj, func_t func)
Definition
steam_api_internal.h:152
CCallback::func_t
void(T::*) func_t(P *)
Definition
steam_api_common.h:216
CCallback::m_pObj
T * m_pObj
Definition
steam_api_common.h:228
CCallback::Run
virtual void Run(void *pvParam) S_OVERRIDE
Definition
steam_api_internal.h:174
CCallbackImpl
Definition
steam_api_common.h:164
CCallbackImpl::CCallbackMgr
friend class CCallbackMgr
Definition
steam_api_common.h:170
CCallbackImpl::GetCallbackSizeBytes
virtual int GetCallbackSizeBytes() S_OVERRIDE
Definition
steam_api_common.h:173
CCallbackImpl::~CCallbackImpl
virtual ~CCallbackImpl()
Definition
steam_api_common.h:166
CCallbackImpl::Run
virtual void Run(void *pvParam, bool, SteamAPICall_t) S_OVERRIDE
Definition
steam_api_common.h:172
CCallbackImpl::Run
virtual void Run(void *pvParam) S_OVERRIDE=0
CCallbackImpl::SetGameserverFlag
void SetGameserverFlag()
Definition
steam_api_common.h:167
CCallbackManual::CCallbackManual
CCallbackManual()
Definition
steam_api_common.h:241
S_API
#define S_API
Definition
steam_api_common.h:35
S_OVERRIDE
#define S_OVERRIDE
Definition
steam_api_common.h:42
HSteamPipe
int32 HSteamPipe
Definition
steam_api_common.h:54
SteamAPI_RunCallbacks
S_API void S_CALLTYPE SteamAPI_RunCallbacks()
k_cchMaxSteamErrMsg
const int k_cchMaxSteamErrMsg
Definition
steam_api_common.h:60
SteamErrMsg
char SteamErrMsg[k_cchMaxSteamErrMsg]
Definition
steam_api_common.h:61
uint32
const char *typedef uint32(S_CALLTYPE *SteamAPI_CheckCallbackRegistered_t)(int iCallbackNum)
Definition
steam_api_common.h:73
SteamGameServer_RunCallbacks
S_API void S_CALLTYPE SteamGameServer_RunCallbacks()
void
typedef void(S_CALLTYPE *SteamAPIWarningMessageHook_t)(int
HSteamUser
int32 HSteamUser
Definition
steam_api_common.h:56
steam_api_internal.h
SteamAPI_UnregisterCallback
S_API void S_CALLTYPE SteamAPI_UnregisterCallback(class CCallbackBase *pCallback)
steamclientpublic.h
steamtypes.h
int32
int int32
Definition
steamtypes.h:57
SteamAPICall_t
uint64 SteamAPICall_t
Definition
steamtypes.h:93
S_CALLTYPE
#define S_CALLTYPE
Definition
steamtypes.h:6
uint8
unsigned char uint8
Definition
steamtypes.h:11
ThirdParty
SteamworksSDK
include
steam
steam_api_common.h
Generated on
for Rise by
1.18.0