mirror of https://github.com/OpenTTD/OpenTTD
Add: initialize plugin when found
parent
3122a992bf
commit
e354b747f9
|
@ -289,6 +289,7 @@ static void ShutdownGame()
|
|||
|
||||
if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
|
||||
|
||||
SocialIntegration::Shutdown();
|
||||
DriverFactoryBase::ShutdownDrivers();
|
||||
|
||||
UnInitWindowSystem();
|
||||
|
|
|
@ -20,6 +20,25 @@
|
|||
|
||||
#include "safeguards.h"
|
||||
|
||||
/**
|
||||
* Container to track information per plugin.
|
||||
*/
|
||||
class InternalSocialIntegrationPlugin {
|
||||
public:
|
||||
InternalSocialIntegrationPlugin(const std::string &filename, const std::string &basepath) : library(filename)
|
||||
{
|
||||
openttd_info.openttd_version = _openttd_revision;
|
||||
}
|
||||
|
||||
OpenTTD_SocialIntegration_v1_PluginInfo plugin_info = {}; ///< Information supplied by plugin.
|
||||
OpenTTD_SocialIntegration_v1_PluginApi plugin_api = {}; ///< API supplied by plugin.
|
||||
OpenTTD_SocialIntegration_v1_OpenTTDInfo openttd_info = {}; ///< Information supplied by OpenTTD.
|
||||
|
||||
LibraryLoader library; ///< Library handle.
|
||||
};
|
||||
|
||||
static std::vector<std::unique_ptr<InternalSocialIntegrationPlugin>> _plugins; ///< List of loaded plugins.
|
||||
|
||||
/** Helper for scanning for files with SocialIntegration as extension */
|
||||
class SocialIntegrationFileScanner : FileScanner {
|
||||
public:
|
||||
|
@ -40,6 +59,45 @@ public:
|
|||
{
|
||||
std::string basepath = filename.substr(basepath_length);
|
||||
Debug(misc, 1, "[Social Integration: {}] Loading ...", basepath);
|
||||
|
||||
auto &plugin = _plugins.emplace_back(std::make_unique<InternalSocialIntegrationPlugin>(filename, basepath));
|
||||
|
||||
if (plugin->library.HasError()) {
|
||||
Debug(misc, 0, "[Social Integration: {}] Failed to load library: {}", basepath, plugin->library.GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
OpenTTD_SocialIntegration_v1_GetInfo getinfo_func = plugin->library.GetFunction("SocialIntegration_v1_GetInfo");
|
||||
if (plugin->library.HasError()) {
|
||||
Debug(misc, 0, "[Social Integration: {}] Failed to find symbol SocialPlugin_v1_GetInfo: {}", basepath, plugin->library.GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
OpenTTD_SocialIntegration_v1_Init init_func = plugin->library.GetFunction("SocialIntegration_v1_Init");
|
||||
if (plugin->library.HasError()) {
|
||||
Debug(misc, 0, "[Social Integration: {}] Failed to find symbol SocialPlugin_v1_Init: {}", basepath, plugin->library.GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
getinfo_func(&plugin->plugin_info);
|
||||
|
||||
auto state = init_func(&plugin->plugin_api, &plugin->openttd_info);
|
||||
switch (state) {
|
||||
case OTTD_SOCIAL_INTEGRATION_V1_INIT_SUCCESS:
|
||||
Debug(misc, 1, "[Social Integration: {}] Loaded for {}: {} ({})", basepath, plugin->plugin_info.social_platform, plugin->plugin_info.name, plugin->plugin_info.version);
|
||||
return true;
|
||||
|
||||
case OTTD_SOCIAL_INTEGRATION_V1_INIT_FAILED:
|
||||
Debug(misc, 0, "[Social Integration: {}] Failed to initialize", basepath);
|
||||
return false;
|
||||
|
||||
case OTTD_SOCIAL_INTEGRATION_V1_INIT_PLATFORM_NOT_RUNNING:
|
||||
Debug(misc, 1, "[Social Integration: {}] Failed to initialize: {} is not running", basepath, plugin->plugin_info.social_platform);
|
||||
return false;
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -48,3 +106,8 @@ void SocialIntegration::Initialize()
|
|||
SocialIntegrationFileScanner fs;
|
||||
fs.Scan();
|
||||
}
|
||||
|
||||
void SocialIntegration::Shutdown()
|
||||
{
|
||||
_plugins.clear();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ public:
|
|||
* Initialize the social integration system, loading any social integration plugins that are available.
|
||||
*/
|
||||
static void Initialize();
|
||||
|
||||
/**
|
||||
* Shutdown the social integration system, and all social integration plugins that are loaded.
|
||||
*/
|
||||
static void Shutdown();
|
||||
};
|
||||
|
||||
#endif /* SOCIAL_INTEGRATION_H */
|
||||
|
|
Loading…
Reference in New Issue