Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port - Optimized ISODD/ISEVEN #28208

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/__DEFINES/_math.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@

#define ISABOUTEQUAL(a, b, deviation) (deviation ? abs((a) - (b)) <= deviation : abs((a) - (b)) <= 0.1)

#define ISEVEN(x) (x % 2 == 0)
#define ISEVEN(x) (!((x) & 1))

#define ISODD(x) (x % 2 != 0)
#define ISODD(x) ((x) & 1)

// Returns true if val is from min to max, inclusive.
#define ISINRANGE(val, min, max) (min <= val && val <= max)
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

/proc/ui_hand_position(i)
// values based on old hand ui positions (CENTER:-/+16,SOUTH:5)
var/x_off = i % 2 ? 0 : -1
var/x_off = ISODD(i) ? 0 : -1
var/y_off = round((i-1) / 2)
return"CENTER+[x_off]:16,SOUTH+[y_off]:5"

Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
return copytext(new_message, 1, length + 1)
if(delta == 1)
return new_message + " "
if(delta % 2)
if(ISODD(delta))
new_message = " " + new_message
delta--
var/spaces = add_lspace("",delta/2-1)
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
f = round(f)
f = max(low, f)
f = min(high, f)
if((f % 2) == 0) //Ensure the last digit is an odd number
if(ISEVEN(f)) //Ensure the last digit is an odd number
f += 1
return f

Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/footstep.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
if(steps >= 6)
steps = 0

if(steps % 2)
if(ISODD(steps))
return

if(steps != 0 && !has_gravity(LM, T)) // don't need to step as often when you hop around
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/effects/spawners/airlock_spawner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ This spawner places pipe leading up to the interior door, you will need to finis
var/obj/machinery/access_button/the_button = spawn_button(T, is_this_an_interior_airlock ? interior_direction : exterior_direction, is_this_an_interior_airlock)
if(one_door_only == DOOR_NORMAL_PLACEMENT) //We only need one door, we are done
return
if(!(tiles_in_x_direction % 2) && (is_this_an_interior_airlock && north_or_south_interior || !is_this_an_interior_airlock && north_or_south_exterior)) //Handle extra airlock for aesthetics
if(ISEVEN(tiles_in_x_direction) && (is_this_an_interior_airlock && north_or_south_interior || !is_this_an_interior_airlock && north_or_south_exterior)) //Handle extra airlock for aesthetics
A = new door_type(get_step(T, EAST))
handle_door_stuff(A, is_this_an_interior_airlock)
if(one_door_only == DOOR_FLIPPED_PLACEMENT)
the_button.forceMove(get_step(the_button, EAST))
else if(!(tiles_in_y_direction % 2) && (is_this_an_interior_airlock && !north_or_south_interior || !is_this_an_interior_airlock && !north_or_south_exterior)) //Handle extra airlock for aesthetics
else if(ISEVEN(tiles_in_y_direction) && (is_this_an_interior_airlock && !north_or_south_interior || !is_this_an_interior_airlock && !north_or_south_exterior)) //Handle extra airlock for aesthetics
A = new door_type(get_step(T, NORTH))
handle_door_stuff(A, is_this_an_interior_airlock)
if(one_door_only == DOOR_FLIPPED_PLACEMENT)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/structures/safe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ GLOBAL_LIST_EMPTY(safes)
for(var/i = 1 to ticks)
dial = WRAP(dial - 1, 0, 100)

var/invalid_turn = current_tumbler_index % 2 == 0 || current_tumbler_index > number_of_tumblers
var/invalid_turn = ISEVEN(current_tumbler_index) || current_tumbler_index > number_of_tumblers
if(invalid_turn) // The moment you turn the wrong way or go too far, the tumblers reset
current_tumbler_index = 1

Expand All @@ -313,7 +313,7 @@ GLOBAL_LIST_EMPTY(safes)
for(var/i = 1 to ticks)
dial = WRAP(dial + 1, 0, 100)

var/invalid_turn = current_tumbler_index % 2 != 0 || current_tumbler_index > number_of_tumblers
var/invalid_turn = ISODD(current_tumbler_index) || current_tumbler_index > number_of_tumblers
if(invalid_turn) // The moment you turn the wrong way or go too far, the tumblers reset
current_tumbler_index = 1

Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/traitor/datum_traitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ RESTRICT_TYPE(/datum/antagonist/traitor)
if(freq < 1451 || freq > 1459)
freqlist += freq
freq += 2
if((freq % 2) == 0)
if(ISEVEN(freq))
freq += 1
freq = pick(freqlist)

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/carbon_life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

//Start of a breath chain, calls breathe()
/mob/living/carbon/handle_breathing(times_fired)
if(times_fired % 2 == 1)
if(ISODD(times_fired))
var/datum/milla_safe/carbon_breathe/milla = new()
milla.invoke_async(src)
else
Expand Down
2 changes: 1 addition & 1 deletion code/modules/procedural_mapping/mapGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

//Even sphere correction engage
var/offByOneOffset = 1
if(bigZ % 2 == 0)
if(ISEVEN(bigZ))
offByOneOffset = 0

for(var/i = lilZ, i <= bigZ+offByOneOffset, i++)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/ruins/lavalandruin_code/puzzle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
if(current_ordering[j] < checked_value)
swap_tally++

return swap_tally % 2 == 0
return ISEVEN(swap_tally)

//swap two tiles in same row
/obj/effect/sliding_puzzle/proc/make_solvable()
Expand Down