Sending multiple messages
Code: Select all
{
messageTransport=multi
framesent=64,
messagecount=2,
senderAI="shard",
messages={
{
id=1,
message="printmessage",
consolestring="hello world1"
},
{
id=2,
message="printmessage",
consolestring="hello world2"
}
}
-- etc
}
}
Where multi is a predefined constant indicating that there are multiple messages to be processed.
Sending a single message
A 'single' messageTransport would also be available to cut down on processing for when only an individual message is sent. At which point it would look more like this:
Code: Select all
{
messageTransport=single
framesent=64,
senderAI="shard",
message="printmessage",
consolestring="hello world1"
}
Returning data
A gadget processing a multiple message string wanting to return data might send the following back:
Code: Select all
{
{
returned="success"
},
{
return="failure",
}
}
Detection
Code: Select all
If first character of string == '{'
Implementation points
On the lua gadget side, I envisage there will be a standard gadget that gets shared across all games ( possibly engine bundled ) that processes these messages, and then issues its own callins on other gadgets for handling.
Unsynced widgets
This can be added to such a gadget as mentioned above, perhaps with a message key specifying if the target is Synced or Unsynced code.
Discovery
Early on in the first frame or Init call, an AI should send a message to the gadgets asking for a response with as much information as possible. This response should include the version of the processing gadget, any game information that is not a part of the standard engine archive info, a list of present gadgets, and any AI APIs that the game wishes to expose, with there chosen AI API Identifiers, and version numbers, and what messages they support. A list of possible events should also be returned and the number of parameters.
This message should only need to be sent once, and should not be requested during active gameplay save for when load/save mechanics are employed.
AI Request Mechanics
Early on in the frame processing, the AI should make a request to check if new events have occurred ( e.g. xyz has started a jumpjet, ABC has teleported across the map, or 123 has been turned into a potatoe ). This should ideally be one of the first things done on each frame. The AI may wish to issue other commands in this request in a multiple message table.
The AI should then aim to batch the commands and requests it needs then send all at once to minimize on serialisation/de-serialisation costs, and the cost of messages being routed through the engine API calls.
AIs should aim to send as few single/individual messages, and use the single message format purely as an optimisation to save processing power. This may be unrealistic in some cases, and so the AI should aim to stay within 3 messages per frame.
Messages & AI engine events
Should a message be needed on an event such as abcFinished, or xyzDied, then the message should be queued and sent in the next frame along with the initial request for events message.
Custom code execution
The AI should be able to send a message 'function', which has a parameter function, whose value is a string function that is to be executed in gadget land. It's return values are to be packaged up into the standard gadget return value format. This should allow AIs the ability to execute unsynced commands it otherwise wouldn't be able to, and to be able to interact with gadgets that may not have an AI API.