mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-17 05:03:28 +00:00
* Icon smooth refactor (#52864) bitflag list construct added: an associative list of bitflags for cheap and quick element comparison between two lists using the same system. canSmoothWith list turned into a bitflag list. smoothing_groups list added to substitute the type path list. smoothing procs turned into atom procs, refactored and optimized a bit. smooth directions redefined in order to fit in 8 bits for a future smoothing system some variable names changed, foreseeing a second smoothing system SMOOTH_OBJ flag added, for things that need to scan turfs for smoothing. The old locate() optimization has the risk of returning false negatives by finding a child and returning null while there might be one of the wanted type as well, as it doesn't match the type exactly. SMOOTH_TRUE and SMOOTH_MORE condensed into SMOOTH_CORNERS. The old behavior can be replicated using smoothing groups without loss. Does very minor code cleanup. Processing-wise didn't find a noticeable difference. The system loses on init a bit by setting the bitflag_lists, and by scanning whole turf contents for object smoothing (increasing accuracy), and gains by making less checks per target to smooth, through the same bitflag_lists. Memory-wise there should be a small improvement, given that on the old system we had 63512 canSmoothWith lists (a few typelists, most unique), and on this new system canSmoothWith + smoothing_groups are both bitflag_lists from the same pool, totaling 46 in number. Could be tested a bit to see if I missed any icons not properly smoothing. * Icon smooth refactor Co-authored-by: Rohesie <rohesie@gmail.com>
26 lines
1014 B
Plaintext
26 lines
1014 B
Plaintext
GLOBAL_LIST_EMPTY(bitflag_lists)
|
|
|
|
/**
|
|
* System for storing bitflags past the 24 limit, making use of an associative list.
|
|
*
|
|
* Macro converts a list of integers into an associative list of bitflag entries for quicker comparison.
|
|
* Example: list(0, 4, 26, 32)) => list( "0" = ( (1<<0) | (1<<4) ), "1" = ( (1<<2) | (1<<8) ) )
|
|
* Lists are cached into a global list of lists to avoid identical duplicates.
|
|
* This system makes value comparisons faster than pairing every element of one list with every element of the other for evaluation.
|
|
*
|
|
* Arguments:
|
|
* * target - List of integers.
|
|
*/
|
|
#define SET_BITFLAG_LIST(target) \
|
|
do { \
|
|
var/txt_signature = target.Join("-"); \
|
|
if(!GLOB.bitflag_lists[txt_signature]) { \
|
|
var/list/new_bitflag_list = list(); \
|
|
for(var/value in target) { \
|
|
new_bitflag_list["[round(value / 24)]"] |= (1 << (value % 24)); \
|
|
}; \
|
|
GLOB.bitflag_lists[txt_signature] = new_bitflag_list; \
|
|
}; \
|
|
target = GLOB.bitflag_lists[txt_signature]; \
|
|
} while (FALSE)
|