move THISCALL define to header, clean up code a little

develop
Jeremy Apthorp 2019-12-13 23:54:27 -08:00
parent dfab521a71
commit 7fce6fe0b0
2 changed files with 15 additions and 11 deletions

@ -45,6 +45,17 @@ using std::endl;
#define DFHACK_FUNCTION_SIG __func__
#endif
#ifdef _WIN32
// On x86 MSVC, __thiscall passes |this| in ECX. On x86_64, __thiscall is the
// same as the standard calling convention.
// See https://docs.microsoft.com/en-us/cpp/cpp/thiscall for more info.
#define THISCALL __thiscall
#else
// On other platforms, there's no special calling convention for calling member
// functions.
#define THISCALL
#endif
namespace DFHack {
class color_ostream;
}

@ -541,20 +541,13 @@ string Units::getRaceName(df::unit* unit)
return getRaceNameById(unit->race);
}
#ifdef _WIN32
#define THISCALL __thiscall
#else
#define THISCALL
#endif
typedef void (THISCALL *df_unit_physical_description_fn)(df::unit*, string*);
void df_unit_physical_description(df::unit* unit, string* out_str)
{
static df_unit_physical_description_fn fn =
reinterpret_cast<df_unit_physical_description_fn>(
static auto* const fn =
reinterpret_cast<void(THISCALL *)(df::unit*, string*)>(
Core::getInstance().vinfo->getAddress("unit_physical_description"));
if (fn)
fn(unit, out_str);
CHECK_NULL_POINTER(fn);
fn(unit, out_str);
}
string Units::getDescription(df::unit* unit)