1
0
forked from 0ad/0ad
Commit Graph

363 Commits

Author SHA1 Message Date
f22d0d899e Add final to classes introduced in f9114a87f2
A class which can not be derived from should tell that in the
declaration.
2024-08-25 13:38:09 +02:00
6ea44f6fb4 Log rejected promises
Forgoten in f9114a87f2

Comments by: @Stan
Differential Revision: https://code.wildfiregames.com/D5305
This was SVN commit r28155.
2024-07-22 08:40:33 +00:00
62692ca270 Add files forgotten in f9114a87f2
This was SVN commit r28146.
2024-07-08 19:46:42 +00:00
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
6ce2fc53ea Allow to use a generator as MapGenerator
This way it's clear what's the input and what's the output of the
computation.
All map generation scripts should reman working. They are adopted in a
future commit.

`Engine.SetProgress` and `Engine.ExportMap` can be removed in a future
commit.

Comments by: @marder, @sera, @Stan
Differential Revision: https://code.wildfiregames.com/D5220
This was SVN commit r28093.
2024-05-22 15:52:12 +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
e33aafc4e2 Put the CMapGeneratorWorker completely inside the task
The return-slot provided by the `Future` is used for synchronisation.

Refs: #5874

Comments By: @Stan, @vladislavbelov, @wraitii
Differential Revision: https://code.wildfiregames.com/D5001
This was SVN commit r27944.
2023-11-19 19:19:32 +00:00
3d2561f096 No recursive calls in FunctionWrapper.h
Accepted By: @wraitii, @vladislavbelov
Comments By: @Stan
Differential Revision: https://code.wildfiregames.com/D4728
This was SVN commit r27821.
2023-09-02 14:20:25 +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
dafa5ab774 Minor optimisations when calling JS functions from C++
ScriptFunction::Call_ checks HasProperty, but then JS_CallFunctionName
calls GetProperty. This is redundant and can be simplified.

Reviewed By: phosit
Differential Revision: https://code.wildfiregames.com/D5000
This was SVN commit r27726.
2023-06-20 11:40:18 +00:00
61e932a890 Turn off SPECTRE mitigation in jit code
SPECTRE attacks mitigations were added to SpiderMonkey's JIT output in
version 57. Turning these off is a very large speedup, around 10-20%
wall time (on my computer) depending on the map and the situation.
For the most part, from profiling on my machine, this is from memory
fences after JIT -> C++ calls. 0 A.D. does a lot of these.

The SPECTRE class of attack is a timing attack based on speculative
execution to leak sensitive information, and it seems extraordinarily
unlikely that something like this could be successfully mounted using 0
A.D.

Differential Revision: https://code.wildfiregames.com/D5014
This was SVN commit r27699.
2023-06-14 07:44:23 +00:00
e5acc73fcf Remove useless line from 507f44f7f9
This is unused and makes the function twice as slow as it needs to be.

Differential Revision: https://code.wildfiregames.com/D5015
This was SVN commit r27697.
2023-06-14 07:28:37 +00:00
b31e698f12 Use override in classes derived from AbstractProfileTable.
Patch By: phosit
Differential Revision: https://code.wildfiregames.com/D4825
This was SVN commit r27414.
2023-01-10 22:32:08 +00:00
d5db03c303 [SM91] Update to Spidermonkey 91.1.3 APIs
Fixes: #5986
Patch by: @wraitii
Comments by: @nwtour, @Stan
Differential Revision: https://code.wildfiregames.com/D4428
This was SVN commit r27409.
2023-01-10 17:06:47 +00:00
a33e0ccc84 Remove some duplicated code from ScriptInterface.cpp
Tested by: @Langbart
Patch by: @smiley
Differential Revision: https://code.wildfiregames.com/D4574
This was SVN commit r26725.
2022-03-28 21:58:22 +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
712b7ebf9a Remove JS_New in favour of JS::Construct in preparation for SM91
Spidermonkey 91, the next ESR, removes JS_New in favour or
JS::Construct.
See
https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/migration-guide/docs/Migration%20Guide.md#object-construction
and
https://bugzilla.mozilla.org/show_bug.cgi?id=1491055

This change is SM78 compatible and therefore done beforehand.

Tested by: Freagarach
Refs #5986

Differential Revision: https://code.wildfiregames.com/D4427
This was SVN commit r26205.
2022-01-12 16:51:32 +00:00
af567560b8 Drops custom utf16 string implementation (from cdd3317ded), uses C++11 one.
Patch By: sera
Differential Revision: https://code.wildfiregames.com/D4223
This was SVN commit r26023.
2021-11-29 12:10:41 +00:00
31b70309b3 Debundle Valgrind and make it optional
If a *nix user wishes to build `pyrogenesis` with support for Valgrind
(such as
it is), then can do so by passing `--with-valgrind` to
`update-workspaces.sh`.
(They will need Valgrind installed and locateable via `pkg-config`.)


Reviewed By: sera, Stan
Fixes: #2904
Differential Revision: https://code.wildfiregames.com/D3646
This was SVN commit r25933.
2021-09-20 22:18:28 +00:00
f5f493681d Fix atlas crash with RM capture the relic.
As no default values got set, some game settings became NaN, which
triggered exceptions.
This sets sane default.

This also includes better debugging logic in case of exception, so it's
easier to know what happens.

Fixes #6200

Reported by: langbart
Differential Revision: https://code.wildfiregames.com/D4113
This was SVN commit r25736.
2021-06-07 18:48:16 +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
41a29a590a Fixes broken PCH after wraitii commits (4f972bc623, 0f60bf3a97) and Itms (833c9f108c).
This was SVN commit r25443.
2021-05-15 14:50:24 +00:00
507f44f7f9 Remove all external usage of CmptPrivate. Header cleanup.
This removes usage of CmptPrivate outside of ScriptInterface.
ScriptRequest can now be used to safely recover the scriptInterface from
a JSContext instead of going through ScriptInterface, which allows more
code cleanup.

Follows 34b1920e7b

Differential Revision: https://code.wildfiregames.com/D3963
This was SVN commit r25442.
2021-05-15 13:54:58 +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
f368e1a69e Remove unused m_rng member from ScriptInterface.
The one in ScriptInterface_Impl is actually used.
Introduced in e9e05f4efc and from what I can tell never actually used.

Differential Revision: https://code.wildfiregames.com/D3960
This was SVN commit r25433.
2021-05-14 09:27:12 +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
61e0aef0b4 Split JS conversions from ScriptInterface.
All ToJSVal/FromJSVal definitions are put in a separate header.
Remove AssignOr[To/From]JSVal duplication.

The functions were already static so this is rather straightforward.

Follows 34b1920e7b and 2bae30c454

Differential Revision: https://code.wildfiregames.com/D3953
This was SVN commit r25428.
2021-05-13 09:43:33 +00:00
4ad78018f9 Fix no-pch build. Potentially fixes bb49fbe793, 0198942a79, 34b1920e7b, 8b08f4ae7a 0dbf417171, 3af1fc64d2, 5fbdbaa3bc, 6fbf036ae4.
Comments by: @vladislavbelov, @wraitii.
Differential Revision: https://code.wildfiregames.com/D3948
This was SVN commit r25423.
2021-05-12 13:48:55 +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
8b08f4ae7a Change GUI settings to explicitly be member variables.
Completes work starting in D2313 / a33fd55e81:
- Make C++ mistakes where values can be changed without messages being
sent easier to notice / harder to do.
- Make the IGUISetting interface more flexible, allowing custom settings
implementing their own logic. This is used to clean up hotkey code
introduced in 33af6da5e1.

Side effects:
- FromJSVal_Vector clears the vector being passed in. I have some vague
memory of not doing that in D24 / 2bae30c454 as an optimisation, but it
seems more like a footgun to me.
- Most usage of SetSettingFromString is replaced by direct method calls,
as we can generally cast to the proper GUI object type. Where we can't,
it is kept as a poor's man virtual dispatch.
- It moves a few member variables elsewhere, e.g. TextOwner now gets its
own member variable settings.

Differential Revision: https://code.wildfiregames.com/D3892
This was SVN commit r25392.
2021-05-06 08:22:37 +00:00
34b1920e7b Split ScriptRequest in its own header.
We often only need to include ScriptRequest.h and not the full
ScriptInterface.h

Differential Revision: https://code.wildfiregames.com/D3920
This was SVN commit r25366.
2021-05-03 16:07:26 +00:00
0406c4dfde Throw errors instead of warnings on wrong implicit conversions.
This prints out a stack trace, which is quite helpful when debugging.
Also fixes an issue with stack trace not always being reported.

Differential Revision: https://code.wildfiregames.com/D3210
This was SVN commit r25365.
2021-05-03 15:44:06 +00:00
6d10a35d97 Fix some warnings.
- 25332f9b86 added 'override' to a method in ShaderProgram.cpp. This
adds it to the rest.
- BinarySerializer.cpp had custom JS includes, because putting those in
ScriptExtraHeaders failed. The cause is that gloox leaves "#define
lookup" up. This has been reported upstream, and fixed here.
- VS17 complains about an uninitialised variable, though the usage is
safe.

Differential Revision: https://code.wildfiregames.com/D3916
This was SVN commit r25359.
2021-05-02 15:45:40 +00:00
3801a4dd47 Allow implicit JS boolean -> string conversions.
`false` becomes `"false"`, `true` becomes `"true"`.

Differential Revision: https://code.wildfiregames.com/D3917
This was SVN commit r25358.
2021-05-02 15:43:59 +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
518fb7eafa Set a stack quota for JS scripts to prevent crashes from infinite loops.
Infinite loop will instead trigger JS exceptions, which will make error
reports much nicer.

Differential Revision: https://code.wildfiregames.com/D3851
This was SVN commit r25280.
2021-04-16 16:49:18 +00:00
fc60d80af1 Simplify GUI Proxy implementation & customisation.
This finishes 7c04ea0211 and 1b67a079fb.
GUI Proxy objects are now easier to specialize, code duplication is
reduced, code is made safer.
In details:
- the proxy private is always the IGUIObject* pointer
- the private data is accessed through a safer wrapper
- CreateJSObject returns an opaque type to allow easier extension &
prevent errors.
- The implementation of CreateJSObject is moved near the GUI Proxy
template instantiation, and both are wrapped in a convenient macro (this
makes it so that if you use the macro, you can't forget to overload the
method, and vice-versa).
- The common IGUIObject JS interface no longer needs to be repeated.
- All specialisations are again put in the same file, for improved
compile-time & clarity, given there are so few lines now.
- While at it, implement toSource which makes it possible to `uneval`
components (does the same as toString though).


Differential Revision: https://code.wildfiregames.com/D3826
This was SVN commit r25225.
2021-04-09 18:01:47 +00:00
969112b9c8 Replaces CPos by more a consistent CVector2D, reduces geometry code duplication.
Tested By: Freagarach, Langbart
Differential Revision: https://code.wildfiregames.com/D3759
This was SVN commit r25152.
2021-03-28 21:55:13 +00:00
87a2c3347f Make real directory paths on the VFS predictable (retry)
This is the same commit as 4bb31f084e, reverted in 5d1899785a. Noted
issues were fixed.

Partial revert/fix of 2f19cf86d3 and 2567fee329.

Before this diff, it was possible for a mod containing a cache/ or a
config/ folder to get written to incorrectly.
The issue is VFS can map multiple directories to one 'virtual' path, for
reading mods. However, writing data is problematic: which path to
choose?
The only viable solution is to use a path relative to the highest
priority directory encountered in the VFS path, or write paths could be
'hijacked' by lower-priority mods.

This fixes these issues by:
- Adding a new lookup mode ('Real-path') that explicitly picks the real
path relative to the highest-priority subdirectory in the VFS Path.
- Preventing overwriting a real directory with a lower priority one in
general.
- Revert c0c8132dd4's GetRealPath change, re-introducing the function as
GetOriginalPath.

This also cleans up some duplication that led to empty mod folders in
the user mod path, and cleans up loading the 'user' mod.
It also makes it explicit that a directory must be passed to Mount().

Note that the new 'realpath' lookup can still be somewhat complex with
many mount points at various hierarchy levels, but it is at least
predictable/deterministic without having to be careful about populating
order.

Fixes #2553

Differential Revision: https://code.wildfiregames.com/D3728
This was SVN commit r25107.
2021-03-23 12:46:59 +00:00
2e4639e6dc Removes unused containers included in headers.
This was SVN commit r25004.
2021-03-03 23:01:08 +00:00
e104b41be2 Cleanups includes for cassert and streams.
This was SVN commit r25002.
2021-03-03 22:26:49 +00:00
cb346e207b Refactor all usage of RegisterFunction to ScriptFunction::Register
- Replace ScriptInterface::RegisterFunction with
ScriptFunction::Register
 - Mostly removing unused cmpPrivate*
 - Some usage introduces specific getters (mapgenerator, AIWorker,
XmppClient,...)
 - Several passthrough functions are simply removed in favour of calling
the original, reducing duplication
 - Make use of ScriptRequest/ScriptInterface capabilities where
relevant.
- Make JSI_* headers only expose necessary functions, lightening them
considerably and reducing duplication
 - Reuse namespaces in JSI_* implementations directly, reducing visual
noise there

Follows f3aedf88a6

Differential Revision: https://code.wildfiregames.com/D3626
This was SVN commit r24983.
2021-03-02 20:01:14 +00:00
2838873c0a Fixes & improvements to FunctionWrapper
- HandleValue needed to explicitly pass UndefinedHandleValue for
'default' arguments.
- Allow passing ScriptInterface as first argument.
- Statically check that a getter is provided for object methods instead
of crashing at runtime
- A few stylistic improvements

Differential Revision: https://code.wildfiregames.com/D3625
This was SVN commit r24981.
2021-03-02 16:55:22 +00:00
a64536b45f Fix MSVC unknown pragma warning
Follows f3aedf88a6.

Reported by: Stan
Reviewed By: Stan
Differential Revision: https://code.wildfiregames.com/D3623
This was SVN commit r24976.
2021-03-02 15:00:33 +00:00
f3aedf88a6 Introduce C++ templates replacements for DEFINE_INTERFACE_X and RegisterFunction macros
The new methods:
- aren't included in ScriptInterface.h directly, lightening that header
- don't use boost CPP
- don't need argument types or number or constness to be specified
- can work with object methods somewhat transparently
- support optional cmptPrivate (allowing removal of many UNUSED macro)
- support optional const ScriptRequest&, which is safer.

This first diff changes only some of the JSI files & the component
manager. Further diffs will update other files and finally delete the
current code.

Differential Revision: https://code.wildfiregames.com/D2818
This was SVN commit r24969.
2021-03-01 20:52:24 +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
6a67e9a52d Address concerns in 5473393e30 (RL interface)
Fixes 5473393e30.

This:
- Puts RL code under the RL namespace to avoid name collisions
- Avoids usage of new/delete
- Adds more documentation
- Does general cleanup (const-correctness, move semantics, argument
types, early returns...)

Patch by: irishninja
Comments by: Vladislavbelov, wraitii
Differential Revision: https://code.wildfiregames.com/D2947
This was SVN commit r24631.
2021-01-15 16:30:05 +00:00
b1a89fbd89 Replaces UNICODE characters in the code by consistent ASCII characters.
Beside consistency improves reading for such console tools like svn diff
or vim diff.

This was SVN commit r24625.
2021-01-15 10:07:36 +00:00