Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/docs/SimulationDocs.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 550 Lines • ▼ Show 20 Lines | |||||
@section communication Component communication | @section communication Component communication | ||||
@subsection message-passing Message passing | @subsection message-passing Message passing | ||||
For one-to-many communication, you can send indirect messages to components. | For one-to-many communication, you can send indirect messages to components. | ||||
From C++, use CComponentManager::PostMessage to send a message to a specific entity, and | From C++, use CComponentManager::PostMessage to send a message to a specific entity, | ||||
CComponentManager::DistributeMessage to send to an array of entities and | |||||
CComponentManager::BroadcastMessage to send to all entities. | CComponentManager::BroadcastMessage to send to all entities. | ||||
(In all cases, messages will only be received by components that subscribed to the corresponding message type). | (In all cases, messages will only be received by components that subscribed to the corresponding message type). | ||||
@code | @code | ||||
CMessageExample msg(10, 20); | CMessageExample msg(10, 20); | ||||
GetSimContext().GetComponentManager().PostMessage(ent, msg); | GetSimContext().GetComponentManager().PostMessage(ent, msg); | ||||
GetSimContext().GetComponentManager().DistributeMessage(entities, msg); | |||||
GetSimContext().GetComponentManager().BroadcastMessage(msg); | GetSimContext().GetComponentManager().BroadcastMessage(msg); | ||||
@endcode | @endcode | ||||
From JS, use @ref CComponentManager::Script_PostMessage "Engine.PostMessage" and | From JS, use @ref CComponentManager::Script_PostMessage "Engine.PostMessage", | ||||
@ref CComponentManager::Script_DistributeMessage "Engine.DistributeMessage" and | |||||
@ref CComponentManager::Script_BroadcastMessage "Engine.BroadcastMessage", using the | @ref CComponentManager::Script_BroadcastMessage "Engine.BroadcastMessage", using the | ||||
@c MT_* constants to identify the message type: | @c MT_* constants to identify the message type: | ||||
@code | @code | ||||
Engine.PostMessage(ent, MT_Example, { x: 10, y: 20 }); | Engine.PostMessage(ent, MT_Example, { x: 10, y: 20 }); | ||||
Engine.PostMessage(entities, MT_Example, { x: 10, y: 20 }); | |||||
Engine.BroadcastMessage(MT_Example, { x: 10, y: 20 }); | Engine.BroadcastMessage(MT_Example, { x: 10, y: 20 }); | ||||
@endcode | @endcode | ||||
Messages will be received and processed synchronously, before the PostMessage/BroadcastMessage calls return. | Messages will be received and processed synchronously, before the PostMessage/BroadcastMessage calls return. | ||||
@subsection query-interface Retrieving interfaces | @subsection query-interface Retrieving interfaces | ||||
You can also directly retrieve the component implementing a given interface for a given entity, | You can also directly retrieve the component implementing a given interface for a given entity, | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator