Пример #1
0
void EventableObject::event_AddEvent(TimedEvent * ptr)
{
	m_lock.Acquire();

	if(!m_holder)
	{
		m_event_Instanceid = event_GetInstanceID();
		m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);
	}

	ptr->IncRef();
	ptr->instanceId = m_event_Instanceid;
	pair<uint32,TimedEvent*> p(ptr->eventType, ptr);
	m_events.insert( p );
	m_lock.Release();

	/* Add to event manager */
	if(!m_holder)
	{
		/* relocate to -1 eventholder :/ */
		m_event_Instanceid = WORLD_INSTANCE;
		m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);
		ASSERT(m_holder);
	}

	m_holder->AddEvent(ptr);
}
Пример #2
0
void EventableObject::event_Relocate()
{
	/* prevent any new stuff from getting added */
	m_lock.Acquire();

	EventableObjectHolder * nh = sEventMgr.GetEventHolder(event_GetInstanceID());
	if(nh != m_holder)
	{
		// whee, we changed event holder :>
		// doing this will change the instanceid on all the events, as well as add to the new holder.
		
		// no need to do this if we don't have any events, though.
		if(!nh)
			nh = sEventMgr.GetEventHolder( WORLD_INSTANCE );

		nh->AddObject(this);

		// reset our m_holder pointer and instance id
		m_event_Instanceid = nh->GetInstanceID();
		m_holder = nh;
	}

	/* safe again to add */
	m_lock.Release();
}
Пример #3
0
void EventableObject::event_Relocate()
{
    /* prevent any new stuff from getting added */
    m_lock.Acquire();

    EventableObjectHolder* nh = sEventMgr.GetEventHolder(event_GetInstanceID());
    if(nh != m_holder)
    {
        // whee, we changed event holder :>
        // doing this will change the instanceid on all the events, as well as add to the new holder.

        //If nh is NULL then we were removed from world. There's no reason to be added to WORLD_INSTANCE EventMgr, let's just wait till something will add us again to world.
        if(nh == NULL)
        {
            //set instaceId to 0 to each event of this EventableObject, so EventableObjectHolder::Update() will remove them from its EventList.
            for(EventMap::iterator itr = m_events.begin(); itr != m_events.end(); ++itr)
            {
                itr->second->instanceId = 0;
            }
            // reset our instance id.
            m_event_Instanceid = 0;
        }
        else
        {
            nh->AddObject(this);
            // reset our instance id
            m_event_Instanceid = nh->GetInstanceID();
        }
        // reset our m_holder pointer
        m_holder = nh;
    }

    /* safe again to add */
    m_lock.Release();
}
Пример #4
0
void EventableObject::event_Relocate()
{
    int32 instance = event_GetInstanceID();
    EventableObjectHolder * h = sEventMgr.GetEventHolder(instance);
    assert(h);
    if(h != m_eventHolder && m_eventHolder && m_active == 1)
        m_eventHolder->RemoveObject(this);        

    m_eventHolder = h;
    if(m_active)
        m_eventHolder->AddObject(this);
}
Пример #5
0
void EventableObject::event_AddEvent(TimedEvent* ptr)
{
    m_lock.Acquire();

    if(m_holder == NULL)
    {
        m_event_Instanceid = event_GetInstanceID();
        m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);

        if(m_holder == NULL)
        {

            ///////////////////////////////////////// this is for me for debugging purposes - dfighter ////////////////////////////
            // ARCEMU_ASSERT( false );
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            // We still couldn't find an eventholder for us so let's run in WorldRunnable
            m_event_Instanceid = WORLD_INSTANCE;
            m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);
        }
    }

    // We still couldn't find an event holder for ourselves :(
    ARCEMU_ASSERT(m_holder != NULL);

    // If we are flagged not to run in WorldRunnable then we won't!
    // This is much better than adding us to the eventholder and removing on an update
    if(m_event_Instanceid == WORLD_INSTANCE && (ptr->eventFlag & EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT))
    {
        delete ptr->cb;
        delete ptr;

        ///////////////////////////////////////// this is for me for debugging purposes - dfighter ////////////////////////////
        // ARCEMU_ASSERT( false );
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        m_lock.Release();
        return;
    }

    ptr->IncRef();
    ptr->instanceId = m_event_Instanceid;
    pair<uint32, TimedEvent*> p(ptr->eventType, ptr);
    m_events.insert(p);
    m_lock.Release();


    /* Add to event manager */
    m_holder->AddEvent(ptr);
}