Exemple #1
0
	// This function should be only ran when the temporary buffer size is not 0 (otherwise, data is copied directly to the threads)
	bool CheckReceiveThreads()
	{
		SortReceiveThreads();

		bool wokeThreads = false;
		bool freedSpace = false;
		while (!receiveWaitingThreads.empty() && GetUsedSize() > 0)
		{
			MsgPipeWaitingThread *thread = &receiveWaitingThreads.front();
			// Receive as much as possible, even if it's not enough to wake up.
			u32 bytesToSend = std::min(thread->freeSize, GetUsedSize());

			thread->WriteBuffer(Memory::GetPointer(buffer), bytesToSend);
			// Put the unused data at the start of the buffer.
			nmp.freeSize += bytesToSend;
			memmove(Memory::GetPointer(buffer), Memory::GetPointer(buffer) + bytesToSend, GetUsedSize());
			freedSpace = true;

			if (thread->waitMode == SCE_KERNEL_MPW_ASAP || thread->freeSize == 0)
			{
				thread->Complete(GetUID(), 0);
				receiveWaitingThreads.erase(receiveWaitingThreads.begin());
				wokeThreads = true;
				thread = NULL;
			}
			// Stop at the first that can't wake up.
			else
				break;
		}

		if (freedSpace)
			wokeThreads |= CheckSendThreads();

		return wokeThreads;
	}
Exemple #2
0
	bool CheckSendThreads()
	{
		SortSendThreads();

		bool wokeThreads = false;
		bool filledSpace = false;
		while (!sendWaitingThreads.empty() && nmp.freeSize > 0)
		{
			MsgPipeWaitingThread *thread = &sendWaitingThreads.front();
			u32 bytesToSend = std::min(thread->freeSize, (u32) nmp.freeSize);

			thread->ReadBuffer(Memory::GetPointer(buffer + GetUsedSize()), bytesToSend);
			nmp.freeSize -= bytesToSend;
			filledSpace = true;

			if (thread->waitMode == SCE_KERNEL_MPW_ASAP || thread->freeSize == 0)
			{
				thread->Complete(GetUID(), 0);
				sendWaitingThreads.erase(sendWaitingThreads.begin());
				wokeThreads = true;
				thread = NULL;
			}
			// Unlike receives, we don't do partial sends.  Stop at first blocked thread.
			else
				break;
		}

		if (filledSpace)
			wokeThreads |= CheckReceiveThreads();

		return wokeThreads;
	}
Exemple #3
0
/* allocate a POSIX shared memory segment */
int
jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si)
{
	jack_shm_registry_t* registry;
	int shm_fd;
	int rc = -1;
	char name[SHM_NAME_MAX+1];

	if (jack_shm_lock_registry () < 0) {
        jack_error ("jack_shm_lock_registry fails...");
        return -1;
    }

	if ((registry = jack_get_free_shm_info ()) == NULL) {
		jack_error ("shm registry full");
		goto unlock;
	}

	/* On Mac OS X, the maximum length of a shared memory segment
	 * name is SHM_NAME_MAX (instead of NAME_MAX or PATH_MAX as
	 * defined by the standard).  Unfortunately, Apple sets this
	 * value so small (about 31 bytes) that it is useless for
	 * actual names.  So, we construct a short name from the
	 * registry index for uniqueness and ignore the shm_name
	 * parameter.  Bah!
	 */
	snprintf (name, sizeof (name), "/jack-%d-%d", GetUID(), registry->index);

	if (strlen (name) >= sizeof (registry->id)) {
		jack_error ("shm segment name too long %s", name);
		goto unlock;
	}

	if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) < 0) {
		jack_error ("Cannot create shm segment %s (%s)",
			    name, strerror (errno));
		goto unlock;
	}

	if (ftruncate (shm_fd, size) < 0) {
		jack_error ("Cannot set size of engine shm "
			    "registry 0 (%s)",
			    strerror (errno));
		close (shm_fd);
		goto unlock;
	}

	close (shm_fd);
	registry->size = size;
	strncpy (registry->id, name, sizeof (registry->id));
	registry->allocator = GetPID();
	si->index = registry->index;
	si->ptr.attached_at = MAP_FAILED;	/* not attached */
	rc = 0;				/* success */

 unlock:
	jack_shm_unlock_registry ();
	return rc;
}
PNamedShape CCPACSControlSurfaceDevice::getFlapShape()
{
    PNamedShape loft =  outerShape.GetLoft(
                _segment->GetWing().GetWingCleanShape(),
                getNormalOfControlSurfaceDevice());
    loft->SetName(GetUID().c_str());
    return loft;
}
Exemple #5
0
	void SortThreads(std::vector<MsgPipeWaitingThread> &waitingThreads, bool usePrio)
	{
		// Clean up any not waiting at the same time.
		HLEKernel::CleanupWaitingThreads(WAITTYPE_MSGPIPE, GetUID(), waitingThreads);

		if (usePrio)
			std::stable_sort(waitingThreads.begin(), waitingThreads.end(), __KernelMsgPipeThreadSortPriority);
	}
Exemple #6
0
void CItemSpawn::AddObj(CGrayUID uid)
{
	ADDTOCALLSTACK("CitemSpawn:AddObj");
	// NOTE: This function is also called when loading spawn items
	// on server startup. In this case, some objs UID still invalid
	// (not loaded yet) so just proceed without any checks.

	bool bIsSpawnChar = IsType(IT_SPAWN_CHAR);
	if ( !g_Serv.IsLoading() )
	{
		if ( !uid.IsValidUID() )
			return;

		if ( bIsSpawnChar )				// IT_SPAWN_CHAR can only spawn NPCs
		{
			CChar *pChar = uid.CharFind();
			if ( !pChar || !pChar->m_pNPC )
				return;
		}
		else if ( !uid.ItemFind() )		// IT_SPAWN_ITEM can only spawn items
			return;

		CItemSpawn *pPrevSpawn = static_cast<CItemSpawn*>(uid.ObjFind()->m_uidSpawnItem.ItemFind());
		if ( pPrevSpawn )
		{
			if ( pPrevSpawn == this )		// obj already linked to this spawn
				return;
			pPrevSpawn->DelObj(uid);		// obj linked to other spawn, remove the link before proceed
		}
	}

	BYTE iMax = maximum(GetAmount(), 1);
	for (BYTE i = 0; i < iMax; i++ )
	{
		if ( !m_obj[i].IsValidUID() )
		{
			m_obj[i] = uid;
			m_currentSpawned++;

			// objects are linked to the spawn at each server start
			if ( !g_Serv.IsLoading() )
			{
				uid.ObjFind()->m_uidSpawnItem = GetUID();
				if ( bIsSpawnChar )
				{
					CChar *pChar = uid.CharFind();
					ASSERT(pChar->m_pNPC);
					pChar->StatFlag_Set(STATF_Spawned);
					pChar->m_ptHome = GetTopPoint();
					pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(m_itSpawnChar.m_DistMax);
				}
			}
			break;
		}
	}
	if ( !g_Serv.IsLoading() )
		ResendTooltip();
}
Exemple #7
0
void ZActor::Attack_Range(rvector& dir)
{
	m_Animation.Input(ZA_INPUT_ATTACK_RANGE);

	SetDirection(dir);
	rvector pos;
	pos = m_Position + rvector(0, 0, 100);
	ZPostNPCRangeShot(GetUID(), g_pGame->GetTime(), pos, pos + 10000.f*dir, MMCIP_PRIMARY);
}
Exemple #8
0
int       Session::Kick(int reason)
{
    if(GetState() == Session::PLAYER_STATE_KICKING )
    {
        return -1;
    }
    LOG_DEBUG("kick uid = %lu reason = %u [maybe todo notify reason]",GetUID(),reason);
    if(player)
    {
        player->Detach();
    }
    sessionMgr->GetLoginLogic().Logout(sessionMgr->GetSession(GetUID()));
    //-----------------------------------------------------------------
    ResponseClient(gate::GateSSMsg::EVENT_CLOSE,
                   gate::GateSSMsg::CONNECTION_CLOSE_BY_DEFAULT); 
    SetState(Session::PLAYER_STATE_KICKING);
    return 0;
}
PNamedShape CTiglAbstractGeometricComponent::GetLoft(void)
{
    if (!(loft)) {
#ifdef DEBUG
        LOG(INFO) << "Building loft " << GetUID();
#endif
        loft = BuildLoft();
    }
    return loft;
}
bool CItemMulti::Multi_IsPartOf( const CItem * pItem ) const
{
	// Assume it is in my area test already.
	// IT_MULTI
	// IT_SHIP
	ASSERT( pItem );
	if ( pItem == this )
		return( true );
	return ( pItem->m_uidLink == GetUID());
}
/*
*********************************************************************************************************
*	函 数 名: GetMACAdress
*	功能说明: 获取设备MAC地址。MAC地址前面三个地址是IEEE给ST公司分配的数据
*	形    参: 将MAC地址写入mac指针
*	返 回 值: 无
*********************************************************************************************************
*/
void  GetMACAdress(uint8_t *mac) 
{
	uint8_t uid[12];
	GetUID(uid); 
	mac[0]=MAC0;
	mac[1]=MAC1;
	mac[2]=MAC2;
	mac[3]=uid[0]^uid[3]^uid[6]^uid[9];
	mac[4]=uid[1]^uid[4]^uid[7]^uid[10];
	mac[5]=uid[2]^uid[5]^uid[8]^uid[11];
}   
Exemple #12
0
void CItem::Spawn_GenerateChar( CResourceDef * pDef )
{
	if ( ! IsTopLevel())
		return;	// creatures can only be top level.
	if ( m_itSpawnChar.m_current >= GetAmount())
		return;
	int iComplexity = GetTopSector()->GetCharComplexity();
	if ( iComplexity > g_Cfg.m_iMaxCharComplexity )
	{
		DEBUG_MSG(( "Spawn uid=0%lx too complex (%d>%d)\n", GetUID(), iComplexity, g_Cfg.m_iMaxCharComplexity ));
		return;
	}

	int iDistMax = m_itSpawnChar.m_DistMax;
	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		int i = pSpawnGroup->GetRandMemberIndex();
		if ( i >= 0 )
		{
			rid = pSpawnGroup->GetMemberID(i);
		}
	}
	
	CREID_TYPE id;
	if ( rid.GetResType() == RES_CHARDEF || 
		rid.GetResType() == RES_UNKNOWN )
	{
		id = (CREID_TYPE) rid.GetResIndex();
	}
	else
	{
		return;
	}

	CChar * pChar = CChar::CreateNPC( id );
	if ( pChar == NULL )
		return;
	ASSERT(pChar->m_pNPC);

	m_itSpawnChar.m_current ++;
	pChar->Memory_AddObjTypes( this, MEMORY_ISPAWNED );
	// Move to spot "near" the spawn item.
	pChar->MoveNearObj( this, iDistMax );
	if ( iDistMax )
	{
		pChar->m_ptHome = GetTopPoint();
		pChar->m_pNPC->m_Home_Dist_Wander = iDistMax;
	}
	pChar->Update();
}
Exemple #13
0
    int Shm::shmalloc (const char * /*shm_name*/, jack_shmsize_t size, jack_shm_info_t* si) {
        jack_shm_registry_t* registry;
        int shm_fd;
        int rc = -1;
        char name[SHM_NAME_MAX+1];
 
        if (shm_lock_registry () < 0) {
           jack_error ("jack_shm_lock_registry fails...");
           return -1;
        }

		sp<IAndroidShm> service = getShmService();
		if(service == NULL){
			rc = errno;
			jack_error("shm service is null");
			goto unlock;
		}
 
        if ((registry = get_free_shm_info ()) == NULL) {
           jack_error ("shm registry full");
           goto unlock;
        }

        snprintf (name, sizeof (name), "/jack-%d-%d", GetUID(), registry->index);
        if (strlen (name) >= sizeof (registry->id)) {
           jack_error ("shm segment name too long %s", name);
           goto unlock;
        }

        if((shm_fd = service->allocShm(size)) < 0) {
           rc = errno;
           jack_error ("Cannot create shm segment %s", name);
           goto unlock;
        }
        
        //close (shm_fd);
        registry->size = size;
        strncpy (registry->id, name, sizeof (registry->id) - 1);
        registry->id[sizeof (registry->id) - 1] = '\0';
        registry->allocator = GetPID();
        registry->fd = shm_fd;
        si->fd = shm_fd;
        si->index = registry->index;
        si->ptr.attached_at = MAP_FAILED;  /* not attached */
        rc = 0;  /* success */
        
        jack_d ("[APA] jack_shmalloc : ok ");

unlock:
        shm_unlock_registry ();
        return rc;
    }
Exemple #14
0
/* set a unique per-user, per-server shm prefix string
 *
 * According to the POSIX standard:
 *
 *   "The name argument conforms to the construction rules for a
 *   pathname. If name begins with the slash character, then processes
 *   calling shm_open() with the same value of name refer to the same
 *   shared memory object, as long as that name has not been
 *   removed. If name does not begin with the slash character, the
 *   effect is implementation-defined. The interpretation of slash
 *   characters other than the leading slash character in name is
 *   implementation-defined."
 *
 * Since the Linux implementation does not allow slashes *within* the
 * name, in the interest of portability we use colons instead.
 */
static void
jack_set_server_prefix (const char *server_name)
{
#ifdef WIN32
    char buffer[UNLEN+1]={0};
    DWORD len = UNLEN+1;
    GetUserName(buffer, &len);
    snprintf (jack_shm_server_prefix, sizeof (jack_shm_server_prefix),
		  "jack-%s:%s:", buffer, server_name);
#else
    snprintf (jack_shm_server_prefix, sizeof (jack_shm_server_prefix),
		  "jack-%d:%s:", GetUID(), server_name);
#endif
}
Exemple #15
0
// get short name for loft
std::string CCPACSFuselage::GetShortShapeName ()
{
    unsigned int findex = 0;
    for (int i = 1; i <= GetConfiguration().GetFuselageCount(); ++i) {
        tigl::CCPACSFuselage& f = GetConfiguration().GetFuselage(i);
        if (GetUID() == f.GetUID()) {
            findex = i;
            std::stringstream shortName;
            shortName << "F" << findex;
            return shortName.str();
        }
    }
    return "UNKNOWN";
}
void CHSAsteroid::DoCycle(void)
{
	CHSObject *cObj;
	CHSUniverse *uSrc;
	CHSShip *Target;
	int idx;
	double dDistance;

		
	  uSrc = uaUniverses.FindUniverse(GetUID());
	  if (!uSrc)
		  return;
	
	  // Grab all of the objects in the universe, and see if they're in the area.
	  for (idx = 0; idx < HS_MAX_OBJECTS; idx++)
	  {
		  cObj = uSrc->GetUnivObject(idx);
		  if (!cObj)
			  continue;
		  if (cObj->GetType() != HST_SHIP)
			  continue;

		  Target = (CHSShip *) cObj;
		  dDistance = Dist3D(GetX(),GetY(),GetZ(),Target->GetX(),Target->GetY(),Target->GetZ());
		  
		  if (dDistance > GetSize() * 100)
			  continue;

		  if (GetDensity() < getrandom(50 / Target->GetSize() * ((Target->GetSpeed() + 1) / 1000)))
			  continue;

		  int strength;

		  strength = getrandom(GetDensity() * Target->GetSize() * ((Target->GetSpeed() + 1) / 1000));

		  Target->m_hull_points -= strength;

		  Target->NotifySrooms("The ship shakes as asteroids impact on the hull");

		  	// Is hull < 0?
			if (Target->m_hull_points < 0)
			{
				Target->ExplodeMe();
				if (!hsInterface.HasFlag(m_objnum, TYPE_THING, THING_HSPACE_SIM))
					Target->KillShipCrew("THE SHIP EXPLODES!!");
			} 

	  }

}
/*
*********************************************************************************************************
*	函 数 名: PrintUID
*	功能说明: 串口打印UID信息
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void PrintUID(void)
{
	#ifdef	UID_DEBUG 
	uint8_t i;
	uint8_t uid[12];
	GetUID(uid);
	printf("UID =%X",uid[0]);
	for(i=1;i<12;i++)
	{
		printf("-%X",uid[i]);
	} 
	printf("H\r\n");
	#endif	
}  
Exemple #18
0
int CUT_POP3Client::GetUID(LPWSTR uid, size_t maxSize, int msgNumber, size_t *size) {

	int retval;
	
	if(maxSize > 0) {
		char * uidA = new char [maxSize];
		
		if(uidA != NULL) {
			retval = GetUID( uidA, maxSize, msgNumber, size);
			
			if(retval == UTE_SUCCESS) {
				CUT_Str::cvtcpy(uid, maxSize, uidA);
			}
			
			delete [] uidA;
			
		}
		else {
			retval = UTE_OUT_OF_MEMORY;
		}
	}
	else {
		if(size == NULL) (retval = UTE_NULL_PARAM);
		else {
			LPCSTR lpStr = GetUID(msgNumber);
			if(lpStr != NULL) {
				*size = strlen(lpStr)+1;
				retval = UTE_BUFFER_TOO_SHORT;
			}
			else {
				retval = UTE_INDEX_OUTOFRANGE;
			}
		}
	}
	return retval;

}
bool CItemMulti::Multi_CreateComponent( ITEMID_TYPE id, int dx, int dy, int dz, DWORD dwKeyCode )
{
	CItem * pItem = CreateTemplate( id );
	ASSERT(pItem);

	CPointMap pt = GetTopPoint();
	pt.m_x += dx;
	pt.m_y += dy;
	pt.m_z += dz;

	bool fNeedKey = false;

	switch ( pItem->GetType() )
	{
	case IT_KEY:	// it will get locked down with the house ?
	case IT_SIGN_GUMP:
	case IT_SHIP_TILLER:
		pItem->m_itKey.m_lockUID.SetPrivateUID( dwKeyCode );	// Set the key id for the key/sign.
		fNeedKey = true;
		break;
	case IT_DOOR:
		pItem->SetType(IT_DOOR_LOCKED);
fNeedKey = true;
		break;
	case IT_CONTAINER:
		pItem->SetType(IT_CONTAINER_LOCKED);
fNeedKey = true;
		break;
	case IT_SHIP_SIDE:
		pItem->SetType(IT_SHIP_SIDE_LOCKED);
		break;
	case IT_SHIP_HOLD:
		pItem->SetType(IT_SHIP_HOLD_LOCK);
		break;
	}

	pItem->SetAttr( ATTR_MOVE_NEVER | (m_Attr&(ATTR_MAGIC|ATTR_INVIS)));
	pItem->SetHue( GetHue());
	pItem->m_uidLink = GetUID();	// lock it down with the structure.

	if ( pItem->IsTypeLockable() || pItem->IsTypeLocked())
	{
		pItem->m_itContainer.m_lockUID.SetPrivateUID( dwKeyCode );	// Set the key id for the door/key/sign.
		pItem->m_itContainer.m_lock_complexity = 10000;	// never pickable.
	}

	pItem->MoveTo( pt );
	return( fNeedKey );
}
bool CItemStone::CheckValidMember( CStoneMember * pMember )
{
	ADDTOCALLSTACK("CItemStone::CheckValidMember");
	ASSERT(pMember);
	ASSERT( pMember->GetParent() == this );

	if ( GetAmount()==0 || g_Serv.m_iExitFlag )	// no reason to elect new if the stone is dead.
		return( true );	// we are deleting anyhow.

	switch ( pMember->GetPriv())
	{
		case STONEPRIV_MASTER:
		case STONEPRIV_MEMBER:
		case STONEPRIV_CANDIDATE:
		case STONEPRIV_ACCEPTED:
			if ( GetMemoryType())
			{
				// Make sure the member has a memory that links them back here.
				CChar * pChar = pMember->GetLinkUID().CharFind();
				if ( pChar == NULL )
					break;
				if ( pChar->Guild_Find( GetMemoryType()) != this )
					break;
			}
			return( true );
		case STONEPRIV_ENEMY:
			{
				CItemStone * pEnemyStone = dynamic_cast <CItemStone *>( pMember->GetLinkUID().ItemFind());
				if ( pEnemyStone == NULL )
					break;
				CStoneMember * pEnemyMember = pEnemyStone->GetMember(this);
				if ( pEnemyMember == NULL )
					break;
				if ( pMember->GetWeDeclared() && ! pEnemyMember->GetTheyDeclared())
					break;
				if ( pMember->GetTheyDeclared() && ! pEnemyMember->GetWeDeclared())
					break;
			}
			return( true );

		default:
			break;
	}

	// just delete this member. (it is mislinked)
	DEBUG_ERR(( "Stone UID=0%lx has mislinked member uid=0%lx\n", 
		(DWORD) GetUID(), (DWORD) pMember->GetLinkUID()));
	return( false );
}
void CHSBlackHole::DoCycle(void)
{
	CHSObject *cObj;
	CHSUniverse *uSrc;
	CHSShip *Target;
	int idx;
	double dDistance;

		
	  uSrc = uaUniverses.FindUniverse(GetUID());
	  if (!uSrc)
		  return;
	
	  // Grab all of the objects in the universe, and see if they're in the area.
	  for (idx = 0; idx < HS_MAX_OBJECTS; idx++)
	  {
		  cObj = uSrc->GetUnivObject(idx);
		  if (!cObj)
			  continue;
		  if (cObj->GetType() != HST_SHIP)
			  continue;

		  Target = (CHSShip *) cObj;
		  dDistance = Dist3D(GetX(),GetY(),GetZ(),Target->GetX(),Target->GetY(),Target->GetZ());
		  
		  if (dDistance > GetSize() * 100 - 0.01)
			  continue;

		  int strength;

		  strength = (GetSize() * 100) / dDistance * 100 - 100;

		  Target->MoveTowards(m_x, m_y, m_z, strength);

		  Target->m_hull_points -= strength;

		  Target->NotifySrooms("The hull buckles from the black hole's gravity.");

		  	// Is hull < 0?
			if (Target->m_hull_points < 0)
			{
				Target->ExplodeMe();
				if (!hsInterface.HasFlag(m_objnum, TYPE_THING, THING_HSPACE_SIM))
					Target->KillShipCrew("THE SHIP EXPLODES!!");
			} 

	  }

}
void IntersectItem::SaveData( int nParentID )
{	
	if( GetUID() >=0 )
	{
		CString strSQL;
		GetUpdateSQL(strSQL);
		CADODatabase::ExecuteSQLStatement(strSQL);
	}
	else // insert data
	{	
		CString strSQL;
		GetInsertSQL(nParentID, strSQL);
		m_nUID = CADODatabase::ExecuteSQLStatementAndReturnScopeID(strSQL);
	}	
}
Exemple #23
0
    char* JackTools::UserDir()
    {
        static char user_dir[JACK_PATH_MAX + 1] = "";

        /* format the path name on the first call */
        if (user_dir[0] == '\0') {
            if (getenv ("JACK_PROMISCUOUS_SERVER")) {
                snprintf(user_dir, sizeof(user_dir), "%s/jack", jack_tmpdir);
            } else {
                snprintf(user_dir, sizeof(user_dir), "%s/jack-%d", jack_tmpdir, GetUID());
            }
        }

        return user_dir;
    }
// Return false if the entity is to be destroyed
bool CAmmoEntity::Update(TFloat32 updateTime)
{

	if (!landed)
	{
		Position().y -= m_FallSpeed * updateTime;

		if (Position().y < m_Height)
		{
			landed = true;
		}
	}
	else
	{
		m_SinWave += updateTime;
		Position().y = m_Height + sin(m_SinWave);
		// Rotate on the spot and bob up and down (for effect)
		Matrix().RotateY((kfPi / 3) * updateTime);

	}

	//TODO: Collision detection
	TInt32 enumID;
	EntityManager.BeginEnumEntities(enumID, "", "", "Tank");
	CTankEntity* theTank = dynamic_cast<CTankEntity*> (EntityManager.EnumEntity(enumID));
	while (theTank)
	{
		float radius = Template()->Mesh()->BoundingRadius();
		if (Length(Position() - theTank->Position()) < (theTank->GetRadius() + radius))	//If distance between the ammo and the tank is less than the tank's radius
		{
			EntityManager.EndEnumEntities(enumID);
			// Hit the tank, send the hit message and destroy the bullet
			SMessage theCollectMessage;
			theCollectMessage.from = GetUID();
			theCollectMessage.type = Msg_Ammo;
			theCollectMessage.intParam = m_RefillSize;
			Messenger.SendMessageA(theTank->GetUID(), theCollectMessage);
			return false;
		}


		theTank = dynamic_cast<CTankEntity*> (EntityManager.EnumEntity(enumID));
	}

	EntityManager.EndEnumEntities(enumID);

	return true;
}
Exemple #25
0
void CItem::Spawn_OnTick( bool fExec )
{
	int iMinutes;
	if ( m_itSpawnChar.m_TimeHiMin <= 0 )
	{
		iMinutes = Calc_GetRandVal(30) + 1;
	}
	else
	{
		iMinutes = min( m_itSpawnChar.m_TimeHiMin, m_itSpawnChar.m_TimeLoMin ) + Calc_GetRandVal( abs( m_itSpawnChar.m_TimeHiMin - m_itSpawnChar.m_TimeLoMin ));
	}

	if ( iMinutes <= 0 )
		iMinutes = 1;

	if ( !fExec || IsTimerExpired() )
	{
		SetTimeout( iMinutes * 60 * TICK_PER_SEC );	// set time to check again.
	}

	if ( ! fExec )
		return;

	CResourceDef * pDef = Spawn_FixDef();
	if ( pDef == NULL )
	{
		RESOURCE_ID_BASE rid;
		if ( IsType(IT_SPAWN_ITEM))
		{
			rid = m_itSpawnItem.m_ItemID;
		}
		else
		{
			rid = m_itSpawnChar.m_CharID;
		}
		DEBUG_ERR(( "Bad Spawn point uid=0%lx, id=%s\n", (DWORD) GetUID(), g_Cfg.ResourceGetName(rid) ));
		return;
	}

	if ( IsType(IT_SPAWN_ITEM))
	{
		Spawn_GenerateItem(pDef);
	}
	else
	{
		Spawn_GenerateChar(pDef);
	}
}
Exemple #26
0
int
jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si)
{
	jack_shm_registry_t* registry;
	HANDLE shm_fd;
	int rc = -1;
	char name[SHM_NAME_MAX+1];

	if (jack_shm_lock_registry () < 0) {
        jack_error ("jack_shm_lock_registry fails...");
        return -1;
    }

	if ((registry = jack_get_free_shm_info ()) == NULL) {
		jack_error ("shm registry full");
		goto unlock;
	}

	snprintf (name, sizeof (name), "jack-%d-%d", GetUID(), registry->index);

	if (strlen (name) >= sizeof (registry->id)) {
		jack_error ("shm segment name too long %s", name);
		goto unlock;
	}

	if ((shm_fd = CreateFileMapping(INVALID_HANDLE_VALUE,
									0, PAGE_READWRITE,
									0, size,
									name)) == NULL || (shm_fd == INVALID_HANDLE_VALUE)) {
		int rc = GetLastError();
		jack_error ("Cannot create shm segment (%ld)",rc);
		goto unlock;
	}

	//CloseHandle (shm_fd); // TO CHECK

	registry->size = size;
	strncpy (registry->id, name, sizeof (registry->id));
	registry->allocator = _getpid();
	si->index = registry->index;
	si->ptr.attached_at = NULL;	/* not attached */
	rc = 0;				/* success */

 unlock:
	jack_shm_unlock_registry ();
	return rc;
}
Exemple #27
0
CChar *CItemCorpse::IsCorpseSleeping() const
{
	ADDTOCALLSTACK("CItemCorpse::IsCorpseSleeping");
	// Is this corpse really a sleeping person ?
	// CItemCorpse
	if ( !IsType(IT_CORPSE) )
	{
		DEBUG_ERR(("Corpse (0%x) doesn't have type T_CORPSE! (it has %d)\n", (dword)GetUID(), GetType()));
		return NULL;
	}

	CChar *pCharCorpse = m_uidLink.CharFind();
	if ( pCharCorpse && pCharCorpse->IsStatFlag(STATF_Sleeping) && !GetTimeStamp().IsTimeValid() )
		return pCharCorpse;

	return NULL;
}
bool CItemMulti::Ship_MoveDelta( CPointBase pdelta )
{
	// Move the ship one space in some direction.

	ASSERT( m_pRegion->m_iLinkedSectors );

	int znew = GetTopZ() + pdelta.m_z;
	if ( pdelta.m_z > 0 )
	{
		if ( znew >= (UO_SIZE_Z - PLAYER_HEIGHT )-1 )
			return( false );
	}
	else if ( pdelta.m_z < 0 )
	{
		if ( znew <= (UO_SIZE_MIN_Z + 3 ))
			return( false );
	}

	// Move the ship and everything on the deck
	CObjBase * ppObjs[MAX_MULTI_LIST_OBJS+1];
	int iCount = Ship_ListObjs( ppObjs );

	for ( int i=0; i <iCount; i++ )
	{
		CObjBase * pObj = ppObjs[i];
		ASSERT(pObj);
		CPointMap pt = pObj->GetTopPoint();
		pt += pdelta;
		if ( ! pt.IsValidPoint())  // boat goes out of bounds !
		{
			DEBUG_ERR(( "Ship uid=0%x out of bounds\n", (DWORD) GetUID()));
			continue;
		}
		pObj->MoveTo( pt );
		if ( pObj->IsChar())
		{
			ASSERT( m_pRegion->m_iLinkedSectors );
			pObj->RemoveFromView(); // Get rid of the blink/walk
			pObj->Update();
		}
	}

	return( true );
}
  void GetImageStatisticsWithImageConnected()
  {
    //create rules connection
    auto statisticsNode = mitk::CreateImageStatisticsNode(m_statisticsContainer, "testStatistics");
    CreateNodeRelationImage(m_statisticsContainer.GetPointer(), m_image.GetPointer());
    auto standaloneDataStorage = mitk::StandaloneDataStorage::New();
    standaloneDataStorage->Add(statisticsNode);

    //rule: (image-->statistics), 1 connected image --> test return image statistics
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImage;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImage = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImage->GetUID(), m_statisticsContainer->GetUID());

    //new rule: (image2-->statistics2 AND mask --> statistics2)
    CreateNodeRelationImage(m_statisticsContainer2.GetPointer(), m_image2.GetPointer());
    CreateNodeRelationMask(m_statisticsContainer2.GetPointer(), m_mask.GetPointer());

    auto statisticsNode2 = mitk::CreateImageStatisticsNode(m_statisticsContainer2, "testStatistics2");
    standaloneDataStorage->Add(statisticsNode2);

    //--> test return (still) image statistics (!= statistics2)
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageAgain;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAgain = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID(), m_statisticsContainer->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID() != m_statisticsContainer2->GetUID(), true);

    //--> test return image statistics 2
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAgain = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image2.GetPointer(), m_mask.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID(), m_statisticsContainer2->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID() != m_statisticsContainer->GetUID(), true);

    //add another newer statistic: should return this newer one
    auto statisticsContainerNew = mitk::ImageStatisticsContainer::New();
    CreateNodeRelationImage(statisticsContainerNew.GetPointer(), m_image.GetPointer());

    auto statisticsNodeNew = mitk::CreateImageStatisticsNode(statisticsContainerNew, "testStatisticsNew");
    standaloneDataStorage->Add(statisticsNodeNew);
    statisticsContainerNew->Modified();

    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageNew;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageNew = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageNew->GetUID(), statisticsContainerNew->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageNew->GetUID() != m_statisticsContainer->GetUID(), true);
  }
Exemple #30
0
bool MMatchChannel::AddStage(MMatchStage* pStage)
{
	if (m_UnusedStageIndexList.empty()) return false;

	int nRecommendedStageIndex = *(m_UnusedStageIndexList.begin());
	m_UnusedStageIndexList.pop_front();
	if ((nRecommendedStageIndex < 0) || (nRecommendedStageIndex > m_nMaxStages)) return false;

	pStage->SetOwnerChannel(GetUID(), nRecommendedStageIndex);

	if (m_pStages[nRecommendedStageIndex] != NULL)
	{
		_ASSERT(0);
	}

	m_pStages[nRecommendedStageIndex] = pStage;

	return true;
}