draconisPW / PWMAngband

A free, multi-player roguelike dungeon exploration game based on Angband
36 stars 12 forks source link

add daytime to player structure #438

Closed igroglaz closed 3 years ago

igroglaz commented 3 years ago

atm there are a lot of places in the code which checks is it day or night:

image

check is:

/*
 * Say whether a turn is during day or not
 */
bool is_daytime_turn(hturn *ht_ptr)
{
    return ((ht_ptr->turn % (10L * z_info->day_length)) < (u32b)((10L * z_info->day_length) / 2));
}

What if we will add new paramenet to player or cave with bool day/night? so each turn it will be counted only once and if it was chenged - it will be recorded to structure and game won't needed to recalculate it some more times.

I'm planning to add some new features based at day/night mechanics - eg vampires won't like walking in daylight, werewolfs will be able to turn into wolves at nights, etc... so maybe it's good idea to optimize this calculations so game will work faster and more effective terms of server resources? I'm rookie, so maybe it's stupid idea ;)

draconisPW commented 3 years ago

This calculation only uses constants so this doesn't make sense at all...

igroglaz commented 3 years ago

Yep, but still we can optimize it? it's 5 operations % * < % /

I don't understand why to calculate it a lot of times if we can do it once and store in structure? Please explain to poor rookie :)❤️

draconisPW commented 3 years ago

Because it changes every turn so you need to calculate it every turn. Storing the result makes no sense since the value would be obsolete immediately.

igroglaz commented 3 years ago

Hm.. yep, but if we calculate daytime in several parts of the code - we can calculate it once somewhere in the 'top' part of the code and when the program continue to process to the bottom - it won't need to calculate it again.. I mean - if we call the same function in different parts of the code - game has to calculate it again and again? Or compiler optimize it by himself during compilation and calculate it only once?