コード例 #1
0
ファイル: subsidy.cpp プロジェクト: koreapyj/openttd-yapp
/**
 * Tries to create a cargo subsidy with a town as source.
 * @return True iff the subsidy was created.
 */
bool FindSubsidyTownCargoRoute()
{
	if (!Subsidy::CanAllocateItem()) return false;

	SourceType src_type = ST_TOWN;

	/* Select a random town. */
	const Town *src_town = Town::GetRandom();

	uint32 town_cargo_produced = src_town->cargo_produced;

	/* Passenger subsidies are not handled here. */
	ClrBit(town_cargo_produced, CT_PASSENGERS);

	/* No cargo produced at all? */
	if (town_cargo_produced == 0) return false;

	/* Choose a random cargo that is produced in the town. */
	uint8 cargo_number = RandomRange(CountBits(town_cargo_produced));
	CargoID cid;
	FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) {
		if (cargo_number == 0) break;
		cargo_number--;
	}

	/* Avoid using invalid NewGRF cargoes. */
	if (!CargoSpec::Get(cid)->IsValid()) return false;

	/* Quit if the percentage transported is large enough. */
	if (src_town->GetPercentTransported(cid) > SUBSIDY_MAX_PCT_TRANSPORTED) return false;

	SourceID src = src_town->index;

	return FindSubsidyCargoDestination(cid, src_type, src);
}
コード例 #2
0
ファイル: bitvec.cpp プロジェクト: Reinis/openbabel
 /** Retrieve a list of bit offsets
    The \p bit_offsets vector is first cleared.
    \param[out] bit_offsets A list of bit offsets, in ascending order
 */
 void OBBitVec::ToVecInt(std::vector<int> & bit_offsets) const
 {
   bit_offsets.clear();
   bit_offsets.reserve(CountBits());
   for (int i = NextBit(-1);i != -1;i = NextBit(i))
     bit_offsets.push_back(i);
 }
コード例 #3
0
ファイル: mpivis.cpp プロジェクト: Adidasman1/source-sdk-2013
void ReceiveBasePortalVis( uint64 iWorkUnit, MessageBuffer *pBuf, int iWorker )
{
	portal_t * p = &portals[iWorkUnit];
	if ( p->portalflood != 0 || p->portalfront != 0 || p->portalvis != 0) 
	{
		Msg("Duplicate portal %llu\n", iWorkUnit);
	}
	
	if ( pBuf->getLen() - pBuf->getOffset() != portalbytes*2 )
		Error( "Invalid packet in ReceiveBasePortalVis." );

	//
	// allocate memory for bitwise vis solutions for this portal
	//
	p->portalfront = (byte*)malloc (portalbytes);
	pBuf->read( p->portalfront, portalbytes );
	
	p->portalflood = (byte*)malloc (portalbytes);
	pBuf->read( p->portalflood, portalbytes );

	p->portalvis = (byte*)malloc (portalbytes);
	memset (p->portalvis, 0, portalbytes);

	p->nummightsee = CountBits( p->portalflood, g_numportals*2 );
}
コード例 #4
0
/*
==============
LeafVectorFromPortalVector
==============
*/
int LeafVectorFromPortalVector(byte * portalbits, byte * leafbits)
{
	int             i, j, leafnum;
	vportal_t      *p;
	int             c_leafs;


	for(i = 0; i < numportals * 2; i++)
	{
		if(portalbits[i >> 3] & (1 << (i & 7)))
		{
			p = portals + i;
			leafbits[p->leaf >> 3] |= (1 << (p->leaf & 7));
		}
	}

	for(j = 0; j < portalclusters; j++)
	{
		leafnum = j;
		while(leafs[leafnum].merged >= 0)
			leafnum = leafs[leafnum].merged;
		//if the merged leaf is visible then the original leaf is visible
		if(leafbits[leafnum >> 3] & (1 << (leafnum & 7)))
		{
			leafbits[j >> 3] |= (1 << (j & 7));
		}
	}

	c_leafs = CountBits(leafbits, portalclusters);

	return c_leafs;
}
コード例 #5
0
int main(){
	printf("Enter the value for n : ");
	int n, count;
	scanf("%d", &n);
	count = CountBits(n);
	printf("Bit Count: %d", count);
	return 0;
}
コード例 #6
0
ファイル: multiclass.c プロジェクト: frasten/openleu
int GetClassLevel(struct char_data *ch, int iClass)
{

  if (IS_SET(ch->player.iClass, iClass)) {
    return(GET_LEVEL(ch, CountBits(iClass)-1));
  }
  return(0);
}
コード例 #7
0
ファイル: script_goal.cpp プロジェクト: Ayutac/OpenTTD
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
{
	CCountedPtr<Text> counter(question);

	EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
	EnforcePrecondition(false, question != NULL);
	const char *text = question->GetEncodedText();
	EnforcePreconditionEncodedText(false, text);
	EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
	EnforcePrecondition(false, CountBits(buttons) >= 1 && CountBits(buttons) <= 3);
	EnforcePrecondition(false, buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
	EnforcePrecondition(false, type < ::GOAL_QUESTION_TYPE_COUNT);

	uint8 c = company;
	if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;

	return ScriptObject::DoCommand(0, uniqueid | (c << 16) | (type << 24), buttons, CMD_GOAL_QUESTION, text);
}
コード例 #8
0
int main(){


int num=9;

printf("\nNo of set bits : %d",CountBits(num));

return 0;
}
コード例 #9
0
ファイル: WAVFile.cpp プロジェクト: Tphive/mpc-be
bool CWAVFile::ProcessWAVEFORMATEX()
{
	if (!m_fmtdata || m_fmtsize < sizeof(WAVEFORMATEX)) {
		return false;
	}

	WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_fmtdata;
	if (wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE && m_fmtsize >= sizeof(WAVEFORMATEXTENSIBLE)) {
		WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)m_fmtdata;
		m_subtype = wfex->SubFormat;
		if (CountBits(wfex->dwChannelMask) != wfex->Format.nChannels) {
			// fix incorrect dwChannelMask
			wfex->dwChannelMask = GetDefChannelMask(wfex->Format.nChannels);
		}
	} else {
		m_subtype = FOURCCMap(wfe->wFormatTag);
	}

	if (wfe->wFormatTag == WAVE_FORMAT_PCM && (wfe->nChannels > 2 || wfe->wBitsPerSample != 8 && wfe->wBitsPerSample != 16)
			|| wfe->wFormatTag == WAVE_FORMAT_IEEE_FLOAT && wfe->nChannels > 2) {
		// convert incorrect WAVEFORMATEX to WAVEFORMATEXTENSIBLE

		WAVEFORMATEXTENSIBLE* wfex = DNew WAVEFORMATEXTENSIBLE;
		wfex->Format.wFormatTag				= WAVE_FORMAT_EXTENSIBLE;
		wfex->Format.nChannels				= wfe->nChannels;
		wfex->Format.nSamplesPerSec			= wfe->nSamplesPerSec;
		wfex->Format.wBitsPerSample			= (wfe->wBitsPerSample + 7) & ~7;
		wfex->Format.nBlockAlign			= wfex->Format.nChannels * wfex->Format.wBitsPerSample / 8;
		wfex->Format.nAvgBytesPerSec		= wfex->Format.nSamplesPerSec * wfex->Format.nBlockAlign;
		wfex->Format.cbSize					= 22;
		wfex->Samples.wValidBitsPerSample	= wfe->wBitsPerSample;
		wfex->dwChannelMask					= GetDefChannelMask(wfe->nChannels);
		wfex->SubFormat						= m_subtype;

		delete[] m_fmtdata;

		m_fmtdata = (BYTE*)wfex;
		m_fmtsize = sizeof(WAVEFORMATEXTENSIBLE);
		wfe = (WAVEFORMATEX*)m_fmtdata;
	}

	m_samplerate		= wfe->nSamplesPerSec;
	m_bitdepth			= wfe->wBitsPerSample;
	m_channels			= wfe->nChannels;
	if (wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE && m_fmtsize >= sizeof(WAVEFORMATEXTENSIBLE)) {
		m_layout = ((WAVEFORMATEXTENSIBLE*)m_fmtdata)->dwChannelMask;
	} else {
		m_layout = GetDefChannelMask(wfe->nChannels);
	}
	m_nAvgBytesPerSec	= wfe->nAvgBytesPerSec;
	m_nBlockAlign		= wfe->nBlockAlign;

	m_blocksize			= max(m_nBlockAlign, m_nAvgBytesPerSec / 16); // 62.5 ms
	m_blocksize			-= m_blocksize % m_nBlockAlign;

	return true;
}
コード例 #10
0
ファイル: treehandler.cpp プロジェクト: toughie88/Easy3D-1
int CTreeHandler::CheckMode( int srcmode )
{
	// import か exportは必ず、どちらか1個だけセット
	int chkmask;
	int chkcnt;

	chkmask = TMODE_IMPORT | TMODE_EXPORT;
	chkcnt = CountBits( srcmode & chkmask );
	if( chkcnt != 1 )
		return 1;

	// once または level_once または mult は必ず、どちらか1個だけセット
	chkmask = TMODE_ONCE | TMODE_LEVEL_ONCE | TMODE_MULT;
	chkcnt = CountBits( srcmode & chkmask );
	if( chkcnt != 1 )
		return 1;

	return 0; // 0 が正常なの おほほほほ
}
コード例 #11
0
ファイル: goal.cpp プロジェクト: Ayutac/OpenTTD
/**
 * Ask a goal related question
 * @param tile unused.
 * @param flags type of operation
 * @param p1 various bitstuffed elements
 * - p1 = (bit  0 - 15) - Unique ID to use for this question.
 * - p1 = (bit 16 - 23) - Company for which this question is.
 * @param p2 Buttons of the question.
 * @param text Text of the question.
 * @return the cost of this operation or an error
 */
CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	uint16 uniqueid = (GoalType)GB(p1, 0, 16);
	CompanyID company = (CompanyID)GB(p1, 16, 8);
	byte type = GB(p1, 24, 8);

	if (_current_company != OWNER_DEITY) return CMD_ERROR;
	if (StrEmpty(text)) return CMD_ERROR;
	if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
	if (CountBits(p2) < 1 || CountBits(p2) > 3) return CMD_ERROR;
	if (p2 >= (1 << GOAL_QUESTION_BUTTON_COUNT)) return CMD_ERROR;
	if (type >= GOAL_QUESTION_TYPE_COUNT) return CMD_ERROR;

	if (flags & DC_EXEC) {
		if ((company != INVALID_COMPANY && company == _local_company) || (company == INVALID_COMPANY && Company::IsValidID(_local_company))) ShowGoalQuestion(uniqueid, type, p2, text);
	}

	return CommandCost();
}
コード例 #12
0
//=================================================================================================
bool Quest_Orcs::HandleLocationEvent(LocationEventHandler::Event event)
{
	if(event == LocationEventHandler::CLEARED && prog == Progress::Started)
	{
		levels_cleared |= (1 << L.dungeon_level);
		if(CountBits(levels_cleared) == dungeon_levels)
			SetProgress(Progress::ClearedLocation);
	}
	return false;
}
コード例 #13
0
ファイル: goal.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Ask a goal related question
 * @param tile unused.
 * @param flags type of operation
 * @param p1 various bitstuffed elements
 * - p1 = (bit  0 - 15) - Unique ID to use for this question.
 * - p1 = (bit 16 - 23) - Company or client for which this question is.
 * - p1 = (bit 24 - 25) - Question type.
 * - p1 = (bit 31) - Question target: 0 - company, 1 - client.
 * @param p2 Buttons of the question.
 * @param text Text of the question.
 * @return the cost of this operation or an error
 */
CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	uint16 uniqueid = (GoalType)GB(p1, 0, 16);
	CompanyID company = (CompanyID)GB(p1, 16, 8);
#ifdef ENABLE_NETWORK
	ClientIndex client = (ClientIndex)GB(p1, 16, 8);
#endif
	byte type = GB(p1, 24, 2);
	bool is_client = HasBit(p1, 31);

	if (_current_company != OWNER_DEITY) return CMD_ERROR;
	if (StrEmpty(text)) return CMD_ERROR;
	if (is_client) {
#ifdef ENABLE_NETWORK
		if (!NetworkClientInfo::IsValidID(client)) return CMD_ERROR;
#else
		return CMD_ERROR;
#endif
	} else {
		if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
	}
	if (CountBits(p2) < 1 || CountBits(p2) > 3) return CMD_ERROR;
	if (p2 >= (1 << GOAL_QUESTION_BUTTON_COUNT)) return CMD_ERROR;
	if (type >= GOAL_QUESTION_TYPE_COUNT) return CMD_ERROR;

	if (flags & DC_EXEC) {
		if (is_client) {
#ifdef ENABLE_NETWORK
			if (NetworkClientInfo::Get(client)->client_id != _network_own_client_id) return CommandCost();
#endif
		} else {
			if (company == INVALID_COMPANY && !Company::IsValidID(_local_company)) return CommandCost();
			if (company != INVALID_COMPANY && company != _local_company) return CommandCost();
		}
		ShowGoalQuestion(uniqueid, type, p2, text);
	}

	return CommandCost();
}
コード例 #14
0
uint_32 emitInfo( FILE *fp )
{
    uint_32                     total;
    uint                        u;

    fprintf( fp,"\nstatic const struct abbrev_info {\n"
                "    abbrev_code        valid_mask;\n"
                "    uint_16            bit_index;\n"
                "    uint_8             data_offset;\n"
                "    uint_8             data_len;\n"
                "    uint_16            tag;\n"
                "} abbrevInfo[] = {\n" );
    total = 1;
    u = 0;
    for(;;) {
        fprintf( fp, "/*%-32s*/{ 0x%08lx, 0x%04x, 0x%02x, 0x%02x, 0x%02x }",
            abbrevInfo[u].name,
            (unsigned long)abbrevInfo[u].valid_mask,
            (unsigned)total,
            (unsigned)abbrevExtra[u].data_offset,
            (unsigned)abbrevExtra[u].data_len,
            abbrevInfo[u].tag
        );
        if( abbrevExtra[u].data_offset > 0xff ) {
            /* just change the uint_8 data_offset in the above structure */
            fprintf( stderr, "data_offset too large, must increase size of data_offset field\n" );
            exit( 1 );
        }
        if( abbrevExtra[u].data_len > 0xff ) {
            /* just change the uint_8 data_len in the above structure */
            fprintf( stderr, "data_len too large, must increase size of data_len field\n" );
            exit( 1 );
        }
        if( abbrevInfo[u].tag > 0xffff ) {
            /* just change the uint_16 tag in the above structure */
            fprintf( stderr, "Tag too large, must increase size of tag field\n" );
            exit( 1 );
        }
        total += 1 << CountBits( abbrevInfo[u].valid_mask & ~AB_ALWAYS );
        ++u;
        if( u == AB_MAX ) break;
        if( total > 0xffff ) {
            /* just change the uint_16 bit_index in the above structure */
            fprintf( stderr, "Index too large, must increase size of index field\n" );
            exit( 1 );
        }
        fprintf( fp, ",\n" );
    }
    fprintf( fp, "\n};\n" );
    return( total );
}
コード例 #15
0
ファイル: qvis.c プロジェクト: jayschwa/quake2world
/*
 * @brief
 */
static size_t LeafVectorFromPortalVector(byte *portalbits, byte *leafbits) {
	uint32_t i;

	memset(leafbits, 0, map_vis.leaf_bytes);

	for (i = 0; i < map_vis.num_portals * 2; i++) {
		if (portalbits[i >> 3] & (1 << (i & 7))) {
			const portal_t *p = map_vis.portals + i;
			leafbits[p->leaf >> 3] |= (1 << (p->leaf & 7));
		}
	}

	return CountBits(leafbits, map_vis.portal_clusters);
}
コード例 #16
0
ファイル: ham-mom.cpp プロジェクト: wpoely86/Hubbard-GPU
/**
  * private method used to see if a hopping between state a and b is
  * possible and with which sign. Only for 1D Hubbard.
  * @param ket the ket to use
  * @returns matrix element of the hopping term between the ket and the bra. You still
  * have to multiply this with the hopping strength J
  */
double MomHamiltonian::hopping(myint ket) const
{
    double result = 0;

    while(ket)
    {
        // select rightmost one
        myint hop = ket & (~ket + 1);
        // set it to zero in ket
        ket ^= hop;

        result += -2* cos(2.0*M_PI/L * CountBits(hop-1));
    }

    return result;
}
コード例 #17
0
ファイル: qvis.c プロジェクト: Garux/netradiant-custom
/*
   ==============
   LeafVectorFromPortalVector
   ==============
 */
int LeafVectorFromPortalVector( byte *portalbits, byte *leafbits ){
	int i;
	portal_t    *p;
	int c_leafs;


	memset( leafbits, 0, leafbytes );

	for ( i = 0 ; i < numportals * 2 ; i++ )
	{
		if ( portalbits[i >> 3] & ( 1 << ( i & 7 ) ) ) {
			p = portals + i;
			leafbits[p->leaf >> 3] |= ( 1 << ( p->leaf & 7 ) );
		}
	}

	c_leafs = CountBits( leafbits, portalclusters );

	return c_leafs;
}
コード例 #18
0
ファイル: vvis.cpp プロジェクト: chrizonix/RCBot2
/*
==============
LeafVectorFromPortalVector
==============
*/
int LeafVectorFromPortalVector (byte *portalbits, byte *leafbits)
{
    int			i;
    portal_t	*p;
    int			c_leafs;


    memset (leafbits, 0, leafbytes);

    for (i=0 ; i<g_numportals*2 ; i++)
    {
        if ( CheckBit( portalbits, i ) )
        {
            p = portals+i;
            SetBit( leafbits, p->leaf );
        }
    }

    c_leafs = CountBits (leafbits, portalclusters);

    return c_leafs;
}
コード例 #19
0
static char *PrintConstant(char *s, uint32 n, uint flags)
{

	char *q;
	char buf[40];

	
	if (flags & PF_EA && (q = get_name(BADADDR, n, charbuf, sizeof(charbuf))) != NULL) {
		// check if we don't need to write the type explicitly

		if (flags & PF_TYPEMASK && DontNeedExplicitType( GetTypeOf(n),(flags & PF_TYPEMASK) - 1, !!(flags & PF_EA_STORE))) {
			flags &= ~PF_TYPEMASK;
		}
		
	} else {
		q = buf;
		if (flags & PF_NEGCONST) {
			uint32 tmp_n = (~n) & _typemask_size_masks[flags & PF_TYPEMASK];
			if (CountBits(tmp_n) <= 2) {
				*q++ = '~';
				n = tmp_n;
			}
		}

		if (n < 10) {
			sprintf(q, "%d", n);
		} else {
			sprintf(q, "0x%X", n);
		}
		q = buf;
	}

	if (flags & PF_EA && flags & PF_TYPEMASK) { s = strcpy_e(s, TypeNames[(flags & PF_TYPEMASK) - 1]); }
	s = strcpy_e(s, q);
	if (flags & PF_EA && flags & PF_TYPEMASK ) { s = strcpy_e(s, ">"); }

	return s;
}
コード例 #20
0
void GhostManager::createGhost(SimNetObject *obj)
{
   AssertWarn(refFreeList, "scoping over 1024 ghosts!");
   if (!refFreeList)
      return;
   GhostInfo *giptr = refFreeList;
   refFreeList = refFreeList->nextRef;

   giptr->flags = GhostInfo::NotYetGhosted | GhostInfo::InScope;
   
   if(obj->netFlags.test(SimNetObject::ScopeAlways))
      giptr->flags |= GhostInfo::ScopeAlways;

   giptr->obj = obj;
   giptr->updateMask = 0xFFFFFFFF;
   giptr->updateChain = NULL;
   giptr->updateSkipCount = 0;

   giptr->prevRef = NULL;
   giptr->nextRef = ghostList;

   if(ghostList)
      ghostList->prevRef = giptr;

   ghostList = giptr;

   GhostRef gr;
   gr.ghostManager = this;
   gr.ghostInfo = giptr;

   obj->ghosts.push_back(gr);

   int giSize = CountBits(giptr->ghostIndex);

   if(giSize > sendIdSize)
      sendIdSize = giSize;
}
コード例 #21
0
ファイル: mpivis.cpp プロジェクト: Adidasman1/source-sdk-2013
//-----------------------------------------
//
// Run BasePortalVis across all available processing nodes
// Then collect and redistribute the results.
//
void RunMPIBasePortalVis()
{
	int i;

	Msg( "\n\nportalbytes: %d\nNum Work Units: %d\nTotal data size: %d\n", portalbytes, g_numportals*2, portalbytes*g_numportals*2 );
    Msg("%-20s ", "BasePortalVis:");
	if ( g_bMPIMaster )
		StartPacifier("");


	VMPI_SetCurrentStage( "RunMPIBasePortalVis" );

	// Note: we're aiming for about 1500 portals in a map, so about 3000 work units.
	g_CPUTime.Init();
	double elapsed = DistributeWork( 
		g_numportals * 2,		// # work units
		VMPI_DISTRIBUTEWORK_PACKETID,	// packet ID
		ProcessBasePortalVis,	// Worker function to process work units
		ReceiveBasePortalVis	// Master function to receive work results
		);

	if ( g_bMPIMaster )
	{
		EndPacifier( false );
		Msg( " (%d)\n", (int)elapsed );
	}
	
	//
	// Distribute the results to all the workers.
	//
	if ( g_bMPIMaster )
	{
		if ( !fastvis )
		{
			VMPI_SetCurrentStage( "SendPortalResults" );

			// Store all the portal results in a temp file and multicast that to the workers.
			CUtlVector<char> allPortalData;
			allPortalData.SetSize( g_numportals * 2 * portalbytes * 2 );

			char *pOut = allPortalData.Base();
			for ( i=0; i < g_numportals * 2; i++) 
			{
				portal_t *p = &portals[i];
				
				memcpy( pOut, p->portalfront, portalbytes );
				pOut += portalbytes;
				
				memcpy( pOut, p->portalflood, portalbytes );
				pOut += portalbytes;
			}

			const char *pVirtualFilename = "--portal-results--";
			VMPI_FileSystem_CreateVirtualFile( pVirtualFilename, allPortalData.Base(), allPortalData.Count() );

			char cPacketID[2] = { VMPI_VVIS_PACKET_ID, VMPI_BASEPORTALVIS_RESULTS };
			VMPI_Send2Chunks( cPacketID, sizeof( cPacketID ), pVirtualFilename, strlen( pVirtualFilename ) + 1, VMPI_PERSISTENT );
		}
	}
	else
	{
		VMPI_SetCurrentStage( "RecvPortalResults" );

		// Wait until we've received the filename from the master.
		while ( g_BasePortalVisResultsFilename.Count() == 0 )
		{
			VMPI_DispatchNextMessage();
		}

		// Open 
		FileHandle_t fp = g_pFileSystem->Open( g_BasePortalVisResultsFilename.Base(), "rb", VMPI_VIRTUAL_FILES_PATH_ID );
		if ( !fp )
			Error( "Can't open '%s' to read portal info.", g_BasePortalVisResultsFilename.Base() );

		for ( i=0; i < g_numportals * 2; i++) 
		{
			portal_t *p = &portals[i];

			p->portalfront = (byte*)malloc (portalbytes);
			g_pFileSystem->Read( p->portalfront, portalbytes, fp );
			
			p->portalflood = (byte*)malloc (portalbytes);
			g_pFileSystem->Read( p->portalflood, portalbytes, fp );
		
			p->portalvis = (byte*)malloc (portalbytes);
			memset (p->portalvis, 0, portalbytes);
		
			p->nummightsee = CountBits (p->portalflood, g_numportals*2);
		}

		g_pFileSystem->Close( fp );
	}

	
	if ( !g_bMPIMaster )
	{
		if ( g_iVMPIVerboseLevel >= 1 )
			Msg( "\n%% worker CPU utilization during BasePortalVis: %.1f\n", (g_CPUTime.GetSeconds() * 100.0f / elapsed) / numthreads );
	}
}
コード例 #22
0
static uint32 RailTypeGetRandomBits(const ResolverObject *object)
{
	TileIndex tile = object->u.routes.tile;
	uint tmp = CountBits(tile + (TileX(tile) + TileY(tile)) * TILE_SIZE);
	return GB(tmp, 0, 2);
}
コード例 #23
0
ファイル: Directory.cpp プロジェクト: turbanoff/X-plore
dword C_dir::GetNumDrives(){
   return CountBits(GetDriveMask());
}
コード例 #24
0
ファイル: Directory.cpp プロジェクト: turbanoff/X-plore
dword C_dir::GetNumDrives(){
   return CountBits(win::GetLogicalDrives());
}
コード例 #25
0
ファイル: flowsave.c プロジェクト: Azarien/open-watcom-v2
static void DoCountBits( a_bit_set set )
/**************************************/
{
    bitCount += CountBits( set );
}
コード例 #26
0
ファイル: sss.c プロジェクト: pcastine-lp/LitterPower
void
SssBang(
	tPink* me)
	
	{
	tTaus88DataPtr	tausData	= me->tausData;
	unsigned short	c			= me->counter++;	// We rely on the increment wrapping
													// every 2^16 iterations (16-bit integer
													// representation).
	unsigned long*	curDie	= me->dice;
	unsigned long	sum 	= me->sum;
	int				i;
	
	if (c == 0) {
		// First time through... or wrap around!
		i	= kArraySize;
		sum = 0;
		do { sum += *curDie++ = Taus88(tausData) & kDiceBits; }
			while (--i > 0);
		}
	
	else {
		unsigned long	bitCount	= CountBits(c);
		unsigned 		bit			= 0x01;
		
		if (bitCount == 1) {
			// Just update one die
			while ((bit & c) == 0)
				{
				bit		+= bit;						// Marginally faster than bit <<= 1
				curDie	+= 1;
				}
			sum -= *curDie;
			sum += *curDie = Taus88(tausData) & kDiceBits;
			}
		else if (bitCount < kArraySize / 2) {
			// Still faster to calculate differences
			i = kArraySize;
			do {
				if (bit & c) {
					sum -= *curDie;
					sum += *curDie = Taus88(tausData) & kDiceBits;
					}
				bit		+= bit;						// Marginally faster than bit <<= 1
				curDie	+= 1;
				} while (--i > 0);
			}
		else {
			// Faster just to update and recalculate sum from scratch
			i	= kArraySize;
			sum	= 0;
			do {
				if (bit & c) *curDie = Taus88(tausData) & kDiceBits;
				sum += *curDie++;
				bit += bit;
				} while (--i > 0);
			}
		
		}
	
	me->sum = sum;
	
	if (me->nn != 0) {
		// Adjust output value for NN factor
		sum &= me->nnMask;
		sum += me->nnOffset;
		}
	outlet_float(me->coreObject.o_outlet, ULong2Unit_ZO(sum));
	
	}
コード例 #27
0
ファイル: sss~.c プロジェクト: pcastine-lp/LitterPower
int*
SssPerform(
	int* iParams)
	
	{
	enum {
		paramFuncAddress	= 0,
		paramMe,
		paramVectorSize,
		paramOut,
		
		paramNextLink
		};
	
	long			vecCounter;
	tSampleVector	outNoise;
	tPink*			me = (tPink*) iParams[paramMe];
	unsigned long*	firstDie;
	unsigned long	sum,
					mask,
					offset;
	unsigned short	counter;				// Must be 16-bit value to match "dice" array
	
	if (me->coreObject.z_disabled) goto exit;
	
	// Copy parameters into registers
	vecCounter	= (long) iParams[paramVectorSize];
	outNoise	= (tSampleVector) iParams[paramOut];
	sum			= me->sum;
	firstDie	= me->dice;
	mask		= me->mask;
	offset		= me->offset;
	counter		= me->counter;
	
	// Do our stuff
	do {
		unsigned long*		curDie		= firstDie;
		int				 	bitCount	= CountBits(counter);
		unsigned			bit			= 0x01;
		
		switch (bitCount) {
			case 0:
				InitDice(me);
				sum = me->sum;
				break;
			
			case 1:
				// Just update one die
				while ((bit & counter) == 0)
					{
					bit		*= 2;			// Let compiler choose fastest way to do this
					curDie	+= 1;
					}
				sum -= *curDie;
				sum += *curDie = Taus88(NULL) / kArraySize;
				break;
			
			default:
				if (bitCount < kArraySize / 2) {
					// Still faster to calculate differences
					int i = kArraySize;
					do {
						if (bit & counter) {
							sum -= *curDie;
							sum += *curDie = Taus88(NULL) / kArraySize;
							}
						bit		*= 2;
						curDie	+= 1;
						} while (--i > 0);
					}
				else {
					// Faster just to update and recalculate sum from scratch
					int i	= kArraySize;
					sum	= 0;
					do {
						if (bit & counter)
							*curDie = Taus88(NULL) / kArraySize;
						sum += *curDie++;
						bit *= 2;
						} while (--i > 0);
					}
				break;
			}
		
		*outNoise++	= ULong2Signal((sum & mask) + offset);
		counter++;
		}
		while (--vecCounter > 0);
	
	me->sum		= sum;
	me->counter	= counter;
	
exit:
	return iParams + paramNextLink;
	}
コード例 #28
0
ファイル: search.c プロジェクト: thgreiner/amy
static int CheckExtend(struct Position *p) {
    int kp = p->kingSq[p->turn];
    BitBoard att;

    att = p->atkFr[kp] & p->mask[OPP(p->turn)][0];

    if (CountBits(att) > 1) {

        /*
         * double check, the king has to move
         * count no. of flight squares, if only one, extend deeper
         *
         */

        BitBoard ff;

        int i;
        int cnt = 0;

        DblExt++;

        ff = KingEPM[kp] & ~p->mask[p->turn][0];
        att &= p->slidingPieces;

        while (att) {
            i=FindSetBit(att);
            ClrBit(att, i);
            ff &= ~Ray[i][kp];
        }

        while (ff) {
            i=FindSetBit(ff);
            ClrBit(ff, i);
            if (!(p->atkFr[i] & p->mask[OPP(p->turn)][0])) cnt++;
            if (cnt > 1) return ExtendDoubleCheck;
        }
    } else {
        BitBoard ff;
        BitBoard def;
        BitBoard tmp;

        int atp = FindSetBit(att);
        int cnt = 0;
        int i;
        int nd = 0;

        /* discovered check */
        if (atp != M_TO((p->actLog-1)->gl_Move)) {
            DiscExt++;
            nd = ExtendDiscoveredCheck;
        }

        ff = KingEPM[kp] & ~p->mask[p->turn][0];

        i = FindSetBit(att);
        if (Sliding[TYPE(p->piece[i])]) ff &= ~Ray[i][kp];

        /* check for king flight squares */
        while (ff) {
            i=FindSetBit(ff);
            ClrBit(ff, i);
            if (!(p->atkFr[i] & p->mask[OPP(p->turn)][0])) cnt++;
            if (cnt > 1) return nd;
        }

        /* Find all non-pinned defenders */
        def = p->mask[p->turn][0] & ~p->mask[p->turn][King];

        tmp = (p->mask[OPP(p->turn)][Bishop] | p->mask[OPP(p->turn)][Queen])
              & BishopEPM[kp];
        while (tmp) {
            BitBoard tmp2;
            i=FindSetBit(tmp);
            ClrBit(tmp, i);
            tmp2= InterPath[i][kp];
            if (tmp2 && !(p->mask[OPP(p->turn)][0] & tmp2)) {
                tmp2 &= p->mask[p->turn][0];
                if (CountBits(tmp2) == 1) {
                    ClrBit(def, FindSetBit(tmp2));
                }
            }
        }

        tmp = (p->mask[OPP(p->turn)][Rook] | p->mask[OPP(p->turn)][Queen])
              & RookEPM[kp];
        while (tmp) {
            BitBoard tmp2;
            i=FindSetBit(tmp);
            ClrBit(tmp, i);
            tmp2= InterPath[i][kp];
            if (tmp2 && !(p->mask[OPP(p->turn)][0] & tmp2)) {
                tmp2 &= p->mask[p->turn][0];
                if (CountBits(tmp2) == 1) {
                    ClrBit(def, FindSetBit(tmp2));
                }
            }
        }

        /* All non-pinned defenders are in 'def' */
        tmp = p->atkFr[atp] & def;

        cnt += CountBits(tmp);
        if (cnt > 1) return nd;

        /* if possible, try an interposition */
        if (Sliding[TYPE(p->piece[atp])]) {
            tmp = InterPath[atp][kp];
            while (tmp) {
                BitBoard tmp2;
                i=FindSetBit(tmp);
                ClrBit(tmp, i);
                if ((tmp2 = p->atkFr[i] & def)) {
                    cnt+=CountBits(tmp2);
                }
                if (p->turn == White
                        && (i-8) > 0
                        && TstBit(p->mask[White][Pawn], i-8)
                        && TstBit(def, i-8)) cnt++;
                if (p->turn == Black
                        && (i+8) < 64
                        && TstBit(p->mask[Black][Pawn], i+8)
                        && TstBit(def, i+8)) cnt++;
                if (cnt > 1) return nd;
            }
        }

    }

    /* If we get here, we have only one legal move. */

    SingExt++;
    return ExtendSingularReply;
}
コード例 #29
0
ファイル: newgrf_railtype.cpp プロジェクト: ComLock/OpenTTD
/* virtual */ uint32 RailTypeScopeResolver::GetRandomBits() const
{
	uint tmp = CountBits(this->tile + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE);
	return GB(tmp, 0, 2);
}
コード例 #30
0
ファイル: inpututils.c プロジェクト: aosm/X11server
/**
 * Returns the number of valuators set in the given mask.
 */
int
valuator_mask_num_valuators(const ValuatorMask *mask)
{
    return CountBits(mask->mask, min(mask->last_bit + 1, MAX_VALUATORS));
}