Commit graph

289 commits

Author SHA1 Message Date
animus
b1627f5158 Remove redundant virtual keywords
This commit performs code cleanup to improve
code clarity and consistency:

Remove redundant 'virtual' keywords from methods that are already marked
with 'final' or 'override', as well as reducing redundant 'override
final's to 'final'.
2026-06-12 18:35:32 +02:00
phosit
c042b3ca2c
Start the serializationtest at a specivic turn
This enables to only test critical game sections.
2026-05-10 14:18:48 +02:00
phosit
03a5198ed3
Remove g_GUI usage in simulation2/*
This is the last remaining inclusion of a gui file in simulation2/.
2026-01-23 21:05:18 +01:00
phosit
153dfe7ef1
Don't use g_GUI in TurnManager
The turn-manager shouldn't know about the gui.
2026-01-23 21:05:14 +01:00
Ralph Sennhauser
9ea5a789a7
Fix EntityMap::iterator
Fixes cppcheck error
```
source/simulation2/system/EntityMap.h:104:11: error: Reference to local variable returned. [returnReference]
   return ptr;
```

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-11-11 21:35:01 +01:00
phosit
ef016884ab
Pass debugOptions on construction of CSimulation2
The functions to set them explicitly are removed. This makes the
interface of `CSimulation2` smaller.

Also serializationtest and rejointest can't be active at the same time.
Add a warning about that and use a `std::variant`.
2025-11-01 17:31:54 +01:00
Itms
9150c20818
Remove ScriptTypes and ScriptExtraHeaders headers
The first header was used to include the SpiderMonkey JS API at once,
with safeguards and preprocessor defines. Nowadays, SpiderMonkey
provides modular headers allowing us to include what we use, refs #8086.

Some defines have to be moved to compiler options but it is apparently
a mistake from the SM developers:
https://bugzilla.mozilla.org/show_bug.cgi?id=1987876
2025-09-14 13:17:18 +02:00
Ralph Sennhauser
cc7a165365
Fix includes in source/simulation2
Make include-what-you-use happy with some files in source/simulatation2
and fix what needs to be fixed.

source/simulation2/system/ComponentTest.h uses cxxtest, so add cxxtest
to the deps for simulation2 target.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-08 07:10:11 +02:00
Ralph Sennhauser
2bad15b4c2
Fix includes in source/simulation2
Make include-what-you-use happy with some files in source/simulation2
and fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-07 20:00:49 +02:00
Ralph Sennhauser
32fd10691d
Fix includes in source/simulation2
Make include-what-you-use happy with some files in source/simulation2
and fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-07 08:38:40 +02:00
Ralph Sennhauser
46d44bbc14
Fix includes in source/ps
Make include-what-you-use happy with some files in source/ps and fix
what needs to be fixed.

Delete source/ps/FutureForward.h as it is no longer used.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-05 07:21:22 +02:00
phosit
f721f56ad4 Replace TIMER with PROFILE2
`TIMER` messages where printed to stdout which lead to noise.

Refs: #1003
2025-07-29 18:19:49 +02:00
Ralph Sennhauser
3c1a37985a
Fix includes in source/network
Make include-what-you-use happy with files in source/network and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-23 18:18:47 +02:00
phosit
9822a22573 Replace ScriptException::Raise in Engine functions
Now exceptions can be thrown. The function throwing exceptions becomes
cleaner and doesn't require a `ScriptRequest` anymore.
2025-07-08 19:11:49 +02:00
phosit
891908b801 Remove UNUSED
The `UNUSED` macro is used to mark a variable as unused but with a name.
Those usages are replaced with comments so that `UNUSED` can be removed.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-26 17:25:05 +02:00
phosit
93666d8628 Remove ignore_result
`std::ignore` serves the same purpose and is C++ standard.
2025-06-19 19:05:56 +02:00
phosit
d9795d29fe Remove the name of some unused arguments
Remove some usage of the `UNUSED` macro. Remove only those cases where
the names can be deduced from their type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-18 12:49:59 +02:00
Lancelot de Ferrière
dd74892463 Fix no-pch build following #7829 2025-05-11 11:24:50 +02:00
Lancelot de Ferrière
9eccf1f27d Iterate the component map only once on serialization 2025-05-10 17:08:49 +02:00
Lancelot de Ferrière
ea5a350f83 Cache JS component wrappers 2025-04-19 14:41:45 +02:00
Dunedan
8482f25800
Fix a bunch of spelling mistakes
This fixes a bunch of spelling mistakes found in user facing strings.

Fixes #7716
2025-04-11 06:24:32 +02:00
Lancelot de Ferrière
1b1e00d6c4 Remove profiler 2 spike/aggregated regions
This code is unused and was never actually useful.
Fixes #6620.
2025-01-18 12:36:20 +01:00
Itms
e48b9ea106
Only freeze once the cached JS values of templates
CParamNodes can be quite large, thus we usually cache the JS::Value when
converting them. The AIInterface makes heavy use of it as detected in #7404.

However, the cached values are re-frozen everytime, which is a
significant waste of time on a large number of templates.
2025-01-08 11:39:17 +01:00
elexis
c9e76efe7b Store whether a player is activ in C++
This prevents mods from mutating this value and revealing the map.

Part of this commit is written by @phosit.
2025-01-05 19:57:12 +01:00
elexis
f932b8b9cc Fix subscription time of script component wrapper
Script component wrapper attempted to subscribe to messages before the
script component has been registered.
This defect existed since 7c2e9027c2 but was never noticed since there
is no script component wrapper which subscribes to messages. (Only the
script component it wrapps does.)
2025-01-05 19:57:12 +01:00
Itms
cc72142205
Adapt 0 A.D. to SpiderMonkey ESR 102
This follows the migration guide at:
https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples

Based on patch by: wraitii
Differential Revision: https://code.wildfiregames.com/D5002
2024-12-09 10:43:35 +01:00
Itms
adcb9755ff Refactor freezing of JS objects
- Shallow-freezing of objects is never used in our codebase, so remove
   that code path.
 - Deep-freeze is bugged in recent versions of SpiderMonkey (see bug
   https://bugzilla.mozilla.org/show_bug.cgi?id=1930258). Until a fix
   and/or a better API is provided, reimplement this feature by
   recusively freezing object properties.
 - Add tests for the deepfreeze function.
2024-12-05 17:49:16 +01:00
Itms
5ed3a54603
Do not pin or atomize ParamNode strings
When building a JS::Value from CParamNode, strings have been "interned"
since the conversion was written in dd501b2a5a. This means that the JS
string object could be used outside a JS realm, and also that those
strings could be compared efficiently instead of char-by-char.

This was unnecessary, and the only place in the code where we used
"interned" strings. The upgrade to SpiderMonkey 45 (64b477625d) changed
the name of related methods, and some of them are removed from the
public API in SM 102, so stop pinning and atomizing those strings.

Additionally, the switch of CParamNode to utf8 in 35ed55cfd6 missed one
of the two utf16 handlings, so fix that as well.
2024-11-17 18:59:48 +01:00
phosit
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
vladislavbelov
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
phosit
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
phosit
e72ad82909 Remove the use of std::iterator in EntityMap.h
Accepted By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5105
This was SVN commit r27813.
2023-08-23 12:31:07 +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
vladislavbelov
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
vladislavbelov
4e86f99fe2 Replaces boost string general includes by more precise ones.
Differential Revision: https://code.wildfiregames.com/D5066
This was SVN commit r27746.
2023-06-30 19:10:13 +00:00
wraitii
87063a94ff Pass ScriptRequest instead of ScriptInterface in simulation messages.
The previous code was constructing un-necessary ScriptRequest objects.
Minor optimisation from not entering/leaving realms.

Differential Revision: https://code.wildfiregames.com/D5026
This was SVN commit r27728.
2023-06-21 07:50:00 +00:00
Freagarach
ded41eab31 Allow other root XML than entity.
Implements a `GetOnlyChild()`, following discussion at
https://irclogs.wildfiregames.com/%230ad-dev/2022-05-06-QuakeNet-%230ad-dev.log.

Differential revision: https://code.wildfiregames.com/D4738
Comments by: @phosit, @Stan, @vladislavbelov, @wraitii
This was SVN commit r27323.
2022-12-30 07:34:23 +00:00
vladislavbelov
2ef801f5d0 Remove some unnecessary string copy related to substr.
Patch By: phosit
Differential Revision: https://code.wildfiregames.com/D4772
This was SVN commit r27271.
2022-12-04 19:56:12 +00:00
wraitii
557fa0312e Fix non-visual autostart, as well as client/host autostart.
Follows 8eecc39e71.

Piping the autostart through a GUI page is easy but requires using the
GUI in non-visual mode, which is problematic since it's not initialized.
The GUI is not needed, only its ability to load scripts, so this diff
fixes the problem by adding an 'entrypoint' script in the new
`autostart` folder that gets called with this unique ability, setting
things up properly. The mod mod gets a placeholder.

Other changes:
- Fix some issues with networked autostart:
  - Players were not assigned slots.
  - The host didn't actually wait for other players.
- Move gamesettings from `gui/gamesettings/` to `gamesettings/`. This
moves attributes as well.
- Move autostart files from `gui/autostart/` to ` autostart/`. Note that
`gui/autostart/` still exists as it's used in the tutorial button from
the main menu.
- Rename the JSI_VFS functions to be explicitly about their function:
the ability to write and the potential restricted folders.
- Don't require `autostart` when using `--autostart-client` in
non-visual mode.

Starting the autostart client/host has poor UX in some situations, but
improving that feature is beyond the scope of this diff.

Suggestions for future work:
- Some files in gui/common should probably be moved elsewhere
- Template loading code is duplicated
- The gamesetup code still needs work for proper UI/logic separation.

Help & comments by: smiley

Reported by: vladislav / Langbart
Fixes #6513

Differential Revision: https://code.wildfiregames.com/D4628
This was SVN commit r26879.
2022-05-15 06:34:17 +00:00
wraitii
ee0fcf2b95 Fix map errors from GetTemplate not being available in the sim
Follows ea72437739. Fixes it by providing a convenience function in the
component Manager that matches the API in the GUI / AI

Refs #6444

Differential Revision: https://code.wildfiregames.com/D4630
This was SVN commit r26867.
2022-05-09 18:13:34 +00:00
vladislavbelov
41f2ab87ed Fixes macOS warnings after adding final keyword to simulation classes in 3eee3a444d.
Also fixes GLES.

Differential Revision: https://code.wildfiregames.com/D4528
This was SVN commit r26605.
2022-03-07 23:04:11 +00:00
vladislavbelov
3eee3a444d Adds final keyword to simulation component classes.
Differential Revision: https://code.wildfiregames.com/D4520
This was SVN commit r26537.
2022-03-03 22:42:26 +00:00
wraitii
158cf8ea8d UnitMotion pushing improvements
The main change is the introduction of a 'pushing pressure' counter on
units. This counter increases when units get pushed around, and
decreases over time. In essence, units under high pressure move slower &
are harder to push around.
The major effect is that units can now get bogged down when very dense
groups start colliding. This makes movement more realistic, makes unit
movement more 'chokepointy', and generally improves the mathematical
soundness of the system (lower values are easier to handle for our 200ms
turns).

Other changes:
- The logic to detect units crossing each other's path has been
reworked. Units that run towards each other should not more obviously
avoid each other.
- New parameters: 'Spread' is a measure of how strong the pushing effect
is based on distance. With the current settings, static-pushing is
rather 'on/off', whereas moving-pushing is more gradual (and thus the
max influence distance was increased when moving).
- Default values have been tweaked for lower overlap.
- Units only looked at other units within their grid region. This led to
overlap near grid-borders. Units now look at neighboring grid elements,
which largely removes this issue. While this may be slower, the
performance of pushing was largely negligible before, so it is unlikely
to become a main cause of lag (and overlap was generally disliked by
players).
- Units no longer orient in the direction of pushing, but instead keep
facing their target. This can look slightly odd under very heavy pushing
forces, but vastly improves behaviour of very slow units such as rams
(since they spend much less time turning around). As a side-effect,
clean up angle code following acc780bcbb .

Engine changes:
- Add a debug rendering mode at compile-time to help understand what is
happening.
- Make it possible to constexpr initialise fractional fixed numbers by
using FromFraction

The 'pressure' change was inspired by alre's suggestion at
https://wildfiregames.com/forum/topic/56436-for-a-better-unit-movement/#comment-461987

Refs #6127

Differential Revision: https://code.wildfiregames.com/D4439
This was SVN commit r26245.
2022-01-24 15:36:13 +00:00
vladislavbelov
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
vladislavbelov
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
wraitii
0c23e595fa Include CStrInternStatic where necessary only.
This makes incremental recompilation faster when changing static
interned strings.

Differential Revision: https://code.wildfiregames.com/D3975
This was SVN commit r25457.
2021-05-18 11:09:54 +00:00
wraitii
a19dc1717f Don't include ComponentManager.h in ScriptComponent
ScriptComponent does not use ComponentManager, and its derived classes
(most ICMP*.cpp files) do not either. Therefore, we can skip a lot of
transitive inclusions and speed up recompiling by not including it
there.

Differential Revision: https://code.wildfiregames.com/D3962
This was SVN commit r25447.
2021-05-16 15:12:39 +00:00
wraitii
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
wraitii
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
wraitii
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