1
0
forked from 0ad/0ad
0ad/source/scriptinterface
wraitii 4df03ed2d2 Run the AI in the same Compartment as the simulation. Let the AI access Sim data.
This is a paradigm change for AI computation.
Historically, the AI was intended to be run in a separate thread from
the simulation. The idea was that slow AI wouldn't stop the renderer
from being smooth.

In that original design, the AI received a copy of the game world and
used that to run its logic. This meant the simulation could safely do
whatever it wanted in the meantime. This copy was done via AIProxy &
AIInterface.

This design ended up having significant flaws:
- The copying impacts the simulation negatively, particularly because
AIProxy subscribes to a lot of messages (sometimes sent exclusively to
it). This time cannot be threaded, and impacts MP games without AIs.
- Copying the data is increasingly difficult. Modifiers are a headache,
LOS is not implemented. Lots of logic is duplicated.

The intended benefits of the design also failed to realise somewhat:
- The AI was never threaded, and in fact, it is probably better to try
and thread Sim + AI from the renderer than just the AI, at which point
threading the AI specifically brings little benefit.

The new design is much simpler and straighforward, but this has some
side-effects:
- The AI can now change the simulation. This can be used for cheating,
or possibly for a tutorial AI.
- The AI runs in the same GC zone as the simulation, which may lead to
more frequent Sim GCs (but overall we might expect a reduction in
temporary objects).
- The AI state was essentially cached, so replacing some functions with
Engine.QueryInterface might be slower. The tradeoff should be balanced
by lower AIProxy computation times.

Future work:
- Threading some specific AI tasks could still be worthwhile, but should
be done in specific worker threads, allowed to run over several turns if
needed.

Technical note: the AI 'global' is in its own Realm, which means name
collisions with the same are not possible.

Other notes:
- The RL Interface uses the AI Interface and thus will gradually lose
some data there. Given that the RL Interface can now request data
however, this should be dine.

Refs #5962, #2370

Differential Revision: https://code.wildfiregames.com/D3769
This was SVN commit r26274.
2022-01-30 13:33:34 +00:00
..
tests Fixes broken PCH after wraitii commits (4f972bc623, 0f60bf3a97) and Itms (833c9f108c). 2021-05-15 14:50:24 +00:00
FunctionWrapper.h Remove all external usage of CmptPrivate. Header cleanup. 2021-05-15 13:54:58 +00:00
JSON.cpp Drops custom utf16 string implementation (from cdd3317ded), uses C++11 one. 2021-11-29 12:10:41 +00:00
JSON.h Split off JSON-related function from ScriptInterface, clean up headers. 2021-05-14 10:18:03 +00:00
Object.h Fix atlas crash with RM capture the relic. 2021-06-07 18:48:16 +00:00
ScriptContext.cpp Adds std namespace to shared_ptr usages in scriptinterface and simulation. 2021-05-22 19:30:18 +00:00
ScriptContext.h Adds std namespace to shared_ptr usages in scriptinterface and simulation. 2021-05-22 19:30:18 +00:00
ScriptConversions.cpp Drops custom utf16 string implementation (from cdd3317ded), uses C++11 one. 2021-11-29 12:10:41 +00:00
ScriptConversions.h Fixes broken PCH after wraitii commits (4f972bc623, 0f60bf3a97) and Itms (833c9f108c). 2021-05-15 14:50:24 +00:00
ScriptEngine.h Address concerns in 5473393e30 (RL interface) 2021-01-15 16:30:05 +00:00
ScriptExceptions.cpp Debundle Valgrind and make it optional 2021-09-20 22:18:28 +00:00
ScriptExceptions.h [SM52 2/2] Update to Spidermonkey 52 APIs. 2020-11-18 14:39:04 +00:00
ScriptExtraHeaders.h Split off JSON-related function from ScriptInterface, clean up headers. 2021-05-14 10:18:03 +00:00
ScriptForward.h Split ScriptRequest in its own header. 2021-05-03 16:07:26 +00:00
ScriptInterface.cpp Run the AI in the same Compartment as the simulation. Let the AI access Sim data. 2022-01-30 13:33:34 +00:00
ScriptInterface.h Run the AI in the same Compartment as the simulation. Let the AI access Sim data. 2022-01-30 13:33:34 +00:00
ScriptRequest.h Remove all external usage of CmptPrivate. Header cleanup. 2021-05-15 13:54:58 +00:00
ScriptStats.cpp [SM78 2/2] Update to Spidermonkey 78 APIs 2020-12-06 14:03:02 +00:00
ScriptStats.h Further header & precompiled cleanup, fix no-PCH builds. 2020-12-09 14:39:14 +00:00
ScriptTypes.h [SM78 1/2] Upgrade Spidermonkey build system and binaries to 78.6.0 2020-12-06 14:00:57 +00:00
StructuredClone.cpp Fix no-pch build. Potentially fixes bb49fbe793, 0198942a79, 34b1920e7b, 8b08f4ae7a 0dbf417171, 3af1fc64d2, 5fbdbaa3bc, 6fbf036ae4. 2021-05-12 13:48:55 +00:00
StructuredClone.h Split off StructuredClone from ScriptInterface 2021-05-10 11:51:32 +00:00