Skip to content

Commit dbe817f

Browse files
committed
Refine the definition of agent functions, removing the need for several TODO crosslinks
1 parent bb709ba commit dbe817f

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

src/guide/3-behaviour-definition/1-defining-agent-functions.rst

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ method is the only method supported for the python version of FLAMEGPU2.
1616
Defining an Agent Function
1717
--------------------------
1818

19-
An agent function is defined using the ``FLAMEGPU_AGENT_FUNCTION`` macro. This takes three arguments: a unique name identifying the function, an input
20-
message communication strategy, and an output message communication strategy. We will discuss messages in more detail later, so for now don't worry about the second and third paramters.
19+
Agent Functions can be specified as C++ functions, built at compile time when using the C++ interface, or they can be specified as Run-Time Compiled (RTC) functions when using the C++ interface, or the Python interface.
20+
21+
An agent function is defined using the ``FLAMEGPU_AGENT_FUNCTION`` macro.
22+
This takes three arguments: a unique name identifying the function, an input message communication strategy, and an output message communication strategy.
23+
We will discuss messages in more detail later, so for now don't worry about the second and third parameters.
24+
25+
For Non-RTC functions, when using the C++ interface, the ``FLAMEGPU_AGENT_FUNCTION`` macro can be used to declare and define the agent function, which can then be associated with the ``flamegpu::AgentDescription`` object using the ``newFunction`` method.
2126

22-
In C++, these definitions should appear before your main function. In python, they should be specified in string literals, with the containing variable'state
23-
name matching the unique function identifier:
2427

2528
.. tabs::
2629

@@ -32,65 +35,52 @@ name matching the unique function identifier:
3235
}
3336

3437
int main() {
35-
... // Rest of code
38+
// ...
3639

37-
.. code-tab:: python
40+
// Attach a function called agent_fn1, defined by the symbol agent_fn1 to the AgentDescription object agent.
41+
flamegpu::AgentFunctionDescription& agent_fn1_description = agent.newFunction("agent_fn1", agent_fn1);
3842

39-
# Define an agent function called agent_fn1
40-
agent_fn1_source = r"""
41-
FLAMEGPU_AGENT_FUNCTION(agent_fn1, MessageNone, MessageNone) {
42-
# Behaviour goes here
43+
// ...
4344
}
44-
"""
45-
46-
With the agent function named and defined, it can now be attached to a particular agent type via an ``AgentDescription`` object:
47-
48-
.. tabs::
49-
50-
.. code-tab:: cpp
51-
52-
// Attach a function called agent_fn1 to an agent called agent
53-
// The AgentFunctionDescription is stored in the agent_fn1_description variable
54-
flamegpu::AgentFunctionDescription& agent_fn1_description = agent.newFunction("agent_fn1", agent_fn1_source);
55-
56-
.. code-tab:: python
57-
58-
# Attach a function called agent_fn1 to an agent called agent
59-
# The AgentFunctionDescription is stored in the agent_fn1_description variable
60-
agent_fn1_description = agent.newRTCFunction("agent_fn1", agent_fn1_source);
61-
6245

63-
Defining a Runtime-Compiled Agent Function (C++)
64-
------------------------------------------------
65-
If you are using the python interface, you can only use runtime-compiled agent functions and this was presented in
66-
the previous section, so you can *TODO: skip to the next section*
67-
68-
The previously described method for defining an agent function results in the function being compiled at compile time.
69-
If you know that you want to define your agent behaviours at runtime, you can instead use this method. Otherwise, you can
70-
*TODO: skip to the next section*
71-
72-
To define a runtime-compiled agent function, the function source should be stored in a string:
46+
When using the Run-Time Compiled (RTC) functions, optionally in the C++ interface or required by the Python interface, the function must be defined in a string and associated with the AgentDescription using the ``newRTCFunction`` method.
7347

7448
.. tabs::
7549

7650
.. code-tab:: cpp
7751

78-
// Define an agent function called agent_fn1 which will be compiled at runtime
7952
const char* agent_fn1_source = R"###(
53+
// Define an agent function called agent_fn1 - specified ahead of main function
8054
FLAMEGPU_AGENT_FUNCTION(agent_fn1, flamegpu::MessageNone, flamegpu::MessageNone) {
8155
// Behaviour goes here
8256
}
8357
)###";
8458

85-
The function can then be added to an ``AgentDescription`` using the ``newRTCFunction`` method:
59+
int main() {
60+
// ...
8661

87-
.. tabs::
62+
// Attach a function called agent_fn1, defined in the string variable agent_fn1_source to the AgentDescription object agent.
63+
flamegpu::AgentFunctionDescription& agent_fn1_description = agent.newRTCFunction("agent_fn1", agent_fn1_source);
8864

89-
.. code-tab:: cpp
65+
// ...
66+
}
9067

91-
// Attach a runtime-compiled function called agent_fn1 to an agent called agent
92-
// The AgentFunctionDescription is stored in the agent_fn1_description variable
93-
flamegpu::AgentFunctionDescription& agent_fn1_description = agent.newRTCFunction("agent_fn1", agent_fn1_source);
68+
.. code-tab:: python
69+
70+
# Define an agent function called agent_fn1
71+
agent_fn1_source = r"""
72+
FLAMEGPU_AGENT_FUNCTION(agent_fn1, MessageNone, MessageNone) {
73+
# Behaviour goes here
74+
}
75+
"""
76+
77+
# ...
78+
79+
# Attach a function called agent_fn1 to an agent represented by the AgentDescription agent
80+
# The AgentFunctionDescription is stored in the agent_fn1_description variable
81+
agent_fn1_description = agent.newRTCFunction("agent_fn1", agent_fn1_source);
82+
83+
# ...
9484

9585
FLAMEGPU Device Functions
9686
-------------------------

0 commit comments

Comments
 (0)