twhl-community/halflife-updated

Improve code by using modern C++ features

Closed this issue · 1 comments

Half-Life SDK uses old C++ (probably C++98) C++20 can make code safer, easier to read, and faster. Using modern C++ features, halflife-updated will be easier to write code, add features, and debug.

Changes

  • Use C++20.
  • Replace #define macros with enum or constexpr. This makes fixing compile-time errors easier. Use enum for group of constants and constexpr for individual constants.
  • Replace macro functions with inline functions.
  • Replace typedef with using. using is added in C++.
  • Replace typedef struct with struct. C++ structs work without typedef.
  • Use mathematical constants added in C++20. (pi and pi_v)
  • Replace qboolean with bool
  • Replace unsigned char with std::uint8_t for byte.
  • Use auto where it is possible.
  • Replace printf with std::cout. But std::endl won't replace \n.
  • Use decltype or vec_t to avoid float and double collision for vec_t.
  • Use C++ headers.
  • Use pragma once for header files.
  • Replace array with std::array. C++ std::array is safer.
  • Replace call by pointer with call by reference where it is possible.
  • Replace C standard functions (malloc, free) with C++ functions (new, delete).
  • Replace raw pointers to smart pointers (unique_ptr, shared_ptr)
  • Use lambda functions where it is possible.
  • Replace std::string with char* strings. ``std::string:iteratorcan be used. Replace related functions such asatof` with `stof`.

Things that will NOT be changed

  • Variable names, constant names, function names, class names, struct names, etc.
  • General code structure of Half-Life SDK

Proposals

  • Can we move project files under projects/vs2019 to projects/? Or do we need to keep the file structure for compatibility?

Opened pull request #204