1
0
forked from 0ad/0ad
Commit Graph

18 Commits

Author SHA1 Message Date
fa1dc98103 Shutdown mongoose in rl-interface gracefully
When the `RL::Interface` is destroied but the engine isn't completely
shoutdown there was a dangling pointer. The time the dangling pointer is
accessable got expanded with 968e55704a.
Whith this patch there no dangling pointer (in that regard).

Accepted by: @vladislavbelov
Comments by: @Stan, @sera
Trac Tickets: #5989

Differential Revision: https://code.wildfiregames.com/D5254
This was SVN commit r28123.
2024-06-23 17:26:03 +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
968e55704a Make the RLInterface local
refs: #4211

Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5103
This was SVN commit r27908.
2023-10-28 21:11: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
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
35ed55cfd6 ParamNode: switch to utf8, ToXML -> ToXMLString, test tweak, PCH tweak
This changes ParamNode to use UTF8 values internally (XMB files are UTF8
since cb9d0733ef).
This removes the need for a lot of conversions, speeding things up and
allows cleaning up the validator interface & a few other callsites.
ConstructJSVal could be a tad slower because of UTF8->16 conversions
within Spidermonkey; but the difference is unlikely to be noticeable in
practica.

Also:
- Changes `ToXML` to `ToXMLString` for clarity.
- Add a simple "op" test & show a particular behaviour of merge nodes
that I intend to change somewhat in D3830.
- Remove Component.h from simulation2 PCH - brought in too much.

Tested by: langbart
Differential Revision: https://code.wildfiregames.com/D3834
This was SVN commit r25228.
2021-04-11 09:23:10 +00:00
d4c2cf4430 Increase MP Command delay to 4 turns, decrease MP turns to 200ms.
To hide network latency, MP turns send commands not for the next turn
but N turns after that (introduced in c684c211a2).
Further, MP turn length was increased to 500ms compared to 200ms SP
turns (introduced in 6a15b78c98).
Unfortunately, increasing MP turn length has negative consequences:
- makes pathfinding/unit motion much worse & unit behaviour worse in
general.
- makes the game more 'lag-spikey', since computations are done less
often, but thus then can take more time.

This diff essentially reverts 6a15b78c98, instead increasing
COMMAND_DELAY from 2 to 4 in MP. This:
- Reduces the 'inherent command lag' in MP from 1000ms to 800ms
- Increases the lag range at which MP will run smoothtly from 500ms to
600ms
- makes SP and MP turns behave identically again, removing the
hindrances described above.

As a side effect, single-player was not actually using COMMAND_DELAY,
this is now done (can be used to simulate MP command lag).

Refs #3752

Differential Revision: https://code.wildfiregames.com/D3275
This was SVN commit r25001.
2021-03-03 21:02:57 +00:00
df18102e96 Add an 'Evaluate' RL endpoint, intended for dynamic game balancing
This adds a new endpoint to the RL interface for evaluating custom
JavaScript. When combined with the ability to create arbitrary
modifiers, this provides the required functionality for exploring
quantitative game balancing.

Patch By: irishninja
Fixes #5981

Differential Revision: https://code.wildfiregames.com/D3479
This was SVN commit r24962.
2021-02-28 12:16:32 +00:00
d3c593666f Only parse querystring in RL Interface if it exists.
Patch by: @irishninja
Differential Revision: https://code.wildfiregames.com/D3529
This was SVN commit r24844.
2021-02-06 23:00:45 +00:00
e3c44f0bde Fix more issues with the RLInterface
Patch by: @Stan, @irishninja
Differential Revision: https://code.wildfiregames.com/D3385
This was SVN commit r24839.
2021-02-05 12:23:02 +00:00
321e3652f9 Fix and disable some pesky Windows warnings.
Differential Revision: https://code.wildfiregames.com/D3511
This was SVN commit r24838.
2021-02-05 12:20:06 +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
369c2e8801 Further header & precompiled cleanup, fix no-PCH builds.
GUIObjectBase is made a IGUIObject* to avoid including those headers
un-necessarily. Subsequent diffs ought to clean up the various of
pointers for that with a similar type with reference semantics.

Also:
- Add standard C and C++ headers (mostly cstring for memcpy, string and
vector) where needed.
- Swap out some includes for forward declarations
- Clean up un-necessary boost includes in precompiled and other headers.
- Clean up precompiled headers, including fewer things.
- Move ACPI to the windows-specific folder as it's included there only
and mostly specific to that platform.

Thanks Stan for the testing.

Differential Revision: https://code.wildfiregames.com/D3129
This was SVN commit r24352.
2020-12-09 14:39:14 +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
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
5473393e30 Add an interface for Reinforcement Learning.
Implement a simple HTTP server to start games, receive the gamestate and
pass commands to the simulation.
This is mainly intended for training reinforcement learning agents in 0
AD. As such, a python client and a small example are included.

This option can be enabled using the -rl-interface flag.

Patch by: irishninja
Reviewed By: wraitii, Itms
Fixes #5548

Differential Revision: https://code.wildfiregames.com/D2199
This was SVN commit r23917.
2020-08-01 10:52:59 +00:00