2019-02-19 18:37:52 +00:00
## JGR's Patchpack: Low level changes
This document describes low-level changes to the codebase which are not generally visible when actually running/playing the game, this is a non-exhaustive list.
2020-12-10 19:37:54 +00:00
2019-02-19 18:37:52 +00:00
This document does not describe the player-visible changes/additions described in the main readme.
### Crash logger and diagnostics
2022-06-05 14:54:22 +00:00
* Additional logged items: current company ID, map size, configure invocation, thread name, recently executed commands, static NewGRFs.
2020-02-13 00:00:29 +00:00
* Additional logged platform-specific items: detailed OS version (Unix), signal details (Unix, Mac), exception record data (Windows).
2019-02-19 18:37:52 +00:00
* Better handling of crashes which occur in a non-main thread (ask the main thread to do the crash screenshot and savegame).
2019-04-24 17:58:50 +00:00
* Support logging register values on Unix and Mac.
2019-02-19 18:37:52 +00:00
* Support using libbfd for symbol lookup and line numbers (gcc/clang).
2019-04-24 17:58:50 +00:00
* Support using gdb/lldb if available to add further detail to the crashlog (Unix, Mac).
2020-02-13 00:00:29 +00:00
* Support using sigaction and sigaltstack for more information and correct handling of stack overflow crashes (Unix).
* Attempt to log stack overflow and heap corruption exceptions (Windows).
2019-02-19 18:37:52 +00:00
* Demangle C++ symbols (Unix).
2019-02-22 22:38:26 +00:00
* Attempt to handle segfaults which occur within the crashlog handler (Unix).
2019-05-27 23:43:58 +00:00
* Emit a "crash" log, savegame and screenshot on multiplayer desync.
* Add crash/desync information to output screenshot and savegame files.
2019-10-20 18:13:17 +00:00
* Multiplayer server and client exchange desync logs after a desync occurs.
2022-12-20 23:43:31 +00:00
* Multiplayer clients send state hashes and random values since the last sync to the server after a desync, to identify which frame first diverged.
2019-10-20 18:13:17 +00:00
* Decrease sync frame period when desync occurs.
2019-02-19 18:37:52 +00:00
#### Assertions
2020-12-10 19:37:54 +00:00
* Various assertions are extended to log further information on failure.
* Various assertions which check the state of a tile are extended to dump the tile state (m1 - m8, etc.) on failure.
2019-02-19 18:37:52 +00:00
#### Scope annotations
2020-12-10 19:37:54 +00:00
* Scopes (in the main thread) can be annotated with a functor/lambda which is called in the event of a crash to provide further information to add to the crash log.
2019-02-19 18:37:52 +00:00
#### NewGRF debug window
2020-12-10 19:37:54 +00:00
* Add various supplementary non-GRF information, e.g. vehicle variables and flags.
2022-06-05 14:54:22 +00:00
* Add NewGRF sprite group dumping and related functionality.
2019-02-19 18:37:52 +00:00
#### Logging
2023-06-03 20:39:04 +00:00
* Add yapfdesync, linkgraph, sound, and command log levels.
2020-12-10 19:37:54 +00:00
* Extend desync and random logging.
2019-02-19 18:37:52 +00:00
### Map
2020-12-10 19:37:54 +00:00
* Store tunnel start/end pairs in a pool, indexed in the start/end tiles.
* Set bit in map if level crossing is possibly occupied by a road vehicle.
* Cache inferred one-way state of road tiles.
* De-virtualise calls to AnimateTile().
* Cache animated tile speed.
2021-03-02 19:48:50 +00:00
* Cache whether water tiles have water for all neighbouring tiles.
* Improve performance of arctic snow line checks.
2019-02-19 18:37:52 +00:00
### Viewport
2020-12-10 19:37:54 +00:00
* Cache bridge/tunnel start and ends.
* Cache station sign bounds.
* Split sprite sort regions when more than 60 sprites present.
* Reduce unnecessary region redraws when scrolling viewports.
* Reduce viewport invalidation region size of track reservation and signal state changes.
* Cache landscape background in map mode.
2022-11-24 23:17:04 +00:00
* Partial parallelisation of non-map mode viewport rendering.
2020-02-21 20:32:39 +00:00
### Rendering
2020-12-10 19:37:54 +00:00
* Track dirty viewport areas seperately from general screen redraws, using a zoom-level dependant sized grid.
* Use a rectangle array for general screen redraws instead of a block grid.
* Add a dirty bit to windows and widgets, for redrawing entire windows or widgets.
* Clip drawing of window widgets which are not in the redraw area.
* Reduce unnecessary status bar and vehicle list window redraws.
* Filter out tile parts which are entirely outside the drawing area, within DrawTileProc handlers.
2021-03-02 19:48:50 +00:00
* Improve performance of drawing rail catenary.
2023-06-03 20:39:04 +00:00
* Cache which window types are currently shown.
2019-02-19 18:37:52 +00:00
### Data structures
2020-12-10 19:37:54 +00:00
* Various data structures have been replaced with B-tree maps/sets (cpp-btree library).
* Various lists have been replaced with vectors or deques, etc.
* Remove mutexes from SmallStack, only used from the main thread.
2022-12-20 23:43:31 +00:00
* Add a third parameter p3, and an auxiliary data mechanism to DoCommand/CommandContainer.
2020-12-10 19:37:54 +00:00
* Add a free bitmap for pool slots.
* Maintain free list for text effect entries.
* Many fields have been widened.
2019-02-19 18:37:52 +00:00
### Vehicles
2020-12-10 19:37:54 +00:00
* Cache the sprite_seq bounds.
* Index the order list in a vector.
* Observe the operation of the NewGRF when getting the vehicle image/sprite, and elide further calls to the NewGRF if it can be determined that the result will be the same.
* Update train/road vehicle image/sprite on demand (i.e. when on screen) when image is continuously updated by GRF.
* Add consist flag for the case where no vehicles in consist are on a slope.
* Add vehicle flag to mark the last vehicle in a consist with a visual effect.
* Index the vehicle list in per type arrays for use by CallVehicleTicks.
* Cache whether the vehicle should be drawn.
2022-12-20 23:43:31 +00:00
* Pre-compute engine refit capacity callbacks if possible.
2019-02-19 18:37:52 +00:00
### Network/multiplayer
2020-12-10 19:37:54 +00:00
* Add supplementary information to find server UDP packets and reply in an extended format with more info/wider fields if detected.
* Paginate UDP packets longer than the MTU across multiple packets.
* Use larger "packets" where useful in TCP connections.
* Send vehicle caches from network server to clients to avoid desyncs caused by non-deterministic NewGRFs.
2019-02-19 18:37:52 +00:00
### Sprites/blitter
2020-12-10 19:37:54 +00:00
* Add a fast path to Blitter_32bppAnim::Draw.
* Replace sprite cache implementation.
2021-03-02 19:48:50 +00:00
* Add brightness adjusting modes to non-8bpp blitters.
2019-02-19 18:37:52 +00:00
### Link graph
2020-12-10 19:37:54 +00:00
* Completely change link graph job scheduling to make the duration of a job and the number of jobs per thread instance variable according to the estimated size of the job.
* Various use of custom allocators, etc.
* Early abort link graph threads if abandoning/quitting the game.
* Various forms of caching and incremental updates to the link graph overlay.
* Change FlowStat from an RB-tree to a flat map with small-object optimisation.
* Change FlowStatMap from an RB-tree to a B-tree indexed vector.
2022-12-20 23:43:31 +00:00
* Change LinkGraph::EdgeMatrix to a sparse storage format.
2020-12-10 19:37:54 +00:00
* Replace MCF Dijkstra RB-tree with B-tree.
* Reduce performance issues when deleting stale links with refit to any cargo.
2022-12-20 23:43:31 +00:00
* Dynamically adjust accuracy parameters in MCF 1st pass to avoid computing large numbers of excessively small flows.
2019-10-20 18:13:17 +00:00
### Pathfinder
2020-12-10 19:37:54 +00:00
* YAPF: Reduce need to scan open list queue when moving best node to closed list
2019-02-19 18:37:52 +00:00
### Save and load
2020-12-10 19:37:54 +00:00
* Feature versioning, see readme and code.
* Extend gamelog to not truncate version strings.
* Save/load the map in a single chunk, such that it can be saved/loaded in one pass.
* Various other changes to savegame format and settings handling, see readme and code for details.
* Replace read/write accessors and buffering.
* Perform savegame decompression in a separate thread.
* Pre-filter SaveLoad descriptor arrays for current version/mode, for chunks with many objects.
2021-03-02 19:48:50 +00:00
* Support zstd compression for autosaves and network joins.
2019-10-20 18:13:17 +00:00
2020-07-12 10:50:54 +00:00
### AI/GS
2020-12-10 19:37:54 +00:00
* [AI/GS script additions ](docs/script-additions.html ).
* Add AI/GS method to get current day length.
* Add GS method to create river tiles.
2022-01-09 23:03:12 +00:00
* Add AI/GS methods related to road and tram types.
2020-12-10 19:37:54 +00:00
* Add workaround for performance issues when attempting to create a town when no town names are left.
* Fixup a GS otherwise inconsistent with day length.
2020-07-12 10:50:54 +00:00
### NewGRF
2020-12-10 19:37:54 +00:00
* [NewGRF specification additions ](docs/newgrf-additions.html ).
* Add workaround for a known buggy NewGRF to avoid desync issues.
2022-11-24 23:17:04 +00:00
* Apply many optimisations to VarAction2 deterministic sprite groups.
* Avoid making callbacks which can be pre-determined to be unhandled, or which can be statically determined ahead of time.
2022-06-05 14:54:22 +00:00
* Avoid animating industry tiles which are not actually animated in the current layout.
2022-12-20 23:43:31 +00:00
* Setting the animation frame to its current value no longer triggers a redraw.
* Animation is not started if it can be determined that it would stop immediately.
2022-11-24 23:17:04 +00:00
* Avoid unnecessarily triggering or redrawing NewGRF houses.
2020-07-12 10:50:54 +00:00
2020-12-04 17:26:48 +00:00
### SDL2
2020-12-10 19:37:54 +00:00
* Update whole window surface if >= 80% needs updating.
* Only pass a single rectangle to SDL_UpdateWindowSurfaceRects to prevent screen tearing.
* Allow using the hash key (#) as a hotkey.
2020-12-04 17:26:48 +00:00
2019-10-20 18:13:17 +00:00
### Other performance improvements
2020-12-10 19:37:54 +00:00
* Use multiple threads for NewGRF scan MD5 calculations, on multi-CPU machines.
* Avoid redundant re-scans for AI and game script files.
* Avoid iterating vehicle list to release disaster vehicles if there are none.
* Avoid quadratic behaviour in updating station nearby lists in RecomputeCatchmentForAll.
2019-02-19 18:37:52 +00:00
### Command line
2020-12-10 19:37:54 +00:00
* Add switch: -J, quit after N days.
* Add savegame feature versions to output of -q.
2019-02-19 18:37:52 +00:00
### Configure/build
2020-12-10 19:37:54 +00:00
* Changes to gcc/clang detection and flags
* Changes to version detection and the format of the version string.
* Minor CMake changes.
2019-02-19 18:37:52 +00:00
### Misc
2020-12-10 19:37:54 +00:00
* Use of __builtin_expect, byte-swap builtins, overflow builtins, and various bitmath builtins.
* Add various debug console commands.
* Cache font heights.
* Cache resolved names for stations, towns and industries.
* Change inheritance model of class Window to keep UndefinedBehaviorSanitizer happy.
* Various other misc changes and fixes to reduce UndefinedBehaviorSanitizer and ThreadSanitizer spam.
* Add a chicken bits setting, just in case.
2022-12-20 23:43:31 +00:00