Esempio n. 1
0
// 删除事件, 只能操作本线程事件
func (this *Thread) RemoveEvent(e event.IEvent) bool {
	if !e.IsHeader() {
		if len(e.GetName()) > 0 {
			delete(this.evt_names, e.GetName())
		}

		this.PopTimer(e)
		this.PopObj(e)

		return true
	}
	return false
}
Esempio n. 2
0
// 投递定时器事件
func (this *Thread) PostEvent(a event.IEvent) bool {
	check_name := len(a.GetName()) > 0
	if check_name {
		if _, ok := this.evt_names[a.GetName()]; ok {
			return false
		}
	}

	if a.GetTouchTime() < 0 {
		return false
	}

	// 计算放在那一层
	pos := (a.GetTouchTime() + jiekou.Evt_gap_time - 1) >> jiekou.Evt_gap_bit
	if pos < 0 {
		pos = 1
	}

	var header event.IEvent

	if pos < this.evt_lay1Size {
		new_pos := this.evt_lay1Cursor + pos
		if new_pos >= this.evt_lay1Size {
			new_pos = new_pos - this.evt_lay1Size
		}
		pos = new_pos
		header = this.evt_lay1[pos]
	} else {
		if _, ok := this.evt_lay2[pos]; !ok {
			this.evt_lay2[pos] = new(event.EventHeader)
			this.evt_lay2[pos].Init("", 100)
		}
		header = this.evt_lay2[pos]
	}

	old_pre := header.GetPreTimer()
	header.SetPreTimer(a)
	a.SetNextTimer(header)
	a.SetPreTimer(old_pre)
	old_pre.SetNextTimer(a)

	if check_name {
		this.evt_names[a.GetName()] = a
	}

	return true
}