summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h2360
1 files changed, 2360 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h
new file mode 100644
index 0000000..a53f1e7
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h
@@ -0,0 +1,2360 @@
1/*
2 * Copyright (C) 2014-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12
13#ifdef BUILD_KODI_ADDON
14#include "XBMC_vkeys.h"
15#else
16#include "input/XBMC_vkeys.h"
17#endif
18
19//==============================================================================
20/// @addtogroup cpp_kodi_addon_game
21///
22/// To use on Libretro and for stand-alone games or emulators that does not use
23/// the Libretro API.
24///
25/// Possible examples could be, Nvidia GameStream via Limelight or WINE capture
26/// could possible through the Game API.
27///
28
29namespace kodi
30{
31namespace addon
32{
33class CInstanceGame;
34}
35} // namespace kodi
36
37extern "C"
38{
39
40//==============================================================================
41/// \defgroup cpp_kodi_addon_game_Defs Definitions, structures and enumerators
42/// \ingroup cpp_kodi_addon_game
43/// @brief **Game add-on instance definition values**
44//------------------------------------------------------------------------------
45
46//==============================================================================
47/// \ingroup cpp_kodi_addon_game_Defs
48/// @brief **Port ID used when topology is unknown**
49#define DEFAULT_PORT_ID "1"
50//------------------------------------------------------------------------------
51
52//==============================================================================
53/// \ingroup cpp_kodi_addon_game_Defs
54/// @brief **Game add-on error codes**
55///
56/// Used as return values on most Game related functions.
57///
58typedef enum GAME_ERROR
59{
60 /// @brief no error occurred
61 GAME_ERROR_NO_ERROR,
62
63 /// @brief an unknown error occurred
64 GAME_ERROR_UNKNOWN,
65
66 /// @brief the method that the frontend called is not implemented
67 GAME_ERROR_NOT_IMPLEMENTED,
68
69 /// @brief the command was rejected by the game client
70 GAME_ERROR_REJECTED,
71
72 /// @brief the parameters of the method that was called are invalid for this operation
73 GAME_ERROR_INVALID_PARAMETERS,
74
75 /// @brief the command failed
76 GAME_ERROR_FAILED,
77
78 /// @brief no game is loaded
79 GAME_ERROR_NOT_LOADED,
80
81 /// @brief game requires restricted resources
82 GAME_ERROR_RESTRICTED,
83} GAME_ERROR;
84//------------------------------------------------------------------------------
85
86//--==----==----==----==----==----==----==----==----==----==----==----==----==--
87/// \defgroup cpp_kodi_addon_game_Defs_AudioStream 1. Audio stream
88/// \ingroup cpp_kodi_addon_game_Defs
89/// @brief **The for Audio stream used data system**
90///
91/// Used to give Addon currently used audio stream configuration on Kodi and
92/// arrays to give related data to Kodi on callbacks.
93///
94//@{
95
96//==============================================================================
97/// @brief **Stream Format**
98///
99/// From Kodi requested specified audio sample format.
100///
101typedef enum GAME_PCM_FORMAT
102{
103 GAME_PCM_FORMAT_UNKNOWN,
104
105 /// @brief S16NE sample format
106 GAME_PCM_FORMAT_S16NE,
107} GAME_PCM_FORMAT;
108//------------------------------------------------------------------------------
109
110//==============================================================================
111/// @brief **Audio channel**
112///
113/// Channel identification flags.
114///
115typedef enum GAME_AUDIO_CHANNEL
116{
117 /// @brief Channel list terminator
118 GAME_CH_NULL,
119
120 /// @brief Channel front left
121 GAME_CH_FL,
122
123 /// @brief Channel front right
124 GAME_CH_FR,
125
126 /// @brief Channel front center
127 GAME_CH_FC,
128
129 /// @brief Channel Low Frequency Effects / Subwoofer
130 GAME_CH_LFE,
131
132 /// @brief Channel back left
133 GAME_CH_BL,
134
135 /// @brief Channel back right
136 GAME_CH_BR,
137
138 /// @brief Channel front left over center
139 GAME_CH_FLOC,
140
141 /// @brief Channel front right over center
142 GAME_CH_FROC,
143
144 /// @brief Channel back center
145 GAME_CH_BC,
146
147 /// @brief Channel surround/side left
148 GAME_CH_SL,
149
150 /// @brief Channel surround/side right
151 GAME_CH_SR,
152
153 /// @brief Channel top front left
154 GAME_CH_TFL,
155
156 /// @brief Channel top front right
157 GAME_CH_TFR,
158
159 /// @brief Channel top front center
160 GAME_CH_TFC,
161
162 /// @brief Channel top center
163 GAME_CH_TC,
164
165 /// @brief Channel top back left
166 GAME_CH_TBL,
167
168 /// @brief Channel top back right
169 GAME_CH_TBR,
170
171 /// @brief Channel top back center
172 GAME_CH_TBC,
173
174 /// @brief Channel bacl left over center
175 GAME_CH_BLOC,
176
177 /// @brief Channel back right over center
178 GAME_CH_BROC,
179} GAME_AUDIO_CHANNEL;
180//------------------------------------------------------------------------------
181
182//==============================================================================
183/// @brief **Game audio stream properties**
184///
185/// Used by Kodi to pass the currently required audio stream settings to the addon
186///
187typedef struct game_stream_audio_properties
188{
189 GAME_PCM_FORMAT format;
190 const GAME_AUDIO_CHANNEL* channel_map;
191} ATTRIBUTE_PACKED game_stream_audio_properties;
192//------------------------------------------------------------------------------
193
194//==============================================================================
195/// @brief **Audio stream packet**
196///
197/// This packet contains audio stream data passed to Kodi.
198///
199typedef struct game_stream_audio_packet
200{
201 /// @brief Pointer for audio stream data given to Kodi
202 const uint8_t *data;
203
204 /// @brief Size of data array
205 size_t size;
206} ATTRIBUTE_PACKED game_stream_audio_packet;
207//------------------------------------------------------------------------------
208
209//@}
210
211//--==----==----==----==----==----==----==----==----==----==----==----==----==--
212/// \defgroup cpp_kodi_addon_game_Defs_VideoStream 2. Video stream
213/// \ingroup cpp_kodi_addon_game_Defs
214/// @brief **The for Video stream used data system**
215///
216/// Used to give Addon currently used video stream configuration on Kodi and
217/// arrays to give related data to Kodi on callbacks.
218///
219//@{
220
221//==============================================================================
222/// @brief **Pixel format**
223///
224/// From Kodi requested specified video RGB color model format.
225///
226typedef enum GAME_PIXEL_FORMAT
227{
228 GAME_PIXEL_FORMAT_UNKNOWN,
229
230 /// @brief 0RGB8888 Format
231 GAME_PIXEL_FORMAT_0RGB8888,
232
233 /// @brief RGB565 Format
234 GAME_PIXEL_FORMAT_RGB565,
235
236 /// @brief 0RGB1555 Format
237 GAME_PIXEL_FORMAT_0RGB1555,
238} GAME_PIXEL_FORMAT;
239//------------------------------------------------------------------------------
240
241//==============================================================================
242/// @brief **Video rotation position**
243///
244/// To define position how video becomes shown.
245///
246typedef enum GAME_VIDEO_ROTATION
247{
248 /// @brief 0° and Without rotation
249 GAME_VIDEO_ROTATION_0,
250
251 /// @brief rotate 90° counterclockwise
252 GAME_VIDEO_ROTATION_90_CCW,
253
254 /// @brief rotate 180° counterclockwise
255 GAME_VIDEO_ROTATION_180_CCW,
256
257 /// @brief rotate 270° counterclockwise
258 GAME_VIDEO_ROTATION_270_CCW,
259} GAME_VIDEO_ROTATION;
260//------------------------------------------------------------------------------
261
262//==============================================================================
263/// @brief **Game video stream properties**
264///
265/// Used by Kodi to pass the currently required video stream settings to the addon
266///
267typedef struct game_stream_video_properties
268{
269 /// @brief The to used pixel format
270 GAME_PIXEL_FORMAT format;
271
272 /// @brief The nominal used width
273 unsigned int nominal_width;
274
275 /// @brief The nominal used height
276 unsigned int nominal_height;
277
278 /// @brief The maximal used width
279 unsigned int max_width;
280
281 /// @brief The maximal used height
282 unsigned int max_height;
283
284 /// @brief On video stream used aspect ration
285 ///
286 /// @note If aspect_ratio is <= 0.0, an aspect ratio of nominal_width / nominal_height is assumed
287 float aspect_ratio;
288} ATTRIBUTE_PACKED game_stream_video_properties;
289//------------------------------------------------------------------------------
290
291//==============================================================================
292/// @brief **Video stream packet**
293///
294/// This packet contains video stream data passed to Kodi.
295///
296typedef struct game_stream_video_packet
297{
298 /// @brief Video height
299 unsigned int width;
300
301 /// @brief Video width
302 unsigned int height;
303
304 /// @brief Width @ref GAME_VIDEO_ROTATION defined rotation angle.
305 GAME_VIDEO_ROTATION rotation;
306
307 /// @brief Pointer for video stream data given to Kodi
308 const uint8_t *data;
309
310 /// @brief Size of data array
311 size_t size;
312} ATTRIBUTE_PACKED game_stream_video_packet;
313//------------------------------------------------------------------------------
314
315//@}
316
317//--==----==----==----==----==----==----==----==----==----==----==----==----==--
318/// \defgroup cpp_kodi_addon_game_Defs_HardwareFramebuffer 3. Hardware framebuffer stream
319/// \ingroup cpp_kodi_addon_game_Defs
320/// @brief **Hardware framebuffer stream data**
321///
322//@{
323
324//==============================================================================
325/// @brief **Hardware framebuffer type**
326///
327typedef enum GAME_HW_CONTEXT_TYPE
328{
329 /// @brief None context
330 GAME_HW_CONTEXT_NONE,
331
332 /// @brief OpenGL 2.x. Driver can choose to use latest compatibility context
333 GAME_HW_CONTEXT_OPENGL,
334
335 /// @brief OpenGL ES 2.0
336 GAME_HW_CONTEXT_OPENGLES2,
337
338 /// @brief Modern desktop core GL context. Use major/minor fields to set GL version
339 GAME_HW_CONTEXT_OPENGL_CORE,
340
341 /// @brief OpenGL ES 3.0
342 GAME_HW_CONTEXT_OPENGLES3,
343
344 /// @brief OpenGL ES 3.1+. Set major/minor fields.
345 GAME_HW_CONTEXT_OPENGLES_VERSION,
346
347 /// @brief Vulkan
348 GAME_HW_CONTEXT_VULKAN
349} GAME_HW_CONTEXT_TYPE;
350//------------------------------------------------------------------------------
351
352//==============================================================================
353/// @brief **Hardware framebuffer properties**
354///
355typedef struct game_stream_hw_framebuffer_properties
356{
357 /// @brief The API to use.
358 ///
359 GAME_HW_CONTEXT_TYPE context_type;
360
361 /// @brief Set if render buffers should have depth component attached.
362 ///
363 /// @todo: Obsolete
364 ///
365 bool depth;
366
367 /// @brief Set if stencil buffers should be attached.
368 ///
369 /// If depth and stencil are true, a packed 24/8 buffer will be added.
370 /// Only attaching stencil is invalid and will be ignored.
371 ///
372 /// @todo: Obsolete.
373 ///
374 bool stencil;
375
376 /// @brief Use conventional bottom-left origin convention.
377 ///
378 /// If false, standard top-left origin semantics are used.
379 ///
380 /// @todo: Move to GL specific interface
381 ///
382 bool bottom_left_origin;
383
384 /// @brief Major version number for core GL context or GLES 3.1+.
385 unsigned int version_major;
386
387 /// @brief Minor version number for core GL context or GLES 3.1+.
388 unsigned int version_minor;
389
390 /// @brief If this is true, the frontend will go very far to avoid resetting context
391 /// in scenarios like toggling fullscreen, etc.
392 ///
393 /// @todo: Obsolete? Maybe frontend should just always assume this...
394 ///
395 /// The reset callback might still be called in extreme situations such as if
396 /// the context is lost beyond recovery.
397 ///
398 /// For optimal stability, set this to false, and allow context to be reset at
399 /// any time.
400 ///
401 bool cache_context;
402
403 /// @brief Creates a debug context.
404 bool debug_context;
405} ATTRIBUTE_PACKED game_stream_hw_framebuffer_properties;
406//------------------------------------------------------------------------------
407
408//==============================================================================
409/// @brief **Hardware framebuffer buffer**
410///
411typedef struct game_stream_hw_framebuffer_buffer
412{
413 /// @brief
414 uintptr_t framebuffer;
415} ATTRIBUTE_PACKED game_stream_hw_framebuffer_buffer;
416//------------------------------------------------------------------------------
417
418//==============================================================================
419/// @brief **Hardware framebuffer packet**
420///
421typedef struct game_stream_hw_framebuffer_packet
422{
423 /// @brief
424 uintptr_t framebuffer;
425} ATTRIBUTE_PACKED game_stream_hw_framebuffer_packet;
426//------------------------------------------------------------------------------
427
428//==============================================================================
429/// @brief **Hardware framebuffer process function address**
430///
431typedef void (*game_proc_address_t)(void);
432//------------------------------------------------------------------------------
433
434//@}
435
436//--==----==----==----==----==----==----==----==----==----==----==----==----==--
437/// \defgroup cpp_kodi_addon_game_Defs_SoftwareFramebuffer 4. Software framebuffer stream
438/// \ingroup cpp_kodi_addon_game_Defs
439/// @brief **Software framebuffer stream data**
440///
441//@{
442
443//==============================================================================
444/// @brief **Game video stream properties**
445///
446/// Used by Kodi to pass the currently required video stream settings to the addon
447///
448typedef game_stream_video_properties game_stream_sw_framebuffer_properties;
449//------------------------------------------------------------------------------
450
451//==============================================================================
452/// @brief **Hardware framebuffer type**
453///
454typedef struct game_stream_sw_framebuffer_buffer
455{
456 GAME_PIXEL_FORMAT format;
457 uint8_t *data;
458 size_t size;
459} ATTRIBUTE_PACKED game_stream_sw_framebuffer_buffer;
460//------------------------------------------------------------------------------
461
462//==============================================================================
463/// @brief **Video stream packet**
464///
465/// This packet contains video stream data passed to Kodi.
466///
467typedef game_stream_video_packet game_stream_sw_framebuffer_packet;
468//------------------------------------------------------------------------------
469
470//@}
471
472//--==----==----==----==----==----==----==----==----==----==----==----==----==--
473/// \defgroup cpp_kodi_addon_game_Defs_StreamTypes 5. Stream types
474/// \ingroup cpp_kodi_addon_game_Defs
475/// @brief **Stream types data**
476///
477//@{
478
479//==============================================================================
480/// @brief **Game stream types**
481///
482typedef enum GAME_STREAM_TYPE
483{
484 /// @brief Unknown
485 GAME_STREAM_UNKNOWN,
486
487 /// @brief Audio stream
488 GAME_STREAM_AUDIO,
489
490 /// @brief Video stream
491 GAME_STREAM_VIDEO,
492
493 /// @brief Hardware framebuffer
494 GAME_STREAM_HW_FRAMEBUFFER,
495
496 /// @brief Software framebuffer
497 GAME_STREAM_SW_FRAMEBUFFER,
498} GAME_STREAM_TYPE;
499//------------------------------------------------------------------------------
500
501//==============================================================================
502/// @brief **Immutable stream metadata**
503///
504/// This metadata is provided when the stream is opened. If any stream
505/// properties change, a new stream must be opened.
506///
507typedef struct game_stream_properties
508{
509 /// @brief
510 GAME_STREAM_TYPE type;
511 union
512 {
513 /// @brief
514 game_stream_audio_properties audio;
515
516 /// @brief
517 game_stream_video_properties video;
518
519 /// @brief
520 game_stream_hw_framebuffer_properties hw_framebuffer;
521
522 /// @brief
523 game_stream_sw_framebuffer_properties sw_framebuffer;
524 };
525} ATTRIBUTE_PACKED game_stream_properties;
526//------------------------------------------------------------------------------
527
528//==============================================================================
529/// @brief **Stream buffers for hardware rendering and zero-copy support**
530///
531typedef struct game_stream_buffer
532{
533 /// @brief
534 GAME_STREAM_TYPE type;
535 union
536 {
537 /// @brief
538 game_stream_hw_framebuffer_buffer hw_framebuffer;
539
540 /// @brief
541 game_stream_sw_framebuffer_buffer sw_framebuffer;
542 };
543} ATTRIBUTE_PACKED game_stream_buffer;
544//------------------------------------------------------------------------------
545
546//==============================================================================
547/// @brief **Stream packet and ephemeral metadata**
548///
549/// This packet contains stream data and accompanying metadata. The metadata
550/// is ephemeral, meaning it only applies to the current packet and can change
551/// from packet to packet in the same stream.
552///
553typedef struct game_stream_packet
554{
555 /// @brief
556 GAME_STREAM_TYPE type;
557 union
558 {
559 /// @brief
560 game_stream_audio_packet audio;
561
562 /// @brief
563 game_stream_video_packet video;
564
565 /// @brief
566 game_stream_hw_framebuffer_packet hw_framebuffer;
567
568 /// @brief
569 game_stream_sw_framebuffer_packet sw_framebuffer;
570 };
571} ATTRIBUTE_PACKED game_stream_packet;
572//------------------------------------------------------------------------------
573
574//@}
575
576//--==----==----==----==----==----==----==----==----==----==----==----==----==--
577/// \defgroup cpp_kodi_addon_game_Defs_GameTypes 6. Game types
578/// \ingroup cpp_kodi_addon_game_Defs
579/// @brief **Game types data**
580///
581//@{
582
583//==============================================================================
584/// @brief **Game reguin definition**
585///
586/// Returned from game_get_region()
587typedef enum GAME_REGION
588{
589 /// @brief Game region unknown
590 GAME_REGION_UNKNOWN,
591
592 /// @brief Game region NTSC
593 GAME_REGION_NTSC,
594
595 /// @brief Game region PAL
596 GAME_REGION_PAL,
597} GAME_REGION;
598//------------------------------------------------------------------------------
599
600//==============================================================================
601/// @brief **Special game types passed into game_load_game_special().**
602///
603/// @remark Only used when multiple ROMs are required.
604///
605typedef enum SPECIAL_GAME_TYPE
606{
607 /// @brief Game Type BSX
608 SPECIAL_GAME_TYPE_BSX,
609
610 /// @brief Game Type BSX slotted
611 SPECIAL_GAME_TYPE_BSX_SLOTTED,
612
613 /// @brief Game Type sufami turbo
614 SPECIAL_GAME_TYPE_SUFAMI_TURBO,
615
616 /// @brief Game Type super game boy
617 SPECIAL_GAME_TYPE_SUPER_GAME_BOY,
618} SPECIAL_GAME_TYPE;
619//------------------------------------------------------------------------------
620
621//==============================================================================
622/// @brief **Game Memory**
623///
624typedef enum GAME_MEMORY
625{
626 /// @brief Passed to game_get_memory_data/size(). If the memory type doesn't apply
627 /// to the implementation NULL/0 can be returned.
628 GAME_MEMORY_MASK = 0xff,
629
630 /// @brief Regular save ram.
631 ///
632 /// This ram is usually found on a game cartridge, backed
633 /// up by a battery. If save game data is too complex for a single memory
634 /// buffer, the SYSTEM_DIRECTORY environment callback can be used.
635 GAME_MEMORY_SAVE_RAM = 0,
636
637 /// @brief Some games have a built-in clock to keep track of time.
638 ///
639 /// This memory is usually just a couple of bytes to keep track of time.
640 GAME_MEMORY_RTC = 1,
641
642 /// @brief System ram lets a frontend peek into a game systems main RAM
643 GAME_MEMORY_SYSTEM_RAM = 2,
644
645 /// @brief Video ram lets a frontend peek into a game systems video RAM (VRAM)
646 GAME_MEMORY_VIDEO_RAM = 3,
647
648 /// @brief Special memory type
649 GAME_MEMORY_SNES_BSX_RAM = ((1 << 8) | GAME_MEMORY_SAVE_RAM),
650
651 /// @brief Special memory type
652 GAME_MEMORY_SNES_BSX_PRAM = ((2 << 8) | GAME_MEMORY_SAVE_RAM),
653
654 /// @brief Special memory type
655 GAME_MEMORY_SNES_SUFAMI_TURBO_A_RAM = ((3 << 8) | GAME_MEMORY_SAVE_RAM),
656
657 /// @brief Special memory type
658 GAME_MEMORY_SNES_SUFAMI_TURBO_B_RAM = ((4 << 8) | GAME_MEMORY_SAVE_RAM),
659
660 /// @brief Special memory type
661 GAME_MEMORY_SNES_GAME_BOY_RAM = ((5 << 8) | GAME_MEMORY_SAVE_RAM),
662
663 /// @brief Special memory type
664 GAME_MEMORY_SNES_GAME_BOY_RTC = ((6 << 8) | GAME_MEMORY_RTC),
665} GAME_MEMORY;
666//------------------------------------------------------------------------------
667
668//==============================================================================
669/// @brief **ID values for SIMD CPU features**
670typedef enum GAME_SIMD
671{
672 /// @brief SIMD CPU SSE
673 GAME_SIMD_SSE = (1 << 0),
674
675 /// @brief SIMD CPU SSE2
676 GAME_SIMD_SSE2 = (1 << 1),
677
678 /// @brief SIMD CPU VMX
679 GAME_SIMD_VMX = (1 << 2),
680
681 /// @brief SIMD CPU VMX128
682 GAME_SIMD_VMX128 = (1 << 3),
683
684 /// @brief SIMD CPU AVX
685 GAME_SIMD_AVX = (1 << 4),
686
687 /// @brief SIMD CPU NEON
688 GAME_SIMD_NEON = (1 << 5),
689
690 /// @brief SIMD CPU SSE3
691 GAME_SIMD_SSE3 = (1 << 6),
692
693 /// @brief SIMD CPU SSSE3
694 GAME_SIMD_SSSE3 = (1 << 7),
695
696 /// @brief SIMD CPU MMX
697 GAME_SIMD_MMX = (1 << 8),
698
699 /// @brief SIMD CPU MMXEXT
700 GAME_SIMD_MMXEXT = (1 << 9),
701
702 /// @brief SIMD CPU SSE4
703 GAME_SIMD_SSE4 = (1 << 10),
704
705 /// @brief SIMD CPU SSE42
706 GAME_SIMD_SSE42 = (1 << 11),
707
708 /// @brief SIMD CPU AVX2
709 GAME_SIMD_AVX2 = (1 << 12),
710
711 /// @brief SIMD CPU VFPU
712 GAME_SIMD_VFPU = (1 << 13),
713} GAME_SIMD;
714//------------------------------------------------------------------------------
715
716//@}
717
718//--==----==----==----==----==----==----==----==----==----==----==----==----==--
719/// \defgroup cpp_kodi_addon_game_Defs_InputTypes 7. Input types
720/// \ingroup cpp_kodi_addon_game_Defs
721/// @brief **Input types**
722///
723//@{
724
725//==============================================================================
726/// @brief
727typedef enum GAME_INPUT_EVENT_SOURCE
728{
729 /// @brief
730 GAME_INPUT_EVENT_DIGITAL_BUTTON,
731
732 /// @brief
733 GAME_INPUT_EVENT_ANALOG_BUTTON,
734
735 /// @brief
736 GAME_INPUT_EVENT_AXIS,
737
738 /// @brief
739 GAME_INPUT_EVENT_ANALOG_STICK,
740
741 /// @brief
742 GAME_INPUT_EVENT_ACCELEROMETER,
743
744 /// @brief
745 GAME_INPUT_EVENT_KEY,
746
747 /// @brief
748 GAME_INPUT_EVENT_RELATIVE_POINTER,
749
750 /// @brief
751 GAME_INPUT_EVENT_ABSOLUTE_POINTER,
752
753 /// @brief
754 GAME_INPUT_EVENT_MOTOR,
755} GAME_INPUT_EVENT_SOURCE;
756//------------------------------------------------------------------------------
757
758//==============================================================================
759/// @brief
760typedef enum GAME_KEY_MOD
761{
762 /// @brief
763 GAME_KEY_MOD_NONE = 0x0000,
764
765 /// @brief
766 GAME_KEY_MOD_SHIFT = 0x0001,
767
768 /// @brief
769 GAME_KEY_MOD_CTRL = 0x0002,
770
771 /// @brief
772 GAME_KEY_MOD_ALT = 0x0004,
773
774 /// @brief
775 GAME_KEY_MOD_META = 0x0008,
776
777 /// @brief
778 GAME_KEY_MOD_SUPER = 0x0010,
779
780 /// @brief
781 GAME_KEY_MOD_NUMLOCK = 0x0100,
782
783 /// @brief
784 GAME_KEY_MOD_CAPSLOCK = 0x0200,
785
786 /// @brief
787 GAME_KEY_MOD_SCROLLOCK = 0x0400,
788} GAME_KEY_MOD;
789//------------------------------------------------------------------------------
790
791//==============================================================================
792/// @brief Type of port on the virtual game console
793typedef enum GAME_PORT_TYPE
794{
795 /// @brief Game port unknown
796 GAME_PORT_UNKNOWN,
797
798 /// @brief Game port Keyboard
799 GAME_PORT_KEYBOARD,
800
801 /// @brief Game port mouse
802 GAME_PORT_MOUSE,
803
804 /// @brief Game port controller
805 GAME_PORT_CONTROLLER,
806} GAME_PORT_TYPE;
807//------------------------------------------------------------------------------
808
809/*! \cond PRIVATE */
810/*!
811 * @brief "C" Game add-on controller layout.
812 *
813 * Structure used to interface in "C" between Kodi and Addon.
814 *
815 * See @ref AddonGameControllerLayout for description of values.
816 */
817typedef struct game_controller_layout
818{
819 char* controller_id;
820 bool provides_input; // False for multitaps
821 char** digital_buttons;
822 unsigned int digital_button_count;
823 char** analog_buttons;
824 unsigned int analog_button_count;
825 char** analog_sticks;
826 unsigned int analog_stick_count;
827 char** accelerometers;
828 unsigned int accelerometer_count;
829 char** keys;
830 unsigned int key_count;
831 char** rel_pointers;
832 unsigned int rel_pointer_count;
833 char** abs_pointers;
834 unsigned int abs_pointer_count;
835 char** motors;
836 unsigned int motor_count;
837} ATTRIBUTE_PACKED game_controller_layout;
838 /*! \endcond */
839
840//==============================================================================
841/// @brief
842struct AddonGameControllerLayout
843{
844 /*! \cond PRIVATE */
845 explicit AddonGameControllerLayout() = default;
846 AddonGameControllerLayout(const game_controller_layout& layout)
847 {
848 controller_id = layout.controller_id;
849 provides_input = layout.provides_input;
850 for (unsigned int i = 0; i < layout.digital_button_count; ++i)
851 digital_buttons.push_back(layout.digital_buttons[i]);
852 for (unsigned int i = 0; i < layout.analog_button_count; ++i)
853 analog_buttons.push_back(layout.analog_buttons[i]);
854 for (unsigned int i = 0; i < layout.analog_stick_count; ++i)
855 analog_sticks.push_back(layout.analog_sticks[i]);
856 for (unsigned int i = 0; i < layout.accelerometer_count; ++i)
857 accelerometers.push_back(layout.accelerometers[i]);
858 for (unsigned int i = 0; i < layout.key_count; ++i)
859 keys.push_back(layout.keys[i]);
860 for (unsigned int i = 0; i < layout.rel_pointer_count; ++i)
861 rel_pointers.push_back(layout.rel_pointers[i]);
862 for (unsigned int i = 0; i < layout.abs_pointer_count; ++i)
863 abs_pointers.push_back(layout.abs_pointers[i]);
864 for (unsigned int i = 0; i < layout.motor_count; ++i)
865 motors.push_back(layout.motors[i]);
866 }
867 /*! \endcond */
868
869 /// @brief
870 std::string controller_id;
871
872 /// @brief False for multitaps
873 bool provides_input;
874
875 /// @brief
876 std::vector<std::string> digital_buttons;
877
878 /// @brief
879 std::vector<std::string> analog_buttons;
880
881 /// @brief
882 std::vector<std::string> analog_sticks;
883
884 /// @brief
885 std::vector<std::string> accelerometers;
886
887 /// @brief
888 std::vector<std::string> keys;
889
890 /// @brief
891 std::vector<std::string> rel_pointers;
892
893 /// @brief
894 std::vector<std::string> abs_pointers;
895
896 /// @brief
897 std::vector<std::string> motors;
898};
899//------------------------------------------------------------------------------
900
901struct game_input_port;
902
903//==============================================================================
904/// @brief Device that can provide input
905typedef struct game_input_device
906{
907 /// @brief ID used in the Kodi controller API
908 const char* controller_id;
909
910 /// @brief
911 const char* port_address;
912
913 /// @brief
914 game_input_port* available_ports;
915
916 /// @brief
917 unsigned int port_count;
918} ATTRIBUTE_PACKED game_input_device;
919//------------------------------------------------------------------------------
920
921//==============================================================================
922/// @brief Port that can provide input
923///
924/// Ports can accept multiple devices and devices can have multiple ports, so
925/// the topology of possible configurations is a tree structure of alternating
926/// port and device nodes.
927///
928typedef struct game_input_port
929{
930 /// @brief
931 GAME_PORT_TYPE type;
932
933 /// @brief Required for GAME_PORT_CONTROLLER type
934 const char* port_id;
935
936 /// @brief
937 game_input_device* accepted_devices;
938
939 /// @brief
940 unsigned int device_count;
941} ATTRIBUTE_PACKED game_input_port;
942//------------------------------------------------------------------------------
943
944//==============================================================================
945/// @brief The input topology is the possible ways to connect input devices
946///
947/// This represents the logical topology, which is the possible connections that
948/// the game client's logic can handle. It is strictly a subset of the physical
949/// topology. Loops are not allowed.
950///
951typedef struct game_input_topology
952{
953 /// @brief The list of ports on the virtual game console
954 game_input_port *ports;
955
956 /// @brief The number of ports
957 unsigned int port_count;
958
959 /// @brief A limit on the number of input-providing devices, or -1 for no limit
960 int player_limit;
961} ATTRIBUTE_PACKED game_input_topology;
962//------------------------------------------------------------------------------
963
964//==============================================================================
965/// @brief
966typedef struct game_digital_button_event
967{
968 /// @brief
969 bool pressed;
970} ATTRIBUTE_PACKED game_digital_button_event;
971//------------------------------------------------------------------------------
972
973//==============================================================================
974/// @brief
975typedef struct game_analog_button_event
976{
977 /// @brief
978 float magnitude;
979} ATTRIBUTE_PACKED game_analog_button_event;
980//------------------------------------------------------------------------------
981
982//==============================================================================
983/// @brief
984typedef struct game_axis_event
985{
986 /// @brief
987 float position;
988} ATTRIBUTE_PACKED game_axis_event;
989//------------------------------------------------------------------------------
990
991//==============================================================================
992/// @brief
993typedef struct game_analog_stick_event
994{
995 /// @brief
996 float x;
997
998 /// @brief
999 float y;
1000} ATTRIBUTE_PACKED game_analog_stick_event;
1001//------------------------------------------------------------------------------
1002
1003//==============================================================================
1004/// @brief
1005typedef struct game_accelerometer_event
1006{
1007 /// @brief
1008 float x;
1009
1010 /// @brief
1011 float y;
1012
1013 /// @brief
1014 float z;
1015} ATTRIBUTE_PACKED game_accelerometer_event;
1016//------------------------------------------------------------------------------
1017
1018//==============================================================================
1019/// @brief
1020typedef struct game_key_event
1021{
1022 /// @brief
1023 bool pressed;
1024
1025 /// @brief If the keypress generates a printing character
1026 ///
1027 /// The unicode value contains the character generated. If the key is a
1028 /// non-printing character, e.g. a function or arrow key, the unicode value
1029 /// is zero.
1030 uint32_t unicode;
1031
1032 /// @brief
1033 GAME_KEY_MOD modifiers;
1034} ATTRIBUTE_PACKED game_key_event;
1035//------------------------------------------------------------------------------
1036
1037//==============================================================================
1038/// @brief
1039typedef struct game_rel_pointer_event
1040{
1041 /// @brief
1042 int x;
1043
1044 /// @brief
1045 int y;
1046} ATTRIBUTE_PACKED game_rel_pointer_event;
1047//------------------------------------------------------------------------------
1048
1049//==============================================================================
1050/// @brief
1051typedef struct game_abs_pointer_event
1052{
1053 /// @brief
1054 bool pressed;
1055
1056 /// @brief
1057 float x;
1058
1059 /// @brief
1060 float y;
1061} ATTRIBUTE_PACKED game_abs_pointer_event;
1062//------------------------------------------------------------------------------
1063
1064//==============================================================================
1065/// @brief
1066typedef struct game_motor_event
1067{
1068 /// @brief
1069 float magnitude;
1070} ATTRIBUTE_PACKED game_motor_event;
1071//------------------------------------------------------------------------------
1072
1073//==============================================================================
1074/// @brief
1075typedef struct game_input_event
1076{
1077 /// @brief
1078 GAME_INPUT_EVENT_SOURCE type;
1079
1080 /// @brief
1081 const char* controller_id;
1082
1083 /// @brief
1084 GAME_PORT_TYPE port_type;
1085
1086 /// @brief
1087 const char* port_address;
1088
1089 /// @brief
1090 const char* feature_name;
1091 union {
1092 /// @brief
1093 struct game_digital_button_event digital_button;
1094
1095 /// @brief
1096 struct game_analog_button_event analog_button;
1097
1098 /// @brief
1099 struct game_axis_event axis;
1100
1101 /// @brief
1102 struct game_analog_stick_event analog_stick;
1103
1104 /// @brief
1105 struct game_accelerometer_event accelerometer;
1106
1107 /// @brief
1108 struct game_key_event key;
1109
1110 /// @brief
1111 struct game_rel_pointer_event rel_pointer;
1112
1113 /// @brief
1114 struct game_abs_pointer_event abs_pointer;
1115
1116 /// @brief
1117 struct game_motor_event motor;
1118 };
1119} ATTRIBUTE_PACKED game_input_event;
1120//------------------------------------------------------------------------------
1121
1122//@}
1123
1124//--==----==----==----==----==----==----==----==----==----==----==----==----==--
1125/// \defgroup cpp_kodi_addon_game_Defs_EnvironmentTypes 8. Environment types
1126/// \ingroup cpp_kodi_addon_game_Defs
1127/// @brief **Environment types**
1128///
1129//@{
1130
1131//==============================================================================
1132/// @brief Game system timing
1133///
1134struct game_system_timing
1135{
1136 /// @brief FPS of video content.
1137 double fps;
1138
1139 /// @brief Sampling rate of audio.
1140 double sample_rate;
1141};
1142//------------------------------------------------------------------------------
1143
1144//@}
1145
1146
1147//--==----==----==----==----==----==----==----==----==----==----==----==----==--
1148
1149/*!
1150 * @brief Game properties
1151 *
1152 * Not to be used outside this header.
1153 */
1154typedef struct AddonProps_Game
1155{
1156 /*!
1157 * The path of the game client being loaded.
1158 */
1159 const char* game_client_dll_path;
1160
1161 /*!
1162 * Paths to proxy DLLs used to load the game client.
1163 */
1164 const char** proxy_dll_paths;
1165
1166 /*!
1167 * Number of proxy DLL paths provided.
1168 */
1169 unsigned int proxy_dll_count;
1170
1171 /*!
1172 * The "system" directories of the frontend. These directories can be used to
1173 * store system-specific ROMs such as BIOSes, configuration data, etc.
1174 */
1175 const char** resource_directories;
1176
1177 /*!
1178 * Number of resource directories provided
1179 */
1180 unsigned int resource_directory_count;
1181
1182 /*!
1183 * The writable directory of the frontend. This directory can be used to store
1184 * SRAM, memory cards, high scores, etc, if the game client cannot use the
1185 * regular memory interface, GetMemoryData().
1186 */
1187 const char* profile_directory;
1188
1189 /*!
1190 * The value of the <supports_vfs> property from addon.xml
1191 */
1192 bool supports_vfs;
1193
1194 /*!
1195 * The extensions in the <extensions> property from addon.xml
1196 */
1197 const char** extensions;
1198
1199 /*!
1200 * Number of extensions provided
1201 */
1202 unsigned int extension_count;
1203} AddonProps_Game;
1204
1205typedef AddonProps_Game game_client_properties;
1206
1207/*! Structure to transfer the methods from kodi_game_dll.h to Kodi */
1208
1209struct AddonInstance_Game;
1210
1211/*!
1212 * @brief Game callbacks
1213 *
1214 * Not to be used outside this header.
1215 */
1216typedef struct AddonToKodiFuncTable_Game
1217{
1218 KODI_HANDLE kodiInstance;
1219
1220 void (*CloseGame)(void* kodiInstance);
1221 void* (*OpenStream)(void*, const game_stream_properties*);
1222 bool (*GetStreamBuffer)(void*, void*, unsigned int, unsigned int, game_stream_buffer*);
1223 void (*AddStreamData)(void*, void*, const game_stream_packet*);
1224 void (*ReleaseStreamBuffer)(void*, void*, game_stream_buffer*);
1225 void (*CloseStream)(void*, void*);
1226 game_proc_address_t (*HwGetProcAddress)(void* kodiInstance, const char* symbol);
1227 bool (*InputEvent)(void* kodiInstance, const game_input_event* event);
1228} AddonToKodiFuncTable_Game;
1229
1230/*!
1231 * @brief Game function hooks
1232 *
1233 * Not to be used outside this header.
1234 */
1235typedef struct KodiToAddonFuncTable_Game
1236{
1237 kodi::addon::CInstanceGame* addonInstance;
1238
1239 GAME_ERROR(__cdecl* LoadGame)(const AddonInstance_Game*, const char*);
1240 GAME_ERROR(__cdecl* LoadGameSpecial)
1241 (const AddonInstance_Game*, SPECIAL_GAME_TYPE, const char**, size_t);
1242 GAME_ERROR(__cdecl* LoadStandalone)(const AddonInstance_Game*);
1243 GAME_ERROR(__cdecl* UnloadGame)(const AddonInstance_Game*);
1244 GAME_ERROR(__cdecl* GetGameTiming)(const AddonInstance_Game*, game_system_timing*);
1245 GAME_REGION(__cdecl* GetRegion)(const AddonInstance_Game*);
1246 bool(__cdecl* RequiresGameLoop)(const AddonInstance_Game*);
1247 GAME_ERROR(__cdecl* RunFrame)(const AddonInstance_Game*);
1248 GAME_ERROR(__cdecl* Reset)(const AddonInstance_Game*);
1249 GAME_ERROR(__cdecl* HwContextReset)(const AddonInstance_Game*);
1250 GAME_ERROR(__cdecl* HwContextDestroy)(const AddonInstance_Game*);
1251 bool(__cdecl* HasFeature)(const AddonInstance_Game*, const char*, const char*);
1252 game_input_topology*(__cdecl* GetTopology)(const AddonInstance_Game*);
1253 void(__cdecl* FreeTopology)(const AddonInstance_Game*, game_input_topology*);
1254 void(__cdecl* SetControllerLayouts)(const AddonInstance_Game*,
1255 const game_controller_layout*,
1256 unsigned int);
1257 bool(__cdecl* EnableKeyboard)(const AddonInstance_Game*, bool, const char*);
1258 bool(__cdecl* EnableMouse)(const AddonInstance_Game*, bool, const char*);
1259 bool(__cdecl* ConnectController)(const AddonInstance_Game*, bool, const char*, const char*);
1260 bool(__cdecl* InputEvent)(const AddonInstance_Game*, const game_input_event*);
1261 size_t(__cdecl* SerializeSize)(const AddonInstance_Game*);
1262 GAME_ERROR(__cdecl* Serialize)(const AddonInstance_Game*, uint8_t*, size_t);
1263 GAME_ERROR(__cdecl* Deserialize)(const AddonInstance_Game*, const uint8_t*, size_t);
1264 GAME_ERROR(__cdecl* CheatReset)(const AddonInstance_Game*);
1265 GAME_ERROR(__cdecl* GetMemory)(const AddonInstance_Game*, GAME_MEMORY, uint8_t**, size_t*);
1266 GAME_ERROR(__cdecl* SetCheat)(const AddonInstance_Game*, unsigned int, bool, const char*);
1267} KodiToAddonFuncTable_Game;
1268
1269/*!
1270 * @brief Game instance
1271 *
1272 * Not to be used outside this header.
1273 */
1274typedef struct AddonInstance_Game
1275{
1276 AddonProps_Game props;
1277 AddonToKodiFuncTable_Game toKodi;
1278 KodiToAddonFuncTable_Game toAddon;
1279} AddonInstance_Game;
1280
1281} /* extern "C" */
1282
1283namespace kodi
1284{
1285namespace addon
1286{
1287
1288//==============================================================================
1289///
1290/// \addtogroup cpp_kodi_addon_game
1291/// @brief \cpp_class{ kodi::addon::CInstanceGame }
1292/// **Game add-on instance**
1293///
1294/// This class is created at addon by Kodi.
1295///
1296//------------------------------------------------------------------------------
1297class ATTRIBUTE_HIDDEN CInstanceGame : public IAddonInstance
1298{
1299public:
1300 //============================================================================
1301 ///
1302 /// @defgroup cpp_kodi_addon_game_Base 1. Basic functions
1303 /// @ingroup cpp_kodi_addon_game
1304 /// @brief **Functions to manage the addon and get basic information about it**
1305 ///
1306 ///
1307 //@{
1308
1309 //============================================================================
1310 ///
1311 /// @brief Game class constructor
1312 ///
1313 /// Used by an add-on that only supports only Game and only in one instance.
1314 ///
1315 /// This class is created at addon by Kodi.
1316 ///
1317 ///
1318 /// --------------------------------------------------------------------------
1319 ///
1320 ///
1321 /// **Here's example about the use of this:**
1322 /// ~~~~~~~~~~~~~{.cpp}
1323 /// #include <kodi/addon-instance/Game.h>
1324 /// ...
1325 ///
1326 /// class ATTRIBUTE_HIDDEN CGameExample
1327 /// : public kodi::addon::CAddonBase,
1328 /// public kodi::addon::CInstanceGame
1329 /// {
1330 /// public:
1331 /// CGameExample()
1332 /// {
1333 /// }
1334 ///
1335 /// virtual ~CGameExample();
1336 /// {
1337 /// }
1338 ///
1339 /// ...
1340 /// };
1341 ///
1342 /// ADDONCREATOR(CGameExample)
1343 /// ~~~~~~~~~~~~~
1344 ///
1345 CInstanceGame() : IAddonInstance(ADDON_INSTANCE_GAME, GetKodiTypeVersion(ADDON_INSTANCE_GAME))
1346 {
1347 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
1348 throw std::logic_error("kodi::addon::CInstanceGame: Creation of more as one in single "
1349 "instance way is not allowed!");
1350
1351 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
1352 CAddonBase::m_interface->globalSingleInstance = this;
1353 }
1354 //----------------------------------------------------------------------------
1355
1356 //============================================================================
1357 ///
1358 /// @brief Destructor
1359 ///
1360 ~CInstanceGame() override = default;
1361 //----------------------------------------------------------------------------
1362
1363 //============================================================================
1364 ///
1365 /// @brief **Callback to Kodi Function**<br>The path of the game client being loaded.
1366 ///
1367 /// @return the used game client Dll path
1368 ///
1369 /// @remarks Only called from addon itself
1370 ///
1371 std::string GameClientDllPath() const
1372 {
1373 return m_instanceData->props.game_client_dll_path;
1374 }
1375 //----------------------------------------------------------------------------
1376
1377 //============================================================================
1378 ///
1379 /// @brief **Callback to Kodi Function**<br>Paths to proxy DLLs used to load the game client.
1380 ///
1381 /// @param[out] paths vector list to store available dll paths
1382 /// @return true if success and dll paths present
1383 ///
1384 /// @remarks Only called from addon itself
1385 ///
1386 bool ProxyDllPaths(std::vector<std::string>& paths)
1387 {
1388 for (unsigned int i = 0; i < m_instanceData->props.proxy_dll_count; ++i)
1389 {
1390 if (m_instanceData->props.proxy_dll_paths[i] != nullptr)
1391 paths.push_back(m_instanceData->props.proxy_dll_paths[i]);
1392 }
1393 return !paths.empty();
1394 }
1395 //----------------------------------------------------------------------------
1396
1397 //============================================================================
1398 ///
1399 /// @brief **Callback to Kodi Function**<br>The "system" directories of the frontend
1400 ///
1401 /// These directories can be used to store system-specific ROMs such as
1402 /// BIOSes, configuration data, etc.
1403 ///
1404 /// @return the used resource directory
1405 ///
1406 /// @remarks Only called from addon itself
1407 ///
1408 bool ResourceDirectories(std::vector<std::string>& dirs)
1409 {
1410 for (unsigned int i = 0; i < m_instanceData->props.resource_directory_count; ++i)
1411 {
1412 if (m_instanceData->props.resource_directories[i] != nullptr)
1413 dirs.push_back(m_instanceData->props.resource_directories[i]);
1414 }
1415 return !dirs.empty();
1416 }
1417 //----------------------------------------------------------------------------
1418
1419 //============================================================================
1420 ///
1421 /// @brief **Callback to Kodi Function**<br>The writable directory of the frontend
1422 ///
1423 /// This directory can be used to store SRAM, memory cards, high scores,
1424 /// etc, if the game client cannot use the regular memory interface,
1425 /// GetMemoryData().
1426 ///
1427 /// @return the used profile directory
1428 ///
1429 /// @remarks Only called from addon itself
1430 ///
1431 std::string ProfileDirectory() const
1432 {
1433 return m_instanceData->props.profile_directory;
1434 }
1435 //----------------------------------------------------------------------------
1436
1437 //============================================================================
1438 ///
1439 /// @brief **Callback to Kodi Function**<br>The value of the <supports_vfs> property from addon.xml
1440 ///
1441 /// @return true if VFS is supported
1442 ///
1443 /// @remarks Only called from addon itself
1444 ///
1445 bool SupportsVFS() const
1446 {
1447 return m_instanceData->props.supports_vfs;
1448 }
1449 //----------------------------------------------------------------------------
1450
1451 //============================================================================
1452 ///
1453 /// @brief **Callback to Kodi Function**<br>The extensions in the <extensions> property from addon.xml
1454 ///
1455 /// @param[out] extensions vector list to store available extension
1456 /// @return true if success and extensions present
1457 ///
1458 /// @remarks Only called from addon itself
1459 ///
1460 bool Extensions(std::vector<std::string>& extensions)
1461 {
1462 for (unsigned int i = 0; i < m_instanceData->props.extension_count; ++i)
1463 {
1464 if (m_instanceData->props.extensions[i] != nullptr)
1465 extensions.push_back(m_instanceData->props.extensions[i]);
1466 }
1467 return !extensions.empty();
1468 }
1469 //----------------------------------------------------------------------------
1470
1471 //@}
1472
1473//--==----==----==----==----==----==----==----==----==----==----==----==----==--
1474
1475 //============================================================================
1476 ///
1477 /// @defgroup cpp_kodi_addon_game_Operation 2. Game operations
1478 /// @ingroup cpp_kodi_addon_game
1479 /// @brief **Game operations**
1480 ///
1481 /// These are mandatory functions for using this addon to get the available
1482 /// channels.
1483 ///
1484 //@{
1485
1486 //============================================================================
1487 ///
1488 /// @brief Load a game
1489 ///
1490 /// @param[in] url The URL to load
1491 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was loaded
1492 ///
1493 virtual GAME_ERROR LoadGame(const std::string& url)
1494 {
1495 return GAME_ERROR_NOT_IMPLEMENTED;
1496 }
1497 //----------------------------------------------------------------------------
1498
1499 //============================================================================
1500 ///
1501 /// @brief Load a game that requires multiple files
1502 ///
1503 /// @param[in] type The game type
1504 /// @param[in] urls An array of urls
1505 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was loaded
1506 ///
1507 virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector<std::string>& urls)
1508 {
1509 return GAME_ERROR_NOT_IMPLEMENTED;
1510 }
1511 //----------------------------------------------------------------------------
1512
1513 //============================================================================
1514 ///
1515 /// @brief Begin playing without a game file
1516 ///
1517 /// If the add-on supports standalone mode, it must add the <supports_standalone>
1518 /// tag to the extension point in addon.xml:
1519 ///
1520 /// <supports_no_game>false</supports_no_game>
1521 ///
1522 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game add-on was loaded
1523 ///
1524 virtual GAME_ERROR LoadStandalone()
1525 {
1526 return GAME_ERROR_NOT_IMPLEMENTED;
1527 }
1528 //----------------------------------------------------------------------------
1529
1530 //============================================================================
1531 ///
1532 /// @brief Unload the current game
1533 ///
1534 /// Unloads a currently loaded game
1535 ///
1536 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was unloaded
1537 ///
1538 virtual GAME_ERROR UnloadGame()
1539 {
1540 return GAME_ERROR_NOT_IMPLEMENTED;
1541 }
1542 //----------------------------------------------------------------------------
1543
1544 //============================================================================
1545 ///
1546 /// @brief Get timing information about the loaded game
1547 ///
1548 /// @param[out] timing_info The info structure to fill
1549 ///
1550 /// @return the error, or @ref GAME_ERROR_NO_ERROR if info was filled
1551 ///
1552 virtual GAME_ERROR GetGameTiming(game_system_timing& timing_info)
1553 {
1554 return GAME_ERROR_NOT_IMPLEMENTED;
1555 }
1556 //----------------------------------------------------------------------------
1557
1558 //============================================================================
1559 ///
1560 /// @brief Get region of the loaded game
1561 ///
1562 /// @return the region, or @ref GAME_REGION_UNKNOWN if unknown or no game is loaded
1563 ///
1564 virtual GAME_REGION GetRegion()
1565 {
1566 return GAME_REGION_UNKNOWN;
1567 }
1568 //----------------------------------------------------------------------------
1569
1570 //============================================================================
1571 ///
1572 /// @brief Return true if the client requires the frontend to provide a game loop
1573 ///
1574 /// The game loop is a thread that calls RunFrame() in a loop at a rate
1575 /// determined by the playback speed and the client's FPS.
1576 ///
1577 /// @return true if the frontend should provide a game loop, false otherwise
1578 ///
1579 virtual bool RequiresGameLoop()
1580 {
1581 return false;
1582 }
1583 //----------------------------------------------------------------------------
1584
1585 //============================================================================
1586 ///
1587 /// @brief Run a single frame for add-ons that use a game loop
1588 ///
1589 /// @return the error, or @ref GAME_ERROR_NO_ERROR if there was no error
1590 ///
1591 virtual GAME_ERROR RunFrame()
1592 {
1593 return GAME_ERROR_NOT_IMPLEMENTED;
1594 }
1595 //----------------------------------------------------------------------------
1596
1597 //============================================================================
1598 ///
1599 /// @brief Reset the current game
1600 ///
1601 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was reset
1602 ///
1603 virtual GAME_ERROR Reset()
1604 {
1605 return GAME_ERROR_NOT_IMPLEMENTED;
1606 }
1607 //----------------------------------------------------------------------------
1608
1609 //==========================================================================
1610 ///
1611 /// @brief **Callback to Kodi Function**<br>Requests the frontend to stop the current game
1612 ///
1613 /// @remarks Only called from addon itself
1614 ///
1615 void CloseGame(void) { m_instanceData->toKodi.CloseGame(m_instanceData->toKodi.kodiInstance); }
1616 //----------------------------------------------------------------------------
1617
1618 //============================================================================
1619 ///
1620 /// @defgroup cpp_kodi_addon_game_Operation_CStream Class: CStream
1621 /// @ingroup cpp_kodi_addon_game_Operation
1622 /// @brief \cpp_class{ kodi::addon::CInstanceGame::CStream }
1623 /// **Game stream handler**
1624 ///
1625 /// This class will be integrated into the addon, which can then open it if
1626 /// necessary for the processing of an audio or video stream.
1627 ///
1628 ///
1629 /// @note Callback to Kodi class
1630 //@{
1631 class CStream
1632 {
1633 public:
1634 CStream() = default;
1635
1636 CStream(const game_stream_properties& properties)
1637 {
1638 Open(properties);
1639 }
1640
1641 ~CStream()
1642 {
1643 Close();
1644 }
1645
1646 //==========================================================================
1647 ///
1648 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1649 /// @brief Create a stream for gameplay data
1650 ///
1651 /// @param[in] properties The stream properties
1652 /// @return A stream handle, or `nullptr` on failure
1653 ///
1654 /// @remarks Only called from addon itself
1655 ///
1656 bool Open(const game_stream_properties& properties)
1657 {
1658 if (!CAddonBase::m_interface->globalSingleInstance)
1659 return false;
1660
1661 if (m_handle)
1662 {
1663 kodi::Log(ADDON_LOG_INFO, "kodi::addon::CInstanceGame::CStream already becomes reopened");
1664 Close();
1665 }
1666
1667 AddonToKodiFuncTable_Game& cb =
1668 static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
1669 ->m_instanceData->toKodi;
1670 m_handle = cb.OpenStream(cb.kodiInstance, &properties);
1671 return m_handle != nullptr;
1672 }
1673 //--------------------------------------------------------------------------
1674
1675 //==========================================================================
1676 ///
1677 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1678 /// @brief Free the specified stream
1679 ///
1680 /// @remarks Only called from addon itself
1681 ///
1682 void Close()
1683 {
1684 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
1685 return;
1686
1687 AddonToKodiFuncTable_Game& cb =
1688 static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
1689 ->m_instanceData->toKodi;
1690 cb.CloseStream(cb.kodiInstance, m_handle);
1691 m_handle = nullptr;
1692 }
1693 //--------------------------------------------------------------------------
1694
1695 //==========================================================================
1696 ///
1697 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1698 /// @brief Get a buffer for zero-copy stream data
1699 ///
1700 /// @param[in] width The framebuffer width, or 0 for no width specified
1701 /// @param[in] height The framebuffer height, or 0 for no height specified
1702 /// @param[out] buffer The buffer, or unmodified if false is returned
1703 /// @return True if buffer was set, false otherwise
1704 ///
1705 /// @note If this returns true, buffer must be freed using \ref ReleaseBuffer().
1706 ///
1707 /// @remarks Only called from addon itself
1708 ///
1709 bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer& buffer)
1710 {
1711 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
1712 return false;
1713
1714 AddonToKodiFuncTable_Game& cb =
1715 static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
1716 ->m_instanceData->toKodi;
1717 return cb.GetStreamBuffer(cb.kodiInstance, m_handle, width, height, &buffer);
1718 }
1719 //--------------------------------------------------------------------------
1720
1721 //==========================================================================
1722 ///
1723 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1724 /// @brief Add a data packet to a stream
1725 ///
1726 /// @param[in] packet The data packet
1727 ///
1728 /// @remarks Only called from addon itself
1729 ///
1730 void AddData(const game_stream_packet& packet)
1731 {
1732 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
1733 return;
1734
1735 AddonToKodiFuncTable_Game& cb =
1736 static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
1737 ->m_instanceData->toKodi;
1738 cb.AddStreamData(cb.kodiInstance, m_handle, &packet);
1739 }
1740 //--------------------------------------------------------------------------
1741
1742 //==========================================================================
1743 ///
1744 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1745 /// @brief Free an allocated buffer
1746 ///
1747 /// @param[in] buffer The buffer returned from GetStreamBuffer()
1748 ///
1749 /// @remarks Only called from addon itself
1750 ///
1751 void ReleaseBuffer(game_stream_buffer& buffer)
1752 {
1753 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
1754 return;
1755
1756 AddonToKodiFuncTable_Game& cb =
1757 static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
1758 ->m_instanceData->toKodi;
1759 cb.ReleaseStreamBuffer(cb.kodiInstance, m_handle, &buffer);
1760 }
1761 //--------------------------------------------------------------------------
1762
1763 //==========================================================================
1764 ///
1765 /// @ingroup cpp_kodi_addon_game_Operation_CStream
1766 /// @brief To check stream open was OK, e.g. after use of constructor
1767 ///
1768 /// @return true if stream was successfully opened
1769 ///
1770 /// @remarks Only called from addon itself
1771 ///
1772 bool IsOpen() const { return m_handle != nullptr; }
1773 //--------------------------------------------------------------------------
1774
1775 private:
1776 void* m_handle = nullptr;
1777 };
1778 //@}
1779
1780 //@}
1781
1782//--==----==----==----==----==----==----==----==----==----==----==----==----==--
1783
1784 //============================================================================
1785 ///
1786 /// @defgroup cpp_kodi_addon_game_HardwareRendering 3. Hardware rendering operations
1787 /// @ingroup cpp_kodi_addon_game
1788 /// @brief **Hardware rendering operations**
1789 ///
1790 //@{
1791
1792 //============================================================================
1793 ///
1794 /// @brief Invalidates the current HW context and reinitializes GPU resources
1795 ///
1796 /// Any GL state is lost, and must not be deinitialized explicitly.
1797 ///
1798 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the HW context was reset
1799 ///
1800 virtual GAME_ERROR HwContextReset()
1801 {
1802 return GAME_ERROR_NOT_IMPLEMENTED;
1803 }
1804 //----------------------------------------------------------------------------
1805
1806 //============================================================================
1807 ///
1808 /// @brief Called before the context is destroyed
1809 ///
1810 /// Resources can be deinitialized at this step.
1811 ///
1812 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the HW context was destroyed
1813 ///
1814 virtual GAME_ERROR HwContextDestroy()
1815 {
1816 return GAME_ERROR_NOT_IMPLEMENTED;
1817 }
1818
1819 //============================================================================
1820 ///
1821 /// @brief **Callback to Kodi Function**<br>Get a symbol from the hardware context
1822 ///
1823 /// @param[in] sym The symbol's name
1824 ///
1825 /// @return A function pointer for the specified symbol
1826 ///
1827 /// @remarks Only called from addon itself
1828 ///
1829 game_proc_address_t HwGetProcAddress(const char* sym)
1830 {
1831 return m_instanceData->toKodi.HwGetProcAddress(m_instanceData->toKodi.kodiInstance, sym);
1832 }
1833 //----------------------------------------------------------------------------
1834
1835 //@}
1836
1837//--==----==----==----==----==----==----==----==----==----==----==----==----==--
1838
1839 //============================================================================
1840 ///
1841 /// @defgroup cpp_kodi_addon_game_InputOperations 4. Input operations
1842 /// @ingroup cpp_kodi_addon_game
1843 /// @brief **Input operations**
1844 ///
1845 //@{
1846
1847 //============================================================================
1848 ///
1849 /// @brief Check if input is accepted for a feature on the controller
1850 ///
1851 /// If only a subset of the controller profile is used, this can return false
1852 /// for unsupported features to not absorb their input.
1853 ///
1854 /// If the entire controller profile is used, this should always return true.
1855 ///
1856 /// @param[in] controller_id The ID of the controller profile
1857 /// @param[in] feature_name The name of a feature in that profile
1858 /// @return true if input is accepted for the feature, false otherwise
1859 ///
1860 virtual bool HasFeature(const std::string& controller_id, const std::string& feature_name)
1861 {
1862 return false;
1863 }
1864 //----------------------------------------------------------------------------
1865
1866 //============================================================================
1867 ///
1868 /// @brief Get the input topology that specifies which controllers can be connected
1869 ///
1870 /// @return The input topology, or null to use the default
1871 ///
1872 /// If this returns non-null, topology must be freed using FreeTopology().
1873 ///
1874 /// If this returns null, the topology will default to a single port that can
1875 /// accept all controllers imported by addon.xml. The port ID is set to
1876 /// the @ref DEFAULT_PORT_ID constant.
1877 ///
1878 virtual game_input_topology* GetTopology()
1879 {
1880 return nullptr;
1881 }
1882 //----------------------------------------------------------------------------
1883
1884 //============================================================================
1885 ///
1886 /// @brief Free the topology's resources
1887 ///
1888 /// @param[in] topology The topology returned by GetTopology()
1889 ///
1890 virtual void FreeTopology(game_input_topology* topology)
1891 {
1892 }
1893 //----------------------------------------------------------------------------
1894
1895 //============================================================================
1896 ///
1897 /// @brief Set the layouts for known controllers
1898 ///
1899 /// @param[in] controllers The controller layouts
1900 ///
1901 /// After loading the input topology, the frontend will call this with
1902 /// controller layouts for all controllers discovered in the topology.
1903 ///
1904 virtual void SetControllerLayouts(const std::vector<AddonGameControllerLayout>& controllers)
1905 {
1906 }
1907 //----------------------------------------------------------------------------
1908
1909 //============================================================================
1910 ///
1911 /// @brief Enable/disable keyboard input using the specified controller
1912 ///
1913 /// @param[in] enable True to enable input, false otherwise
1914 /// @param[in] controller_id The controller ID if enabling, or unused if disabling
1915 ///
1916 /// @return True if keyboard input was enabled, false otherwise
1917 ///
1918 virtual bool EnableKeyboard(bool enable, const std::string& controller_id)
1919 {
1920 return false;
1921 }
1922 //----------------------------------------------------------------------------
1923
1924 //============================================================================
1925 ///
1926 /// @brief Enable/disable mouse input using the specified controller
1927 ///
1928 /// @param[in] enable True to enable input, false otherwise
1929 /// @param[in] controller_id The controller ID if enabling, or unused if disabling
1930 ///
1931 /// @return True if mouse input was enabled, false otherwise
1932 ///
1933 virtual bool EnableMouse(bool enable, const std::string& controller_id)
1934 {
1935 return false;
1936 }
1937 //--------------------------------------------------------------------------
1938
1939 //==========================================================================
1940 ///
1941 /// @brief Connect/disconnect a controller to a port on the virtual game console
1942 ///
1943 /// @param[in] connect True to connect a controller, false to disconnect
1944 /// @param[in] port_address The address of the port
1945 /// @param[in] controller_id The controller ID if connecting, or unused if disconnecting
1946 /// @return True if the \p controller was (dis-)connected to the port, false otherwise
1947 ///
1948 /// The address is a string that allows traversal of the controller topology.
1949 /// It is formed by alternating port IDs and controller IDs separated by "/".
1950 ///
1951 /// For example, assume that the topology represented in XML for Snes9x is:
1952 ///
1953 /// ~~~~~~~~~~~~~{.xml}
1954 /// <logicaltopology>
1955 /// <port type="controller" id="1">
1956 /// <accepts controller="game.controller.snes"/>
1957 /// <accepts controller="game.controller.snes.multitap">
1958 /// <port type="controller" id="1">
1959 /// <accepts controller="game.controller.snes"/>
1960 /// </port>
1961 /// <port type="controller" id="2">
1962 /// <accepts controller="game.controller.snes"/>
1963 /// </port>
1964 /// ...
1965 /// </accepts>
1966 /// </port>
1967 /// </logicaltopology>
1968 /// ~~~~~~~~~~~~~
1969 ///
1970 /// To connect a multitap to the console's first port, the multitap's controller
1971 /// info is set using the port address:
1972 ///
1973 /// 1
1974 ///
1975 /// To connect a SNES controller to the second port of the multitap, the
1976 /// controller info is next set using the address:
1977 ///
1978 /// 1/game.controller.multitap/2
1979 ///
1980 /// Any attempts to connect a controller to a port on a disconnected multitap
1981 /// will return false.
1982 ///
1983 virtual bool ConnectController(bool connect,
1984 const std::string& port_address,
1985 const std::string& controller_id)
1986 {
1987 return false;
1988 }
1989 //----------------------------------------------------------------------------
1990
1991 //============================================================================
1992 ///
1993 /// @brief Notify the add-on of an input event
1994 ///
1995 /// @param[in] event The input event
1996 ///
1997 /// @return true if the event was handled, false otherwise
1998 ///
1999 virtual bool InputEvent(const game_input_event& event)
2000 {
2001 return false;
2002 }
2003 //----------------------------------------------------------------------------
2004
2005 //============================================================================
2006 ///
2007 /// @brief **Callback to Kodi Function**<br>Notify the port of an input event
2008 ///
2009 /// @param[in] event The input event
2010 /// @return true if the event was handled, false otherwise
2011 ///
2012 /// @note Input events can arrive for the following sources:
2013 /// - \ref GAME_INPUT_EVENT_MOTOR
2014 ///
2015 /// @remarks Only called from addon itself
2016 ///
2017 bool KodiInputEvent(const game_input_event& event)
2018 {
2019 return m_instanceData->toKodi.InputEvent(m_instanceData->toKodi.kodiInstance, &event);
2020 }
2021 //----------------------------------------------------------------------------
2022
2023 //@}
2024
2025//--==----==----==----==----==----==----==----==----==----==----==----==----==--
2026
2027 //============================================================================
2028 ///
2029 /// @defgroup cpp_kodi_addon_game_SerializationOperations 5. Serialization operations
2030 /// @ingroup cpp_kodi_addon_game
2031 /// @brief **Serialization operations**
2032 ///
2033 //@{
2034
2035 //============================================================================
2036 ///
2037 /// @brief Get the number of bytes required to serialize the game
2038 ///
2039 /// @return the number of bytes, or 0 if serialization is not supported
2040 ///
2041 virtual size_t SerializeSize()
2042 {
2043 return 0;
2044 }
2045 //----------------------------------------------------------------------------
2046
2047 //============================================================================
2048 ///
2049 /// @brief Serialize the state of the game
2050 ///
2051 /// @param[in] data The buffer receiving the serialized game data
2052 /// @param[in] size The size of the buffer
2053 ///
2054 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was serialized into the buffer
2055 ///
2056 virtual GAME_ERROR Serialize(uint8_t* data, size_t size)
2057 {
2058 return GAME_ERROR_NOT_IMPLEMENTED;
2059 }
2060 //----------------------------------------------------------------------------
2061
2062 //============================================================================
2063 ///
2064 /// @brief Deserialize the game from the given state
2065 ///
2066 /// @param[in] data A buffer containing the game's new state
2067 /// @param[in] size The size of the buffer
2068 ///
2069 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game deserialized
2070 ///
2071 virtual GAME_ERROR Deserialize(const uint8_t* data, size_t size)
2072 {
2073 return GAME_ERROR_NOT_IMPLEMENTED;
2074 }
2075 //----------------------------------------------------------------------------
2076
2077 //@}
2078
2079//--==----==----==----==----==----==----==----==----==----==----==----==----==--
2080
2081 //============================================================================
2082 ///
2083 /// @defgroup cpp_kodi_addon_game_CheatOperations 6. Cheat operations
2084 /// @ingroup cpp_kodi_addon_game
2085 /// @brief **Cheat operations**
2086 ///
2087 //@{
2088
2089 //============================================================================
2090 ///
2091 /// @brief Reset the cheat system
2092 ///
2093 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the cheat system was reset
2094 ///
2095 virtual GAME_ERROR CheatReset()
2096 {
2097 return GAME_ERROR_NOT_IMPLEMENTED;
2098 }
2099 //----------------------------------------------------------------------------
2100
2101 //============================================================================
2102 ///
2103 /// @brief Get a region of memory
2104 ///
2105 /// @param[in] type The type of memory to retrieve
2106 /// @param[in] data Set to the region of memory; must remain valid until UnloadGame() is called
2107 /// @param[in] size Set to the size of the region of memory
2108 ///
2109 /// @return the error, or @ref GAME_ERROR_NO_ERROR if data was set to a valid buffer
2110 ///
2111 virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t*& data, size_t& size)
2112 {
2113 return GAME_ERROR_NOT_IMPLEMENTED;
2114 }
2115 //----------------------------------------------------------------------------
2116
2117 //============================================================================
2118 ///
2119 /// @brief Set a cheat code
2120 ///
2121 /// @param[in] index
2122 /// @param[in] enabled
2123 /// @param[in] code
2124 ///
2125 /// @return the error, or @ref GAME_ERROR_NO_ERROR if the cheat was set
2126 ///
2127 virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string& code)
2128 {
2129 return GAME_ERROR_NOT_IMPLEMENTED;
2130 }
2131 //----------------------------------------------------------------------------
2132
2133 //@}
2134
2135private:
2136 void SetAddonStruct(KODI_HANDLE instance)
2137 {
2138 if (instance == nullptr)
2139 throw std::logic_error("kodi::addon::CInstanceGame: Creation with empty addon structure not"
2140 "allowed, table must be given from Kodi!");
2141
2142 m_instanceData = static_cast<AddonInstance_Game*>(instance);
2143 m_instanceData->toAddon.addonInstance = this;
2144
2145 m_instanceData->toAddon.LoadGame = ADDON_LoadGame;
2146 m_instanceData->toAddon.LoadGameSpecial = ADDON_LoadGameSpecial;
2147 m_instanceData->toAddon.LoadStandalone = ADDON_LoadStandalone;
2148 m_instanceData->toAddon.UnloadGame = ADDON_UnloadGame;
2149 m_instanceData->toAddon.GetGameTiming = ADDON_GetGameTiming;
2150 m_instanceData->toAddon.GetRegion = ADDON_GetRegion;
2151 m_instanceData->toAddon.RequiresGameLoop = ADDON_RequiresGameLoop;
2152 m_instanceData->toAddon.RunFrame = ADDON_RunFrame;
2153 m_instanceData->toAddon.Reset = ADDON_Reset;
2154
2155 m_instanceData->toAddon.HwContextReset = ADDON_HwContextReset;
2156 m_instanceData->toAddon.HwContextDestroy = ADDON_HwContextDestroy;
2157
2158 m_instanceData->toAddon.HasFeature = ADDON_HasFeature;
2159 m_instanceData->toAddon.GetTopology = ADDON_GetTopology;
2160 m_instanceData->toAddon.FreeTopology = ADDON_FreeTopology;
2161 m_instanceData->toAddon.SetControllerLayouts = ADDON_SetControllerLayouts;
2162 m_instanceData->toAddon.EnableKeyboard = ADDON_EnableKeyboard;
2163 m_instanceData->toAddon.EnableMouse = ADDON_EnableMouse;
2164 m_instanceData->toAddon.ConnectController = ADDON_ConnectController;
2165 m_instanceData->toAddon.InputEvent = ADDON_InputEvent;
2166
2167 m_instanceData->toAddon.SerializeSize = ADDON_SerializeSize;
2168 m_instanceData->toAddon.Serialize = ADDON_Serialize;
2169 m_instanceData->toAddon.Deserialize = ADDON_Deserialize;
2170
2171 m_instanceData->toAddon.CheatReset = ADDON_CheatReset;
2172 m_instanceData->toAddon.GetMemory = ADDON_GetMemory;
2173 m_instanceData->toAddon.SetCheat = ADDON_SetCheat;
2174 }
2175
2176 // --- Game operations ---------------------------------------------------------
2177
2178 inline static GAME_ERROR ADDON_LoadGame(const AddonInstance_Game* instance, const char* url)
2179 {
2180 return instance->toAddon.addonInstance->LoadGame(url);
2181 }
2182
2183 inline static GAME_ERROR ADDON_LoadGameSpecial(const AddonInstance_Game* instance,
2184 SPECIAL_GAME_TYPE type,
2185 const char** urls,
2186 size_t urlCount)
2187 {
2188 std::vector<std::string> urlList;
2189 for (size_t i = 0; i < urlCount; ++i)
2190 {
2191 if (urls[i] != nullptr)
2192 urlList.push_back(urls[i]);
2193 }
2194
2195 return instance->toAddon.addonInstance->LoadGameSpecial(type, urlList);
2196 }
2197
2198 inline static GAME_ERROR ADDON_LoadStandalone(const AddonInstance_Game* instance)
2199 {
2200 return instance->toAddon.addonInstance->LoadStandalone();
2201 }
2202
2203 inline static GAME_ERROR ADDON_UnloadGame(const AddonInstance_Game* instance)
2204 {
2205 return instance->toAddon.addonInstance->UnloadGame();
2206 }
2207
2208 inline static GAME_ERROR ADDON_GetGameTiming(const AddonInstance_Game* instance,
2209 game_system_timing* timing_info)
2210 {
2211 return instance->toAddon.addonInstance->GetGameTiming(*timing_info);
2212 }
2213
2214 inline static GAME_REGION ADDON_GetRegion(const AddonInstance_Game* instance)
2215 {
2216 return instance->toAddon.addonInstance->GetRegion();
2217 }
2218
2219 inline static bool ADDON_RequiresGameLoop(const AddonInstance_Game* instance)
2220 {
2221 return instance->toAddon.addonInstance->RequiresGameLoop();
2222 }
2223
2224 inline static GAME_ERROR ADDON_RunFrame(const AddonInstance_Game* instance)
2225 {
2226 return instance->toAddon.addonInstance->RunFrame();
2227 }
2228
2229 inline static GAME_ERROR ADDON_Reset(const AddonInstance_Game* instance)
2230 {
2231 return instance->toAddon.addonInstance->Reset();
2232 }
2233
2234
2235 // --- Hardware rendering operations -------------------------------------------
2236
2237 inline static GAME_ERROR ADDON_HwContextReset(const AddonInstance_Game* instance)
2238 {
2239 return instance->toAddon.addonInstance->HwContextReset();
2240 }
2241
2242 inline static GAME_ERROR ADDON_HwContextDestroy(const AddonInstance_Game* instance)
2243 {
2244 return instance->toAddon.addonInstance->HwContextDestroy();
2245 }
2246
2247
2248 // --- Input operations --------------------------------------------------------
2249
2250 inline static bool ADDON_HasFeature(const AddonInstance_Game* instance,
2251 const char* controller_id,
2252 const char* feature_name)
2253 {
2254 return instance->toAddon.addonInstance->HasFeature(controller_id, feature_name);
2255 }
2256
2257 inline static game_input_topology* ADDON_GetTopology(const AddonInstance_Game* instance)
2258 {
2259 return instance->toAddon.addonInstance->GetTopology();
2260 }
2261
2262 inline static void ADDON_FreeTopology(const AddonInstance_Game* instance,
2263 game_input_topology* topology)
2264 {
2265 instance->toAddon.addonInstance->FreeTopology(topology);
2266 }
2267
2268 inline static void ADDON_SetControllerLayouts(const AddonInstance_Game* instance,
2269 const game_controller_layout* controllers,
2270 unsigned int controller_count)
2271 {
2272 if (controllers == nullptr)
2273 return;
2274
2275 std::vector<AddonGameControllerLayout> controllerList;
2276 for (unsigned int i = 0; i < controller_count; ++i)
2277 controllerList.push_back(controllers[i]);
2278
2279 instance->toAddon.addonInstance->SetControllerLayouts(controllerList);
2280 }
2281
2282 inline static bool ADDON_EnableKeyboard(const AddonInstance_Game* instance,
2283 bool enable,
2284 const char* controller_id)
2285 {
2286 return instance->toAddon.addonInstance->EnableKeyboard(enable, controller_id);
2287 }
2288
2289 inline static bool ADDON_EnableMouse(const AddonInstance_Game* instance,
2290 bool enable,
2291 const char* controller_id)
2292 {
2293 return instance->toAddon.addonInstance->EnableMouse(enable, controller_id);
2294 }
2295
2296 inline static bool ADDON_ConnectController(const AddonInstance_Game* instance,
2297 bool connect,
2298 const char* port_address,
2299 const char* controller_id)
2300 {
2301 return instance->toAddon.addonInstance->ConnectController(connect, port_address, controller_id);
2302 }
2303
2304 inline static bool ADDON_InputEvent(const AddonInstance_Game* instance,
2305 const game_input_event* event)
2306 {
2307 return instance->toAddon.addonInstance->InputEvent(*event);
2308 }
2309
2310
2311 // --- Serialization operations ------------------------------------------------
2312
2313 inline static size_t ADDON_SerializeSize(const AddonInstance_Game* instance)
2314 {
2315 return instance->toAddon.addonInstance->SerializeSize();
2316 }
2317
2318 inline static GAME_ERROR ADDON_Serialize(const AddonInstance_Game* instance,
2319 uint8_t* data,
2320 size_t size)
2321 {
2322 return instance->toAddon.addonInstance->Serialize(data, size);
2323 }
2324
2325 inline static GAME_ERROR ADDON_Deserialize(const AddonInstance_Game* instance,
2326 const uint8_t* data,
2327 size_t size)
2328 {
2329 return instance->toAddon.addonInstance->Deserialize(data, size);
2330 }
2331
2332
2333 // --- Cheat operations --------------------------------------------------------
2334
2335 inline static GAME_ERROR ADDON_CheatReset(const AddonInstance_Game* instance)
2336 {
2337 return instance->toAddon.addonInstance->CheatReset();
2338 }
2339
2340 inline static GAME_ERROR ADDON_GetMemory(const AddonInstance_Game* instance,
2341 GAME_MEMORY type,
2342 uint8_t** data,
2343 size_t* size)
2344 {
2345 return instance->toAddon.addonInstance->GetMemory(type, *data, *size);
2346 }
2347
2348 inline static GAME_ERROR ADDON_SetCheat(const AddonInstance_Game* instance,
2349 unsigned int index,
2350 bool enabled,
2351 const char* code)
2352 {
2353 return instance->toAddon.addonInstance->SetCheat(index, enabled, code);
2354 }
2355
2356 AddonInstance_Game* m_instanceData;
2357};
2358
2359} /* namespace addon */
2360} /* namespace kodi */