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.
After this change, units will move directly to the nearest resource
dropsite when they are idle but carrying resources at full capticity,
instead of trying to gather, then realising again they are full, and
going back to the dropsite.
Reviewed by: @Freagarach
Comments by: @Angen, @wraitii
Differential Revision: https://code.wildfiregames.com/D2791
This was SVN commit r24172.
- Makes it easier to change down the line (and change is coming)
- Allows making g_ScriptRuntime thread-local easily.
- Remove ParentRuntime, which is not used at the moment.
Part of the SM52 migration, stage: SM45 compatible.
Patch by: Itms
Tested By: Freagarach
Refs #4893
Differential Revision: https://code.wildfiregames.com/D3087
This was SVN commit r24171.
DefPersistentRooted is essentially a wrapper around unique_ptr and has
no real reason to exist.
Part of SM52 migration, stage: SM45 compatible.
Patch by: Itms
Tested by: Freagarach
Refs #4893
Differential Revision: https://code.wildfiregames.com/D3086
This was SVN commit r24170.
When serialising JS objects, we keep track of any encountered object,
and serialize it only once. Any further serialisation instead stores an
ID referring to the original object (essentially an opaque pointer).
The trouble of course is to have a unique, persistent identifier for
such an object.
svn uses an ObjectIDCache, essentially a "JS Object -> ID" map (which
internally is essentially a "JS heap pointer -> ID" map).
JS, since ES15, includes a "Symbol" primitive type, which is a unique,
immutable identifier. They are also not iterable by for..in or
GetOwnPropertyName or related.
This means they can be used to store the tag directly on the object
(since it's impossible overwrite a user property).
Thanks to this, we can forgo ObjectIDCache in the serializers, and since
following D2897 it becomes unused, we can delete it, along with the
Finalization code it used.
Part of SM52 migration, stage: SM45-compatible changes.
Patch by: Itms
Tested By: Freagarach
Refs #4893
Differential Revision: https://code.wildfiregames.com/D3085
This was SVN commit r24167.
By default structures now have a vision range of 4 (to allow them to
reveal themself). Effectively no values are changed (beyond those in
templates/other).
Patch by: @Nescio
Differential Revision: D3036
This was SVN commit r24163.
Follow up on 8bfb449375. Allows saving turret positions in the map file,
instead of relying on the order in which the entities are added.
Differential Revision: D2614
Reviewed by: @wraitii
Comments by: @Angen, @bb, @vladislavbelov.
This was SVN commit r24161.
The script interface has code to serialize/deserialize JS objects with a
user-defined prototype. That code is usable in the AI, but currently
unused (and there are no plans to use it in the long run).
Removing it allows removing more code down the line, which helps with
the SM45-52 migration.
Collaboration with itms.
Refs #4893
Differential Revision: https://code.wildfiregames.com/D2897
This was SVN commit r24157.
Do not use props , to reduce drastically the number of drawcalls. Those
should only be used for uneven terrain.
Do not load the kart struct for every arrow use prop_weap like all the
other weapons.
Do not use basic_trans where not necessary
Noticed by: @vladislavbelov, @OptimusShepard.
This was SVN commit r24156.
ComputeTargetPosition called Dot() with large enough vectors that it
overflowed. Avoid that by not actually doing the full dot product.
Reported by: Itms
Fixes#5852
Differential Revision: https://code.wildfiregames.com/D3061
This was SVN commit r24152.
Where controllability is defined as the ability to receive _any_ order
from the player.
Fixes the concern not raised at a1dc9cadd8#42637.
Differential Revision: D1960
Reviewed By: @wraitii
Comments by: @bb, @Stan.
This was SVN commit r24148.
e07f12bea6 Changed the class names of Defense Towers, but it forgot to
update maps, this patch fixes that.
Differential Revision: D3063
Reviewed By: @Nescio
This was SVN commit r24147.
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.
Introduced in af15d5972d.
Landscape and Biome previews are not updated correctly when reopeneing
gamesetup.
To solve that, remove lastBiome and lastLandscape and always try to
update preview if preview file exists and does not match with current
one.
Differential revision: D3041
Reviewed by: @FreagarachFixes: #5785
This was SVN commit r24139.
70c71bff0f changed modifiers to explicitly support only string or
numeric values.
However, buildRestrictions territories worked with a list, which errored
out. This is now replaced with a string.
Reported by: Asger
Investigated by: Freagarach.
Reviewed By: Freagarach
Fixes#5849
Differential Revision: https://code.wildfiregames.com/D3062
This was SVN commit r24135.
Commented By: Stan
Reported By: Freagarach
Tested By: Freagarach, Stan
Differential Revision: https://code.wildfiregames.com/D3059
This was SVN commit r24129.
Renames helper Entity.js to Position.js and moves to there:
- `EntitiesNearPoint` (from Attacking.js).
- `InterpolatedLocation` (from Attacking.js).
- `TestCollision` (from Attacking.js).
- `PredictTimeToTarget` (from Attack.js).
Also adds a test for the helper.
Differential Revision: D2940
Reviewed By: @wraitii
Comments by: @Stan, @vladislavbelov
This was SVN commit r24128.
Such that now e.g. control groups can be selected using those.
Patch by: @Nescio
Differential Revision: D3029
Accepted by: @wraitii
This was SVN commit r24120.
939002f0dc changed from vectors to grid which broke resetting when
terrain size changed.
Also use SAFE_ARRAY_DELETE for simplicity.
Reported by: vladislavbelov
Reviewed By: vladislavbelov
Differential Revision: https://code.wildfiregames.com/D2961
This was SVN commit r24117.
Added in 9023f4bebb, which changed lobby GUI messages to JS::Values,
requiring a real context. The original code mistakenly inverted the
owning script interfaces.
Given the reproducibility discovered in SM52, the timeline of the bug,
and the nature of the issues encountered in MP, this is a rather safe
fix for #5655.
Reviewed By: Itms
Fixes#5655
Differential Revision: https://code.wildfiregames.com/D2922
This was SVN commit r24116.
This function is currently polling-based, and called by the GUI on each
turn, which results in a big performance hit.
Use the opportunity to rename the set of functions with more generic
names.
Reviewed By: Freagarach, wraitii
Differential Revision: https://code.wildfiregames.com/D2919
This was SVN commit r24114.