no message

This commit is contained in:
sk 2024-09-27 14:31:16 +08:00
parent fcdb12669c
commit 93134b7f57
1 changed files with 90 additions and 5 deletions

View File

@ -6,6 +6,10 @@ import (
"mongo.games.com/goserver/core/module"
)
func init() {
module.RegisteModule(ClockMgrSingleton, time.Millisecond*500, 0)
}
var ClockMgrSingleton = &ClockMgr{
LastHour: -1,
LastDay: -1,
@ -99,9 +103,9 @@ func (this *ClockMgr) Update() {
this.LastSec = sec
this.fireSecondEvent()
min := tNow.Minute()
if min != this.LastMini {
this.LastMini = min
minute := tNow.Minute()
if minute != this.LastMini {
this.LastMini = minute
this.fireMinuteEvent()
hour := tNow.Hour()
@ -182,6 +186,87 @@ func (this *ClockMgr) GetLast() (int, int, int, int, int, int) {
return this.LastSec, this.LastMini, this.LastHour, this.LastDay, this.LastWeek, int(this.LastMonth)
}
func init() {
module.RegisteModule(ClockMgrSingleton, time.Millisecond*500, 0)
type ClockFunc struct {
event int
OnSecTimerFunc func()
OnMiniTimerFunc func()
OnHourTimerFunc func()
OnDayTimerFunc func()
OnWeekTimerFunc func()
OnMonthTimerFunc func()
OnShutdownFunc func()
}
func (s *ClockFunc) InterestClockEvent() int { return s.event }
func (s *ClockFunc) OnSecTimer() {
if s.OnSecTimerFunc != nil {
s.OnSecTimerFunc()
}
}
func (s *ClockFunc) OnMiniTimer() {
if s.OnMiniTimerFunc != nil {
s.OnMiniTimerFunc()
}
}
func (s *ClockFunc) OnHourTimer() {
if s.OnHourTimerFunc != nil {
s.OnHourTimerFunc()
}
}
func (s *ClockFunc) OnDayTimer() {
if s.OnDayTimerFunc != nil {
s.OnDayTimerFunc()
}
}
func (s *ClockFunc) OnWeekTimer() {
if s.OnWeekTimerFunc != nil {
s.OnWeekTimerFunc()
}
}
func (s *ClockFunc) OnMonthTimer() {
if s.OnMonthTimerFunc != nil {
s.OnMonthTimerFunc()
}
}
func (s *ClockFunc) OnShutdown() {
if s.OnShutdownFunc != nil {
s.OnShutdownFunc()
}
}
// RegisterClockFunc 注册时钟事件
func RegisterClockFunc(fs *ClockFunc) {
if fs == nil {
return
}
if fs.OnSecTimerFunc != nil {
fs.event = fs.event ^ ClockEventSecond
}
if fs.OnMiniTimerFunc != nil {
fs.event = fs.event ^ ClockEventMinute
}
if fs.OnHourTimerFunc != nil {
fs.event = fs.event ^ ClockEventHour
}
if fs.OnDayTimerFunc != nil {
fs.event = fs.event ^ ClockEventDay
}
if fs.OnWeekTimerFunc != nil {
fs.event = fs.event ^ ClockEventWeek
}
if fs.OnMonthTimerFunc != nil {
fs.event = fs.event ^ ClockEventMonth
}
if fs.OnShutdownFunc != nil {
fs.event = fs.event ^ ClockEventShutdown
}
ClockMgrSingleton.RegisterSinker(fs)
}