1
0
Fork 0
Commit Graph

968 Commits (7af16bff119577eed88a1e2cf2a7c74d9acb6a70)

Author SHA1 Message Date
Peter Nelson 7af16bff11
Codechange: Use vector for GRFFile parameters instead of array. (#13157)
This simplifies assigning default parameters and removes the param_end member.
2024-12-07 22:08:59 +00:00
Peter Nelson f5d78f9eba
Change: [NewGRF] Install translation tables into overridden NewGRF. (#12879)
When a NewGRF overrides another, any translation table that the overriding NewGRF installs will also be installed in the target file.

This allows the overridden NewGRF to make use of a cargo or rail/road type translation table without directly modifying the original file.
2024-12-07 11:26:53 +00:00
Peter Nelson ce5279a8dc Codechange: Implement SoundLoader interface and cache loaded sounds in memory.
Sounds are loaded into memory on first use, using the SoundLoader interface to support format conversion. Sounds are retained in memory to avoid reloading every time a sound is played.

This deduplicates WAV header parsing between NewGRF and baseset sounds, and will allow different audio formats to be supported.
2024-12-06 18:41:35 +00:00
Peter Nelson f56b6756f1 Codechange: Sort EngineOverrideManager for fast lookups.
Allows quickly finding the EngineID given the type, grfid and local id of an engine, instead a linear scan.

This can reduce loading time when lots of engines are present and also affects performance in-game.
Lookup can be on the order of 10000 times faster.
2024-12-05 18:17:58 +00:00
Peter Nelson bc2513975f Codechange: Don't inherit EngineOverrideManager from std::vector.
Inheriting from std::vector means some operations are needlessly complex, and shouldn't really be done anyway.
2024-12-05 18:17:58 +00:00
Peter Nelson e73d6fcaac Codechange: Store grfid with entity grfprops.
This allows using the grfid without having to dereference the grffile pointer.

Uses no extra storage as it fits within otherwise wasted padding space.
2024-12-05 18:17:58 +00:00
Peter Nelson e750d10cee
Codechange: Use std::array for per-NewGRF rail/road type maps. (#13142)
This allows initialisation to be simplified.
2024-12-05 18:17:25 +00:00
Peter Nelson 3a310f1802
Codechange: Store GRFConfig parameters in a vector. (#13137)
All GRFConfigs have space allocated for parameters, but only configured GRFConfigs need them.

Using a vector instead means that space is only used when parameters are used.
2024-12-01 15:15:21 +00:00
Peter Nelson b6aece5b88
Fix 51bd344f10: Incorrect translation table used for older NewGRFs. (#13131)
Incorrect logic was used to select the default translation table for older GRFs.
2024-11-29 07:46:08 +00:00
Peter Nelson 9bc64b553b
Codechange: Cache callback spritegroups. (#13111)
Each callback result requires a pool memory allocation, each of which is 24 bytes.

Build a cache of results so that if the same result is used later it refers to the same group.
2024-11-27 23:25:35 +00:00
Jonathan G Rennison f5a6a31e4a
Codefix: Avoid divide by 0 in div/mod type varaction2 adjusts (#13123) 2024-11-27 23:24:46 +00:00
Peter Nelson f9b5f78b8a Codechange: Use std::visit for GetActiveCargoLabel. 2024-11-19 18:27:19 +00:00
Michael Lutz d2496b6ec4 Add: [NewGRF] Callback for custom refit mask for engines/vehicles. 2024-11-18 22:10:38 +01:00
Michael Lutz a3ee05737f Add: [NewGRF] Vehicle prop that allows refittability based on cargo class intersection. 2024-11-18 22:10:38 +01:00
Peter Nelson 14e2839087
Codechange: Let's use this new emplace_back() thing. (#13081) 2024-11-15 20:28:17 +00:00
Peter Nelson 98c8445519
Codechange: Limit house default cargo label lists to original slot counts. (#13079)
Same as for IndustrySpec and IndustryTileSpec.
2024-11-15 08:07:02 +00:00
Peter Nelson 61aff3fa49
Codechange: Limit industry default cargo label lists to original slot counts. (#13072)
IndustrySpec and IndustryTileSpec cargo label lists are only used for original industries. Original industries can only have up to 2 inputs and 3 outputs. Therefore having space for 16 input/outputs slots is unnecessary

This saves 216 bytes per industry type, and 164 bytes per industry tile type.
2024-11-14 19:05:18 +00:00
Peter Nelson e076aaf740
Codefix: Use SpriteID when passing sprite IDs. (#13037) 2024-10-27 18:54:49 +00:00
Peter Nelson 51bd344f10
Change: Use default NewGRF cargo translation table. (#12646)
Instead of falling back to bitnum lookup or climate-dependent cargo types, install a default cargo translation table that performs either of these functions instead.

This allows better mapping of climate-dependent or bitnum cargo slots, falling back to INVALID_CARGO if they are not defined, and reduces special-casing.
2024-09-23 23:48:03 +01:00
Peter Nelson 9631c68ce6
Codefix: Implement explicit ByteReader::PeekDWord() instead of type-punning pointer. (#12928) 2024-09-12 06:49:20 +01:00
Jonathan G Rennison e477706bf5
Codechange: Add AssignBit function to assign the value of a single bit (#12934)
* Codechange: Add AssignBit function to assign the value of a single bit

* Codechange: Replace various uses of SB with AssignBit

* Codechange: Replace various uses of SB with a constant with SetBit
2024-09-10 08:36:58 -04:00
Peter Nelson b5264a72ae
Codechange: [NewGRF] Use reference to unique_ptr instead of .get() (#12919)
This allows assignment to reference when creating a new spec instead of setting and refetching.
2024-08-24 22:10:39 +01:00
Peter Nelson ff972ec4ff
Codechange: Store custom station layouts in a map instead of nested vectors. (#12898)
The map key is the platforms and length combined. This simplifies allocation and searching for layouts.
2024-08-14 19:58:56 +01:00
Peter Nelson a03ddb3ccb Add: [NewGRF] Station property 1E, extended station tile flags.
Properties 11, 14 and 15 to set pylons/nowires/blocked intrinsically only support 8 station tiles.

Add new property to define all three flags for each station tile layout.
2024-08-03 14:57:34 +01:00
Peter Nelson 6e553410d3 Feature: [NewGRF] Allow fixed layout up to 256 tiles per NewGRF rail station.
Allow using up to 256 tile layouts in property 0E or callback 24, which defines the layout to be saved into the map.

This was originally limited to 8, because station graphics above 8 referred to other station types but that was changed in 2007.

1) More efficient than using callback 14, as that needs to be checked every time a station tile is rendered.
2) The layout does not get changed when the station is changed (this may or may not be desirable!)

Using more than 256 layouts still requires callback 14.
2024-08-03 14:57:34 +01:00
Peter Nelson 3176de3f1d
Codefix: cargo_(dis)allowed for default refit masks are cargo classes, not CargoTypes. (#12884)
Use an alias for CargoClasses to avoid ambiguity.
2024-07-29 20:58:53 +01:00
Peter Nelson e22eb89b92 Codechange: Call BSWAP32() in the default_grf_overrides initializer.
This causes the BSWAP32 calls to happen only on first initialisation (BSWAP32 is not constexpr), instead of every time GRFs are reloaded.
2024-07-10 20:56:35 +01:00
Peter Nelson b090c8e9bd Codechange: Replace default overrides arrays with std::pair and use range-for.
This avoids indexed array access and use of lengthof.
2024-07-10 20:56:35 +01:00
Peter Nelson ba0acb87eb Fix #12832: Sanitise strings from NewGRF before logging them in Debug output.
NewGRF strings may not be UTF-8 encoded, which causes issues on Windows.
2024-07-10 12:53:23 +01:00
Jonathan G Rennison a43dacd988 Add: NewGRF custom road waypoint support 2024-06-24 22:12:08 +02:00
Jonathan G Rennison eebd5e47db Add: Road waypoint default graphics 2024-06-24 22:12:08 +02:00
Peter Nelson 22d70f9334
Codechange: Pass NewGRF ByteReader by reference. (#12786)
ByteReader must be present and not null, so don't use a pointer.
2024-06-15 10:55:26 +01:00
Peter Nelson 66044472d7 Codechange: Use std::unordered_map for NewGRF language_map.
NewGRFs only use a small subset of the available language IDs. Using an unordered_map allows only the reference languages to have space allocated.

This avoids manual new/delete of array.
2024-06-06 19:53:10 +01:00
Peter Nelson 579ce8eae0
Codefix: Find GRF override entries properly. (#12743)
My naive code from 16 years ago tested for GRF overrides in a way that will create empty 0 entries for each source GRF tested.
2024-06-04 18:06:19 +01:00
Peter Nelson 5fd23a2d70
Codechange: Pre-reserve vectors during NewGRF loading. (#12748)
Call reserve when we are given the number of elements up front. This reduces the number of reallocations and over-allocations done during loading.
2024-06-03 18:40:27 +01:00
Peter Nelson 96fc367bcf
Change: [NewGRF] Treat house max year 0xFFFF as MAX_YEAR. (#12740) 2024-06-01 12:54:49 +01:00
Peter Nelson 856ec901ca
Fix #12685: nullptr dereference when checking for equal loaded/loading groups. (#12686)
Always treat empty groups as non-equal. Given that the case of both being empty is handled earlier, they cannot both be equal and empty.

Additionally if a loaded or loading set are all the same, only add one reference.
2024-05-18 09:17:06 +01:00
Peter Nelson d5671030b1 Codechange: Add NewGRFSpecsBase class to hold class/index information.
Standardises how the class index is stored in the spec, instead of relying ot the Spec structs having the same members.

This allows retrieving class_index and index without searching or using pointer arithmetic.

'cls_id' is renamed to 'class_index' to make it clearer that it is an index rather than the multichar label of the class.
2024-05-11 02:12:41 +01:00
Peter Nelson cf96d49ced
Codechange: Use vector for airport tile layouts. (#12607)
Simplify AirportSpec data by storing layout information together in a vector, instead of separate arrays.

This removes manual memory management and separate count members.

The default layouts will be copied instead of always referring to the originals.
2024-05-02 11:37:54 +00:00
Peter Nelson f146680121
Codechange: Use vector for industry random sounds. (#12606)
Use a vector to store the list of random sounds played for an industry.

The removes manual memory allocation, flags to control memory management, a separate count member, and a try/catch block.
2024-05-01 19:55:00 +00:00
Peter Nelson 7147fe9e7a
Codechange: Use range-for when loading NewGRF deterministic sprite groups. (#12605) 2024-05-01 18:59:46 +00:00
Peter Nelson 1424a184d8
Codechange: Use vector/span when loading wagon overrides. (#12604)
Replaces manual memory allocation and passing pointer with size.
2024-05-01 18:23:27 +01:00
Peter Nelson 72c55128d2
Codechange: Remove write-only spec_id from RoadStopSpec. (#12582)
Comment is incorrect about its value too.
2024-04-26 21:56:30 +01:00
Peter Nelson d465257dd0
Fix 952d111: Houses and industry tiles could accept incorrect cargo. (#12547)
Default cargo label was not cleared (set to CT_INVALID) when using older 3-slot acceptance properties for house and industry tiles.

Missed in #12053 and #12062.
2024-04-21 19:46:05 +01:00
Peter Nelson 959ced71bb
Codechange: Add constants for original input/output cargo counts. (#12548)
This replaces some magic 3s and 2s.
2024-04-20 20:50:48 +01:00
Rubidium e441033d68 Codechange: use std::array instead of C-style array for produced/accepts cargo 2024-04-20 11:29:55 +02:00
Peter Nelson 1c31e4b68c
Change: Disallow using Action A to load sprites above the baseset unless reserved. (#12435)
Using Action A above the baseset is error prone as the sprites are not fixed and can be moved around.

Any NewGRF doing so is likely to break in the future, so force it to break instead.
2024-04-20 10:23:36 +01:00
Peter Nelson 052f421327 Change: Use vector/iterators/algorithms instead of C-array/loops for NewGRF classes. 2024-04-09 21:46:59 +01:00
Peter Nelson 34758d0921 Change: Allow string mapping by function instead of pointer.
This allows mapping of strings to objects that may be moved between loading stages.
2024-04-09 21:46:59 +01:00
Peter Nelson 2976a46d06
Fix 54be756: Terminating NUL byte was not skipped in ReadString(). (#12462) 2024-04-09 15:15:09 +01:00