fs2port/port/include/timeOfDay.h
2026-05-13 21:32:05 -05:00

53 lines
1.4 KiB
C

// Time-of-day state and phase computation. Direct port of FS2 chunk3
// `ComputeDayPhase` plus `DayPhaseTable` (4 seasonal rows, each
// holding the dawn-start / sunrise / sunset / dusk-end (min, hour)
// pairs).
#ifndef TIME_OF_DAY_H
#define TIME_OF_DAY_H
#include <stdint.h>
typedef enum DayPhaseE {
DAY_PHASE_DAY = 0x01,
DAY_PHASE_TWILIGHT = 0x02,
DAY_PHASE_NIGHT = 0x04
} DayPhaseE;
typedef enum SeasonE {
SEASON_WINTER = 0,
SEASON_SPRING = 1,
SEASON_SUMMER = 2,
SEASON_FALL = 3
} SeasonE;
typedef struct TimeOfDayT {
uint8_t hours; // 0..23
uint8_t minutes; // 0..59
uint16_t frameSubMinute; // tick accumulator within the current minute
SeasonE season;
DayPhaseE phase;
} TimeOfDayT;
void timeOfDayInit(TimeOfDayT *t);
// Advance the clock by one simulation frame. The default rate is one
// in-game minute per `TIME_FRAMES_PER_MINUTE` frames (defined inside
// the .c). Phase is recomputed each tick.
void timeOfDayStep(TimeOfDayT *t);
// Recompute the phase from `hours`/`minutes`/`season` against
// FS2's per-quadrant `DayPhaseTable`.
void timeOfDayRecomputePhase(TimeOfDayT *t);
// Set time directly (e.g. from edit mode); recomputes phase.
void timeOfDaySet(TimeOfDayT *t, uint8_t hours, uint8_t minutes);
// Pretty-print phase name. Always non-NULL.
const char *timeOfDayPhaseName(DayPhaseE phase);
#endif