Skip to content

General refactors. #4

@HexDecimal

Description

@HexDecimal

Making a list of various changes to make this code more up-to-date. Most of these are easy on their own. It will just take time to do them all. I've already finished most of these kinds of changes to Umbra.

  • TCODList should be replaced with std::vector in all cases.
  • Remove new/delete from libtcod types. These can be treated as values without major issues. Any exceptions can use smart pointers instead of new.
  • Pointer types should express ownership, ideally with std::unique_ptr, but also std::shared_ptr if necessary. Non-owning pointers would still be raw of course.
  • Class attributes should be initialized. Just put {}; at the end of simple types rather than = nullptr; or = 0;. Any defaults should be moved from the class constructor code to the class itself.
  • Pointers to strings should be replaced with std::string in many cases. Mostly in non-contexpr cases such as class attributes or local variables. In some cases null strings should be replaced with empty strings. Always replace strdup.
  • #define X Y constants should generally be replaced with static constexpr auto X{Y};/static constexpr auto X = Y; constants.
  • #define macros should all be replaced with constexpr functions.
  • Low level calls such as memcpy and strcmp should generally be replaced with high level operations.
  • C-style arrays like int foo[2] should be replaced with std::array<int, 2> foo{}, etc.
  • File operations should use C++17 <filesystem>.
  • For-loops over containers should prefer ranged-based loops. for (auto& x : y);
  • Many class methods are missing const, noexecpt, and [[nodiscard]] qualifiers.
  • Empty constructors and destructors should use = default;, they should not have an empty function in the source.
  • Small functions with few or no dependencies should be moved inline.
  • Functions which take pointers, but don't handle nullptr, should be changed to take references.
  • Macros such as MIN or CLAMP should be replaced by their C++ functions.
  • Virtual class overrides are missing the override qualifier.
  • String formatting functions should use fmt.
  • Temporary local variables which don't change should be qualified with const.
  • Unions should be replaced with std::variant.

In general follow the C++ Core Guidelines.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions