Beispiel #1
0
const set *dbCreate(const sds setName)
{
    set *newSet = NULL;

    if (NULL == setName || 0 == strlen(setName))
    {
        return NULL;
    }

    if (NULL == (newSet = setCreate()))
        return NULL;

    lockWrite(sets);

    if (DICT_OK != dictAdd(sets, setName, newSet))
    {
        unlockWrite(sets);
        setDestroy(newSet);
        return NULL;
    }

    if (0 != registerSyncObject(newSet) && 1 != syncObjectIsRegistered(newSet))
    {
        unlockWrite(sets);
        dictDelete(sets, setName);
        setDestroy(newSet);
        return NULL;
    }

    unlockWrite(sets);
    return newSet;
}
Beispiel #2
0
Set setCopy(Set set) {
	IF_NULL_RETURN_NULL(set)
	IS_SET_VALID(set)
	Set newSet = setCreate(set->copyFunc, set->freeFunc, set->cmpFunc);
	IF_NULL_RETURN_NULL(newSet)
	Node nodeToCopy = set->dummy->next;
	Node lastCopiedNode = newSet->dummy;
	newSet->current = NULL; // in case current was undefined in original set
	while (nodeToCopy != NULL) {
		Node currNode = malloc(sizeof(*currNode));
		if (currNode == NULL) {
			setDestroy(newSet);
			return NULL;
		}
		if (nodeToCopy->data == NULL) {
			currNode->data = NULL;
		} else {
			currNode->data = set->copyFunc(nodeToCopy->data);
			if (currNode->data == NULL) {
				free(currNode);
				setDestroy(newSet);
				return NULL;
			}
		}
		if (nodeToCopy == set->current) {
			newSet->current = currNode;
		}
		currNode->next = NULL;
		lastCopiedNode->next = currNode;
		lastCopiedNode = currNode;
		nodeToCopy = nodeToCopy->next;
	}
	newSet->size = setGetSize(set);
	return newSet;
}
Beispiel #3
0
BOOL CObject::net_Spawn			(CSE_Abstract* data)
{
	PositionStack.clear			();

	VERIFY						(_valid(renderable.xform));

	if (0==Visual() && pSettings->line_exist( cNameSect(), "visual" ) )
		cNameVisual_set	(pSettings->r_string( cNameSect(), "visual" ) );

	if (0==collidable.model) 	{
		if (pSettings->line_exist(cNameSect(),"cform")) {
			//LPCSTR cf			= pSettings->r_string	(*cNameSect(), "cform");
			VERIFY3				(*NameVisual, "Model isn't assigned for object, but cform requisted",*cName());
			collidable.model	= xr_new<CCF_Skeleton>	(this);
		}
	}
	R_ASSERT(spatial.space);	spatial_register();

	if (register_schedule())
		shedule_register		();

	// reinitialize flags
//.	Props.bActiveCounter		= 0;	
	processing_activate			();
	setDestroy					(false);

	MakeMeCrow					();

	return TRUE					;
}
Beispiel #4
0
int dbSet(const sds setName, const set *s)
{
    set *prevSet = NULL;

    if (NULL == setName || 0 == strlen(setName) || NULL == s)
        return -1;

    lockWrite(sets);
    if (NULL != (prevSet = (set *) dictFetchValue(sets, setName)))
    {
        lockWrite(prevSet);
        if (!prevSet->registered)
            setDestroy(prevSet);
        unregisterSyncObject(prevSet);
    }

    if (0 != registerSyncObject(s) && 1 != syncObjectIsRegistered(s))
    {
        unlockWrite(sets);
        return -1;
    }

    dictReplace(sets, setName, (void *) s);
    unlockWrite(sets);
    return 0;
}
Beispiel #5
0
int dbFlushAll(void)
{
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;

    lockWrite(sets);

    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockWrite(sets);
        return -1;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        set *s = (set *) dictGetEntryVal(entry);
        lockWrite(s);
        if (!s->registered)
            setDestroy(s);
        unregisterSyncObject(s);
    }

    dictReleaseIterator(iter);
    dictEmpty(sets);
    unlockWrite(sets);
    return 0;
}
Beispiel #6
0
int sis_final_context(struct drm_device *dev, int context)
{
	int i;

	for (i = 0; i < MAX_CONTEXT; i++) {
		if (global_ppriv[i].used &&
		    (global_ppriv[i].context == context))
			break;
	}

	if (i < MAX_CONTEXT) {
		set_t *set;
		ITEM_TYPE item;
		int retval;

		DRM_DEBUG("find socket %d, context = %d\n", i, context);

		/* Video Memory */
		set = global_ppriv[i].sets[0];
		retval = setFirst(set, &item);
		while (retval) {
			DRM_DEBUG("free video memory 0x%lx\n", item);
#if defined(__linux__) && defined(CONFIG_FB_SIS)
			sis_free(item);
#else
			mmFreeMem((PMemBlock) item);
#endif
			retval = setNext(set, &item);
		}
		setDestroy(set);

		/* AGP Memory */
		set = global_ppriv[i].sets[1];
		retval = setFirst(set, &item);
		while (retval) {
			DRM_DEBUG("free agp memory 0x%lx\n", item);
			mmFreeMem((PMemBlock) item);
			retval = setNext(set, &item);
		}
		setDestroy(set);

		global_ppriv[i].used = 0;
	}

	return 1;
}
int sis_final_context(int context)
{
	int i;

	for(i=0; i<MAX_CONTEXT; i++)
	  if(global_ppriv[i].used && (global_ppriv[i].context == context))
	    break;
          
	if(i < MAX_CONTEXT){
	  set_t *set;
	  unsigned int item;
	  int retval;
	  
  	  DRM_DEBUG("find socket %d, context = %d\n", i, context);

	  /* Video Memory */
	  set = global_ppriv[i].sets[0];
	  retval = setFirst(set, &item);
	  while(retval){
   	    DRM_DEBUG("free video memory 0x%x\n", item);
            sis_free(item);
	    retval = setNext(set, &item);
	  }
	  setDestroy(set);

	  /* AGP Memory */
	  set = global_ppriv[i].sets[1];
	  retval = setFirst(set, &item);
	  while(retval){
   	    DRM_DEBUG("free agp memory 0x%x\n", item);
	    mmFreeMem((PMemBlock)item);
	    retval = setNext(set, &item);
	  }
	  setDestroy(set);
	  
	  global_ppriv[i].used = 0;	  
        }

	/* turn-off auto-flip */
	/* TODO */
#if defined(SIS_STEREO)
	flip_final();
#endif
	
	return 1;
}
Beispiel #8
0
int dbRemove(const sds setName)
{
    int result = DICT_OK;
    set *s = NULL;
    lockWrite(sets);
    s = (set *) dictFetchValue(sets, setName);
    if (NULL != s)
    {
        unregisterSyncObject(s);
        if (!s->registered)
            setDestroy(s);
        result = dictDelete(sets, setName);
    }
    unlockWrite(sets);
    return result;
}
Beispiel #9
0
void cleanupDbEngine(void)
{
    dictIterator *i = NULL;
    dictEntry *de = NULL;
    valType c;

    unregisterSyncObject(sets);
    unregisterSyncObject(objectIndex);

    if (NULL == sets)
        return;

    i = dictGetIterator(sets);

    if (NULL != i)
    {
        while (NULL != (de = dictNext(i)))
        {
            set *setToDelete = (set *) dictGetEntryVal(de);

            if (!setToDelete->registered)
                setDestroy(setToDelete);
        }
    }

    dictReleaseIterator(i);
    dictRelease(sets);

    for (c = 0; c < objectIndexLength; c++)
        if (NULL != objectIndex[c])
        {
            dbObjectRelease((dbObject *) objectIndex[c]);
            free((void *) objectIndex[c]);
        }

    free((void *) objectIndex);
}
Beispiel #10
0
void CGameObject::OnEvent		(NET_Packet& P, u16 type)
{
	switch (type)
	{
	case GE_HIT:
	case GE_HIT_STATISTIC:
		{
/*
			u16				id,weapon_id;
			Fvector			dir;
			float			power, impulse;
			s16				element;
			Fvector			position_in_bone_space;
			u16				hit_type;
			float			ap = 0.0f;

			P.r_u16			(id);
			P.r_u16			(weapon_id);
			P.r_dir			(dir);
			P.r_float		(power);
			P.r_s16			(element);
			P.r_vec3		(position_in_bone_space);
			P.r_float		(impulse);
			P.r_u16			(hit_type);	//hit type
			if ((ALife::EHitType)hit_type == ALife::eHitTypeFireWound)
			{
				P.r_float	(ap);
			}

			CObject*	Hitter = Level().Objects.net_Find(id);
			CObject*	Weapon = Level().Objects.net_Find(weapon_id);

			SHit	HDS = SHit(power, dir, Hitter, element, position_in_bone_space, impulse, (ALife::EHitType)hit_type, ap);
*/
			SHit	HDS;
			HDS.PACKET_TYPE = type;
			HDS.Read_Packet_Cont(P);
//			Msg("Hit received: %d[%d,%d]", HDS.whoID, HDS.weaponID, HDS.BulletID);
			CObject*	Hitter = Level().Objects.net_Find(HDS.whoID);
			CObject*	Weapon = Level().Objects.net_Find(HDS.weaponID);
			HDS.who		= Hitter;
			if (!HDS.who)
			{
				Msg("! ERROR: hitter object [%d] is NULL on client.", HDS.whoID);
			}
			//-------------------------------------------------------
			switch (HDS.PACKET_TYPE)
			{
			case GE_HIT_STATISTIC:
				{
					if (GameID() != eGameIDSingle)
						Game().m_WeaponUsageStatistic->OnBullet_Check_Request(&HDS);
				}break;
			default:
				{
				}break;
			}
			SetHitInfo(Hitter, Weapon, HDS.bone(), HDS.p_in_bone_space, HDS.dir);
			Hit				(&HDS);
			//---------------------------------------------------------------------------
			if (GameID() != eGameIDSingle)
			{
				Game().m_WeaponUsageStatistic->OnBullet_Check_Result(false);
				game_cl_mp*	mp_game = smart_cast<game_cl_mp*>(&Game());
				if (mp_game->get_reward_generator())
					mp_game->get_reward_generator()->OnBullet_Hit(Hitter, this, Weapon, HDS.boneID);
			}
			//---------------------------------------------------------------------------
		}
		break;
	case GE_DESTROY:
		{
			if ( H_Parent() )
			{
				Msg( "! ERROR (GameObject): GE_DESTROY arrived to object[%d][%s], that has parent[%d][%s], frame[%d]",
					ID(), cNameSect().c_str(),
					H_Parent()->ID(), H_Parent()->cName().c_str(), Device.dwFrame );
				
				// This object will be destroy on call function <H_Parent::Destroy>
				// or it will be call <H_Parent::Reject>  ==>  H_Parent = NULL
				// !!! ___ it is necessary to be check!
				break;
			}
#ifdef MP_LOGGING
			Msg("--- Object: GE_DESTROY of [%d][%s]", ID(), cNameSect().c_str());
#endif // MP_LOGGING

			setDestroy		(TRUE);
//			MakeMeCrow		();
		}
		break;
	}
}
Beispiel #11
0
valType dbGC(void)
{
    valType collected = 0, i;
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;
    set *acc = NULL;

    lockWrite(objectIndex);
    lockRead(sets);

    // Step 1. Union all sets in db.
    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    if (NULL == (acc = setCreate()))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        valType currentSetId = 0;
        set *tmp = NULL, *currentSet = (set *) dictGetEntryVal(entry);
        set *flattened = setFlatten(currentSet, 0);

        if (NULL == flattened)
        {
            continue;
        }

        if (1 == dbFindSet(currentSet, &currentSetId, 0))
        {
            if (-1 == setAdd(acc, currentSetId))
            {
                setDestroy(acc);
                dictReleaseIterator(iter);
                unlockRead(sets);
                unlockWrite(objectIndex);
                return 0;
            }
        }

        if (NULL == (tmp = setUnion(acc, flattened)))
        {
            setDestroy(flattened);
            setDestroy(acc);
            dictReleaseIterator(iter);
            unlockRead(sets);
            unlockWrite(objectIndex);
            return 0;
        }

        setDestroy(flattened);
        setDestroy(acc);
        acc = tmp;
    }

    dictReleaseIterator(iter);

    // Step 2. Find objects not present in grand total union.
    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] && !setIsMember(acc, i))
        {
            dbObjectRelease((dbObject *) objectIndex[i]);
            free((dbObject *) objectIndex[i]);
            objectIndex[i] = NULL;

            if (i < objectIndexFreeId)
            {
                objectIndexFreeId = i;
            }

            collected++;
        }
    }

    setDestroy(acc);

    unlockRead(sets);
    unlockWrite(objectIndex);

    return collected;
}