package common import ( "time" "mongo.games.com/goserver/core/module" ) /* 时钟 */ func init() { module.RegisteModule(ClockMgrSingleton, time.Millisecond*500, 0) } var ClockMgrSingleton = &ClockMgr{ LastHour: -1, LastDay: -1, Notifying: false, } const ( ClockEventSecond int = iota ClockEventMinute ClockEventHour ClockEventDay ClockEventWeek ClockEventMonth ClockEventShutdown ClockEventMax ) type ClockSinker interface { InterestClockEvent() int OnSecTimer() OnMiniTimer() OnHourTimer() OnDayTimer() OnWeekTimer() OnMonthTimer() OnShutdown() } type BaseClockSinker struct { } func (s *BaseClockSinker) InterestClockEvent() int { return (1 << ClockEventMax) - 1 } func (s *BaseClockSinker) OnSecTimer() {} func (s *BaseClockSinker) OnMiniTimer() {} func (s *BaseClockSinker) OnHourTimer() {} func (s *BaseClockSinker) OnDayTimer() {} func (s *BaseClockSinker) OnWeekTimer() {} func (s *BaseClockSinker) OnMonthTimer() {} func (s *BaseClockSinker) OnShutdown() {} type ClockMgr struct { sinkers [ClockEventMax][]ClockSinker LastTickTime time.Time LastMonth time.Month LastWeek int LastDay int LastHour int LastMini int LastSec int Notifying bool LastFiveMin int } func (this *ClockMgr) RegisterSinker(sinker ClockSinker) { interest := sinker.InterestClockEvent() for i := 0; i < ClockEventMax; i++ { if (1<