Commit Graph

22285 Commits

Author SHA1 Message Date
Peter Nelson 440a633fcc Codechange: Remove shrink_to_fit for more lists.
A comment about "will actually do nothing" is out of date as that is not the case with std::vector.

These lists are always short lived (either within a command handler or in a window) so don't shrink_to_fit.
2024-04-27 19:25:34 +01:00
Peter Nelson 33aedc43a5 Codechange: Shrink GUIList vectors less often, reserve before use.
After sorting and filter lists for GUI, we often shirnk them to reduce size. However this has very little benefit:

1) The memory has already been allocated, so it doesn't prevent that memory being required.
2) It causes a new allocation and copy when the vector is shrunk, actually using more memory.
3) The list is in window state, so the lifetime is only while the window is open.
4) When a filter is clearer, the original size will be needed again, which will cause another allocation.

In fact it is beneficial to reserve to the known maximum in most cases, so do that instead.
2024-04-27 19:25:34 +01:00
translators 8308998388 Update: Translations from eints
english (au): 3 changes by krysclarke
russian: 3 changes by Ln-Wolf
finnish: 6 changes by hpiirai
dutch: 6 changes by Afoklala
portuguese (brazilian): 4 changes by pasantoro
polish: 3 changes by pAter-exe
2024-04-27 04:40:44 +00:00
Peter Nelson bf8de188ec
Codechange: Use member initialization of GRFFilePropsBase. (#12581)
Don't blame compilers for our sloppy initialisation.

Removes memset, and lengthof.
2024-04-26 22:58:54 +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 a6d401debf
Fix: Properly test for presence of waypoint in NewGRF resolver. (#12579)
Test whether the BaseStation itself a Station or Waypoint, instead of by the station class ID assigned to it.
2024-04-26 17:47:53 +01:00
translators a60a81f34e Update: Translations from eints
swedish: 7 changes by joeax910
vietnamese: 15 changes by anmatngu
greek: 31 changes by gh658804, 2 changes by KyriakosMich
hungarian: 2 changes by egri-nagy
portuguese (brazilian): 2 changes by pasantoro
2024-04-26 04:41:25 +00:00
Rubidium 0fdabca605 Codechange: use std::span instead of custom span in TGP 2024-04-26 06:15:29 +02:00
Peter Nelson f44d8fa2e4
Codechange: Remove CDECL from filter functions. (#12578)
These functions are not passed to qsort()...
2024-04-25 22:13:23 +01:00
Peter Nelson 0075a95278
Codefix: Make three _filter_funcs definitions distinct. (#12573)
Rename the GUIList function lists defined as the same symbol.
2024-04-25 21:01:15 +01:00
Peter Nelson 5bc9854be2
Codechange: Make sort list function lists safer. (#12574)
GUIList has a pointer only to the start of each sort/filter func list, which has the potential for UB as it is unable to validate that the selected sort or filter type is in range.

Use a std::span instead and check if the selected type is in range before using it.
2024-04-25 21:00:49 +01:00
Jonathan G Rennison 9b747a173d Fix #12509: Maintain timer sort invariants when changing period 2024-04-25 20:08:24 +02:00
Jonathan G Rennison 11ec156b64 Codechange: Add a priority field to TimerGameTick::TPeriod
Use this as the primary sort key for TimerGameTick::TPeriod,
to avoid container sort order changes on timer period saveload.
See: #12509
2024-04-25 20:08:24 +02:00
André Cheng 57f5d27427 Doc: Fix documentation of GetDefaultValueCallback 2024-04-25 20:07:54 +02:00
André Cheng ceb0053dd9 Codechange: Correct return type of GetDefaultValueCallback 2024-04-25 20:07:54 +02:00
André Cheng 339b0ea0ff Change: Show correct default value and unit for vehicle service interval setting 2024-04-25 20:07:54 +02:00
André Cheng fd80a1ec66 Fix #11345: Use correct default button value for vehicle service interval setting 2024-04-25 20:07:54 +02:00
André Cheng a4071b78d7 Codechange: Add callback to IntSettingDesc to support more default values 2024-04-25 20:07:54 +02:00
translators e8d25d68b9 Update: Translations from eints
russian: 2 changes by George-VB
2024-04-25 04:42:18 +00:00
Peter Nelson e8249e9075
Codechange: Pass buffers for TarFile's ExtractString as span. (#12567)
ExtractString does not need to find a string terminator as StrMakeValid already does this, so simply pass the full bounds of the buffer.

Removes lengthof, array indices, and needs only the buffer as a parameter.
2024-04-24 21:34:21 +01:00
Peter Nelson 5159aa81d4
Codechange: Use iterators when enabling industries. (#12569)
Removes lengthof and array indices.
2024-04-24 21:33:49 +01:00
Peter Nelson 26bb87ebf1
Codechange: Replace SaveLoad var length arrays with switch block and sizeof. (#12570)
SlCalcConvMemLen(), SlCalcConfFileLen() and CalcOldVarLen() follow a pattern of looking up part of a value in an array.

These function returns the size of bytes of a variable type, but is not very clear. Replace with a switch block instead.

Removes lengthof, array indices, and magic numbers.
2024-04-24 21:33:29 +01:00
Peter Nelson 1dc94d0670
Codechange: Construct string_view with first+last. (#12568)
Avoids needing to calculate size when we already have last.
2024-04-24 21:29:33 +01:00
Peter Nelson 6a3f50aa72
Codechange: Replace separate EffectVehicle arrays. (#12565)
Combine 3 separate arrays into a single struct. This keeps related data together, and avoids needing to check that each array is same length.

Use of constexpr construct ensures data in the array is not default-initialised.

Removes lengthof.
2024-04-24 21:29:12 +01:00
Peter Nelson e20f48799e
Codechange: Make StringToContentType() clearer. (#12566)
Decouples string to ContentType mapping from position within enum.

Slightly less efficient, but removes lengthof, array indices, and casting.
2024-04-24 21:26:31 +01:00
Peter Nelson 5e689ce25e
Codechange: Store cursor sprites in vector. (#12564)
Combine two separate fixed length arrays to allow simpler iteration.

No need to check that arrays are all the same length.
No need to separately store the number of sprites to draw.
Removes the upper limit of the number of sprites that can be drawn.

Removes lengthof and array indices.
2024-04-24 21:26:07 +01:00
translators 9121770582 Update: Translations from eints
korean: 3 changes by telk5093
catalan: 3 changes by J0anJosep
french: 7 changes by ottdfevr
polish: 7 changes by pAter-exe
2024-04-24 04:40:54 +00:00
Peter Nelson ac6a945e26
Revert 2408a68910: Remove work around for an MSVC bug from 17 years ago. (#12557) 2024-04-23 17:05:08 +01:00
Koen Bussemaker bef11941c6 Change: Allow rail and road depot overbuilding in current orientation in order to connect to rail or road 2024-04-23 13:11:31 +02:00
translators 95de90dd4e Update: Translations from eints
norwegian (bokmal): 7 changes by eriksorngard
danish: 7 changes by bscargo
portuguese (brazilian): 4 changes by pasantoro
2024-04-23 04:40:32 +00:00
Peter Nelson 3814adaba8
Codechange: Simplify GetScrolledItemFromWidget() (#12556)
Return `auto`, which allows working with const containers, and use std::next instead of std::advance.
2024-04-22 19:00:14 +00:00
translators c82a2575d7 Update: Translations from eints
english (au): 3 changes by krysclarke
english (us): 3 changes by 2TallTyler
greek: 3 changes by gh658804
russian: 3 changes by Ln-Wolf
finnish: 5 changes by hpiirai
turkish: 7 changes by BeratSJ
portuguese: 3 changes by azulcosta
portuguese (brazilian): 3 changes by pasantoro
2024-04-22 04:40:33 +00:00
Rubidium ded4d63db2 Codechange: simplify access to the current screenshot format 2024-04-21 21:07:05 +02: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 3b01d31280
Fix 8746be8: Reinstate current order test when removing road stop. (#12552)
#12144 replaced pool iteration with FindVehiclesWithOrder, however the test for current_order being OT_GOTO_STATION was erroneously removed.
2024-04-21 19:41:25 +01:00
translators c073165e34 Update: Translations from eints
greek: 5 changes by gh658804
finnish: 2 changes by hpiirai
catalan: 4 changes by J0anJosep
2024-04-21 04:42:00 +00:00
Rubidium aa895535e6 Fix 5008706: improved scenario editor tooltips in map generation stages are out of place 2024-04-20 21:56:27 +02: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
Peter Nelson b4e00fa738
Codechange: Replace C-casts in pool functions. (#12541) 2024-04-20 16:50:13 +01:00
Loïc Guilloux c5ef47ee09
Codechange: [Script] Use std::unique_ptr for Company::ai_instance (#12544) 2024-04-20 16:58:46 +02:00
Rubidium 1dfd0c19f4 Fix: allow only 255 league tables, as 255 is the invalid id sentinel 2024-04-20 16:53:04 +02:00
Rubidium c377c4740d Codechange: replace cpp_lengthof with safe alternatives 2024-04-20 13:36:19 +02:00
Peter Nelson a1a01e21cf
Change: Use std::make_unique instead of passing new() (#12539) 2024-04-20 11:20:49 +01:00
Rubidium fc7f184dbd Codechange: move knowledge about 'packed' orders to the saveload code 2024-04-20 11:58:07 +02:00
Rubidium 1691b41b54 Codechange: use C++ containers for parsing the settings int lists 2024-04-20 11:57:45 +02:00
Rubidium 434c49a1f8 Codechange: remove now unused endof macro 2024-04-20 11:30:46 +02:00
Rubidium 8fe5fdf122 Codechange: use std::none_of to express clearer what the code does 2024-04-20 11:30:46 +02:00
Rubidium 8986fb0385 Codechange: replace C-style array-pointer methods with the appropriate C++ methods 2024-04-20 11:30:46 +02:00
Peter Nelson 2114888485
Change: De-template BaseSetTextfileWindow. (#12536)
The BaseSet type is not needed after the window is constructed, only the filename and name are required, which can be passed as parameters from `ShowBaseSetTextfileWindow()` instead.

This avoids compiling three instances of `BaseSetTextfileWindow`.
2024-04-20 10:30:29 +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