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:
Misa
2021-09-24 17:48:15 -07:00
parent 891ca527f9
commit cace685020
3 changed files with 12 additions and 9 deletions

View File

@@ -4175,7 +4175,7 @@ void editorclass::switch_tileset(const bool reversed)
}
const int modulus = SDL_arraysize(tilesets);
tiles = (tiles % modulus + modulus) % modulus;
tiles = POS_MOD(tiles, modulus);
cl.setroomtileset(levx, levy, tiles);
clamp_tilecol(levx, levy, false);
@@ -4270,7 +4270,7 @@ void editorclass::switch_enemy(const bool reversed)
}
const int modulus = 10;
enemy = (enemy % modulus + modulus) % modulus;
enemy = POS_MOD(enemy, modulus);
cl.setroomenemytype(levx, levy, enemy);
note = "Enemy Type Changed";
@@ -4293,7 +4293,7 @@ void editorclass::switch_warpdir(const bool reversed)
++warpdir;
}
warpdir = (warpdir % modulus + modulus) % modulus;
warpdir = POS_MOD(warpdir, modulus);
cl.setroomwarpdir(levx, levy, warpdir);
switch (warpdir)