1 /* 2 * Copyright (C) 2014-2020 Team Kodi (https://kodi.tv) 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 * See LICENSE.md for more information. 6 */ 7 8 #pragma once 9 10 #include "libretro/ClientBridge.h" 11 #include "libretro/LibretroDLL.h" 12 #include "utils/Timer.h" 13 14 #include <kodi/addon-instance/Game.h> 15 16 namespace LIBRETRO 17 { 18 class CGameInfoLoader; 19 } 20 21 class ATTRIBUTE_HIDDEN CGameLibRetro 22 : public kodi::addon::CAddonBase, 23 public kodi::addon::CInstanceGame 24 { 25 public: 26 CGameLibRetro(); 27 ~CGameLibRetro() override; 28 29 ADDON_STATUS Create() override; 30 ADDON_STATUS GetStatus() override; 31 ADDON_STATUS SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) override; 32 33 // --- Game operations --------------------------------------------------------- 34 35 GAME_ERROR LoadGame(const std::string& url) override; 36 GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector<std::string>& urls) override; 37 GAME_ERROR LoadStandalone() override; 38 GAME_ERROR UnloadGame() override; 39 GAME_ERROR GetGameTiming(game_system_timing& timing_info) override; 40 GAME_REGION GetRegion() override; RequiresGameLoop()41 bool RequiresGameLoop() override { return true; } 42 GAME_ERROR RunFrame() override; 43 GAME_ERROR Reset() override; 44 45 // --- Hardware rendering operations ------------------------------------------- 46 47 GAME_ERROR HwContextReset() override; 48 GAME_ERROR HwContextDestroy() override; 49 50 // --- Input operations -------------------------------------------------------- 51 52 bool HasFeature(const std::string& controller_id, const std::string& feature_name) override; 53 game_input_topology* GetTopology() override; 54 void FreeTopology(game_input_topology* topology) override; 55 void SetControllerLayouts(const std::vector<kodi::addon::GameControllerLayout>& controllers) override; 56 bool EnableKeyboard(bool enable, const std::string& controller_id) override; 57 bool EnableMouse(bool enable, const std::string& controller_id) override; 58 bool ConnectController(bool connect, const std::string& port_address, const std::string& controller_id) override; 59 bool InputEvent(const game_input_event& event) override; 60 61 // --- Serialization operations ------------------------------------------------ 62 63 size_t SerializeSize() override; 64 GAME_ERROR Serialize(uint8_t* data, size_t size) override; 65 GAME_ERROR Deserialize(const uint8_t* data, size_t size) override; 66 67 // --- Cheat operations -------------------------------------------------------- 68 69 GAME_ERROR CheatReset() override; 70 GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t*& data, size_t& size) override; 71 GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string& code) override; 72 73 private: 74 GAME_ERROR AudioAvailable(); 75 76 LIBRETRO::Timer m_timer; 77 LIBRETRO::CLibretroDLL m_client; 78 LIBRETRO::CClientBridge m_clientBridge; 79 std::vector<LIBRETRO::CGameInfoLoader*> m_gameInfo; 80 bool m_supportsVFS = false; // TODO 81 int64_t m_frameTimeLast = 0; 82 }; 83