1
0
forked from 0ad/0ad
Commit Graph

170 Commits

Author SHA1 Message Date
f9114a87f2 Get a promise when starting a GUIpage
When calling `Engine.PushGuiPage` a promise is returned. The promise is
settled when the "child" page is closed. That allows to `await` it
inside `async` functions.
Previously the callback was run right inside the call to
`Engine.PopGuiPage`. Now the continuation of the promise is called at
the end of the "tick".

This won't help performance. It will more likely make things worse.
Since gui pages aren't opened or closed that frequently, it doesn't
matter that much.

Refs: 86c151ebaa

For the engine side:
The promise is stored in the `CGUIManager::SGUIPage` (like previously
the callback). When the promise is fulfilled it enqueues a callback in
the `JobQueue` of the `JSContext`.

Original patch by: @wraitii
Comments by: @wraitii, @Stan, @Polakrity, @lyv, @elexis, @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D3807
This was SVN commit r28145.
2024-07-08 19:07:04 +00:00
9e328ec617 Make the CSimContext constructor take a CTerrain and a CUnitManager
`CSimulationImpl` doesn't has to be a friend anymore.

Comments by: @Stan
Differential Revision: https://code.wildfiregames.com/D5296
This was SVN commit r28138.
2024-07-05 16:55:33 +00:00
6b31999b64 Don't use std::shared_ptr<ScriptContext> in the CSimulation2
Since 1bccfef6fb the `CSimulation2` uses the `std::shared_ptr` only in
the constructor and stores a `ScriptContext&` (inside it's members).
That's a bit dangerous: A caller might think `CSimulation2` takes
ownership of the `ScriptContext`.
With this commit the caller has to pass an `ScriptContext&` to the
constructor.

Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5223
This was SVN commit r28046.
2024-03-08 17:15:25 +00:00
ffc4a56b9f Revert non-ASCII characters from source and configuration files introduced in 157c6af18e.
Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185
This was SVN commit r27965.
2023-12-03 00:30:12 +00:00
1bccfef6fb Don't use std::shared_ptr in ScriptInterface
Differential Revision: https://code.wildfiregames.com/D5159
This was SVN commit r27945.
2023-11-19 20:13:19 +00:00
bb
157c6af18e Make the space in 0 A.D. non-breaking throughout the codebase.
Avoid cases of filenames
Update years in terms and other legal(ish) documents
Don't update years in license headers, since change is not meaningful

Will add linter rule in seperate commit

Happy recompiling everyone!

Original Patch By: Nescio
Comment By: Gallaecio
Differential Revision: D2620
This was SVN commit r27786.
2023-07-27 20:54:46 +00:00
85bc074ae5 Moves script interface Object include out of FunctionWrapper header.
Differential Revision: https://code.wildfiregames.com/D5067
This was SVN commit r27755.
2023-07-07 20:12:16 +00:00
ea72437739 Move GenericName, History and Icon from the civ-JSON to cmpIdentity.
Since the players/civs already have cmpIdentity, use it.
This forces civs to have corresponding XML in the `special/players/`
folder.

Also moves the files from `special/player/` to `special/players/`
consistent with other folders. And moves the generic `player.xml` one
level up.

Differential revision: https://code.wildfiregames.com/D4473
Help and comments by: @Stan, @wraitii
This was SVN commit r26298.
2022-02-05 06:24:45 +00:00
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
b927f163d6 Adds std namespace to shared_ptr usages in scriptinterface and simulation.
This was SVN commit r25528.
2021-05-22 19:30:18 +00:00
4f972bc623 Split off JSON-related function from ScriptInterface, clean up headers.
Follows 34b1920e7b.

JSON functions and ToString are movec to their own headers.
Also clean out a few PersistentRooted usage to use the 2-phase init to
clean up scriptInterface usage.

With these functions split off, we can finally clean out headers and
remove ScriptInterface.h from most of them, in favour of smaller and
more precise headers.


Take the opportunity to clarify some comments regarding Mutability.

Differential Revision: https://code.wildfiregames.com/D3961
This was SVN commit r25434.
2021-05-14 10:18:03 +00:00
0f60bf3a97 Split off Object-related functions from ScriptInterface
Follows 34b1920e7b.

This splits off the object-related functions, such as
[Set/Get/Has]Property, CreateObject, CreateArray, FreezeObject.

It also puts the definitions in the header itself, which might end up
with faster code here & there, though perhaps slower compilation time
(somewhat doubtful since we already included most things anyways).

Differential Revision: https://code.wildfiregames.com/D3956
This was SVN commit r25430.
2021-05-13 17:23:52 +00:00
6fbf036ae4 Split off StructuredClone from ScriptInterface
Follows 34b1920e7b.

This separates StructuredClone & DeepCopy logic into its own header,
reducing the size of the monolithic ScriptInterface header.

Differential Revision: https://code.wildfiregames.com/D3922
This was SVN commit r25419.
2021-05-10 11:51:32 +00:00
d46a417748 Replace ScriptInterface::Call* with new ScriptFunction functions
Finishes work started in f3aedf88a6.
This removes the boost-CPP function wrappers entirely, in favour of pure
templated code in FunctionWrapper.h
The Call* functions were already heavily templated, so there is nothing
really new here. I just use tag dispatch to reduce the number of
overloads slightly.

The new functions do not need the script interface, only the script
request.

Differential Revision: https://code.wildfiregames.com/D3912
This was SVN commit r25354.
2021-05-01 14:04:53 +00:00
0308c2390a Rework the pathfinder path computation setup for threading.
Essentially reverts D1918 / d592bf9cb6.
Instead of copying path requests to workers, setup the result vector,
then setup an index, and compute 'in-place'.
To send messages, the result vectors are read in order. This makes the
order trivially constant no matter how many workers there are, and the
architecture overall makes it much easier to efficiently paralellise.

Tested by: Langbart, Stan
Differential Revision: https://code.wildfiregames.com/D3849
This was SVN commit r25256.
2021-04-14 07:23:47 +00:00
0a59489824 Use unique_ptr for secondary sim data.
Differential Revision: https://code.wildfiregames.com/D3842
This was SVN commit r25250.
2021-04-13 13:46:45 +00:00
b55b236379 Remember OOS on a per-client basis.
Change the OOS notification logic to remember the OOS-ness of each
client. Reset it on client leave.
The server will thus continue checking for OOS if the OOS-client leaves.
This is convenient to ignore observer OOS, or wait for an OOS player
without restarting the game.

Also add the turn number to the OOS dump, to fix #3348: particularly
following d4c2cf4430 the turn is likely to not be the same between
different clients.

Agree by: asterix
Differential Revision: https://code.wildfiregames.com/D3753
This was SVN commit r25170.
2021-03-31 15:55:19 +00:00
c29423c723 Fixes revealed missed includes after e104b41be2.
This was SVN commit r25003.
2021-03-03 22:38:59 +00:00
7a71011149 Refactors smart pointers creation, reduces code duplication and improves exception safety.
This was SVN commit r24915.
2021-02-13 23:53:40 +00:00
82d079d06c Add a Dev Overlay checkbox to activate RejoinTest from the session.
This makes this feature, very useful for checking for OOS, more easily
accessible.

Differential Revision: https://code.wildfiregames.com/D3199
This was SVN commit r24407.
2020-12-17 17:53:13 +00:00
d92a2118b0 [SM78 2/2] Update to Spidermonkey 78 APIs
This ugprades 0 A.D. to the latest ESR at the moment of writing.

Mostly straighforward API changes (see meta-Bug 1633145)
- js::Class is merged with JSClass
- JSNewArrayObject becomes JS::NewArrayObject
- ArrayObject-functions are moved to a new public header Array.h
- JSMSG error messages have again been changed, requiring some tweaks.
- AutoValueArray becomes RootedBalueArray (Bug 1634435)
- 'uneval' is behind a Realm flag (Bug 1565170), but no removal is
planned in the short-term future.
- Some minor GC API changes (Bugs 1569564 and 1633405)
- Error reporting has had some tweaks, and error flags have been removed
(Bug 1620583)
- StructuredClone are now always thread-safe, simplifying an API change
introduced in SM52 (Bug 1607791)

Tested by: Stan, Freagarach, mammadori
Closes #5861

Differential Revision: https://code.wildfiregames.com/D3168
This was SVN commit r24333.
2020-12-06 14:03:02 +00:00
9ae084519f Fix most of the new vs2017 induced warnings.
Refs: https://code.wildfiregames.com/D3096
https://code.wildfiregames.com/D3103 #5862
Reviewed by: @wraitii
Comments by: @Angen
Differential Revision: https://code.wildfiregames.com/D3126
This was SVN commit r24268.
2020-11-26 22:28:50 +00:00
fd8f5abd2e [SM52 2/2] Update to Spidermonkey 52 APIs.
No particularly noteworthy changes, as most complex API changes were
already supported in SM45 and done.
The addition of JSStructuredCloneData allows to remove our custom class.

Changes:
- InformalValueTypeName is back in the API, so remove our
implementation.
- Stop using JSRuntime entirely in favour of JSContext*
- JSPropertyDescriptor is renamed.
- CompartmentOptions are tweaked slightly (no functional changes)
- JS::Construct - API update.
- JSClass split - API update.
- A js.msg error message was removed, so we had to use a different one.
- Tests fix: fix comparison of union instances
- Disable warning in spidermonkey Vector.h
- Update error reporting to SM52 (minor API updates)
- Ignore warnings about unused return values (would come from OOM, which
isn't recoverable)

Most of the patching was done by Itms.

Tested by: Stan, Freagarach
Fixes #4893

Differential Revision: https://code.wildfiregames.com/D3095
This was SVN commit r24203.
2020-11-18 14:39:04 +00:00
25490bfec3 Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.

This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.

Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).

Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893

Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 18:29:17 +00:00
aa15066c69 Rename ScriptRuntime to ScriptContext
SM52 essentially replaces JSRuntime with JSContext (though JSContext
itself was replaced with JSCompartment).
To prepare for this migration, rename all Runtime-related things to
Context.

Part of the SM52 migration, stage: SM45 compatible.

Patch by: Itms
Refs #4893

Differential Revision: https://code.wildfiregames.com/D3091
This was SVN commit r24181.
2020-11-14 10:57:50 +00:00
aae417bd29 Explicitly make ScriptInterface a Compartment wrapper.
ScriptInterface is now a wrapper around a JSCompartment, and thus always
has a well-defined global.

The error reporter is moved to ScriptRuntime in anticipation of that
handling JSContext in a later diff.

Part of the SM52 migration, stage: SM45 compatible.

Patch by: Itms
Tested By: Freagarach
Refs #4893

Differential Revision: https://code.wildfiregames.com/D3090
This was SVN commit r24180.
2020-11-14 08:46:32 +00:00
ee0d204bf6 Wrap JSAutoRequest and replace usage of JSContext* with the wrapper.
JSAutoRequest is required before calling into most JSAPI methods, for GC
reasons.
Calling it is required and fragile as one must not forget.
Further, SM52 and later make manipulating JSContext* dangerous as that
can cross Compartment(Realm in SM68) barriers (and ScriptInterface now
matches a Compartment).

The solution to both problems is to avoid using JSContext* in 0 A.D.
itself. To achieve this, a Request class is introduced, and must be used
to access a JSContext* from a scriptInterface. Further, Request is
passed to other ScriptInterface functions isntead of JSContext*, making
it obvious that the caller has already called it, reducing errors and
redundant JSAutoRequest calls.
Only JSNative functions now get a naked JSContext* without protection,
but the likelihood of forgetting a request is lower since many
ScriptInterface functions now expect it.

JSContext* is directly passed to JSAPI functions only.

Part of the SM52 migration, stage: SM45 compatible

Based on a patch by: Itms
Tested By: Freagarach
Refs #4893

Differential Revision: https://code.wildfiregames.com/D3088
This was SVN commit r24176.
2020-11-13 13:18:22 +00:00
ad7ac8d595 Fix UpdateComponents logic for pathfinding following d592bf9cb6
Following d592bf9cb6, paths requested at turn N were set-up to be
computed between the end of turn N and the start of turn N+1 (which
would ultimately allow threading this computation), via calls to
'StartProcessingMoves' and 'FetchAsyncResultsAndSendMessages'.

However, the call to UpdateGrid() remained at the start of turn N+1,
between the 'start' and 'fetch' calls. Since all paths are currently
computed on the 'start' call, this means all paths are computed on a
(possibly) dirty pathfinder grid.
In particular, this leads to OOS on rejoin since the rejoiner will
recompute the grid before computing the outstanding paths.

This would also obviously be buggy in a threaded environment, since some
paths might be computed on the fresh and some on the dirty grid.

Finally, MT_TurnStart was sent before the paths were computed, which
might lead to further pathfinder grid changes (not a crashing problem
without threading, but still conceptually odd). The 'fetch' call is thus
moved before it.
This thus fixes d592bf9cb6/D1918, after 92ad6a61fa already fixed a first
issue.

Since the grid is now only updated at the end of a turn, we need to
ensure that it is correct on Turn 0, thus the pathfinder recomputes it
on InitGame.

Refs D14

Reported by: Itms
Fixes #5851

Differential Revision: https://code.wildfiregames.com/D3064
This was SVN commit r24142.
2020-11-08 08:58:19 +00:00
aeaba3c14c Use victory conditions json's in Atlas
Reviewed by: @Angen
Differential Revision: https://code.wildfiregames.com/D2393
This was SVN commit r23847.
2020-07-18 17:39:59 +00:00
fc08fe60ab Support testing rejoins on turn 0, refs #3460, #4242, #5185, #5162, 2bf1dbfd13
Differential Revision: https://code.wildfiregames.com/D1522
This was SVN commit r22998.
2019-09-26 12:09:19 +00:00
35408e7e7e Save replay metadata for non-visual games too, refs #4577, #5548, fixes #5565.
Remove gui/common/ hack by going through the GUIInterface and fragile
EndGame() hardcoding by saving if and only if a ReplayLogger exists
following 7470e88624, refs #4020.
Refs D2211, D2213.

Differential Revision: https://code.wildfiregames.com/D2197
Based on patch by: irishninja
Tested on: clang 8.0.1, Jenkins

This was SVN commit r22991.
2019-09-25 10:06:12 +00:00
d592bf9cb6 Move path computations to an actual worker to prepare for threading.
This moves the "async" pathfinding computations to a worker, preparing
the architecture for threading.

Tested By: Kuba386, Stan`
Differential Revision: https://code.wildfiregames.com/D1918
This was SVN commit r22902.
2019-09-15 09:27:10 +00:00
a84e2e57df Use ScriptInterface::CreateObject for ToJSVal<CColor>, and for ToJSVal<Grid<u8> >, ToJSVal<Grid<u16> > used by the AIManager obtaining the pathfinder grid.
Make that function static, so that it can be used for these functions
without slowly having to obtain the ScriptInterface instance using
GetScriptInterfaceAndCBData just to get the JSContext again.
Remove few redundant conversions for CreateObject arguments.

Differential Revision: https://code.wildfiregames.com/D2128
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Tedious performance testing in: D2128, D2127

This was SVN commit r22894.
2019-09-13 00:56:51 +00:00
b4626359f5 Provide ScriptInterface CreateObject and CreateArray functions to replace Eval calls following 7c2e9027c2, 1c0536bf08 and later.
Differential Revision: https://code.wildfiregames.com/D2080
Previous version reviewed By: Krinkle
Comments By: historic_bruno, wraitii
This was SVN commit r22528.
2019-07-22 19:35:14 +00:00
262b27d770 Remove unnecessary argument from CSimulation2::InitGame
Reviewed By: Itms
Differential Revision: https://code.wildfiregames.com/D1289
This was SVN commit r21166.
2018-02-09 19:50:01 +00:00
7e05d7edc9 Initialize the AIManager AISeed immediately in C++ rather than too late and in JS.
Fixes #4907
Differential Revision: https://code.wildfiregames.com/D1178
Reviewed By: mimo
Refs D1159, f88ee2766e

This was SVN commit r20700.
2017-12-27 16:51:25 +00:00
f7206dc77d More ScriptInterface const.
Reviewed By: elexis; some comments by bb
Differential Revision: https://code.wildfiregames.com/D863
This was SVN commit r20519.
2017-11-25 06:49:58 +00:00
ce580f0de0 Always delete CMapReader. Patch by Sandarac. Fixes #4154.
This fixes an assertion failure in ScriptEngine that can occur when
closing
the game while in the loading screen.

Reviewed By: vladislavbelov, leper
Differential Revision: https://code.wildfiregames.com/D684
This was SVN commit r20035.
2017-08-25 00:37:48 +00:00
9defd11440 Pass ScriptInterface as a const ref where possible.
Reviewed By: elexis
Differential Revision: https://code.wildfiregames.com/D739
This was SVN commit r20028.
2017-08-24 00:32:42 +00:00
51f62818f7 Fix all broken checks for the absent (random-mapgen+simulation) Seed property in the engine, refs #3965.
Hence display the originally intended useful warnings (instead of the
characterless JS "Script value conversion check failed" warning and
skipping the intended warnings).

This was SVN commit r19718.
2017-06-02 15:07:58 +00:00
2bf1dbfd13 An awesome Rejoin-test tool by wraitii and Itms, fixes #4242, refs #3460.
Contrary to the serializationtest, initializes the secondary simstate
only once
before progressively applying updates.
Thus reproducing actual multiplayer rejoining, enabling developers to
analyze OOS reports solely from the replay file of the rejoined and a
non-rejoined client.

This was SVN commit r18940.
2016-11-15 13:26:58 +00:00
6eaf76d653 Actually seed the random number generator used in the simulation. Reviewed by sanderd17, fixes #4127.
This was SVN commit r18604.
2016-08-14 16:28:54 +00:00
bb1f86f515 Remove duplication of the Hexify function.
Remove the useless extern keyword from function declarations in
ps/Util.h.

Patch by echotangoecho, refs #4095

This was SVN commit r18591.
2016-08-08 12:50:39 +00:00
4c0f12bce3 Fix autostart replays following a23884d79a by grabbing g_GameAttributes from the simulation instead of the GUI. Patch by Imarok, refs #3143.
Don't remove attribs from the init attributes as that is still used by
the loading screen to show the mapname.

This was SVN commit r18510.
2016-07-12 01:49:48 +00:00
898ab5229b Change profiling calls to get a better view of what is actually slow and what is not.
This was SVN commit r18438.
2016-06-25 13:12:35 +00:00
6f744aef88 Simulation context cleanup, refs #3991, #3168.
Save the viewed player in the CGame class.
Add the const keyword back to the SimContext to help find mistakes at
compiletime.

This was SVN commit r18201.
2016-05-19 19:42:07 +00:00
f4e69b7c07 Cleanup of #3255, fixes #3966.
Don't create an empty oos_logs directory when starting the game.
Rename getDateIndexSubdirectory to createDateIndexSubdirectory.
Add a comment for the breakpoint argument of CreateDirectories.

This was SVN commit r18183.
2016-05-16 00:56:07 +00:00
d61e315f4d Fix few style issues remarked by leper.
Add a unit (seconds) to the network-timeout warning.
Rename isChatAddressee to parseChatAddressee as it changes the message.
Early return for EnableOOSLog to avoid printing duplicate messages.

This was SVN commit r17895.
2016-03-15 04:37:41 +00:00
b155a28698 Immediately set the fog-of-war instead of waiting for session.js to load, refs #3168.
This was SVN commit r17832.
2016-03-06 13:56:07 +00:00
a32ed75bff Fix a race-condition when two games have been started simultaneously and attempt to create the same replay directory, refs #3255.
Instead of triggering a debug-breakpoint, print a warning to stdout and
succeed in the N'th retry when having started N processes
simultaneously.
Previously the problem had been addressed by using the processID in the
directory name.

This was SVN commit r17776.
2016-02-19 11:22:32 +00:00