mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-22 23:46:55 +01:00
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
//* This file is explicitly licensed under the MIT license. *//
|
|
//* Copyright (c) 2025 Citadel Station Developers *//
|
|
|
|
/**
|
|
* * `ID` must be unique and in `snake_case`
|
|
* * `BIT_TO_NAME` should be an list() with `BITFIELD_NAMED()`'s inside it.
|
|
*/
|
|
#define DECLARE_BITFIELD(ID, BIT_TO_NAME); \
|
|
/datum/bitfield/##ID/get_bit_constants() { \
|
|
return BIT_TO_NAME; \
|
|
}
|
|
|
|
/// BIT: must be the define, name will be the define itself.
|
|
#define BITFIELD(BIT) #BIT = BIT
|
|
/// NAME: must be a string
|
|
/// VALUE: the actual enum value, whatever it is
|
|
#define BITFIELD_NAMED(NAME, VALUE) NAME = ##VALUE
|
|
|
|
/**
|
|
* * `ID` the same in `DECLARE_BITFIELD`
|
|
* * `PATH` is `/your/path/whatever` (example)
|
|
* * `VARNAME` is without quotes. This allows us to compile-time check it.
|
|
*
|
|
* CAVEATS:
|
|
* * Performance of bitfield reflection is heavily dependent on how many things share the same variable
|
|
* name. Please ensure all bitfields are called distinct names, including across different paths.
|
|
*/
|
|
#define ASSIGN_BITFIELD(ID, PATH, VARNAME) \
|
|
/datum/bitfield/##ID/New() { \
|
|
..(); \
|
|
if(paths[PATH]) { \
|
|
paths[PATH] += NAMEOF_TYPE(PATH, VARNAME); \
|
|
} \
|
|
else { \
|
|
paths[PATH] = list(NAMEOF_TYPE(PATH, VARNAME)); \
|
|
} \
|
|
}
|