1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef AI_LIBRARY_MANAGER_H
#define AI_LIBRARY_MANAGER_H
#include "IAILibraryManager.h"
#include "AIInterfaceLibrary.h"
#include "AIInterfaceLibraryInfo.h"
#include "SkirmishAILibraryInfo.h"
#include <vector>
#include <map>
#include <set>
/**
* Manages AI Interfaces and Skirmish AIs; their info and current status.
* It loads info about AI Interfaces and Skirmish AIs from info files
* in the data directories, from InterfaceInfo.lua and AIInfo.lua files.
* In addition to that, it keeps track fo which Interfaces and AIs
* are currently loaded, and unloads them when they are not needed anymore.
*/
class CAILibraryManager : public IAILibraryManager {
public:
CAILibraryManager();
/**
* Unloads all Interface and AI shared libraries that are currently loaded.
*/
~CAILibraryManager();
virtual const T_interfaceSpecs& GetInterfaceKeys() const;
virtual const T_skirmishAIKeys& GetSkirmishAIKeys() const;
virtual const T_interfaceInfos& GetInterfaceInfos() const;
virtual const T_skirmishAIInfos& GetSkirmishAIInfos() const;
virtual const T_dupInt& GetDuplicateInterfaceInfos() const;
virtual const T_dupSkirm& GetDuplicateSkirmishAIInfos() const;
virtual std::vector<SkirmishAIKey> FittingSkirmishAIKeys(
const SkirmishAIKey& skirmishAIKey) const;
virtual const CSkirmishAILibrary* FetchSkirmishAILibrary(
const SkirmishAIKey& skirmishAIKey);
virtual void ReleaseSkirmishAILibrary(const SkirmishAIKey& skirmishAIKey);
private:
/** Unloads all currently loaded AIs and interfaces. */
void ReleaseEverything();
/**
* Loads the interface if it is not yet loaded; increments load count.
*/
CAIInterfaceLibrary* FetchInterface(const AIInterfaceKey& interfaceKey);
/**
* Unloads the interface if its load count reaches 0.
*/
void ReleaseInterface(const AIInterfaceKey& interfaceKey);
/**
* Loads info about available AI Interfaces from Lua info-files.
*
* The files are searched in all data-dirs (see fs.GetDataDirectories())
* in the following sub-dirs:
* {AI_INTERFACES_DATA_DIR}/{*}/InterfaceInfo.lua
* {AI_INTERFACES_DATA_DIR}/{*}/{*}/InterfaceInfo.lua
*
* examples:
* AI/Interfaces/C/0.1/InterfaceInfo.lua
* AI/Interfaces/Java/0.1/InterfaceInfo.lua
*/
void GatherInterfaceLibrariesInfos();
/**
* Loads info about available Skirmish AIs from Lua info- and option-files.
* -> AI libraries can not corrupt the engines memory
*
* The files are searched in all data-dirs (see fs.GetDataDirectories())
* in the following sub-dirs:
* {SKIRMISH_AI_DATA_DIR}/{*}/AIInfo.lua
* {SKIRMISH_AI_DATA_DIR}/{*}/AIOptions.lua
* {SKIRMISH_AI_DATA_DIR}/{*}/{*}/AIInfo.lua
* {SKIRMISH_AI_DATA_DIR}/{*}/{*}/AIOptions.lua
*
* examples:
* AI/Skirmish/KAIK-0.13/AIInfo.lua
* AI/Skirmish/RAI/0.601/AIInfo.lua
* AI/Skirmish/RAI/0.601/AIOptions.lua
*/
void GatherSkirmishAIsLibrariesInfos();
void GatherSkirmishAIsLibrariesInfosFromLuaFiles(T_dupSkirm duplicateSkirmishAIInfoCheck);
void GatherSkirmishAIsLibrariesInfosFromInterfaceLibrary(T_dupSkirm duplicateSkirmishAIInfoCheck);
void StoreSkirmishAILibraryInfos(T_dupSkirm duplicateSkirmishAIInfoCheck, CSkirmishAILibraryInfo* skirmishAIInfo, const std::string& sourceDesc);
/// Filter out Skirmish AIs that are specified multiple times
void FilterDuplicateSkirmishAILibrariesInfos(T_dupSkirm duplicateSkirmishAIInfoCheck);
/**
* Clears info about available AIs.
*/
void ClearAllInfos();
/**
* Finds the best fitting interface.
* The short name has to fit perfectly, and the version of the interface
* has to be equal or higher then the requested one.
* If there are multiple fitting interfaces, the one with the next higher
* version is selected, eg:
* wanted: 0.2
* available: 0.1, 0.3, 0.5
* chosen: 0.3
*
* @see IAILibraryManager::VersionCompare()
*/
static AIInterfaceKey FindFittingInterfaceSpecifier(
const std::string& shortName,
const std::string& minVersion,
const T_interfaceSpecs& specs);
typedef std::map<const AIInterfaceKey, CAIInterfaceLibrary*>
T_loadedInterfaces;
T_loadedInterfaces loadedAIInterfaceLibraries;
T_interfaceSpecs interfaceKeys;
T_skirmishAIKeys skirmishAIKeys;
T_interfaceInfos interfaceInfos;
T_skirmishAIInfos skirmishAIInfos;
T_dupInt duplicateInterfaceInfos;
T_dupSkirm duplicateSkirmishAIInfos;
};
#endif // AI_LIBRARY_MANAGER_H
|