1 /* 2 * Copyright (C) 2014-2020 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 #ifndef C_API_ADDONINSTANCE_GAME_H 10 #define C_API_ADDONINSTANCE_GAME_H 11 12 #include "../addon_base.h" 13 14 #include <stddef.h> /* size_t */ 15 16 //============================================================================== 17 /// @ingroup cpp_kodi_addon_game_Defs 18 /// @brief **Port ID used when topology is unknown** 19 #define DEFAULT_PORT_ID "1" 20 //------------------------------------------------------------------------------ 21 22 #ifdef __cplusplus 23 extern "C" 24 { 25 #endif /* __cplusplus */ 26 27 //============================================================================ 28 /// @ingroup cpp_kodi_addon_game_Defs 29 /// @brief **Game add-on error codes** 30 /// 31 /// Used as return values on most Game related functions. 32 /// 33 typedef enum GAME_ERROR 34 { 35 /// @brief no error occurred 36 GAME_ERROR_NO_ERROR, 37 38 /// @brief an unknown error occurred 39 GAME_ERROR_UNKNOWN, 40 41 /// @brief the method that the frontend called is not implemented 42 GAME_ERROR_NOT_IMPLEMENTED, 43 44 /// @brief the command was rejected by the game client 45 GAME_ERROR_REJECTED, 46 47 /// @brief the parameters of the method that was called are invalid for this operation 48 GAME_ERROR_INVALID_PARAMETERS, 49 50 /// @brief the command failed 51 GAME_ERROR_FAILED, 52 53 /// @brief no game is loaded 54 GAME_ERROR_NOT_LOADED, 55 56 /// @brief game requires restricted resources 57 GAME_ERROR_RESTRICTED, 58 } GAME_ERROR; 59 //---------------------------------------------------------------------------- 60 61 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 62 /// @defgroup cpp_kodi_addon_game_Defs_AudioStream 1. Audio stream 63 /// @ingroup cpp_kodi_addon_game_Defs 64 /// @brief **The for Audio stream used data system** 65 /// 66 /// Used to give Addon currently used audio stream configuration on Kodi and 67 /// arrays to give related data to Kodi on callbacks. 68 /// 69 ///@{ 70 71 //============================================================================ 72 /// @brief **Stream Format** 73 /// 74 /// From Kodi requested specified audio sample format. 75 /// 76 typedef enum GAME_PCM_FORMAT 77 { 78 GAME_PCM_FORMAT_UNKNOWN, 79 80 /// @brief S16NE sample format 81 GAME_PCM_FORMAT_S16NE, 82 } GAME_PCM_FORMAT; 83 //---------------------------------------------------------------------------- 84 85 //============================================================================ 86 /// @brief **Audio channel** 87 /// 88 /// Channel identification flags. 89 /// 90 typedef enum GAME_AUDIO_CHANNEL 91 { 92 /// @brief Channel list terminator 93 GAME_CH_NULL, 94 95 /// @brief Channel front left 96 GAME_CH_FL, 97 98 /// @brief Channel front right 99 GAME_CH_FR, 100 101 /// @brief Channel front center 102 GAME_CH_FC, 103 104 /// @brief Channel Low Frequency Effects / Subwoofer 105 GAME_CH_LFE, 106 107 /// @brief Channel back left 108 GAME_CH_BL, 109 110 /// @brief Channel back right 111 GAME_CH_BR, 112 113 /// @brief Channel front left over center 114 GAME_CH_FLOC, 115 116 /// @brief Channel front right over center 117 GAME_CH_FROC, 118 119 /// @brief Channel back center 120 GAME_CH_BC, 121 122 /// @brief Channel surround/side left 123 GAME_CH_SL, 124 125 /// @brief Channel surround/side right 126 GAME_CH_SR, 127 128 /// @brief Channel top front left 129 GAME_CH_TFL, 130 131 /// @brief Channel top front right 132 GAME_CH_TFR, 133 134 /// @brief Channel top front center 135 GAME_CH_TFC, 136 137 /// @brief Channel top center 138 GAME_CH_TC, 139 140 /// @brief Channel top back left 141 GAME_CH_TBL, 142 143 /// @brief Channel top back right 144 GAME_CH_TBR, 145 146 /// @brief Channel top back center 147 GAME_CH_TBC, 148 149 /// @brief Channel bacl left over center 150 GAME_CH_BLOC, 151 152 /// @brief Channel back right over center 153 GAME_CH_BROC, 154 } GAME_AUDIO_CHANNEL; 155 //---------------------------------------------------------------------------- 156 157 //============================================================================ 158 /// @brief **Game audio stream properties** 159 /// 160 /// Used by Kodi to pass the currently required audio stream settings to the addon 161 /// 162 typedef struct game_stream_audio_properties 163 { 164 GAME_PCM_FORMAT format; 165 const GAME_AUDIO_CHANNEL* channel_map; 166 } ATTRIBUTE_PACKED game_stream_audio_properties; 167 //---------------------------------------------------------------------------- 168 169 //============================================================================ 170 /// @brief **Audio stream packet** 171 /// 172 /// This packet contains audio stream data passed to Kodi. 173 /// 174 typedef struct game_stream_audio_packet 175 { 176 /// @brief Pointer for audio stream data given to Kodi 177 const uint8_t* data; 178 179 /// @brief Size of data array 180 size_t size; 181 } ATTRIBUTE_PACKED game_stream_audio_packet; 182 //---------------------------------------------------------------------------- 183 184 ///@} 185 186 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 187 /// @defgroup cpp_kodi_addon_game_Defs_VideoStream 2. Video stream 188 /// @ingroup cpp_kodi_addon_game_Defs 189 /// @brief **The for Video stream used data system** 190 /// 191 /// Used to give Addon currently used video stream configuration on Kodi and 192 /// arrays to give related data to Kodi on callbacks. 193 /// 194 ///@{ 195 196 //============================================================================ 197 /// @brief **Pixel format** 198 /// 199 /// From Kodi requested specified video RGB color model format. 200 /// 201 typedef enum GAME_PIXEL_FORMAT 202 { 203 GAME_PIXEL_FORMAT_UNKNOWN, 204 205 /// @brief 0RGB8888 Format 206 GAME_PIXEL_FORMAT_0RGB8888, 207 208 /// @brief RGB565 Format 209 GAME_PIXEL_FORMAT_RGB565, 210 211 /// @brief 0RGB1555 Format 212 GAME_PIXEL_FORMAT_0RGB1555, 213 } GAME_PIXEL_FORMAT; 214 //---------------------------------------------------------------------------- 215 216 //============================================================================ 217 /// @brief **Video rotation position** 218 /// 219 /// To define position how video becomes shown. 220 /// 221 typedef enum GAME_VIDEO_ROTATION 222 { 223 /// @brief 0° and Without rotation 224 GAME_VIDEO_ROTATION_0, 225 226 /// @brief rotate 90° counterclockwise 227 GAME_VIDEO_ROTATION_90_CCW, 228 229 /// @brief rotate 180° counterclockwise 230 GAME_VIDEO_ROTATION_180_CCW, 231 232 /// @brief rotate 270° counterclockwise 233 GAME_VIDEO_ROTATION_270_CCW, 234 } GAME_VIDEO_ROTATION; 235 //---------------------------------------------------------------------------- 236 237 //============================================================================ 238 /// @brief **Game video stream properties** 239 /// 240 /// Used by Kodi to pass the currently required video stream settings to the addon 241 /// 242 typedef struct game_stream_video_properties 243 { 244 /// @brief The to used pixel format 245 GAME_PIXEL_FORMAT format; 246 247 /// @brief The nominal used width 248 unsigned int nominal_width; 249 250 /// @brief The nominal used height 251 unsigned int nominal_height; 252 253 /// @brief The maximal used width 254 unsigned int max_width; 255 256 /// @brief The maximal used height 257 unsigned int max_height; 258 259 /// @brief On video stream used aspect ration 260 /// 261 /// @note If aspect_ratio is <= 0.0, an aspect ratio of nominal_width / nominal_height is assumed 262 float aspect_ratio; 263 } ATTRIBUTE_PACKED game_stream_video_properties; 264 //---------------------------------------------------------------------------- 265 266 //============================================================================ 267 /// @brief **Video stream packet** 268 /// 269 /// This packet contains video stream data passed to Kodi. 270 /// 271 typedef struct game_stream_video_packet 272 { 273 /// @brief Video height 274 unsigned int width; 275 276 /// @brief Video width 277 unsigned int height; 278 279 /// @brief Width @ref GAME_VIDEO_ROTATION defined rotation angle. 280 GAME_VIDEO_ROTATION rotation; 281 282 /// @brief Pointer for video stream data given to Kodi 283 const uint8_t* data; 284 285 /// @brief Size of data array 286 size_t size; 287 } ATTRIBUTE_PACKED game_stream_video_packet; 288 //---------------------------------------------------------------------------- 289 290 ///@} 291 292 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 293 /// @defgroup cpp_kodi_addon_game_Defs_HardwareFramebuffer 3. Hardware framebuffer stream 294 /// @ingroup cpp_kodi_addon_game_Defs 295 /// @brief **Hardware framebuffer stream data** 296 /// 297 ///@{ 298 299 //============================================================================ 300 /// @brief **Hardware framebuffer type** 301 /// 302 typedef enum GAME_HW_CONTEXT_TYPE 303 { 304 /// @brief None context 305 GAME_HW_CONTEXT_NONE, 306 307 /// @brief OpenGL 2.x. Driver can choose to use latest compatibility context 308 GAME_HW_CONTEXT_OPENGL, 309 310 /// @brief OpenGL ES 2.0 311 GAME_HW_CONTEXT_OPENGLES2, 312 313 /// @brief Modern desktop core GL context. Use major/minor fields to set GL version 314 GAME_HW_CONTEXT_OPENGL_CORE, 315 316 /// @brief OpenGL ES 3.0 317 GAME_HW_CONTEXT_OPENGLES3, 318 319 /// @brief OpenGL ES 3.1+. Set major/minor fields. 320 GAME_HW_CONTEXT_OPENGLES_VERSION, 321 322 /// @brief Vulkan 323 GAME_HW_CONTEXT_VULKAN 324 } GAME_HW_CONTEXT_TYPE; 325 //---------------------------------------------------------------------------- 326 327 //============================================================================ 328 /// @brief **Hardware framebuffer properties** 329 /// 330 typedef struct game_stream_hw_framebuffer_properties 331 { 332 /// @brief The API to use. 333 /// 334 GAME_HW_CONTEXT_TYPE context_type; 335 336 /// @brief Set if render buffers should have depth component attached. 337 /// 338 /// @todo: Obsolete 339 /// 340 bool depth; 341 342 /// @brief Set if stencil buffers should be attached. 343 /// 344 /// If depth and stencil are true, a packed 24/8 buffer will be added. 345 /// Only attaching stencil is invalid and will be ignored. 346 /// 347 /// @todo: Obsolete. 348 /// 349 bool stencil; 350 351 /// @brief Use conventional bottom-left origin convention. 352 /// 353 /// If false, standard top-left origin semantics are used. 354 /// 355 /// @todo: Move to GL specific interface 356 /// 357 bool bottom_left_origin; 358 359 /// @brief Major version number for core GL context or GLES 3.1+. 360 unsigned int version_major; 361 362 /// @brief Minor version number for core GL context or GLES 3.1+. 363 unsigned int version_minor; 364 365 /// @brief If this is true, the frontend will go very far to avoid resetting context 366 /// in scenarios like toggling fullscreen, etc. 367 /// 368 /// @todo: Obsolete? Maybe frontend should just always assume this... 369 /// 370 /// The reset callback might still be called in extreme situations such as if 371 /// the context is lost beyond recovery. 372 /// 373 /// For optimal stability, set this to false, and allow context to be reset at 374 /// any time. 375 /// 376 bool cache_context; 377 378 /// @brief Creates a debug context. 379 bool debug_context; 380 } ATTRIBUTE_PACKED game_stream_hw_framebuffer_properties; 381 //---------------------------------------------------------------------------- 382 383 //============================================================================ 384 /// @brief **Hardware framebuffer buffer** 385 /// 386 typedef struct game_stream_hw_framebuffer_buffer 387 { 388 /// @brief 389 uintptr_t framebuffer; 390 } ATTRIBUTE_PACKED game_stream_hw_framebuffer_buffer; 391 //---------------------------------------------------------------------------- 392 393 //============================================================================ 394 /// @brief **Hardware framebuffer packet** 395 /// 396 typedef struct game_stream_hw_framebuffer_packet 397 { 398 /// @brief 399 uintptr_t framebuffer; 400 } ATTRIBUTE_PACKED game_stream_hw_framebuffer_packet; 401 //---------------------------------------------------------------------------- 402 403 //============================================================================ 404 /// @brief **Hardware framebuffer process function address** 405 /// 406 typedef void (*game_proc_address_t)(void); 407 //---------------------------------------------------------------------------- 408 409 ///@} 410 411 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 412 /// @defgroup cpp_kodi_addon_game_Defs_SoftwareFramebuffer 4. Software framebuffer stream 413 /// @ingroup cpp_kodi_addon_game_Defs 414 /// @brief **Software framebuffer stream data** 415 /// 416 ///@{ 417 418 //============================================================================ 419 /// @brief **Game video stream properties** 420 /// 421 /// Used by Kodi to pass the currently required video stream settings to the addon 422 /// 423 typedef game_stream_video_properties game_stream_sw_framebuffer_properties; 424 //---------------------------------------------------------------------------- 425 426 //============================================================================ 427 /// @brief **Hardware framebuffer type** 428 /// 429 typedef struct game_stream_sw_framebuffer_buffer 430 { 431 GAME_PIXEL_FORMAT format; 432 uint8_t* data; 433 size_t size; 434 } ATTRIBUTE_PACKED game_stream_sw_framebuffer_buffer; 435 //---------------------------------------------------------------------------- 436 437 //============================================================================ 438 /// @brief **Video stream packet** 439 /// 440 /// This packet contains video stream data passed to Kodi. 441 /// 442 typedef game_stream_video_packet game_stream_sw_framebuffer_packet; 443 //---------------------------------------------------------------------------- 444 445 ///@} 446 447 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 448 /// @defgroup cpp_kodi_addon_game_Defs_StreamTypes 5. Stream types 449 /// @ingroup cpp_kodi_addon_game_Defs 450 /// @brief **Stream types data** 451 /// 452 ///@{ 453 454 //============================================================================ 455 /// @brief **Game stream types** 456 /// 457 typedef enum GAME_STREAM_TYPE 458 { 459 /// @brief Unknown 460 GAME_STREAM_UNKNOWN, 461 462 /// @brief Audio stream 463 GAME_STREAM_AUDIO, 464 465 /// @brief Video stream 466 GAME_STREAM_VIDEO, 467 468 /// @brief Hardware framebuffer 469 GAME_STREAM_HW_FRAMEBUFFER, 470 471 /// @brief Software framebuffer 472 GAME_STREAM_SW_FRAMEBUFFER, 473 } GAME_STREAM_TYPE; 474 //---------------------------------------------------------------------------- 475 476 //============================================================================ 477 /// @brief **Immutable stream metadata** 478 /// 479 /// This metadata is provided when the stream is opened. If any stream 480 /// properties change, a new stream must be opened. 481 /// 482 typedef struct game_stream_properties 483 { 484 /// @brief 485 GAME_STREAM_TYPE type; 486 union 487 { 488 /// @brief 489 game_stream_audio_properties audio; 490 491 /// @brief 492 game_stream_video_properties video; 493 494 /// @brief 495 game_stream_hw_framebuffer_properties hw_framebuffer; 496 497 /// @brief 498 game_stream_sw_framebuffer_properties sw_framebuffer; 499 }; 500 } ATTRIBUTE_PACKED game_stream_properties; 501 //---------------------------------------------------------------------------- 502 503 //============================================================================ 504 /// @brief **Stream buffers for hardware rendering and zero-copy support** 505 /// 506 typedef struct game_stream_buffer 507 { 508 /// @brief 509 GAME_STREAM_TYPE type; 510 union 511 { 512 /// @brief 513 game_stream_hw_framebuffer_buffer hw_framebuffer; 514 515 /// @brief 516 game_stream_sw_framebuffer_buffer sw_framebuffer; 517 }; 518 } ATTRIBUTE_PACKED game_stream_buffer; 519 //---------------------------------------------------------------------------- 520 521 //============================================================================ 522 /// @brief **Stream packet and ephemeral metadata** 523 /// 524 /// This packet contains stream data and accompanying metadata. The metadata 525 /// is ephemeral, meaning it only applies to the current packet and can change 526 /// from packet to packet in the same stream. 527 /// 528 typedef struct game_stream_packet 529 { 530 /// @brief 531 GAME_STREAM_TYPE type; 532 union 533 { 534 /// @brief 535 game_stream_audio_packet audio; 536 537 /// @brief 538 game_stream_video_packet video; 539 540 /// @brief 541 game_stream_hw_framebuffer_packet hw_framebuffer; 542 543 /// @brief 544 game_stream_sw_framebuffer_packet sw_framebuffer; 545 }; 546 } ATTRIBUTE_PACKED game_stream_packet; 547 //---------------------------------------------------------------------------- 548 549 ///@} 550 551 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 552 /// @defgroup cpp_kodi_addon_game_Defs_GameTypes 6. Game types 553 /// @ingroup cpp_kodi_addon_game_Defs 554 /// @brief **Game types data** 555 /// 556 ///@{ 557 558 //============================================================================ 559 /// @brief **Game reguin definition** 560 /// 561 /// Returned from game_get_region() 562 typedef enum GAME_REGION 563 { 564 /// @brief Game region unknown 565 GAME_REGION_UNKNOWN, 566 567 /// @brief Game region NTSC 568 GAME_REGION_NTSC, 569 570 /// @brief Game region PAL 571 GAME_REGION_PAL, 572 } GAME_REGION; 573 //---------------------------------------------------------------------------- 574 575 //============================================================================ 576 /// @brief **Special game types passed into game_load_game_special().** 577 /// 578 /// @remark Only used when multiple ROMs are required. 579 /// 580 typedef enum SPECIAL_GAME_TYPE 581 { 582 /// @brief Game Type BSX 583 SPECIAL_GAME_TYPE_BSX, 584 585 /// @brief Game Type BSX slotted 586 SPECIAL_GAME_TYPE_BSX_SLOTTED, 587 588 /// @brief Game Type sufami turbo 589 SPECIAL_GAME_TYPE_SUFAMI_TURBO, 590 591 /// @brief Game Type super game boy 592 SPECIAL_GAME_TYPE_SUPER_GAME_BOY, 593 } SPECIAL_GAME_TYPE; 594 //---------------------------------------------------------------------------- 595 596 //============================================================================ 597 /// @brief **Game Memory** 598 /// 599 typedef enum GAME_MEMORY 600 { 601 /// @brief Passed to game_get_memory_data/size(). If the memory type doesn't apply 602 /// to the implementation NULL/0 can be returned. 603 GAME_MEMORY_MASK = 0xff, 604 605 /// @brief Regular save ram. 606 /// 607 /// This ram is usually found on a game cartridge, backed 608 /// up by a battery. If save game data is too complex for a single memory 609 /// buffer, the SYSTEM_DIRECTORY environment callback can be used. 610 GAME_MEMORY_SAVE_RAM = 0, 611 612 /// @brief Some games have a built-in clock to keep track of time. 613 /// 614 /// This memory is usually just a couple of bytes to keep track of time. 615 GAME_MEMORY_RTC = 1, 616 617 /// @brief System ram lets a frontend peek into a game systems main RAM 618 GAME_MEMORY_SYSTEM_RAM = 2, 619 620 /// @brief Video ram lets a frontend peek into a game systems video RAM (VRAM) 621 GAME_MEMORY_VIDEO_RAM = 3, 622 623 /// @brief Special memory type 624 GAME_MEMORY_SNES_BSX_RAM = ((1 << 8) | GAME_MEMORY_SAVE_RAM), 625 626 /// @brief Special memory type 627 GAME_MEMORY_SNES_BSX_PRAM = ((2 << 8) | GAME_MEMORY_SAVE_RAM), 628 629 /// @brief Special memory type 630 GAME_MEMORY_SNES_SUFAMI_TURBO_A_RAM = ((3 << 8) | GAME_MEMORY_SAVE_RAM), 631 632 /// @brief Special memory type 633 GAME_MEMORY_SNES_SUFAMI_TURBO_B_RAM = ((4 << 8) | GAME_MEMORY_SAVE_RAM), 634 635 /// @brief Special memory type 636 GAME_MEMORY_SNES_GAME_BOY_RAM = ((5 << 8) | GAME_MEMORY_SAVE_RAM), 637 638 /// @brief Special memory type 639 GAME_MEMORY_SNES_GAME_BOY_RTC = ((6 << 8) | GAME_MEMORY_RTC), 640 } GAME_MEMORY; 641 //---------------------------------------------------------------------------- 642 643 //============================================================================ 644 /// @brief **ID values for SIMD CPU features** 645 typedef enum GAME_SIMD 646 { 647 /// @brief SIMD CPU SSE 648 GAME_SIMD_SSE = (1 << 0), 649 650 /// @brief SIMD CPU SSE2 651 GAME_SIMD_SSE2 = (1 << 1), 652 653 /// @brief SIMD CPU VMX 654 GAME_SIMD_VMX = (1 << 2), 655 656 /// @brief SIMD CPU VMX128 657 GAME_SIMD_VMX128 = (1 << 3), 658 659 /// @brief SIMD CPU AVX 660 GAME_SIMD_AVX = (1 << 4), 661 662 /// @brief SIMD CPU NEON 663 GAME_SIMD_NEON = (1 << 5), 664 665 /// @brief SIMD CPU SSE3 666 GAME_SIMD_SSE3 = (1 << 6), 667 668 /// @brief SIMD CPU SSSE3 669 GAME_SIMD_SSSE3 = (1 << 7), 670 671 /// @brief SIMD CPU MMX 672 GAME_SIMD_MMX = (1 << 8), 673 674 /// @brief SIMD CPU MMXEXT 675 GAME_SIMD_MMXEXT = (1 << 9), 676 677 /// @brief SIMD CPU SSE4 678 GAME_SIMD_SSE4 = (1 << 10), 679 680 /// @brief SIMD CPU SSE42 681 GAME_SIMD_SSE42 = (1 << 11), 682 683 /// @brief SIMD CPU AVX2 684 GAME_SIMD_AVX2 = (1 << 12), 685 686 /// @brief SIMD CPU VFPU 687 GAME_SIMD_VFPU = (1 << 13), 688 } GAME_SIMD; 689 //---------------------------------------------------------------------------- 690 691 ///@} 692 693 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 694 /// @defgroup cpp_kodi_addon_game_Defs_InputTypes 7. Input types 695 /// @ingroup cpp_kodi_addon_game_Defs 696 /// @brief **Input types** 697 /// 698 ///@{ 699 700 //============================================================================ 701 /// @brief 702 typedef enum GAME_INPUT_EVENT_SOURCE 703 { 704 /// @brief 705 GAME_INPUT_EVENT_DIGITAL_BUTTON, 706 707 /// @brief 708 GAME_INPUT_EVENT_ANALOG_BUTTON, 709 710 /// @brief 711 GAME_INPUT_EVENT_AXIS, 712 713 /// @brief 714 GAME_INPUT_EVENT_ANALOG_STICK, 715 716 /// @brief 717 GAME_INPUT_EVENT_ACCELEROMETER, 718 719 /// @brief 720 GAME_INPUT_EVENT_KEY, 721 722 /// @brief 723 GAME_INPUT_EVENT_RELATIVE_POINTER, 724 725 /// @brief 726 GAME_INPUT_EVENT_ABSOLUTE_POINTER, 727 728 /// @brief 729 GAME_INPUT_EVENT_MOTOR, 730 } GAME_INPUT_EVENT_SOURCE; 731 //---------------------------------------------------------------------------- 732 733 //============================================================================ 734 /// @brief 735 typedef enum GAME_KEY_MOD 736 { 737 /// @brief 738 GAME_KEY_MOD_NONE = 0x0000, 739 740 /// @brief 741 GAME_KEY_MOD_SHIFT = 0x0001, 742 743 /// @brief 744 GAME_KEY_MOD_CTRL = 0x0002, 745 746 /// @brief 747 GAME_KEY_MOD_ALT = 0x0004, 748 749 /// @brief 750 GAME_KEY_MOD_META = 0x0008, 751 752 /// @brief 753 GAME_KEY_MOD_SUPER = 0x0010, 754 755 /// @brief 756 GAME_KEY_MOD_NUMLOCK = 0x0100, 757 758 /// @brief 759 GAME_KEY_MOD_CAPSLOCK = 0x0200, 760 761 /// @brief 762 GAME_KEY_MOD_SCROLLOCK = 0x0400, 763 } GAME_KEY_MOD; 764 //---------------------------------------------------------------------------- 765 766 //============================================================================ 767 /// @brief Type of port on the virtual game console 768 typedef enum GAME_PORT_TYPE 769 { 770 /// @brief Game port unknown 771 GAME_PORT_UNKNOWN, 772 773 /// @brief Game port Keyboard 774 GAME_PORT_KEYBOARD, 775 776 /// @brief Game port mouse 777 GAME_PORT_MOUSE, 778 779 /// @brief Game port controller 780 GAME_PORT_CONTROLLER, 781 } GAME_PORT_TYPE; 782 //---------------------------------------------------------------------------- 783 784 /*! @cond PRIVATE */ 785 /*! 786 * @brief "C" Game add-on controller layout. 787 * 788 * Structure used to interface in "C" between Kodi and Addon. 789 * 790 * See @ref AddonGameControllerLayout for description of values. 791 */ 792 typedef struct game_controller_layout 793 { 794 char* controller_id; 795 bool provides_input; // False for multitaps 796 char** digital_buttons; 797 unsigned int digital_button_count; 798 char** analog_buttons; 799 unsigned int analog_button_count; 800 char** analog_sticks; 801 unsigned int analog_stick_count; 802 char** accelerometers; 803 unsigned int accelerometer_count; 804 char** keys; 805 unsigned int key_count; 806 char** rel_pointers; 807 unsigned int rel_pointer_count; 808 char** abs_pointers; 809 unsigned int abs_pointer_count; 810 char** motors; 811 unsigned int motor_count; 812 } ATTRIBUTE_PACKED game_controller_layout; 813 /*! @endcond */ 814 815 struct game_input_port; 816 817 //============================================================================ 818 /// @brief Device that can provide input 819 typedef struct game_input_device 820 { 821 /// @brief ID used in the Kodi controller API 822 const char* controller_id; 823 824 /// @brief 825 const char* port_address; 826 827 /// @brief 828 struct game_input_port* available_ports; 829 830 /// @brief 831 unsigned int port_count; 832 } ATTRIBUTE_PACKED game_input_device; 833 //---------------------------------------------------------------------------- 834 835 //============================================================================ 836 /// @brief Port that can provide input 837 /// 838 /// Ports can accept multiple devices and devices can have multiple ports, so 839 /// the topology of possible configurations is a tree structure of alternating 840 /// port and device nodes. 841 /// 842 typedef struct game_input_port 843 { 844 /// @brief 845 GAME_PORT_TYPE type; 846 847 /// @brief Required for GAME_PORT_CONTROLLER type 848 const char* port_id; 849 850 /// @brief 851 game_input_device* accepted_devices; 852 853 /// @brief 854 unsigned int device_count; 855 } ATTRIBUTE_PACKED game_input_port; 856 //---------------------------------------------------------------------------- 857 858 //============================================================================ 859 /// @brief The input topology is the possible ways to connect input devices 860 /// 861 /// This represents the logical topology, which is the possible connections that 862 /// the game client's logic can handle. It is strictly a subset of the physical 863 /// topology. Loops are not allowed. 864 /// 865 typedef struct game_input_topology 866 { 867 /// @brief The list of ports on the virtual game console 868 game_input_port* ports; 869 870 /// @brief The number of ports 871 unsigned int port_count; 872 873 /// @brief A limit on the number of input-providing devices, or -1 for no limit 874 int player_limit; 875 } ATTRIBUTE_PACKED game_input_topology; 876 //---------------------------------------------------------------------------- 877 878 //============================================================================ 879 /// @brief 880 typedef struct game_digital_button_event 881 { 882 /// @brief 883 bool pressed; 884 } ATTRIBUTE_PACKED game_digital_button_event; 885 //---------------------------------------------------------------------------- 886 887 //============================================================================ 888 /// @brief 889 typedef struct game_analog_button_event 890 { 891 /// @brief 892 float magnitude; 893 } ATTRIBUTE_PACKED game_analog_button_event; 894 //---------------------------------------------------------------------------- 895 896 //============================================================================ 897 /// @brief 898 typedef struct game_axis_event 899 { 900 /// @brief 901 float position; 902 } ATTRIBUTE_PACKED game_axis_event; 903 //---------------------------------------------------------------------------- 904 905 //============================================================================ 906 /// @brief 907 typedef struct game_analog_stick_event 908 { 909 /// @brief 910 float x; 911 912 /// @brief 913 float y; 914 } ATTRIBUTE_PACKED game_analog_stick_event; 915 //---------------------------------------------------------------------------- 916 917 //============================================================================ 918 /// @brief 919 typedef struct game_accelerometer_event 920 { 921 /// @brief 922 float x; 923 924 /// @brief 925 float y; 926 927 /// @brief 928 float z; 929 } ATTRIBUTE_PACKED game_accelerometer_event; 930 //---------------------------------------------------------------------------- 931 932 //============================================================================ 933 /// @brief 934 typedef struct game_key_event 935 { 936 /// @brief 937 bool pressed; 938 939 /// @brief If the keypress generates a printing character 940 /// 941 /// The unicode value contains the character generated. If the key is a 942 /// non-printing character, e.g. a function or arrow key, the unicode value 943 /// is zero. 944 uint32_t unicode; 945 946 /// @brief 947 GAME_KEY_MOD modifiers; 948 } ATTRIBUTE_PACKED game_key_event; 949 //---------------------------------------------------------------------------- 950 951 //============================================================================ 952 /// @brief 953 typedef struct game_rel_pointer_event 954 { 955 /// @brief 956 int x; 957 958 /// @brief 959 int y; 960 } ATTRIBUTE_PACKED game_rel_pointer_event; 961 //---------------------------------------------------------------------------- 962 963 //============================================================================ 964 /// @brief 965 typedef struct game_abs_pointer_event 966 { 967 /// @brief 968 bool pressed; 969 970 /// @brief 971 float x; 972 973 /// @brief 974 float y; 975 } ATTRIBUTE_PACKED game_abs_pointer_event; 976 //---------------------------------------------------------------------------- 977 978 //============================================================================ 979 /// @brief 980 typedef struct game_motor_event 981 { 982 /// @brief 983 float magnitude; 984 } ATTRIBUTE_PACKED game_motor_event; 985 //---------------------------------------------------------------------------- 986 987 //============================================================================ 988 /// @brief 989 typedef struct game_input_event 990 { 991 /// @brief 992 GAME_INPUT_EVENT_SOURCE type; 993 994 /// @brief 995 const char* controller_id; 996 997 /// @brief 998 GAME_PORT_TYPE port_type; 999 1000 /// @brief 1001 const char* port_address; 1002 1003 /// @brief 1004 const char* feature_name; 1005 union 1006 { 1007 /// @brief 1008 struct game_digital_button_event digital_button; 1009 1010 /// @brief 1011 struct game_analog_button_event analog_button; 1012 1013 /// @brief 1014 struct game_axis_event axis; 1015 1016 /// @brief 1017 struct game_analog_stick_event analog_stick; 1018 1019 /// @brief 1020 struct game_accelerometer_event accelerometer; 1021 1022 /// @brief 1023 struct game_key_event key; 1024 1025 /// @brief 1026 struct game_rel_pointer_event rel_pointer; 1027 1028 /// @brief 1029 struct game_abs_pointer_event abs_pointer; 1030 1031 /// @brief 1032 struct game_motor_event motor; 1033 }; 1034 } ATTRIBUTE_PACKED game_input_event; 1035 //---------------------------------------------------------------------------- 1036 1037 ///@} 1038 1039 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 1040 /// @defgroup cpp_kodi_addon_game_Defs_EnvironmentTypes 8. Environment types 1041 /// @ingroup cpp_kodi_addon_game_Defs 1042 /// @brief **Environment types** 1043 /// 1044 ///@{ 1045 1046 //============================================================================ 1047 /// @brief Game system timing 1048 /// 1049 struct game_system_timing 1050 { 1051 /// @brief FPS of video content. 1052 double fps; 1053 1054 /// @brief Sampling rate of audio. 1055 double sample_rate; 1056 }; 1057 //---------------------------------------------------------------------------- 1058 1059 ///@} 1060 1061 1062 //--==----==----==----==----==----==----==----==----==----==----==----==----==-- 1063 1064 /*! 1065 * @brief Game properties 1066 * 1067 * Not to be used outside this header. 1068 */ 1069 typedef struct AddonProps_Game 1070 { 1071 /*! 1072 * The path of the game client being loaded. 1073 */ 1074 const char* game_client_dll_path; 1075 1076 /*! 1077 * Paths to proxy DLLs used to load the game client. 1078 */ 1079 const char** proxy_dll_paths; 1080 1081 /*! 1082 * Number of proxy DLL paths provided. 1083 */ 1084 unsigned int proxy_dll_count; 1085 1086 /*! 1087 * The "system" directories of the frontend. These directories can be used to 1088 * store system-specific ROMs such as BIOSes, configuration data, etc. 1089 */ 1090 const char** resource_directories; 1091 1092 /*! 1093 * Number of resource directories provided 1094 */ 1095 unsigned int resource_directory_count; 1096 1097 /*! 1098 * The writable directory of the frontend. This directory can be used to store 1099 * SRAM, memory cards, high scores, etc, if the game client cannot use the 1100 * regular memory interface, GetMemoryData(). 1101 */ 1102 const char* profile_directory; 1103 1104 /*! 1105 * The value of the <supports_vfs> property from addon.xml 1106 */ 1107 bool supports_vfs; 1108 1109 /*! 1110 * The extensions in the <extensions> property from addon.xml 1111 */ 1112 const char** extensions; 1113 1114 /*! 1115 * Number of extensions provided 1116 */ 1117 unsigned int extension_count; 1118 } AddonProps_Game; 1119 1120 typedef void* KODI_GAME_STREAM_HANDLE; 1121 1122 /*! Structure to transfer the methods from kodi_game_dll.h to Kodi */ 1123 1124 struct AddonInstance_Game; 1125 1126 /*! 1127 * @brief Game callbacks 1128 * 1129 * Not to be used outside this header. 1130 */ 1131 typedef struct AddonToKodiFuncTable_Game 1132 { 1133 KODI_HANDLE kodiInstance; 1134 1135 void (*CloseGame)(KODI_HANDLE kodiInstance); 1136 KODI_GAME_STREAM_HANDLE (*OpenStream)(KODI_HANDLE, const struct game_stream_properties*); 1137 bool (*GetStreamBuffer)(KODI_HANDLE, 1138 KODI_GAME_STREAM_HANDLE, 1139 unsigned int, 1140 unsigned int, 1141 struct game_stream_buffer*); 1142 void (*AddStreamData)(KODI_HANDLE, KODI_GAME_STREAM_HANDLE, const struct game_stream_packet*); 1143 void (*ReleaseStreamBuffer)(KODI_HANDLE, KODI_GAME_STREAM_HANDLE, struct game_stream_buffer*); 1144 void (*CloseStream)(KODI_HANDLE, KODI_GAME_STREAM_HANDLE); 1145 game_proc_address_t (*HwGetProcAddress)(KODI_HANDLE kodiInstance, const char* symbol); 1146 bool (*InputEvent)(KODI_HANDLE kodiInstance, const struct game_input_event* event); 1147 } AddonToKodiFuncTable_Game; 1148 1149 /*! 1150 * @brief Game function hooks 1151 * 1152 * Not to be used outside this header. 1153 */ 1154 typedef struct KodiToAddonFuncTable_Game 1155 { 1156 KODI_HANDLE addonInstance; 1157 1158 GAME_ERROR(__cdecl* LoadGame)(const struct AddonInstance_Game*, const char*); 1159 GAME_ERROR(__cdecl* LoadGameSpecial) 1160 (const struct AddonInstance_Game*, enum SPECIAL_GAME_TYPE, const char**, size_t); 1161 GAME_ERROR(__cdecl* LoadStandalone)(const struct AddonInstance_Game*); 1162 GAME_ERROR(__cdecl* UnloadGame)(const struct AddonInstance_Game*); 1163 GAME_ERROR(__cdecl* GetGameTiming) 1164 (const struct AddonInstance_Game*, struct game_system_timing*); 1165 GAME_REGION(__cdecl* GetRegion)(const struct AddonInstance_Game*); 1166 bool(__cdecl* RequiresGameLoop)(const struct AddonInstance_Game*); 1167 GAME_ERROR(__cdecl* RunFrame)(const struct AddonInstance_Game*); 1168 GAME_ERROR(__cdecl* Reset)(const struct AddonInstance_Game*); 1169 GAME_ERROR(__cdecl* HwContextReset)(const struct AddonInstance_Game*); 1170 GAME_ERROR(__cdecl* HwContextDestroy)(const struct AddonInstance_Game*); 1171 bool(__cdecl* HasFeature)(const struct AddonInstance_Game*, const char*, const char*); 1172 game_input_topology*(__cdecl* GetTopology)(const struct AddonInstance_Game*); 1173 void(__cdecl* FreeTopology)(const struct AddonInstance_Game*, struct game_input_topology*); 1174 void(__cdecl* SetControllerLayouts)(const struct AddonInstance_Game*, 1175 const struct game_controller_layout*, 1176 unsigned int); 1177 bool(__cdecl* EnableKeyboard)(const struct AddonInstance_Game*, bool, const char*); 1178 bool(__cdecl* EnableMouse)(const struct AddonInstance_Game*, bool, const char*); 1179 bool(__cdecl* ConnectController)(const struct AddonInstance_Game*, 1180 bool, 1181 const char*, 1182 const char*); 1183 bool(__cdecl* InputEvent)(const struct AddonInstance_Game*, const struct game_input_event*); 1184 size_t(__cdecl* SerializeSize)(const struct AddonInstance_Game*); 1185 GAME_ERROR(__cdecl* Serialize)(const struct AddonInstance_Game*, uint8_t*, size_t); 1186 GAME_ERROR(__cdecl* Deserialize)(const struct AddonInstance_Game*, const uint8_t*, size_t); 1187 GAME_ERROR(__cdecl* CheatReset)(const struct AddonInstance_Game*); 1188 GAME_ERROR(__cdecl* GetMemory) 1189 (const struct AddonInstance_Game*, enum GAME_MEMORY, uint8_t**, size_t*); 1190 GAME_ERROR(__cdecl* SetCheat) 1191 (const struct AddonInstance_Game*, unsigned int, bool, const char*); 1192 } KodiToAddonFuncTable_Game; 1193 1194 /*! 1195 * @brief Game instance 1196 * 1197 * Not to be used outside this header. 1198 */ 1199 typedef struct AddonInstance_Game 1200 { 1201 struct AddonProps_Game* props; 1202 struct AddonToKodiFuncTable_Game* toKodi; 1203 struct KodiToAddonFuncTable_Game* toAddon; 1204 } AddonInstance_Game; 1205 1206 #ifdef __cplusplus 1207 } 1208 #endif /* __cplusplus */ 1209 1210 #endif /* !C_API_ADDONINSTANCE_GAME_H */ 1211