Beispiel #1
0
void timer_tick(struct timer_t * timer) {		
	uint32_t slot = timer->current%timer->ticklistn;
	struct tobjqueue_t * tick = &timer->ticklist[slot];
	uint32_t num = tick->objn;
	while (num-- > 0) {
		struct tobj_t * tobj = uq_pophead(tick);
		if (NULL == tobj) break;	
		timer->ticking = tobj->id;						//设置为正在触发状态
		int erased = 0;
		if (tobj->repeat > 0 && --tobj->repeat == 0) 
			erased = 1;
		tobj->cb(tobj->ud, tobj->id, erased);
		if (erased) {
			tobj->cb = NULL;
			uq_addtail(&timer->freelist, tobj);
		} else {
			add_obj_raw(timer, tobj, tobj->timeout, tobj->timeout, tobj->repeat, tobj->ud, tobj->cb);
		}
	}
	timer->current = (++timer->current)%timer->ticklistn;
	timer->ticking = 0;
	if (timer->current == 0) {
		struct tobjqueue_t tmptick;
		memset(&tmptick, 0, sizeof(tmptick));
		struct tobj_t * tobj = uq_pophead(&timer->longlist);
		while (tobj) {
			if (tobj->timeleft < timer->ticklistn) {
				add_obj_raw(timer, tobj, tobj->timeleft, tobj->timeout, tobj->repeat, tobj->ud, tobj->cb);
			} else {
				tobj->timeleft -= timer->ticklistn;
				uq_addtail(&tmptick, tobj);
			}
			tobj = uq_pophead(&timer->longlist);
		}

		tobj = uq_pophead(&tmptick);
		while (tobj) {
			uq_addtail(&timer->longlist, tobj);
			tobj = uq_pophead(&tmptick);
		}
	}
}
Beispiel #2
0
uint32_t timer_add(struct timer_t * timer, uint32_t timeout, void * ud, func_timer_callback cb, uint32_t repeat) {
	struct tobj_t * tobj = uq_pophead(&timer->freelist);
	if (!tobj) {
		expand_objpool(timer);
		tobj = uq_pophead(&timer->freelist);
	}

	assert(tobj);
	add_obj_raw(timer, tobj, timeout, timeout, repeat, ud, cb);
	return tobj->id;
}
Beispiel #3
0
gfx_rv EntityList::add_obj_raw(Object& obj)
{
    /// @author ZZ
    /// @details This function puts an entity in the list

    // Don't add if it is hidden.
    if (obj.isHidden())
    {
        return gfx_fail;
    }

    // Don't add if it's in another character's inventory.
    if (_currentModule->getObjectHandler().exists(obj.inwhich_inventory))
    {
        return gfx_fail;
    }

    // Add!
    _lst[_size].ichr = GET_INDEX_PCHR(&obj);
    _lst[_size].iprt = INVALID_PRT_REF;
    _size++;

    // Notify it that it is in a do list.
    obj.inst.indolist = true;

    // Add any weapons it is holding.
    Object *holding;
    holding = _currentModule->getObjectHandler().get(obj.holdingwhich[SLOT_LEFT]);
    if (holding && _size < CAPACITY)
    {
        add_obj_raw(*holding);
    }
    holding = _currentModule->getObjectHandler().get(obj.holdingwhich[SLOT_RIGHT]);
    if (holding && _size < CAPACITY)
    {
        add_obj_raw(*holding);
    }
    return gfx_success;
}