mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 01:48:15 +03:00
Add POS_MOD macro and use for all positive modulos
This macro is to make it so it won't be error-prone to write the semi-confusing `(a % b + b) % b` statement, and you can just use an easy macro instead. Currently, the only places a positive modulo is needed is when switching tilesets, enemies, and warp directions in the editor, as well as when getting a tile in the tower, since towers just repeat themselves vertically. Towers used this weird while-loop to sort of emulate a modulo, which isn't half-bad, but is unnecessary, and I don't think any compiler would recognize it as a modulo. (And if it's not optimized to a proper modulo... what happens if the number being moduloed is really, really big?)
This commit is contained in:
@@ -88,6 +88,11 @@ void _VVV_between(
|
||||
} \
|
||||
while (false)
|
||||
|
||||
/* Positive modulo, because C/C++'s modulo operator sucks and is negative given
|
||||
* negative divisors.
|
||||
* WARNING! This double- and triple- evaluates. */
|
||||
#define POS_MOD(a, b) (((a) % (b) + (b)) % (b))
|
||||
|
||||
//helperClass
|
||||
class UtilityClass
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user