Improve code by using modern C++ features
Closed this issue · 1 comments
fel1x-developer commented
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 withenum
orconstexpr
. This makes fixing compile-time errors easier. Useenum
for group of constants andconstexpr
for individual constants. - Replace macro functions with inline functions.
- Replace
typedef
withusing
.using
is added in C++. - Replace
typedef struct
withstruct
. C++ structs work withouttypedef
. - Use mathematical constants added in C++20. (
pi
andpi_v
) - Replace
qboolean
withbool
- Replace
unsigned char
withstd::uint8_t
forbyte
. - Use
auto
where it is possible. - Replace
printf
withstd::cout
. Butstd::endl
won't replace\n
. - Use
decltype
orvec_t
to avoidfloat
anddouble
collision forvec_t
. - Use C++ headers.
- Use
pragma once
for header files. - Replace
array
withstd::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
withchar*
strings. ``std::string:iteratorcan be used. Replace related functions such as
atof` 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
toprojects/
? Or do we need to keep the file structure for compatibility?
fel1x-developer commented
Opened pull request #204