zaimoni / Cataclysm

A post-apocalyptic roguelike. New features relative to C:Whales are scheduled for after 0.2.0, the savefile breaking release.
http://www.bay12forums.com/smf/index.php?topic=174897
Other
27 stars 3 forks source link

#define has a more functional role than expected #66

Open zaimoni opened 3 years ago

zaimoni commented 3 years ago

Contrary to what one might expect from style guides, they actually have some architectural uses. Snap impression when viewing grep results on July 12 2020 was:

** we have some "closely correlated macros" that reasonably can treated the same as this.

** examples of model configuration: construction.cpp, crafting.cpp, itypedef.cpp, missiondef.cpp, mtypedef.cpp, mutation_def.cpp. trapdef.cpp, veh_typedef.cpp. A "correct fix" for these is direct conversion to loading from JSON files.

* examples of automating declaration and definition: c_bitmap.h, enum_json.h . "correct fix" usually does not exist, even though they interfere with IDE source code browsing tools: the alternatives are intentionally sabotaging formal verification, or reimplementing the C preprocessor and doing the preprocessing as an extra build step (which is predicted to not* play nice with the build system)

*** set_vector.h has wrappers for a particular archaic idiom that, before upgrade to C++11, was actually undefined behavior. They would be made irrelevant by converting model configuration to external JSON files; this is an example of a "correct fix"

zaimoni commented 3 years ago

For something that isn't formally standardized, #pragma once has very widespread support. In particular, OpenXCom Extended Plus ( https://github.com/MeridianOXC/OpenXcom ) uses #pragma once instead of include guard defines. Cf. https://en.wikipedia.org/wiki/Pragma_once for where this extension actually works.

Contrary to my initial impression above, I'm now ok with eliminating all include guard macros in favor of #pragma once.

hirdrac commented 3 years ago

I generally use include guards in my own code but pragma once is fine as well.

zaimoni commented 3 years ago

The variadic setup macros (often targeting varargs constructors) generally look like they should be using C++17 initializer-lists after de-macroing. I'm fine with this replacement strategy (and have used it where it eliminated debugmsg calls at source).

Theoretically, this could be made obsolete by modding support, but I think it should be possible to do C++ configuration for core game and JSON configuration for mod content at the same time.

Aside: think I may have been unclear how the release cycle works (I announced 0.2.3 on Bay12 and reddit, but only did a wiki update to the release schedule here). Intent was to provide a ~6 week window for high-risk changes before switching to making the game stable for release. I can push out the high risk window end date, if useful.