package main import ( "time" "mongo.games.com/goserver/core/module" ) var ClockMgrSington = &ClockMgr{ LastHour: -1, LastDay: -1, Notifying: false, } const ( CLOCK_EVENT_SECOND int = iota CLOCK_EVENT_MINUTE CLOCK_EVENT_HOUR CLOCK_EVENT_DAY CLOCK_EVENT_WEEK CLOCK_EVENT_MONTH CLOCK_EVENT_SHUTDOWN CLOCK_EVENT_MAX ) type ClockSinker interface { InterestClockEvent() int OnSecTimer() OnMiniTimer() OnHourTimer() OnDayTimer() OnWeekTimer() OnMonthTimer() OnShutdown() } type BaseClockSinker struct { } func (s *BaseClockSinker) InterestClockEvent() int { return (1 << CLOCK_EVENT_MAX) - 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 [CLOCK_EVENT_MAX][]ClockSinker LastTickTime time.Time LastMonth time.Month LastWeek int LastDay int LastHour int LastMini int LastSec int Notifying bool LastFiveMin int } func (this *ClockMgr) RegisteSinker(sinker ClockSinker) { interest := sinker.InterestClockEvent() for i := 0; i < CLOCK_EVENT_MAX; i++ { if (1<