#[repr(C)]pub struct SSkirmishAILibrary {
pub getLevelOfSupportFor: Option<unsafe extern "C" fn(aiShortName: *const c_char, aiVersion: *const c_char, engineVersionString: *const c_char, engineVersionNumber: c_int, aiInterfaceShortName: *const c_char, aiInterfaceVersion: *const c_char) -> LevelOfSupport>,
pub init: Option<unsafe extern "C" fn(skirmishAIId: c_int, callback: *const SSkirmishAICallback) -> c_int>,
pub release: Option<unsafe extern "C" fn(skirmishAIId: c_int) -> c_int>,
pub handleEvent: Option<unsafe extern "C" fn(skirmishAIId: c_int, topicId: c_int, data: *const c_void) -> c_int>,
}
Expand description
@brief Skirmish Artificial Intelligence library interface
This is the interface between the engine and an implementation of a Skirmish AI. The engine will address AIs through this interface, but AIs will not actually implement it. It is the job of the AI Interface library, to make sure the engine can address AI implementations through instances of this struct.
An example of loading a C AI through the C AI Interface: The C AI exports functions fitting the function pointers in this struct. When the engine requests C-AI-X on the C AI Interface, the interface loads the shared library, eg C-AI-X.dll, creates a new instance of this struct, and sets the member function pointers to the addresses of the fitting functions exported by the shared AI library. This struct then goes to the engine which calls the functions appropriately.
Fields§
§getLevelOfSupportFor: Option<unsafe extern "C" fn(aiShortName: *const c_char, aiVersion: *const c_char, engineVersionString: *const c_char, engineVersionNumber: c_int, aiInterfaceShortName: *const c_char, aiInterfaceVersion: *const c_char) -> LevelOfSupport>
Level of Support for a specific engine version and AI interface version.
[optional] An AI not exporting this function is still valid.
@param aiShortName this is indisposable for non-native interfaces, as they need a means of redirecting from one wrapper function to the respective non-native libraries @param aiVersion see aiShortName @return the level of support for the supplied engine and AI interface versions
init: Option<unsafe extern "C" fn(skirmishAIId: c_int, callback: *const SSkirmishAICallback) -> c_int>
This function is called, when an AI instance shall be created for skirmishAIId. It is called before the first call to handleEvent() for that AI instance.
A typical series of events (engine point of view, conceptual): [code] KAIK.init(1) KAIK.handleEvent(EVENT_INIT, InitEvent(1)) RAI.init(2) RAI.handleEvent(EVENT_INIT, InitEvent(2)) KAIK.handleEvent(EVENT_UPDATE, UpdateEvent(0)) RAI.handleEvent(EVENT_UPDATE, UpdateEvent(0)) KAIK.handleEvent(EVENT_UPDATE, UpdateEvent(1)) RAI.handleEvent(EVENT_UPDATE, UpdateEvent(1)) … [/code]
This method exists only for performance reasons, which come into play on OO languages. For non-OO language AIs, this method can be ignored, because using only EVENT_INIT will cause no performance decrease.
[optional] An AI not exporting this function is still valid.
@param skirmishAIId the ID this library shall create an instance for @param callback the callback for this Skirmish AI @return 0: ok != 0: error
release: Option<unsafe extern "C" fn(skirmishAIId: c_int) -> c_int>
This function is called, when an AI instance shall be deleted. It is called after the last call to handleEvent() for that AI instance.
A typical series of events (engine point of view, conceptual): [code] … KAIK.handleEvent(EVENT_UPDATE, UpdateEvent(654321)) RAI.handleEvent(EVENT_UPDATE, UpdateEvent(654321)) KAIK.handleEvent(EVENT_UPDATE, UpdateEvent(654322)) RAI.handleEvent(EVENT_UPDATE, UpdateEvent(654322)) KAIK.handleEvent(EVENT_RELEASE, ReleaseEvent(1)) KAIK.release(1) RAI.handleEvent(EVENT_RELEASE, ReleaseEvent(2)) RAI.release(2) [/code]
This method exists only for performance reasons, which come into play on OO languages. For non-OO language AIs, this method can be ignored, because using only EVENT_RELEASE will cause no performance decrease.
[optional] An AI not exporting this function is still valid.
@param skirmishAIId the ID the library shall release the instance of @return 0: ok != 0: error
handleEvent: Option<unsafe extern "C" fn(skirmishAIId: c_int, topicId: c_int, data: *const c_void) -> c_int>
Through this function, the AI receives events from the engine. For details about events that may arrive here, see file AISEvents.h.
@param skirmishAIId the AI instance the event is addressed to // * @param fromId the id of the AI the event comes from, // * or FROM_ENGINE_ID if it comes from the engine // * @param eventId used on asynchronous events. this allows the AI to // * identify a possible result message, which was sent // * with the same eventId @param topicId unique identifier of a message (see EVENT_* defines in AISEvents.h) @param data an topic specific struct, which contains the data associatedwith the event (see S*Event structs in AISEvents.h) @return 0: ok != 0: error
Trait Implementations§
Source§impl Clone for SSkirmishAILibrary
impl Clone for SSkirmishAILibrary
Source§fn clone(&self) -> SSkirmishAILibrary
fn clone(&self) -> SSkirmishAILibrary
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more