Commit graph

244 commits

Author SHA1 Message Date
Ralph Sennhauser
518ed74496
Replace all use of POSIX unlink
Use `<filesystem>` instead of `unlink` and remove `unlink` portability
wrapper.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-15 15:33:59 +02: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
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
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
Vantha
4d08446285 Improve Engine.GetTextSize deprecation message 2025-12-23 14:37:23 +01:00
Itms
866d6f0527
Add an engine "compatible" version
When a patch version is released, it must declare compatibility with the
previous patch versions of the same main release. This allows players to
keep replaying their games and to keep playing online with users of
other patches of the same main release.

This should have anticipated for dae7a8c394
2025-10-26 09:16:46 +01:00
Itms
50f6da2a13
Use the PYROGENESIS_VERSION macro instead of a global
Reviewed-At: https://gitea.wildfiregames.com/0ad/0ad/pulls/8222
2025-10-26 09:16:44 +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
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
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
8a6d7b6c65
Fix includes in source/ps
Make include-what-you-use happy with some iles in source/ps and fix what
needs to be fixed.

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

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-28 16:59:04 +02:00
Ralph Sennhauser
9c7bbd531f
Fix some includes in source/lib
Make include-what-you-use happy with some files in source/lib and fix
what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-25 07:11:21 +02:00
Itms
781d2b6ab6
Throw exception, detected by C4834 warning 2025-07-23 10:21:27 +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
Ralph Sennhauser
863b0b90b7
Update headers in i18n
Remove external_libraries headers for icu and tinygettext, as they
neither add any workarounds needed and as quite a few other libraries
don't have such a header either. As for the warnings suppressed, this is
no longer needed as they were fixed and with vs2019 added support for
-isystem or equivalent would make this useless eitherway.

Further make include-what-you-use happy with files in source/118n and
fix what needs to be fixed after.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-01 09:01:00 +02:00
trompetin17
571b536e1f
Log GUISize/GetTextSize deprecations once
Replace repeated LOGWARNING calls with ONCE(LOGWARNING) in
JSInterface_CGUISize.cpp and JSInterface_Main.cpp.

Why – The old behaviour printed a warning every time the deprecated
API was used, cluttering the log and annoying modders. We still want to
nudge them toward the new APIs (object.size = {...} and
guiObject.GetPreferedTextSize/getTextSize), but a single reminder is
enough.

What changed

CGUISimpleSetting<CGUISize>::DoFromJSVal now wraps the deprecation
message in ONCE(...).

Engine.GetTextSize warning is likewise wrapped.

Impact – Functionality is unchanged; only the frequency of the
warnings is throttled to one per session, making the transition less
intrusive and more user-friendly.
2025-06-29 09:12:21 -05:00
trompetin17
e845da025a
Add deprecation warning to GetTextSize API
Adds a runtime warning to `Engine.GetTextSize` indicating that the API
is deprecated and will be removed in a future version.

This API does not simulate GUI rendering accurately, as it treats markup
tags like [color], [font], or [icon] as visible characters. This leads
to incorrect size measurements in modern GUI layouts.

New recommended alternatives:
- Use `Engine.GetGUITextSize(...)` for accurate measurement of raw text
  blocks, fully simulating GUI rendering.
- Use `guiObject.getTextSize()` when working within a specific GUI
  object, as it accounts for maxWidth, padding (bufferZone), and object
  constraints.

A warning is now emitted at runtime to guide developers toward these
updated APIs.
2025-06-26 17:11:24 -05: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
elexis
67eaa8f1a9
Fix change perspective in replays
Fixes change perspective features of multiplayer replays following cheat
protection in 023527e56e.

Fixes: #8020
2025-06-03 13:52:26 +02:00
trompetin17
bdd94bd264
Add font engine aware of Gui.scale
This commit enhances text rendering by leveraging FreeType and a dynamic
font atlas. Previously, GUI scaling relied on bitmap fonts, which led to
blurry and distorted text when scaling up. Now, we scale the font size
directly using FreeType, resulting in much sharper and more readable
text at any GUI scale.

Key improvements:
- Replaced bitmap font scaling with true font size scaling via FreeType.
- Reduced glyph cache dependency on fixed positions, relying on shader
  scaling instead.
- Switched to float-based glyph positioning for more accurate rendering
  and scaling.

These changes ensure clean and consistent text appearance across
different GUI scales.
2025-05-26 13:12:47 -05:00
phosit
2d206708cd Start Atlas by closing the root page
Theere is now an  `Engine.startAtlas` property that will start Atlas
when it's returned from the root page. The `Engine.RestartInAtlas`
function is removed.
2025-03-26 13:07:57 +01:00
phosit
40762c257d Quit Engine by closing the root page
When the root page gets closed the engine quits instead or crashing.
The root pages are changed to use that mechanism to quit the engine.
This removes the need of `Engine.Exit` for the GUI.
2025-03-12 12:07:37 +01:00
Itms
9f023825e0
Export a 10-char commit hash in the build version
This avoids collisions in the user report, fixes #7174.
Update the user report version to account for the new build version
format, fixes #7173.

The build version displayed in the GUI is kept at 5 characters for
main menu clutter concerns.
2025-01-07 13:51:45 +01:00
elexis
e19a5eda9f Fix changing view to observer
`id` was compared to the wrong player.
This defect was introduced in 023527e56e.
2025-01-05 15:16:41 +01:00
Dunedan
8a9813234e
Remove GetFileMTime() 2024-12-29 09:32:17 +01:00
Dunedan
894e349ebf
Add a deprecation warning for using GetFileMTime() 2024-12-29 09:32:17 +01:00
elexis
023527e56e Prevent players to reveal the map from GUI script
`Engine.SetViewedPlayer` and `Engine.SetPlayerID` could be used to
reveal the map from GUI scripts and the in game console.

This is prevented by querying the simulation whether this player is
allowed to call thous functions.

These two vulnerabilities were introduced with their respective
features:
20e7d2224a introduced SetPlayerID to allow controlling other players
	using the developer overlay.
a2f7d4d82a introduced SetViewedPlayer to allow observers to change the
	perspective.
2024-12-27 19:01:53 +01:00
phosit
b90280855f Multiplayer saved games
Enables to save multiplayer games.
When the savegame is loaded, the settings are frozen (except the non-AI-player assignment settings).
2024-12-19 21:36:51 +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
b698558102 Get rid of svnversion. 2024-08-20 19:10:54 +02:00
phosit
ba04cf3bd1 Use templates instead of macros to restrict access to the VFS
Subscribers: @sera, @Stan, @wraitii, @vladislavbelov

Differential Revision: https://code.wildfiregames.com/D5195
This was SVN commit r28066.
2024-04-13 17:12:47 +00:00
phosit
2abf0d8db2 Fix missing includes when building without precompiled headers
Patch By: @Riesi
Comments By: @sera
Differential Revision: https://code.wildfiregames.com/D5209
This was SVN commit r27973.
2023-12-04 20:23:37 +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
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
phosit
29b57026a6 Remove Engine.IsGameStarted completely
Revert 89e511def9

refs: #4211, bc6da5e3f2

Accepted By: elexis
Differential Revision: https://code.wildfiregames.com/D5152
This was SVN commit r27883.
2023-10-12 19:20:56 +00:00
phosit
3fff9df4a0 Return CTerrain and CUnitManager references from CWorld instead of pointers
Accepted By: @vladislavbelov
Comments By: @Stan
Differential Revision: https://code.wildfiregames.com/D4739
This was SVN commit r27861.
2023-09-26 20:10:40 +00:00
phosit
4524188611 Rename requires to required in Hotkey.*
Accepted By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5104
This was SVN commit r27812.
2023-08-23 12:24: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
Angen
017fe7e263 Restrict access for Read/WriteFile functions
For security reasons planing to restrict access for ReadFile,
ReadFileLines, WriteJSONFile, ReadJSONFile, ListDirectoryFiles,
FileExists to the following folders/files:

"gui, simulation, maps, campaigns, saves/campaigns,
config/matchsettings.json, config/matchsettings.mp.json"
adding "moddata" if some mods need to access and ship custom files that
don't fit into other locations mentioned above

Differential revision: D4617
Reviewed by: @phosit
Comments by: @Stan @vladislavbelov
Fixes: #5850

This was SVN commit r27202.
2022-11-05 08:33:27 +00:00
Angen
281bb0b2ec Remove user.cfg from javascript
remove path from javascript
path is defined by the configuration scope

combine some calls
remove not needed calls

Differential revision: D4616
Accepted by: @Freagarach, @nani
Comments by: @phosit
This was SVN commit r27192.
2022-11-02 07:21:25 +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
vladislavbelov
a8caed8348 Uses correct value_type to iterate over the map in JSInterface_Hotkey. Refs a4852c4c01.
Patch By: phosit
Differential Revision: https://code.wildfiregames.com/D4633
This was SVN commit r26847.
2022-05-02 10:03:34 +00:00
Stan
687174e5d9 Fix crash when creating JSON file that do not exist.
Tested by: @Langbart
Refs: #6450
Differential Revision: https://code.wildfiregames.com/D4529
This was SVN commit r26604.
2022-03-07 15:46:28 +00:00
bb
8eecc39e71 Let the Gamesetup.cpp Autostart (starting from cl) use the gamesettings via the autostart gui page.
Comments and testing By: Langbart
Fixes #6433
Differential Revision: D4492
Includes/Obsoletes D4287

This was SVN commit r26584.
2022-03-06 21:12:16 +00:00
Stan
9ce9273c35 Add quotes to the logged filenames.
Differential Revision: https://code.wildfiregames.com/D2212
This was SVN commit r26546.
2022-03-05 18:30:38 +00:00
Stan
b9d3d00c50 Show system_info.txt, console.txt, json file, userreport_hw.txt paths in the terminal when it's written to the disk.
Discussed with: @vladislavbelov
Idea by: @elexis
Differential Revsion: https://code.wildfiregames.com/D2212

This was SVN commit r26544.
2022-03-05 17:28:00 +00:00
bb
7c3aed5f36 Set the size of the overlaybox without relying on the arbitrary initSize
Comments By: vladislav
Differential Revision: D4489
This was SVN commit r26523.
2022-03-02 16:27:11 +00:00