1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Add consistent monotonic day counter - get_day_count()

I've written several experimental bits of code that revolve around the
need for a consistent calendar, but implementing one is extremely hard
in mods due to time changes and mods overriding core.get_timeofday(),
which will conflict.

The second part of the problem is that doing this from a mod requires
constant maintenance of a settings file.

An implementation in core is trivial, however, and solves all of
these problems at virtually no cost: No extra branches in server
steps, and a single branch when minetest.set_time_of_day(), which is
entirely reasonable.

We store the day_count value in env_meta.txt.

The use case is obvious: This change allows mods to create an actual
virtual calendar, or properly account for seasonal changes, etc..

We add a "/days" chatcommand that displays the current day count. No
permissions are needed. It can only retrieve the day count, not
modify it.
This commit is contained in:
Auke Kok 2016-03-06 12:02:21 -08:00 committed by est31
parent 3ce6642a26
commit 4e59fcf5c1
6 changed files with 46 additions and 1 deletions

View file

@ -95,6 +95,8 @@ public:
void setDayNightRatioOverride(bool enable, u32 value);
u32 getDayCount();
// counter used internally when triggering ABMs
u32 m_added_objects;
@ -117,6 +119,9 @@ protected:
// Overriding the day-night ratio is useful for custom sky visuals
bool m_enable_day_night_ratio_override;
u32 m_day_night_ratio_override;
// Days from the server start, accounts for time shift
// in game (e.g. /time or bed usage)
Atomic<u32> m_day_count;
/*
* Above: values managed by m_time_lock
*/