11 #include "../AddonBase.h"
12 #include "../c-api/addon-instance/game.h"
53 for (
unsigned int i = 0; i < layout.digital_button_count; ++i)
55 for (
unsigned int i = 0; i < layout.analog_button_count; ++i)
57 for (
unsigned int i = 0; i < layout.analog_stick_count; ++i)
59 for (
unsigned int i = 0; i < layout.accelerometer_count; ++i)
61 for (
unsigned int i = 0; i < layout.key_count; ++i)
62 keys.push_back(layout.keys[i]);
63 for (
unsigned int i = 0; i < layout.rel_pointer_count; ++i)
65 for (
unsigned int i = 0; i < layout.abs_pointer_count; ++i)
67 for (
unsigned int i = 0; i < layout.motor_count; ++i)
68 motors.push_back(layout.motors[i]);
93 std::vector<std::string>
keys;
163 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
164 throw std::logic_error(
"kodi::addon::CInstanceGame: Creation of more as one in single "
165 "instance way is not allowed!");
167 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
168 CAddonBase::m_interface->globalSingleInstance =
this;
200 for (
unsigned int i = 0; i < m_instanceData->props->proxy_dll_count; ++i)
202 if (m_instanceData->props->proxy_dll_paths[i] !=
nullptr)
203 paths.push_back(m_instanceData->props->proxy_dll_paths[i]);
205 return !paths.empty();
222 for (
unsigned int i = 0; i < m_instanceData->props->resource_directory_count; ++i)
224 if (m_instanceData->props->resource_directories[i] !=
nullptr)
225 dirs.push_back(m_instanceData->props->resource_directories[i]);
227 return !dirs.empty();
254 bool SupportsVFS()
const {
return m_instanceData->props->supports_vfs; }
268 for (
unsigned int i = 0; i < m_instanceData->props->extension_count; ++i)
270 if (m_instanceData->props->extensions[i] !=
nullptr)
271 extensions.push_back(m_instanceData->props->extensions[i]);
273 return !extensions.empty();
422 void CloseGame(
void) { m_instanceData->toKodi->CloseGame(m_instanceData->toKodi->kodiInstance); }
463 if (!CAddonBase::m_interface->globalSingleInstance)
473 *
static_cast<CInstanceGame*
>(CAddonBase::m_interface->globalSingleInstance)
474 ->m_instanceData->toKodi;
475 m_handle = cb.OpenStream(cb.kodiInstance, &properties);
476 return m_handle !=
nullptr;
488 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
492 *
static_cast<CInstanceGame*
>(CAddonBase::m_interface->globalSingleInstance)
493 ->m_instanceData->toKodi;
494 cb.CloseStream(cb.kodiInstance, m_handle);
514 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
518 *
static_cast<CInstanceGame*
>(CAddonBase::m_interface->globalSingleInstance)
519 ->m_instanceData->toKodi;
520 return cb.GetStreamBuffer(cb.kodiInstance, m_handle, width, height, &buffer);
534 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
538 *
static_cast<CInstanceGame*
>(CAddonBase::m_interface->globalSingleInstance)
539 ->m_instanceData->toKodi;
540 cb.AddStreamData(cb.kodiInstance, m_handle, &packet);
554 if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
558 *
static_cast<CInstanceGame*
>(CAddonBase::m_interface->globalSingleInstance)
559 ->m_instanceData->toKodi;
560 cb.ReleaseStreamBuffer(cb.kodiInstance, m_handle, &buffer);
572 bool IsOpen()
const {
return m_handle !=
nullptr; }
576 KODI_GAME_STREAM_HANDLE m_handle =
nullptr;
638 return m_instanceData->toKodi->HwGetProcAddress(m_instanceData->toKodi->kodiInstance, sym);
675 virtual bool HasFeature(
const std::string& controller_id,
const std::string& feature_name)
743 virtual bool EnableMouse(
bool enable,
const std::string& controller_id)
793 const std::string& port_address,
794 const std::string& controller_id)
826 return m_instanceData->toKodi->InputEvent(m_instanceData->toKodi->kodiInstance, &event);
955 void SetAddonStruct(KODI_HANDLE instance)
957 if (instance ==
nullptr)
958 throw std::logic_error(
"kodi::addon::CInstanceGame: Creation with empty addon structure not"
959 "allowed, table must be given from Kodi!");
962 m_instanceData->toAddon->addonInstance =
this;
964 m_instanceData->toAddon->LoadGame = ADDON_LoadGame;
965 m_instanceData->toAddon->LoadGameSpecial = ADDON_LoadGameSpecial;
966 m_instanceData->toAddon->LoadStandalone = ADDON_LoadStandalone;
967 m_instanceData->toAddon->UnloadGame = ADDON_UnloadGame;
968 m_instanceData->toAddon->GetGameTiming = ADDON_GetGameTiming;
969 m_instanceData->toAddon->GetRegion = ADDON_GetRegion;
970 m_instanceData->toAddon->RequiresGameLoop = ADDON_RequiresGameLoop;
971 m_instanceData->toAddon->RunFrame = ADDON_RunFrame;
972 m_instanceData->toAddon->Reset = ADDON_Reset;
974 m_instanceData->toAddon->HwContextReset = ADDON_HwContextReset;
975 m_instanceData->toAddon->HwContextDestroy = ADDON_HwContextDestroy;
977 m_instanceData->toAddon->HasFeature = ADDON_HasFeature;
978 m_instanceData->toAddon->GetTopology = ADDON_GetTopology;
979 m_instanceData->toAddon->FreeTopology = ADDON_FreeTopology;
980 m_instanceData->toAddon->SetControllerLayouts = ADDON_SetControllerLayouts;
981 m_instanceData->toAddon->EnableKeyboard = ADDON_EnableKeyboard;
982 m_instanceData->toAddon->EnableMouse = ADDON_EnableMouse;
983 m_instanceData->toAddon->ConnectController = ADDON_ConnectController;
984 m_instanceData->toAddon->InputEvent = ADDON_InputEvent;
986 m_instanceData->toAddon->SerializeSize = ADDON_SerializeSize;
987 m_instanceData->toAddon->Serialize = ADDON_Serialize;
988 m_instanceData->toAddon->Deserialize = ADDON_Deserialize;
990 m_instanceData->toAddon->CheatReset = ADDON_CheatReset;
991 m_instanceData->toAddon->GetMemory = ADDON_GetMemory;
992 m_instanceData->toAddon->SetCheat = ADDON_SetCheat;
999 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->LoadGame(url);
1007 std::vector<std::string> urlList;
1008 for (
size_t i = 0; i < urlCount; ++i)
1010 if (urls[i] !=
nullptr)
1011 urlList.push_back(urls[i]);
1014 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1015 ->LoadGameSpecial(type, urlList);
1020 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->LoadStandalone();
1025 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->UnloadGame();
1031 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1032 ->GetGameTiming(*timing_info);
1037 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->
GetRegion();
1042 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->RequiresGameLoop();
1047 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->RunFrame();
1052 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->Reset();
1060 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->HwContextReset();
1065 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->HwContextDestroy();
1072 const char* controller_id,
1073 const char* feature_name)
1075 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1076 ->HasFeature(controller_id, feature_name);
1081 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->GetTopology();
1087 static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->FreeTopology(topology);
1091 const game_controller_layout* controllers,
1092 unsigned int controller_count)
1094 if (controllers ==
nullptr)
1097 std::vector<GameControllerLayout> controllerList;
1098 for (
unsigned int i = 0; i < controller_count; ++i)
1099 controllerList.push_back(controllers[i]);
1101 static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1102 ->SetControllerLayouts(controllerList);
1107 const char* controller_id)
1109 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1110 ->EnableKeyboard(enable, controller_id);
1115 const char* controller_id)
1117 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1118 ->EnableMouse(enable, controller_id);
1123 const char* port_address,
1124 const char* controller_id)
1126 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1127 ->ConnectController(connect, port_address, controller_id);
1133 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->InputEvent(*event);
1141 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->SerializeSize();
1148 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->Serialize(data, size);
1152 const uint8_t* data,
1155 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->Deserialize(data, size);
1163 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)->CheatReset();
1171 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1172 ->GetMemory(type, *data, *size);
1180 return static_cast<CInstanceGame*
>(instance->toAddon->addonInstance)
1181 ->SetCheat(index, enabled, code);
Definition: AddonBase.h:186
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:177
@ ADDON_INSTANCE_GAME
Game instance, see kodi::addon::CInstanceGame.
Definition: versions.h:223
CInstanceGame()
Game class constructor.
Definition: Game.h:161
std::string GameClientDllPath() const
Callback to Kodi Function The path of the game client being loaded.
Definition: Game.h:186
bool ProxyDllPaths(std::vector< std::string > &paths)
Callback to Kodi Function Paths to proxy DLLs used to load the game client.
Definition: Game.h:198
bool ResourceDirectories(std::vector< std::string > &dirs)
Callback to Kodi Function The "system" directories of the frontend.
Definition: Game.h:220
std::string ProfileDirectory() const
Callback to Kodi Function The writable directory of the frontend.
Definition: Game.h:243
bool SupportsVFS() const
Callback to Kodi Function The value of the <supports_vfs> property from addon.xml.
Definition: Game.h:254
~CInstanceGame() override=default
Destructor.
bool Extensions(std::vector< std::string > &extensions)
Callback to Kodi Function The extensions in the <extensions> property from addon.xml.
Definition: Game.h:266
virtual GAME_ERROR CheatReset()
Reset the cheat system.
Definition: Game.h:916
virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t *&data, size_t &size)
Get a region of memory.
Definition: Game.h:931
virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string &code)
Set a cheat code.
Definition: Game.h:946
Game system timing.
Definition: game.h:1050
GAME_REGION
Game reguin definition
Definition: game.h:563
SPECIAL_GAME_TYPE
Special game types passed into game_load_game_special().
Definition: game.h:581
GAME_MEMORY
Game Memory
Definition: game.h:600
@ GAME_REGION_UNKNOWN
Game region unknown.
Definition: game.h:565
void(* game_proc_address_t)(void)
Hardware framebuffer process function address
Definition: game.h:406
Stream buffers for hardware rendering and zero-copy support
Definition: game.h:507
Stream packet and ephemeral metadata
Definition: game.h:529
Immutable stream metadata
Definition: game.h:483
GAME_ERROR
Game add-on error codes
Definition: game.h:34
@ GAME_ERROR_NOT_IMPLEMENTED
the method that the frontend called is not implemented
Definition: game.h:42
virtual GAME_ERROR HwContextDestroy()
Called before the context is destroyed.
Definition: Game.h:622
virtual GAME_ERROR HwContextReset()
Invalidates the current HW context and reinitializes GPU resources.
Definition: Game.h:609
game_proc_address_t HwGetProcAddress(const char *sym)
Callback to Kodi Function Get a symbol from the hardware context
Definition: Game.h:636
bool IsOpen() const
To check stream open was OK, e.g. after use of constructor.
Definition: Game.h:572
void ReleaseBuffer(game_stream_buffer &buffer)
Free an allocated buffer.
Definition: Game.h:552
void Close()
Free the specified stream.
Definition: Game.h:486
bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer &buffer)
Get a buffer for zero-copy stream data.
Definition: Game.h:512
void AddData(const game_stream_packet &packet)
Add a data packet to a stream.
Definition: Game.h:532
bool Open(const game_stream_properties &properties)
Create a stream for gameplay data.
Definition: Game.h:461
virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector< std::string > &urls)
Load a game that requires multiple files.
Definition: Game.h:321
virtual GAME_ERROR UnloadGame()
Unload the current game.
Definition: Game.h:350
virtual GAME_ERROR GetGameTiming(game_system_timing &timing_info)
Get timing information about the loaded game.
Definition: Game.h:363
virtual GAME_ERROR RunFrame()
Run a single frame for add-ons that use a game loop.
Definition: Game.h:399
virtual bool RequiresGameLoop()
Return true if the client requires the frontend to provide a game loop.
Definition: Game.h:388
virtual GAME_ERROR Reset()
Reset the current game.
Definition: Game.h:410
virtual GAME_ERROR LoadStandalone()
Begin playing without a game file.
Definition: Game.h:337
void CloseGame(void)
Callback to Kodi Function Requests the frontend to stop the current game
Definition: Game.h:422
virtual GAME_ERROR LoadGame(const std::string &url)
Load a game.
Definition: Game.h:308
virtual GAME_REGION GetRegion()
Get region of the loaded game.
Definition: Game.h:374
virtual GAME_ERROR Deserialize(const uint8_t *data, size_t size)
Deserialize the game from the given state.
Definition: Game.h:884
virtual GAME_ERROR Serialize(uint8_t *data, size_t size)
Serialize the state of the game.
Definition: Game.h:870
virtual size_t SerializeSize()
Get the number of bytes required to serialize the game.
Definition: Game.h:856
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
std::string ATTRIBUTE_HIDDEN GetRegion(const std::string &id)
Returns your regions setting as a string for the specified id.
Definition: General.h:478
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749
Game instance.
Definition: game.h:1200
Game callbacks.
Definition: game.h:1132