Ref<TimerObject> NewTimer::wait_trigger(float p_time, Object *p_target, String p_method) {
    const String timer_key = "new_timer";
    MainLoop *main_loop = OS::get_singleton()->get_main_loop();
    SceneTree *tree = main_loop->cast_to<SceneTree>();
    ERR_FAIL_COND_V(tree == NULL, NULL);

    Viewport *viewport = tree->get_root();
    ERR_FAIL_COND_V(viewport == NULL, NULL);
    TimerNode *timerNode;
    if (timerNode == NULL) {
        timerNode = memnew(TimerNode);
        timerNode->set_name(timer_key);

        Vector<Variant> vector;
        vector.push_back(Variant(timerNode));

        tree->connect("idle_frame", this, "_add_node", vector, 0);

    }else {
        timerNode = viewport->get_node(timer_key)->cast_to<TimerNode>();
    }

    Ref<TimerObject> obj = memnew(TimerObject);
    obj->time = p_time;
    obj->target = p_target;
    obj->method = p_method;
    timerNode->timer_objs.push_back(obj);
    timerNode->check_queue();
    return obj;
}
Exemple #2
0
		int Find(unsigned long tick, unsigned int *rt_event, void **rt_data){
			TimerNode *findNode = NULL;
			list<TimerNode*>::iterator nodeIter;

			for(nodeIter = node->begin();nodeIter != node->end(); nodeIter++){
				findNode = *nodeIter;
				if(findNode->GetExpTick() >= tick){
					node->erase(nodeIter);

					*rt_event = findNode->GetEvent();
					*rt_data = findNode->GetData();

					delete findNode;

					return 1;
				}
			}

			return 0;
		};
Exemple #3
0
	void TimerManager::Update()
	{
		
		CleanRemove();
		uint64 tick = m_pTime->Tick();

		TimerNode* pNode = m_head->next;


		std::vector<TimerNode*> l;

		while(pNode)
		{

			if((tick - pNode->start_tick) < pNode->interval)
			{
				break;
			}

			TimerNode* pTmp = pNode;

			pNode = pNode->next;


			pTmp->handler(pTmp, pTmp->interval);
			

			UnLink(pTmp);

			l.push_back(pTmp);

		}

		for(size_t i = 0; i <l.size(); ++i)
		{
			InsertNode(l[i]);
		}
		CleanRemove();
	}
Exemple #4
0
void TimerManager::Update()
{
	int tick = GetTickCount();

	TimerNode* pNode = m_head->next;


	std::vector<TimerNode*> l;

	while(pNode)
	{

		if((tick - pNode->start_tick) < pNode->interval)
		{
			break;
		}

		TimerNode* pTmp = pNode;

		pNode = pNode->next;


		pTmp->handler(pTmp, pTmp->interval, pTmp->handler_context);
		

		UnLink(pTmp);

		l.push_back(pTmp);

	}

	for(size_t i = 0; i <l.size(); ++i)
	{
		InsertNode(l[i]);
	}

}