/
kodi_game_dll.h
340 lines (304 loc) · 10.6 KB
/
kodi_game_dll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
* Copyright (C) 2014-2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#ifndef KODI_GAME_DLL_H_
#define KODI_GAME_DLL_H_
#include "kodi_game_types.h"
#ifdef __cplusplus
extern "C" {
#endif
// --- Game operations ---------------------------------------------------------
/*!
* \brief Load a game
*
* \param url The URL to load
*
* return the error, or GAME_ERROR_NO_ERROR if the game was loaded
*/
GAME_ERROR LoadGame(const char* url);
/*!
* \brief Load a game that requires multiple files
*
* \param type The game stype
* \param urls An array of urls
* \param urlCount The number of urls in the array
*
* \return the error, or GAME_ERROR_NO_ERROR if the game was loaded
*/
GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const char** urls, size_t urlCount);
/*!
* \brief Begin playing without a game file
*
* If the add-on supports standalone mode, it must add the <supports_standalone>
* tag to the extension point in addon.xml:
*
* <supports_no_game>false</supports_no_game>
*
* \return the error, or GAME_ERROR_NO_ERROR if the game add-on was loaded
*/
GAME_ERROR LoadStandalone(void);
/*!
* \brief Unload the current game
*
* \return the error, or GAME_ERROR_NO_ERROR if the game was unloaded
*/
/*! Unloads a currently loaded game */
GAME_ERROR UnloadGame(void);
/*!
* \brief Get information about the loaded game
*
* \param info The info structure to fill
*
* \return the error, or GAME_ERROR_NO_ERROR if info was filled
*/
GAME_ERROR GetGameInfo(game_system_av_info* info);
/*!
* \brief Get region of the loaded game
*
* \return the region, or GAME_REGION_UNKNOWN if unknown or no game is loaded
*/
GAME_REGION GetRegion(void);
/*!
* \brief Return true if the client requires the frontend to provide a game loop
*
* The game loop is a thread that calls RunFrame() in a loop at a rate
* determined by the playback speed and the client's FPS.
*
* \return true if the frontend should provide a game loop, false otherwise
*/
bool RequiresGameLoop(void);
/*!
* \brief Run a single frame for add-ons that use a game loop
*
* \return the error, or GAME_ERROR_NO_ERROR if there was no error
*/
GAME_ERROR RunFrame(void);
/*!
* \brief Reset the current game
*
* \return the error, or GAME_ERROR_NO_ERROR if the game was reset
*/
GAME_ERROR Reset(void);
// --- Hardware rendering operations -------------------------------------------
/*!
* \brief Invalidates the current HW context and reinitializes GPU resources
*
* Any GL state is lost, and must not be deinitialized explicitly.
*
* \return the error, or GAME_ERROR_NO_ERROR if the HW context was reset
*/
GAME_ERROR HwContextReset(void);
/*!
* \brief Called before the context is destroyed
*
* Resources can be deinitialized at this step.
*
* \return the error, or GAME_ERROR_NO_ERROR if the HW context was destroyed
*/
GAME_ERROR HwContextDestroy(void);
// --- Input operations --------------------------------------------------------
/*!
* \brief Check if input is accepted for a feature on the controller
*
* If only a subset of the controller profile is used, this can return false
* for unsupported features to not absorb their input.
*
* If the entire controller profile is used, this should always return true.
*
* \param controller_id The ID of the controller profile
* \param feature_name The name of a feature in that profile
* \return true if input is accepted for the feature, false otherwise
*/
bool HasFeature(const char* controller_id, const char* feature_name);
/*!
* \brief Get the input topolgy that specifies which controllers can be connected
*
* \return The input topology, or null to use the default
*
* If this returns non-null, topology must be freed using FreeTopology().
*
* If this returns null, the topology will default to a single port that can
* accept all controllers imported by addon.xml. The port ID is set to
* the DEFAULT_PORT_ID constant.
*/
game_input_topology* GetTopology();
/*!
* \brief Free the topology's resources
*
* \param topology The topology returned by GetTopology()
*/
void FreeTopology(game_input_topology* topology);
/*!
* \brief Enable/disable keyboard input using the specified controller
*
* \param enable True to enable input, false otherwise
* \param controller The controller info if enabling, or unused if disabling
*
* \return True if keyboard input was enabled, false otherwise
*/
bool EnableKeyboard(bool enable, const game_controller* controller);
/*!
* \brief Enable/disable mouse input using the specified controller
*
* \param enable True to enable input, false otherwise
* \param controller The controller info if enabling, or unused if disabling
*
* \return True if mouse input was enabled, false otherwise
*/
bool EnableMouse(bool enable, const game_controller* controller);
/*!
* \brief Connect/disconnect a controller to a port on the virtual game console
*
* \param connect True to connect a controller, false to disconnect
* \param address The address of the port
* \param controller The controller info if connecting, or unused if disconnecting
*
* The address is a string that allows traversal of the controller topology.
* It is formed by alternating port IDs and controller IDs separated by "/".
*
* For example, assume that the topology represented in XML for Snes9x is:
*
* <logicaltopology>
* <port type="controller" id="1">
* <accepts controller="game.controller.snes"/>
* <accepts controller="game.controller.snes.multitap">
* <port type="controller" id="1">
* <accepts controller="game.controller.snes"/>
* </port>
* <port type="controller" id="2">
* <accepts controller="game.controller.snes"/>
* </port>
* ...
* </accepts>
* </port>
* </logicaltopology>
*
* To connect a multitap to the console's first port, the multitap's controller
* info is set using the port address:
*
* 1
*
* To connect a SNES controller to the second port of the multitap, the
* controller info is next set using the address:
*
* 1/game.controller.multitap/2
*
* Any attempts to connect a controller to a port on a disconnected multitap
* will return false.
*/
bool ConnectController(bool connect, const char* port_address, const game_controller* controller);
/*!
* \brief Notify the add-on of an input event
*
* \param event The input event
*
* \return true if the event was handled, false otherwise
*/
bool InputEvent(const game_input_event* event);
// --- Serialization operations ------------------------------------------------
/*!
* \brief Get the number of bytes required to serialize the game
*
* \return the number of bytes, or 0 if serialization is not supported
*/
size_t SerializeSize(void);
/*!
* \brief Serialize the state of the game
*
* \param data The buffer receiving the serialized game data
* \param size The size of the buffer
*
* \return the error, or GAME_ERROR_NO_ERROR if the game was serialized into the buffer
*/
GAME_ERROR Serialize(uint8_t* data, size_t size);
/*!
* \brief Deserialize the game from the given state
*
* \param data A buffer containing the game's new state
* \param size The size of the buffer
*
* \return the error, or GAME_ERROR_NO_ERROR if the game deserialized
*/
GAME_ERROR Deserialize(const uint8_t* data, size_t size);
// --- Cheat operations --------------------------------------------------------
/*!
* \brief Reset the cheat system
*
* \return the error, or GAME_ERROR_NO_ERROR if the cheat system was reset
*/
GAME_ERROR CheatReset(void);
/*!
* \brief Get a region of memory
*
* \param type The type of memory to retrieve
* \param data Set to the region of memory; must remain valid until UnloadGame() is called
* \param size Set to the size of the region of memory
*
* \return the error, or GAME_ERROR_NO_ERROR if data was set to a valid buffer
*/
GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t** data, size_t* size);
/*!
* \brief Set a cheat code
*
* \param index
* \param enabled
* \param code
*
* \return the error, or GAME_ERROR_NO_ERROR if the cheat was set
*/
GAME_ERROR SetCheat(unsigned int index, bool enabled, const char* code);
// --- Add-on helper implementation --------------------------------------------
/*!
* \brief Called by Kodi to assign the function pointers of this add-on to pClient
*
* Note that get_addon() is defined here, so it will be available in all
* compiled game clients.
*/
void __declspec(dllexport) get_addon(void* ptr)
{
AddonInstance_Game* pClient = static_cast<AddonInstance_Game*>(ptr);
pClient->toAddon.LoadGame = LoadGame;
pClient->toAddon.LoadGameSpecial = LoadGameSpecial;
pClient->toAddon.LoadStandalone = LoadStandalone;
pClient->toAddon.UnloadGame = UnloadGame;
pClient->toAddon.GetGameInfo = GetGameInfo;
pClient->toAddon.GetRegion = GetRegion;
pClient->toAddon.RequiresGameLoop = RequiresGameLoop;
pClient->toAddon.RunFrame = RunFrame;
pClient->toAddon.Reset = Reset;
pClient->toAddon.HwContextReset = HwContextReset;
pClient->toAddon.HwContextDestroy = HwContextDestroy;
pClient->toAddon.HasFeature = HasFeature;
pClient->toAddon.GetTopology = GetTopology;
pClient->toAddon.FreeTopology = FreeTopology;
pClient->toAddon.EnableKeyboard = EnableKeyboard;
pClient->toAddon.EnableMouse = EnableMouse;
pClient->toAddon.ConnectController = ConnectController;
pClient->toAddon.InputEvent = InputEvent;
pClient->toAddon.SerializeSize = SerializeSize;
pClient->toAddon.Serialize = Serialize;
pClient->toAddon.Deserialize = Deserialize;
pClient->toAddon.CheatReset = CheatReset;
pClient->toAddon.GetMemory = GetMemory;
pClient->toAddon.SetCheat = SetCheat;
}
#ifdef __cplusplus
}
#endif
#endif // KODI_GAME_DLL_H_