mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-09 07:46:20 +00:00
* Implements usage of the REVERSE_DIR macro throughout the code. (#77122) ## About The Pull Request Replaces a ton of `turn(dir, 180)` calls with the aforementioned macro. ## Why It's Good For The Game Afaik, `REVERSE_DIR` was coded to be faster than the classic `turn(dir, 180)` call, being a simple set of binary operations. To sum it up, micro optimization. ## Changelog N/A * Implements usage of the REVERSE_DIR macro throughout the code. --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
48 lines
1.4 KiB
Plaintext
48 lines
1.4 KiB
Plaintext
// Byond direction defines, because I want to put them somewhere.
|
|
// #define NORTH 1
|
|
// #define SOUTH 2
|
|
// #define EAST 4
|
|
// #define WEST 8
|
|
|
|
/// North direction as a string "[1]"
|
|
#define TEXT_NORTH "[NORTH]"
|
|
/// South direction as a string "[2]"
|
|
#define TEXT_SOUTH "[SOUTH]"
|
|
/// East direction as a string "[4]"
|
|
#define TEXT_EAST "[EAST]"
|
|
/// West direction as a string "[8]"
|
|
#define TEXT_WEST "[WEST]"
|
|
|
|
//dir macros
|
|
///Returns true if the dir is diagonal, false otherwise
|
|
#define ISDIAGONALDIR(d) (d&(d-1))
|
|
///True if the dir is north or south, false therwise
|
|
#define NSCOMPONENT(d) (d&(NORTH|SOUTH))
|
|
///True if the dir is east/west, false otherwise
|
|
#define EWCOMPONENT(d) (d&(EAST|WEST))
|
|
///Flips the dir for north/south directions
|
|
#define NSDIRFLIP(d) (d^(NORTH|SOUTH))
|
|
///Flips the dir for east/west directions
|
|
#define EWDIRFLIP(d) (d^(EAST|WEST))
|
|
|
|
/// Inverse direction, taking into account UP|DOWN if necessary.
|
|
#define REVERSE_DIR(dir) ( ((dir & 85) << 1) | ((dir & 170) >> 1) )
|
|
|
|
/// Create directional subtypes for a path to simplify mapping.
|
|
#define MAPPING_DIRECTIONAL_HELPERS(path, offset) ##path/directional/north {\
|
|
dir = NORTH; \
|
|
pixel_y = offset; \
|
|
} \
|
|
##path/directional/south {\
|
|
dir = SOUTH; \
|
|
pixel_y = -offset; \
|
|
} \
|
|
##path/directional/east {\
|
|
dir = EAST; \
|
|
pixel_x = offset; \
|
|
} \
|
|
##path/directional/west {\
|
|
dir = WEST; \
|
|
pixel_x = -offset; \
|
|
}
|