Commit Graph

289 Commits (eca73a810c19ed5cfb3f24cb5560d0735e19ea00)

Author SHA1 Message Date
Loïc Guilloux 8a083cd7f8
Fix 68f2213: Don't use GetPoolSize() for end of pool iterator (#9461) 3 years ago
Charles Pigott f1dfc2f482 Codechange: Make OverflowSafeInt constexpr 3 years ago
Charles Pigott 549a58731f Codechange: Remove (unused) ability to specify min/max of OverflowSafeInt 3 years ago
Charles Pigott e6e2a67aa1 Codechange: Use GCC/clang builtins for overflow safety when supported 3 years ago
Charles Pigott 3d0d9edafd Fix: OverflowSafeInt could underflow
Notably, a company with an extremely negative amount of money would
suddenly become very rich
3 years ago
Charles Pigott 1e439979f7 Fix: OverflowSafeInt negation not handling INT64_MIN
INT64_MIN negated is above INT64_MAX, and would overflow.
Instead, when negating INT64_MIN make it INT64_MAX.
This does mean that -(-(INT64_MIN)) != INT64_MIN.
3 years ago
glx22 ce813ce644 Cleanup: Remove now unused FOR_EACH_SET_BIT_EX macro 3 years ago
glx22 89ab8b79a5 Codechange: Remove FOR_EACH_SET_BIT 3 years ago
Patric Stout 7dd5fd6ed4 Feature: framework to make savegames self-descriptive
We won't be able to make it fully self-descriptive (looking at you
MAP-chunks), but anything else can. With this framework, we can
add headers for each chunk explaining how each chunk looks like
in detail.

They also will all be tables, making it a lot easier to read in
external tooling, and opening the way to consider a database
(like SQLite) to use as savegame format.

Lastly, with the headers in the savegame, you can freely add
fields without needing a savegame version bump; older versions
of OpenTTD will simply ignore the new field. This also means
we can remove all the SLE_CONDNULL, as they are irrelevant.

The next few commits will start using this framework.
3 years ago
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 3 years ago
Patric Stout 28e90769f7 Codechange: use "[[maybe_unused]]" instead of a wide variety of other ways we had
While at it, replace OTTD_ASSERT with WITH_ASSERT, as this
is always set if assert() is valid. No matter if NDEBUG is set
or not.
3 years ago
Patric Stout 9fff00ba20
Codechange: C++-ify lists for SaveLoad (#9323)
Basically, this changes "SaveLoad *" to either:
1) "SaveLoadTable" if a list of SaveLoads was meant
2) "SaveLoad &" if a single entry was meant

As added bonus, this removes SL_END / SLE_END / SLEG_END. This
also adds core/span.hpp, a "std::span"-lite.
3 years ago
rubidium42 b9797a81c0 Codechange: pass large parameter by reference instead of value, especially in a recursive function 3 years ago
Peter Nelson 5ff15443e9 Cleanup: Replace single-use Pair struct with std::pair.
This struct is defined in geometry_type but not used by any geometry-related
code, only for subsidy code where both parameters are cast from int to
NewsReferenceType.
3 years ago
Patric Stout 4d501655ad
Fix: building on Raspberry Pi failed because of const vs constexpr (#8924) 3 years ago
Patric Stout 8e0d48a0f6
Fix: [SDL2] simplify what to redraw to prevent tearing (#8685)
When there are a lot of rects to redraw, of which one of the last
ones is almost the full screen, visual tearing happens over the
vertical axis. This is most visible when scrolling the map.

This can be prevented by using less rects. To simplify the situation,
and as solutions like OpenGL need this anyway, keep a single rect
that shows the biggest size that updates everything correctly.

Although this means it needs a bit more time redrawing where it
is strictly seen not needed, it also means less commands have
to be executed in the backend. In the end, this is a trade-off,
and from experiments it seems the approach of this commit gives
a better result.
3 years ago
Charles Pigott 9b800a96ed
Codechange: Remove min/max functions in favour of STL variants (#8502) 3 years ago
Charles Pigott 860c270c73 Codechange: Replace assert_compile macro with static_assert 4 years ago
Michael Lutz 79240eab1e Codechange: Make use of the improved C++17 emplace_back function. 4 years ago
TechGeekNZ 716c883737 Fix: Globally apply preprocessor directive coding style
Global; except for the 32-bit SSE blitter, which has some #DEFINEs
in not-very-nice places.
4 years ago
Patric Stout 56d54cf60e Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.

Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.

This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.

Addtiionally, this heavily improves our detection of libraries, etc.
4 years ago
Michael Lutz f2b40f40aa Codechange: Replace SmallPair with std::pair.
std::pair is already the smallest possible pair, and it already handles non-POD types correctly.
4 years ago
Charlène 2196cd3cf8 Fix: OpenBSD endianness detection 4 years ago
Jonathan G Rennison 150dfba95b Codechange: Remove std::function from Pool iteration wrapper
Add a separate template wrapper for filtered iteration
4 years ago
glx e3c75a30ba Fix: unused variable warnings 5 years ago
glx ae532008ff Cleanup: remove FOR_ALL_ITEMS 5 years ago
glx 68f22134cb Add: Allow iteration of pools in range-based for loops 5 years ago
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 5 years ago
Gabda 652fb40652 Codechange: Performance improvement in k-d tree FindNearest() 5 years ago
JMcKiern 04f659e768 Fix: Some typos found using codespell 5 years ago
Nikolas Nyby 28e11623bd Codechange: math functions - use cpp-style casts 5 years ago
Gabda b870596f15 Add #6887: Option to show zone inside local authority boundary of towns
Can be found at town information > local authority window
Layout for button is same as Graph Keys
Turn on/off for every town individually
5 years ago
glx 26aa3b8623 Remove: grow() helper function 5 years ago
Charles Pigott 9e19a5f93e Remove: (Simple)TinyEnumT 5 years ago
peter1138 66cd32a252 Codechange: Use std::underlying_type for DECLARE_POSTFIX_INCREMENT. 5 years ago
peter1138 ac1e1a272f Fix: Replace int with std::underlying_type in DECLARE_ENUM_AS_BIT_SET.
This fixes 64 bit uses of this macro.
5 years ago
glx ebd4f32d15 Cleanup: remove core/sort_func.hpp as it's not used anymore 5 years ago
glx 9195f2337a Codechange: use std::vector for _resolutions 5 years ago
Michael Lutz 38729297f9 Codechange: No need for AutoFreePtr if there's std::unique_ptr. 5 years ago
Michael Lutz 4e85ccf3c0 Codechange: Replace SmallStackSafeStackAlloc with std::array.
The only port that ever used it to make heap allocations instead of stack ones was the NDS port, which got thrown out some time ago.
5 years ago
glx 410b81537c Fix 801cbea9c: operator< is not always the best idea
Also removes unused and anyway broken SmallMap::SortByKey() function.
5 years ago
glx 801cbea9cc Codechange: use std::sort() for all std::vector types 5 years ago
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 5 years ago
Michael Lutz 8b1880187a Remove: AutoFreeSmallVector.
The last use was for storing a list of memory blocks. As the way these lists are accessed is very
specific, it is easier to just write an explicit destructor instead of trying to exactly match the behaviour.
5 years ago
Michael Lutz e804173595 Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector. 5 years ago
Michael Lutz c7b9987d08 Codechange: Switch DropDownList to directly use std::vector, thus making AutoDeleteSmallVector obsolete.
DropDownListItem are strongly managed using std::unique_ptr to ensure leak-free handling. Appropriate use
of move-semantics make intent a lot clearer than parameter comments and allows the compiler to generate
copy-free code for most situations.
5 years ago
Michael Lutz 05f4e73608 Codechange: Replace custom mutex code with C++11 mutex'es.
A conforming compiler with a valid <mutex>-header is expected.
Most parts of the code assume that locking a mutex will never fail unexpectedly,
which is generally true on all common platforms that don't just pretend to
be C++11. The use of condition variables in driver code is checked.
5 years ago
Michael Lutz 21d9e87b46 Fix #7165: Const overload SmallMap::Contains(key) compared wrong types.
Const and non-const Find() have different return types.
5 years ago
stormcone ee260e4704 Fix #7165: SmallMap::Erase(key) does not work correctly 5 years ago
glx22 66dd7c3879
Fix: MSVC warnings (#7423) 5 years ago