Commit graph

1549 commits

Author SHA1 Message Date
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
Vantha
e0db65ba1b Remove pointless const's from ICmpCinemaManager.h
Were mistakenly introduced in d882ab74a1
2026-03-24 11:15:27 +01:00
Lancelot de Ferrière
25fd3aa93c Small optimisation for VertexPathfinder edge handling.
Previously, edges where bundled collected first then sorted in 4 AA and 1 unaligned bucket. We can separate the unaligned edges right away, which is a little faster.

Also make sure Vertex::pred is initialized.
2026-03-11 18:45:23 +01:00
Lancelot de Ferrière
a6e0a623b4 Avoid constructing temporaries for Edge objects in VertexPathfinder 2026-03-11 18:45:20 +01:00
Vantha
d882ab74a1 Revamp CinemaManager component
Clean up the the implementation, improve the naming, and
add some more documentation as well as more in-depth tests.
2026-03-03 11:25:52 +01:00
Vantha
1d3cdec48d Move cutscene mode to renderer
This patch splits "cutscene mode" (disabling silhouttes, territory
borders and other visual overlays) from the cinema manager component
and moves it to the renderer, since it doesn't influence the simulation
anyway. The mode can now be independently controlled by the GUI. This
is done so it can also be used for other narrative elements like speech
or dialogue in the future. Cutscene mode is still always enabled while
cinema paths are playing, though.
By design, this also fixes the issue that range overlays weren't hidden
during cutscene mode.
2026-03-03 11:25:52 +01:00
Vantha
c7247936bf Introduce separate LosRevealWholeMapForAll flag
It was previously stored at the end of the array of per-player flags and
set by calling SetLosRevealWholeMap with the player ID -1. However, ever
since the introduction of observer mode in 883f307b40, -1 is the player
ID of observers everywhere else including for GetLosRevealWhole:
GetLosRevealWhole(-1) always returns true in order to reveal the map to
observers, however, the cinema manager, for example, called it meaning
to find out whether the whole map is revealed to all players.
To fix this and avoid confusion about this in the future, this patch
splits this flag from the per-player flag array and introduces new
functions to set and retrieve it.
2026-03-03 11:25:52 +01:00
Vantha
21a61721a7 LosRevealAll -> LosRevealWholeMap
This name is more descriptive.
And the plan is to split off the extra player value of the vector into
an own flag in the future, and LosRevealAllForAll would have been a poor
name for that.
2026-03-03 11:25:52 +01:00
Vantha
d7eafb8c5d Fix wrong cinema path duration at nondefault sim rates
For example, at 2x, the cutscenes were cut off in half -- by the cinema
manager disabling itself to early.

Refs #3814
2026-03-03 11:25:52 +01:00
phosit
00f173685a
Use std::optional for m_RejoinTestTurn
This removes a `-1` from #8468.
2026-02-08 19:56:01 +01:00
phosit
df18e22277
Remove Script::CreateArray
It's better to construct a js-array from a `JS::RootedValueVector`.
Because it is more strongly typed and the index doesn't has to be
specified when appending an element.
Some usages are replaced with `JS::RootedValueArray`.

Fixes: #8702
2026-02-08 19:27:50 +01:00
Atrik
99e3799883 Fix formation reshuffling after entity rename
When entities in formations were renamed (e.g., during promotion),
the formation would immediately recalculate all member positions,
and queue movement orders causing visible shuffling.

Changes:
1. Transfer existing offsets movement to the renamed entity
   to maintain current formation structure
2. Schedule offset recalculation for the next tick to allow proper
   reordering after all systems have updated

This preserves formation integrity during renames while allowing
eventual optimal position recalculation.

Fixes #8656
2026-02-04 11:05:07 +01:00
Atrik
6cdbdae87c Add tolerance to offset destination checks
The 0 tolerance to prevent the "waltzing" that was set before this
cannot happen anymore as we now since check for being at destination
before sending a move request in UnitAI. Adding a new small tolerance
now prevents some small movement adjustments of formation members
near their destination.

Fixes #8592
2026-02-04 11:05:07 +01:00
Atrik
8e15b9c000 Fix unit acceleration reset on upgrade
Fixes #7625
2026-02-04 11:05:07 +01:00
Ralph Sennhauser
0d60bdfd2e
Readd JS API function Engine.Exit()
Requested in #8244 for scripting purposes and automated testing. Extend
the original design by adding a means to pass an exit status. This also
comes in handy in case one wants to cleanly error out from JS on parsing
errors of command line arguments as reported in #7967.

Fixes: #8244
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-01-29 20:03:56 +01: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
phosit
ba2351611c
Remove LoadScripts from CSimualation2
`LoadScripts` and `LoadDefaultScripts` have to be called imediately
after the `CSimulation2` constructor.

By doing the necesarry work in the constructor and removing
`LoadScripts` and `LoadDefaultScripts` the interface of `CSimulation2`
is simplified.
2026-01-01 17:27:54 +01:00
Atrik
f856565de9 Add formations paths to UnitMotionDebugOverlay
Formation controllers now display their movement paths when enabling
UnitMotion debug overlay.

Key changes:
- Formation controllers show long paths in blue and short paths in green
- Formation controllers path are rendered if selecting
  some of the formation's members
- Prevent the gui from making redundant calls to SetMotionDebugOverlay

Existing limitations (not regressions):
- Paths are often cleared before entities complete them
- Formation members have short paths that rarely get rendered
2025-12-29 14:30:14 +01:00
phosit
5586802b86
Use a coroutine for Loader tasks
Some tasks are invoked multiple times. Normally those tasks are broken
up inside a loop and had to be continued there. With coroutines that is
easier as it's possible to suspend inside a loop.

Coroutines which are lambdas should not capture anythig as the lifetime
of the captured values might end before the coroutine completes. For
that purpose `std::bind_front` is used.
2025-12-21 15:51:46 +01:00
phosit
b686dfa047
Use range based for loop in TestSerializerPerf
CppCheck warned that `i` might be out of bound.
2025-12-13 18:58:17 +01:00
phosit
1917d034fd
Introduce a namespace in Loader
All functions had a `LDR_` prefix. The prefix is removed.
Functions and globals which are only used in Loader.cpp are now
contained in an anonymous namespace.
2025-12-13 18:58:17 +01:00
phosit
a1ba9e34c4
Remove unused m_DeltaTime
Seems to be unused since c684c211a2
2025-11-30 13:49:31 +01:00
Vantha
ccd1046d67 Parallelize the execution of range queries
Use futures to spawn several threads that concurrently work through the
active range queries each turn instead of doing everything serially on
the main thread -- similar to how the pathfinder computes pathfinding
requests asynchronously. This significantly increases performance.
Note: It still can't run in parallel to the rest of the simulation update since
the range computations depend on the state of the simulation (like the
position of units).
2025-11-26 16:10:29 +01:00
Ralph Sennhauser
7452bf882f
Add test for loading players templates
Checks that those templates can be loaded, i.e. are adhering to the
schema.

Refs: #8540
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-11-22 08:41:02 +01:00
phosit
9a526bcae1
Throw error when simulation script can't be loaded
When a script in "simulation/helpers/" contained an error. Files in
"simulation/components" aren't loaded. The return value of
`LoadDefaultScripts` indicated an error but was ignored. The simulation
still tried to start.

Now instead of returning a ignoreable error code the error is thrown. In
the common path the error is implicitly rethrown to the JS-function
which tried to start the game.

fixes: #8133
2025-11-20 19:38:36 +01:00
Ralph Sennhauser
9ffbf15ee1
Fix -Wunnecessary-virtual-specifier warnings
Commit 3eee3a444d added final keyword to
simulation classes but left virtual keywords in place.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-11-11 21:35:01 +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
phosit
10afb7d856
Pass ooslog-activate flag on construction
This deduplicates the activation logic and removes the only
`m_EnableOOSLog` mutation.
2025-11-01 16:35:39 +01:00
Ralph Sennhauser
0fe18e1d84
Enable test loading all templates
The test takes about 0.5s in release build and about 2s in debug build,
hardly qualifying as slow. As such enable it.

About the noise, it's of little interest anyway so don't spam.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-11-01 16:15:31 +01:00
Ralph Sennhauser
eba8439295
Replace boost::filesystem std::filyestem
Bumping the minimum version of macOS to 10.15 for spidermonky [1] also
allows us to use std::filesystem instead of boosts implementation.

[1] f14a98e26f

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-10-29 09:56:32 +01:00
fahad-accordion-19
56d7be5334 Remove <type> from minimap schema and templates
The <minimap> element in resource templates previously included a <type>
child element that was required by CCmpMinimap.cpp. This commit removes
the <type> field from the minimap schema in CCmpMinimap.cpp and from all
affected templates, making the minimap component resource-agnostic and
simplifying template definitions.

Refs: #8170
2025-10-26 21:43:25 +01:00
real_tabasco_sauce
c43aa1d609 fix debug build by directly setting probability for the inverse binomial in Decay.cpp 2025-10-08 17:00:09 +02:00
real_tabasco_sauce
f8e0a78d6d Add a random chance for a decay sinking event to occur.
Adds a 1/125 chance for a corpse to undergo a decay movement in a given frame.
This allows a probability passed from the template to determine the sinking behavior of the entity.
Fixes #7548
2025-09-23 17:11:12 +02: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
4136b2f6f7
Clone InitAttributes for serialization test
Commit 8b11f6a151 requires InitAttributes to be available, which isn't
the case for the secondary context in serialization test. So clone
InitAttributes to make it available.

```
ERROR: JavaScript error: simulation/helpers/Commands.js line 89
InitAttributes is not defined
  reveal-map@simulation/helpers/Commands.js:89:7
  ProcessCommand@simulation/helpers/Commands.js:932:23
ERROR: Failed to call ProcessCommand() global script function
```

Reported-by: phosit <phosit@autistici.org>
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-09-06 13:13:25 +02:00
phosit
d85eef067b Make TaskManager independent of Future
`TaskManager` and `Future` where coupled together. When a task is pushed
a future is returned. Also the `Future::Wrap` function was inconvenient
to use.
Now `TaskManager::PushTask` doesn't return a `Future` anymore. This
alows to use different `Future`-like types.
Also it's possible to easily use the `Future` with a different type that
implements a `PushTask` function.
2025-08-28 20:01:39 +02:00
Itms
7038d87454 Update SpiderMonkey to ESR 128.13
Fixes #7662
2025-08-15 19:43:34 +02:00
Ralph Sennhauser
5b5f678e3f
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Add markers to precompiled.h header includes to avoid
include-what-you-use wanting them to be removed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-14 20:15:30 +02:00
Ralph Sennhauser
3647921bed
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-13 19:38:21 +02:00
phosit
0a2bd6a5a4 Use proper js-modules for ai common-api
The common-api already used a coding pattern which was called modules.
That is replaced with native js-modules.

Refs: #8081
2025-08-13 14:04:16 +02:00
phosit
4da78788c8 Use proper js-modules for petra
Petra already used a coding pattern which was called modules. That is
replaced with native js-modules.

Refs: #8081
Fixes: #1024
2025-08-13 14:04:16 +02:00
Ralph Sennhauser
4a14e382d5
Replace deprecated std::is_pod
std::is_pod is deprecated in C++20 and as such triggers
-Wdeprecated-declarations when built with C++20, "is_standard_layout &&
is_trivial" is the equivalent, so migrate to that.

While at it replace runtime dispatch with compile time and reduce the
required trait for memcpy to what is really needed.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-12 20:45:15 +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
Ralph Sennhauser
86255ed66f
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-03 17:16:27 +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