Esempio n. 1
0
double noise::operator () (double &t) const
{
	while (t >= t_rand) { // time to get a new random sample
		i_old = i_rand;
		q_old = q_rand;
		if (n == 0) {
			double x, y, r;
			do {
				x = (double) rnd_uint32() / 2147483648U - 1;
				y = (double) rnd_uint32() / 2147483648U - 1;
				r = x * x + y * y;
			} while (r > 1 || r == 0);
			r = sqrt(-variance * log(r) / r);
			i_rand = filter1(x * r);
			q_rand = filter2(y * r);
		} else {
			i_rand = filter1(0);
			q_rand = filter2(0);
		}
		if (!(++n % 4)) n = 0;
		t_rand += period;
		// This uses a filter to do a 4x oversampling, and then a linear interpolation.
	}
	double tau = (t_rand - t) / period;
	double i = i_old * tau + i_rand * (1 - tau);
	double q = q_old * tau + q_rand * (1 - tau);
	double y = i * sin(omega * t) + q * cos(omega * t);
	t += t_sine;
	return y;
}
//---------------------------------------------------------
// !!!TEMP
// !!!TEMP
// !!!TEMP
// !!!TEMP
//
// (sjb)
//---------------------------------------------------------
void CGenericNPC::TempGunEffect( void )
{
	QAngle vecAngle;
	Vector vecDir, vecShot;
	Vector vecMuzzle, vecButt;

	GetAttachment( 2, vecMuzzle, vecAngle );
	GetAttachment( 3, vecButt, vecAngle );

	vecDir = vecMuzzle - vecButt;
	VectorNormalize( vecDir );

	// CPVSFilter filter( GetAbsOrigin() );
	//te->ShowLine( filter, 0.0, vecSpot, vecSpot + vecForward );
	//UTIL_Sparks( vecMuzzle );

	bool fSound = false;
	
	if( random->RandomInt( 0, 3 ) == 0 )
	{
		fSound = true;
	}

	Vector start = vecMuzzle + vecDir * 64;
	Vector end = vecMuzzle + vecDir * 4096;
	UTIL_Tracer( start, end, 0, TRACER_DONT_USE_ATTACHMENT, 5500, fSound );
	CPASAttenuationFilter filter2( this, "GenericNPC.GunSound" );
	EmitSound( filter2, entindex(), "GenericNPC.GunSound" );
}
void test_cute_filter_runner_ArgvFilter() {
	char const *argv[] = { "dummy", "testsuite1", "testsuite2#test1",
			"testsuite2#test3", 0 };
	std::vector<std::string> args;
	std::copy(argv + 1, argv + sizeof(argv) / sizeof(*argv) - 1,
			std::back_inserter(args));
	cute::runner_aux::ArgvTestFilter filter1("", args);
	ASSERT(filter1.shouldRun("any"));
	cute::runner_aux::ArgvTestFilter filter2("testsuite1", args);
	ASSERT(filter2.shouldrunsuite);
	ASSERT(filter2.shouldRun("test"));
	ASSERT(filter2.shouldRun("test1"));
	ASSERT(filter2.shouldRun("test2"));
	ASSERT(filter2.shouldRun("test3"));
	ASSERT(filter2.shouldRun("test4"));
	cute::runner_aux::ArgvTestFilter filter3("dummy", args);

	ASSERT(!filter3.shouldrunsuite);
	cute::runner_aux::ArgvTestFilter filter4("testsuite2", args);
	ASSERT(filter4.shouldrunsuite);
	ASSERT(!filter4.shouldRun("test"));
	ASSERT(filter4.shouldRun("test1"));
	ASSERT(!filter4.shouldRun("test2"));
	ASSERT(filter4.shouldRun("test3"));
	ASSERT(!filter4.shouldRun("test4"));

}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pEvent - 
//-----------------------------------------------------------------------------
void CNPC_Monk::HandleAnimEvent( animevent_t *pEvent )
{
	switch ( pEvent->event )
	{
		case AE_MONK_FIRE_GUN:
		{
			Vector vecShootOrigin;
			QAngle vecAngles;
			GetAttachment( "muzzle", vecShootOrigin, vecAngles );

			Vector vecShootDir = GetShootEnemyDir( vecShootOrigin );

			CPASAttenuationFilter filter2( this, "NPC_Monk.Fire" );
			EmitSound( filter2, entindex(), "NPC_Monk.Fire" );

			UTIL_Smoke( vecShootOrigin, random->RandomInt(20, 30), 10 );
			FireBullets( 1, vecShootOrigin, vecShootDir, vec3_origin, MAX_TRACE_LENGTH, m_nAmmoType, 0 );
			m_fEffects |= EF_MUZZLEFLASH;
			break;
		}

		default:
		{
			BaseClass::HandleAnimEvent( pEvent );
		}
	}
}
Esempio n. 5
0
/****
*	function: frictionNoise7
*	note:	generation of filtered noise to mimic turbulent noise
*		iside the vocal tract. Computer generated random numbers
*		undergo two filters: a highpass to cutoff low freaquency
*		components below 500 Hz and a lowpass filter (-6dB/oct)
*		to shape noise at high frequencies.
*
*		The low pass filter is a simple first order integrater
*		with alpha = 0.8
*
*		The 7-th order highpass filter is used for the low cut.
*		The cutoff frequency is 0.02 (normalized by sampling
*		frequency.) Actaul cutoff frequency varyies depending on
*		the sampling frequency as below:
*			20 kHz: 400 Hz
*			16 kHz: 320 Hz
*			10 kHz: 200 Hz
****/
float	frictionNoise7(
					   int	Entry,		/* if =0, initialization */
					   float	inBuf[4][3],	/* fixed work array (input memories) */
					   float	outBuf[4][3],	/* fixed work array (output memories)*/
					   float	*mem)		/* fixed memory for lowcut filter */
{
	static	float	a[4][3] ={{1.000000, -0.836060, 0.000000},
	{1.000000, -1.697388, 0.724731},
	{1.000000, -1.772522, 0.801086},
	{1.000000, -1.893677, 0.924164}};

	static	float	b[4][3] ={{0.459015, -0.918030, 0.459015},
	{1.711121, -1.711121, 0.000000},
	{0.893433, -1.786865, 0.893433},
	{1.042725, -2.085449, 1.042725}};
	static	float	max, alpha=0.8;
	float	s;
	int	i, j;

	if(Entry == 0)
	{ //randomize();
		max = 2./(float)RAND_MAX;
		for(j=0; j<7; j++)
		{
			for(i=0; i<4; i++)		/* lowcut filter */
			{ if(i==0) inBuf[0][0] = max*(float)rand() - 1.;
			else     inBuf[i][0] = outBuf[i-1][0];
			filter2(inBuf[i], outBuf[i], a[i], b[i]);
			}
			s = outBuf[3][0];
			s += alpha*(*mem); *mem = s; 	/* -6dB/oct */
		}
	}
	for(i=0; i<4; i++)
	{ if(i==0) inBuf[0][0] = max*(float)rand() - 1.;
	else     inBuf[i][0] = outBuf[i-1][0];
	filter2(inBuf[i], outBuf[i], a[i], b[i]);
	}
	s = outBuf[3][0];
	s += alpha*(*mem); *mem = s;	/* -6dB/oct */

	return(s);
}
Esempio n. 6
0
int main () 
{
  X = RANDOM_INPUT();
  INIT = TRUE;
  while (TRUE) {
    X = RANDOM_INPUT();
    filter2 ();
    INIT = FALSE;
  }
  return 0;
}
Esempio n. 7
0
void CGrenadeMP5::Detonate(void)
{
	if (!m_bIsLive)
	{
		return;
	}
	m_bIsLive		= false;
	m_takedamage	= DAMAGE_NO;	

	CPASFilter filter( GetAbsOrigin() );

	te->Explosion( filter, 0.0,
		&GetAbsOrigin(), 
		GetWaterLevel() == 0 ? g_sModelIndexFireball : g_sModelIndexWExplosion,
		(m_flDamage - 50) * .60, 
		15,
		TE_EXPLFLAG_NONE,
		m_DmgRadius,
		m_flDamage );

	trace_t tr;	
	tr = CBaseEntity::GetTouchTrace();

	if ( (tr.m_pEnt != GetWorldEntity()) || (tr.hitbox != 0) )
	{
		// non-world needs smaller decals
		UTIL_DecalTrace( &tr, "SmallScorch");
	}
	else
	{
		UTIL_DecalTrace( &tr, "Scorch" );
	}

	CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );

	RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_flDamage * 2.5, CLASS_NONE, NULL );

	CPASAttenuationFilter filter2( this );
	EmitSound( filter2, entindex(), "GrenadeMP5.Detonate" );

	if ( GetWaterLevel() == 0 )
	{
		int sparkCount = random->RandomInt( 0,3 );
		QAngle angles;
		VectorAngles( tr.plane.normal, angles );

		for ( int i = 0; i < sparkCount; i++ )
			Create( "spark_shower", GetAbsOrigin(), angles, NULL );
	}

	UTIL_Remove( this );
}
int main(int argc,char **argv)
{
	struct file_node *head=NULL;
	struct same_size *h2=NULL,*h3=NULL;

	scan_sys2(*(argv+1),&head);

	h2=filter2(head);
	printf("\n\nDuplicate files:");
	display_same(h2);
	return 0;

}
Esempio n. 9
0
/****
*	function: frictionNoise3
*	note:	generation of filtered noise to mimic turbulent noise
*		inside the vocal tract. Computer generated random numbers
*		undergo two filters: a highpass to cutoff low freaquency
*		components below 200 Hz and a lowpass filter (-6dB/oct)
*		to shape noise at high frequencies.
*
*		The low pass filter is a simple first order integrater
*		with alpha = 0.8
*
*		The 3rd order highpass filter is used for the low cut.
*		The cutoff frequency is 200 Hz when the sampling frequency
*		is 10 kHz.
****/
float	frictionNoise3(
					   int	Entry,		/* if =0, initialization */
					   float	mem1[4][3],	/* fixed work array (input memories) */
					   float	mem2[4][3],     /* fixed work array (output memories)*/
					   float	*mem)		/* fixed memory for lowcut filter */
{
	static	float	a[2][3] ={{1.0000, -1.8977, 0.9069},
	{1.0000, -0.9067, 0.0000}};
	static	float	b[2][3] ={{0.9546, -1.9093, 0.9546},
	{0.9974, -0.9974, 0.0000}};
	static	float	max, alpha=0.8;
	float	s;
	int	i, j;

	if(Entry == 0)
	{ 
		//randomize();
		max = 2./(float)RAND_MAX;
		for(j=0; j<3; j++)
		{
			for(i=0; i<2; i++)		/* lowcut filter */
			{ if(i==0) mem1[0][0] = max*(float)rand() - 1.;
			else     mem1[i][0] = mem2[i-1][0];
			filter2(mem1[i], mem2[i], a[i], b[i]);
			}
			s = mem2[1][0];
			s += alpha*(*mem); *mem = s; 	/* -6dB/oct */
		}
	}
	for(i=0; i<2; i++)
	{ if(i==0) mem1[0][0] = max*(float)rand() - 1.;
	else     mem1[i][0] = mem2[i-1][0];
	filter2(mem1[i], mem2[i], a[i], b[i]);
	}
	s = mem2[1][0];
	s += alpha*(*mem); *mem = s;	/* -6dB/oct */

	return(s);
}
Esempio n. 10
0
int main()
{
  X = 0;
  INIT1 = TRUE;
  INIT2 = TRUE;
  while (TRUE) {
    X = 0.98*X + 85.;
    if (X >= -400. && X <= 400.) {
      filter1();
      X = X + 100.;
      INIT1 = FALSE;
    }
    else if (X >= -800. && X <= 800.) {
      filter2();
      X = X - 50.;
      INIT2 = FALSE;
    }

    __VERIFIER_assert(X >= -1155. && X <= 4251.);
  }
  return 0;
}
//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CGrenadePathfollower::Detonate(void)
{
	StopSound(entindex(), CHAN_BODY, STRING(m_sFlySound));

	m_takedamage	= DAMAGE_NO;	

	if(m_hRocketTrail)
	{
		UTIL_Remove(m_hRocketTrail);
		m_hRocketTrail = NULL;
	}

	CPASFilter filter( GetAbsOrigin() );

	te->Explosion( filter, 0.0,
		&GetAbsOrigin(), 
		g_sModelIndexFireball,
		0.5, 
		15,
		TE_EXPLFLAG_NONE,
		m_DmgRadius,
		m_flDamage );

	Vector vecForward = GetAbsVelocity();
	VectorNormalize(vecForward);
	trace_t		tr;
	UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward,  MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, & tr);

	UTIL_DecalTrace( &tr, "Scorch" );

	UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );
	CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin(), 400, 0.2 );

	RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST ), GetAbsOrigin(),  m_DmgRadius, CLASS_NONE, NULL );
	CPASAttenuationFilter filter2( this, "GrenadePathfollower.StopSounds" );
	EmitSound( filter2, entindex(), "GrenadePathfollower.StopSounds" );
	UTIL_Remove( this );
}
Esempio n. 12
0
cv::Mat SIFT::sp_find_sift_grid( Mat I,Mat gridX,Mat gridY,int patchSize, float sigma_edge )
{
	int num_angles=8;
	float num_bins=4;
	int num_samples=num_bins*num_bins;
	int alpha = 9;

	//此处需要判断总共传入多少个变量,如果变量数小于5,就把sigma_edge设置为1
	float angle_step=2*pi/num_angles;

	//初始化angles 为一个一维矩阵从0到2*pi;间隔为angle_step
	Mat angles=create(0,2*pi,angle_step);
	angles=deleteO(angles); //删除最后一个元素

	CvSize size=I.size();
	//int hgt=size.height;
	//int wid=size.width;

	int num_patches=gridX.total();//计算gridX总共有多少个元素

	Mat sift_arr=Mat::zeros(num_patches,num_samples*num_angles,CV_32F);

	//计算滤波算子
	int  f_wid = 4 * ceil(sigma_edge) + 1;
	Mat G=gaussian(f_wid,sigma_edge);

	Mat GX=gradientX(G);
	Mat GY=gradientY(G);


	GX=GX*2/totalSumO(GX);
	GY=GY*2/totalSumO(GY);



	Mat I_X(I.rows,I.cols,CV_32F);
	I_X=filter2(GX,I);              //因为I,图片读入不同,所以I_X不同,与I有关的均布相同,但是,都正确


	Mat I_Y(I.rows,I.cols,CV_32F);
	I_Y=filter2(GY,I);

	Mat T(I_X.rows,I_X.cols,CV_32F);
	add(I_X.mul(I_X),I_Y.mul(I_Y),T);
	Mat I_mag(I_X.rows,I_X.cols,CV_32F);
	sqrt(T,I_mag);
	Mat I_theta=matan2(I_Y,I_X);

	Mat interval=create(2/num_bins,2,2/num_bins);
	interval-=(1/num_bins+1);

	Mat sample_x=meshgrid_X(interval,interval);


	Mat sample_y=meshgrid_Y(interval,interval);

	sample_x=reshapeX(sample_x);//变为一个1维矩阵

	sample_y=reshapeX(sample_y);

	Mat I_orientation[8] = {Mat::zeros(size,CV_32F)};
	for(int i=0;i<8;i++)
	{
		I_orientation[i] = Mat::zeros(size,CV_32F);
	}
	float *pt=angles.ptr<float>(0);

	for(int a=0;a<num_angles;a++)
	{
		Mat tep1=mcos(I_theta-pt[a]);//cos
		//cout<<tep1.at<float>(0,1)<<endl;
		Mat tep(tep1.rows,tep1.cols,CV_32F);
		pow(tep1,alpha,tep);
		tep=compareB(tep,0);
		I_orientation[a]=tep.mul(I_mag);
	}

	for(int i=0;i<num_patches;i++)
	{

		double r=patchSize/2;
		float l=(float)(i/gridX.rows);
		float m=i%gridX.rows;
		float cx=gridX.at<float>(m,l)+r-0.5;
		float cy=gridY.at<float>(m,l)+r-0.5;

		Mat sample_x_t=Add(sample_x*r,cx);
		Mat sample_y_t=Add(sample_y*r,cy);
		float *pt1=sample_y_t.ptr<float>(0);
		float sample_res=pt1[1]-pt1[0];

// 		int c=(int)i/gridX.rows;
// 		float *ptc1=gridX.ptr<float>(c);
// 		int x_lo=ptc1[i%gridX.rows];

		int x_lo = gridX.at<float>(i % gridX.rows, i / gridX.rows);
		int x_hi=patchSize+x_lo-1;
/*		float *ptc2=gridY.ptr<float>(c);*/


		int y_lo=gridY.at<float>(i % gridY.rows, i / gridY.rows);
		int y_hi=y_lo+patchSize-1;

		Mat A=create(x_lo,x_hi,1);
		Mat B=create(y_lo,y_hi,1);


		Mat sample_px=meshgrid_X(A,B);
		Mat sample_py=meshgrid_Y(A,B);

		int num_pix = sample_px.total();//计算sample_px元素总数
		sample_px=reshapeY(sample_px);
		sample_py=reshapeY(sample_py);


		Mat dist_px=abs(repmat(sample_px,1,num_samples)-repmat(sample_x_t,num_pix,1));
		Mat dist_py=abs(repmat(sample_py,1,num_samples)-repmat(sample_y_t,num_pix,1));


		Mat weights_x=dist_px/sample_res;
		Mat weights_x_l=Less(weights_x,1);
		weights_x=(1-weights_x).mul(weights_x_l);

		Mat weights_y=dist_py/sample_res;
		Mat weights_y_l=Less(weights_y,1);
		weights_y=(1-weights_y).mul(weights_y_l);
		Mat weights=weights_x.mul(weights_y);

		Mat curr_sift=Mat::zeros(num_angles,num_samples,CV_32F);
		for(int a=0;a<num_angles;a++)
		{
			//Mat I=getNum(I_orientation[a],y_lo,y_hi,x_lo,x_hi);
			Mat I = I_orientation[a](Range(y_lo, y_hi), Range(x_lo, x_hi));
			Mat tep=reshapeY(I);

			// Fill tep with zeros to fit size of weight
			if (tep.cols < weights.cols)
			{
				for (int i = tep.rows; i < weights.rows; i++)
					tep.push_back(0.0f);
			}

			tep=repmat(tep,1,num_samples);
			Mat t=tep.mul(weights);
			Mat ta=sum_every_col(t);
			float *p=ta.ptr<float>(0);
			for(int i=0;i<curr_sift.cols;i++)
			{
				curr_sift.at<float>(a,i)=p[i];
			}

		}
		Mat tp=reshapeX(curr_sift);
		float *p=tp.ptr<float>(0);
		for(int j=0;j<sift_arr.cols;j++)
		{
			sift_arr.at<float>(i,j)=p[j];
		}

	}

	return sift_arr;
}
void run_function() {
    ASSERT(!filter_node_count, NULL);

    const size_t number_of_filters = 3;

    input_filter<type1> i_filter;
    middle_filter<type1, type2> m_filter;
    output_filter<type2> o_filter;

    unsigned limit = 1;
    // Test pipeline that contains number_of_filters filters
    for( unsigned i=0; i<number_of_filters; ++i)
        limit *= number_of_filter_types;
    // Iterate over possible filter sequences
    for( unsigned numeral=0; numeral<limit; ++numeral ) {
        unsigned temp = numeral;
        tbb::filter::mode filter_type[number_of_filter_types];
        for( unsigned i=0; i<number_of_filters; ++i, temp/=number_of_filter_types ) 
            filter_type[i] = filter_table[temp%number_of_filter_types];

        tbb::filter_t<void, type1> filter1( filter_type[0], i_filter );
        tbb::filter_t<type1, type2> filter2( filter_type[1], m_filter );
        tbb::filter_t<type2, void> filter3( filter_type[2], o_filter );
        ASSERT(filter_node_count==3, "some filter nodes left after previous iteration?");
        // Create filters sequence when parallel_pipeline() is being run
        tbb::parallel_pipeline( n_tokens, filter1 & filter2 & filter3 );
        check_and_reset();

        // Create filters sequence partially outside parallel_pipeline() and also when parallel_pipeline() is being run
        tbb::filter_t<void, type2> filter12;
        filter12 = filter1 & filter2;
        tbb::parallel_pipeline( n_tokens, filter12 & filter3 );
        check_and_reset();

        tbb::filter_t<void, void> filter123 = filter12 & filter3;
        // Run pipeline twice with the same filter sequence
        for( unsigned i = 0; i<2; i++ ) {
            tbb::parallel_pipeline( n_tokens, filter123 );
            check_and_reset();
        }

        // Now copy-construct another filter_t instance, and use it to run pipeline
        {
            tbb::filter_t<void, void> copy123( filter123 );
            tbb::parallel_pipeline( n_tokens, copy123 );
            check_and_reset();
        }

        // Construct filters and create the sequence when parallel_pipeline() is being run
        tbb::parallel_pipeline( n_tokens, 
                   tbb::make_filter<void, type1>(filter_type[0], i_filter) &
                   tbb::make_filter<type1, type2>(filter_type[1], m_filter) &
                   tbb::make_filter<type2, void>(filter_type[2], o_filter) );
        check_and_reset();

        // Construct filters, make a copy, destroy the original filters, and run with the copy
        int cnt = filter_node_count;
        {
            tbb::filter_t<void, void>* p123 = new tbb::filter_t<void,void> (
                   tbb::make_filter<void, type1>(filter_type[0], i_filter) &
                   tbb::make_filter<type1, type2>(filter_type[1], m_filter) &
                   tbb::make_filter<type2, void>(filter_type[2], o_filter) );
            ASSERT(filter_node_count==cnt+5, "filter node accounting error?");
            tbb::filter_t<void, void> copy123( *p123 );
            delete p123;
            ASSERT(filter_node_count==cnt+5, "filter nodes deleted prematurely?");
            tbb::parallel_pipeline( n_tokens, copy123 );
            check_and_reset();
        }
        ASSERT(filter_node_count==cnt, "scope ended but filter nodes not deleted?");

#if __TBB_LAMBDAS_PRESENT
        tbb::atomic<int> counter;
        counter = max_counter;
        // Construct filters using lambda-syntax and create the sequence when parallel_pipeline() is being run;
        tbb::parallel_pipeline( n_tokens, 
            tbb::make_filter<void, type1>(filter_type[0], [&counter]( tbb::flow_control& control ) -> type1 {
                    if( --counter < 0 )
                        control.stop();
                    return type1(); }
            ) &
            tbb::make_filter<type1, type2>(filter_type[1], []( type1 /*my_storage*/ ) -> type2 {
                    return type2(); }
            ) &
            tbb::make_filter<type2, void>(filter_type[2], [] ( type2 ) -> void { 
                    tmp_counter++; }
            ) 
        );
        check_and_reset();
#endif
    }
    ASSERT(!filter_node_count, "filter_node objects leaked");
}
Esempio n. 14
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CNPC_PoisonZombie::Spawn( void )
{
	Precache();

	m_fIsTorso = m_fIsHeadless = false;

#ifdef HL2_EPISODIC
	SetBloodColor( BLOOD_COLOR_ZOMBIE );
#else
	SetBloodColor( BLOOD_COLOR_YELLOW );
#endif // HL2_EPISODIC

	m_iHealth = sk_zombie_poison_health.GetFloat();
	m_flFieldOfView = 0.2;

	CapabilitiesClear();
	CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_INNATE_MELEE_ATTACK1 | bits_CAP_INNATE_RANGE_ATTACK1 | bits_CAP_INNATE_RANGE_ATTACK2 );

	BaseClass::Spawn();

	CPASAttenuationFilter filter( this, ATTN_IDLE );
	m_pFastBreathSound = ENVELOPE_CONTROLLER.SoundCreate( filter, entindex(), CHAN_ITEM, "NPC_PoisonZombie.FastBreath", ATTN_IDLE );
	ENVELOPE_CONTROLLER.Play( m_pFastBreathSound, 0.0f, 100 );

	CPASAttenuationFilter filter2( this );
	m_pSlowBreathSound = ENVELOPE_CONTROLLER.SoundCreate( filter2, entindex(), CHAN_ITEM, "NPC_PoisonZombie.Moan1", ATTN_NORM );
	ENVELOPE_CONTROLLER.Play( m_pSlowBreathSound, BREATH_VOL_MAX, 100 );

	int nCrabs = m_nCrabCount;
	if ( !nCrabs )
	{
		nCrabs = MAX_CRABS;
	}
	m_nCrabCount = 0;

	//
	// Generate a random set of crabs based on the crab count
	// specified by the level designer.
	//
	int nBits[] = 
	{
		// One bit
		0x01,
		0x02,
		0x04,

		// Two bits
		0x03,
		0x05,
		0x06,
	};

	int nBitMask = 7;
	if (nCrabs == 1)
	{
		nBitMask = nBits[random->RandomInt( 0, 2 )];
	}
	else if (nCrabs == 2)
	{
		nBitMask = nBits[random->RandomInt( 3, 5 )];
	}

	for ( int i = 0; i < MAX_CRABS; i++ )
	{
		EnableCrab( i, ( nBitMask & ( 1 << i ) ) != 0 );
	}
}
Esempio n. 15
0
/** Calculate image orientation
 *  @param image_orientation A image orientation map
 *  @param[out] conv_im The output convolutional image
 */
void SIFT::ImageOrientation(double* gray_im, double* image_orientation)
{
  double* im_vert_edge = new double[param.image_pixel];
  double* im_hori_edge = new double[param.image_pixel];

  filter2(gray_im, delta_gauss_x, param.filter_size, im_vert_edge);
  filter2(gray_im, delta_gauss_y, param.filter_size, im_hori_edge);

  double* im_magnitude = new double[param.image_pixel];
  double* im_cos_theta = new double[param.image_pixel];
  double* im_sin_theta = new double[param.image_pixel];

  for (int i = 0; i < param.image_height; i++)
  {
	  for (int j = 0; j < param.image_width; j++)
	  {
		  double tmpV = im_vert_edge[i * param.image_width + j];
		  double tmpH = im_hori_edge[i * param.image_width + j];
		  double tmpMagnitude = sqrt(pow(tmpV, 2) + pow(tmpH, 2));
		  im_magnitude[i * param.image_width + j] = tmpMagnitude;
		  im_cos_theta[i * param.image_width + j] = tmpV / tmpMagnitude;
		  im_sin_theta[i * param.image_width + j] = tmpH / tmpMagnitude;
	  }
  }

  delete[] im_vert_edge;
  delete[] im_hori_edge;

  double cos_array[8];
  double sin_array[8];
  cos_array[0] = 1.0;
  cos_array[1] = 0.7071;
  cos_array[2] = 0.0;
  cos_array[3] = -0.7071;
  cos_array[4] = -1.0;
  cos_array[5] = -0.7071;
  cos_array[6] = 0.0;
  cos_array[7] = 0.7071;

  sin_array[0] = 0.0;
  sin_array[1] = 0.7071;
  sin_array[2] = 1.0;
  sin_array[3] = 0.7071;
  sin_array[4] = 0.0;
  sin_array[5] = -0.7071;
  sin_array[6] = -1.0;
  sin_array[7] = -0.7071;
  for (int index = 0; index < param.angle_nums; index++)
  {
	  for (int pt = 0; pt < param.image_pixel; pt++)
	  {
		  double tmp1 = im_cos_theta[pt] * cos_array[index] + im_sin_theta[pt] * sin_array[index];
		  double tmp = pow(tmp1,3);

		  if (tmp > 0)
			  tmp = tmp;
		  else
			  tmp = 0;
		  image_orientation[index * param.image_pixel + pt] = tmp * im_magnitude[pt];
	  }
  }

  delete[] im_magnitude;
  delete[] im_cos_theta;
  delete[] im_sin_theta;
}
Esempio n. 16
0
Masek::IMAGE* Masek::canny(IMAGE *im, double sigma, double scaling, 
						   double vert, double horz, filter *gradient, filter *orND)
{

	filter  gaussian, *newim;
	int i, j;
	int hsize[2];
	int rows, cols;
	double xscaling, yscaling;
	double *h, *v, *d1, *d2, X, Y, begin, end;

	xscaling = vert;
	yscaling = horz;

	hsize[0] = (int)(6*sigma+1);
	hsize[1] = (int)(6*sigma+1);  // % The filter size.

	gaussian.hsize[0] = hsize[0];
	gaussian.hsize[1] = hsize[1];
	gaussian.data = (double*) malloc(sizeof(double)*hsize[0]*hsize[1]);

	/*gaussian = fspecial('gaussian',hsize,sigma);
	im = filter2(gaussian,im);        % Smoothed image.*/
	
    CREATEGAUSS (hsize, sigma, &gaussian);
	
	newim = filter2(gaussian,im);
	
	newim = imresize(newim, scaling);
	
	rows = newim->hsize[0];
	cols = newim->hsize[1];

	h = (double*)malloc(sizeof(double)*rows*cols);

	for (i = 0; i<rows; i++)
	{
		for (j = 0; j<cols; j++)
		{
			if (j == 0)
				*(h+i*cols+j) = (newim->data[i*cols+1]);
			else if (j == cols-1)
				*(h+i*cols+j) = (-newim->data[i*cols+j-1]);
			else
				*(h+i*cols+j) = (newim->data[i*cols+j+1]-newim->data[i*cols+j-1]);
			
		}
	}

	v = (double*)malloc(sizeof(double)*rows*cols);

	for (i = 0; i<rows; i++)
	{
		for (j = 0; j<cols; j++)
		{
			if (i == 0)
				*(v+i*cols+j) = (newim->data[(i+1)*cols+j]);
			else if (i == rows-1)
				*(v+i*cols+j) = -newim->data[(i-1)*cols+j];
			else
				*(v+i*cols+j) = (newim->data[(i+1)*cols+j]-newim->data[(i-1)*cols+j]);
			
		}
	}

	d1 = (double*)malloc(sizeof(double)*rows*cols);
	d2 = (double*)malloc(sizeof(double)*rows*cols);

	for (i = 0; i<rows; i++)
	{
		for (j = 0; j<cols; j++)
		{
			if (i == rows-1 || j == cols-1)
				begin = 0;
			else
				begin = newim->data[(i+1)*cols+j+1];
			
			if (i == 0 || j == 0)
				end = 0;
			else
				end = newim->data[(i-1)*cols+j-1];
					
			*(d1+i*cols+j) = begin-end;
			
		}
	}

	for (i = 0; i<rows; i++)
	{
		for (j = 0; j<cols; j++)
		{
			if (i == 0 || j == cols-1)
				begin = 0;
			else
				begin = newim->data[(i-1)*cols+j+1];
			
			if (i == rows-1 || j == 0)
				end = 0;
			else
				end = newim->data[(i+1)*cols+j-1];
					
			*(d2+i*cols+j) = begin-end;
			
		}
	}

	orND->data = (double*)malloc(sizeof(double)*rows*cols);
	orND->hsize[0] = rows;
	orND->hsize[1] = cols;

	gradient->data = (double*)malloc(sizeof(double)*rows*cols);
	gradient->hsize[0] = rows;
	gradient->hsize[1] = cols;

	
	for (i = 0; i<rows*cols;i++)
	{
        X = (h[i]+(d1[i]+d2[i])/2.0)*xscaling;
		
		Y = (v[i]+(d1[i]-d2[i])/2.0)*yscaling;

		gradient->data[i] = sqrt(X*X+Y*Y);
	
		orND->data[i] = atan2(-Y, X);
		
		/*if (i == 14)
		{
		printf("h is %f, d1 is %f, d2 is %f, v is %f xscaling is %f, yscaling is %f\n", h[i], d1[i], d2[i], v[i], xscaling, yscaling);
		printf("X is %f, Y is %f\n", X, Y);
		printf("orND is %f\n", orND->data[i]);
		}
*/
					
		if (orND->data[i]<0)
			orND->data[i]+=PI;
		
//		if (i == 14)
//			printf("orND is %f\n", orND->data[i]);		
		
		orND->data[i] = (orND->data[i]/PI)*180;
//		if (i == 14)
//			printf("orND is %f\n", orND->data[i]);		
		
		
	}
	
	free (gaussian.data);
	free(d1);
	free(d2);
	free(h);
	free(v);

	free(newim->data);
	free(newim);

	return im;
}
//=========================================================
// Hornet is flying, gently tracking target
//=========================================================
void CNPC_Hornet::TrackTarget ( void )
{
	Vector	vecFlightDir;
	Vector	vecDirToEnemy;
	float	flDelta;

	StudioFrameAdvance( );

	if (gpGlobals->curtime > m_flStopAttack)
	{
		SetTouch( NULL );
		SetThink( &CBaseEntity::SUB_Remove );
		SetNextThink( gpGlobals->curtime + 0.1f );
		return;
	}

	// UNDONE: The player pointer should come back after returning from another level
	if ( GetEnemy() == NULL )
	{// enemy is dead.
		GetSenses()->Look( 1024 );
		SetEnemy( BestEnemy() );
	}
	
	if ( GetEnemy() != NULL && FVisible( GetEnemy() ))
	{
		m_vecEnemyLKP = GetEnemy()->BodyTarget( GetAbsOrigin() );
	}
	else
	{
		m_vecEnemyLKP = m_vecEnemyLKP + GetAbsVelocity() * m_flFlySpeed * 0.1;
	}

	vecDirToEnemy = m_vecEnemyLKP - GetAbsOrigin();
	VectorNormalize( vecDirToEnemy );

	if ( GetAbsVelocity().Length() < 0.1 )
		vecFlightDir = vecDirToEnemy;
	else 
	{
		vecFlightDir = GetAbsVelocity();
		VectorNormalize( vecFlightDir );
	}

	SetAbsVelocity( vecFlightDir + vecDirToEnemy );

	// measure how far the turn is, the wider the turn, the slow we'll go this time.
	flDelta = DotProduct ( vecFlightDir, vecDirToEnemy );
	
	if ( flDelta < 0.5 )
	{// hafta turn wide again. play sound
		CPASAttenuationFilter filter( this );
		EmitSound( filter, entindex(), "Hornet.Buzz" );
	}

	if ( flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED )
	{// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far.
		flDelta = 0.25;
	}

	Vector vecVel = vecFlightDir + vecDirToEnemy;
	VectorNormalize( vecVel );

	if ( GetOwnerEntity() && (GetOwnerEntity()->GetFlags() & FL_NPC) )
	{
		// random pattern only applies to hornets fired by monsters, not players. 

		vecVel.x += random->RandomFloat ( -0.10, 0.10 );// scramble the flight dir a bit.
		vecVel.y += random->RandomFloat ( -0.10, 0.10 );
		vecVel.z += random->RandomFloat ( -0.10, 0.10 );
	}
	
	switch ( m_iHornetType )
	{
		case HORNET_TYPE_RED:
			SetAbsVelocity( vecVel * ( m_flFlySpeed * flDelta ) );// scale the dir by the ( speed * width of turn )
			SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.1, 0.3 ) );
			break;
		default:
			Assert( false );	//fall through if release
		case HORNET_TYPE_ORANGE:
			SetAbsVelocity( vecVel * m_flFlySpeed );// do not have to slow down to turn.
			SetNextThink( gpGlobals->curtime + 0.1f );// fixed think time
			break;
	}

	QAngle angNewAngles;
	VectorAngles( GetAbsVelocity(), angNewAngles );
	SetAbsAngles( angNewAngles );
	
	SetSolid( SOLID_BBOX );

	// if hornet is close to the enemy, jet in a straight line for a half second.
	// (only in the single player game)
	if ( GetEnemy() != NULL && !g_pGameRules->IsMultiplayer() )
	{
		if ( flDelta >= 0.4 && ( GetAbsOrigin() - m_vecEnemyLKP ).Length() <= 300 )
		{
			CPVSFilter filter( GetAbsOrigin() );
			te->Sprite( filter, 0.0,
				&GetAbsOrigin(), // pos
				iHornetPuff,	// model
				0.2,				//size
				128				// brightness
			);

			CPASAttenuationFilter filter2( this );
			EmitSound( filter2, entindex(), "Hornet.Buzz" );
			SetAbsVelocity( GetAbsVelocity() * 2 );
			SetNextThink( gpGlobals->curtime + 1.0f );
			// don't attack again
			m_flStopAttack = gpGlobals->curtime;
		}
	}
}
Esempio n. 18
0
void CGrenadeHomer::Detonate(void)
{
	StopRocketTrail();

	StopSound(entindex(), CHAN_BODY, STRING(m_sFlySound));

	m_takedamage	= DAMAGE_NO;	

	CPASFilter filter( GetAbsOrigin() );

	te->Explosion( filter, 0.0,
		&GetAbsOrigin(), 
		g_sModelIndexFireball,
		2.0, 
		15,
		TE_EXPLFLAG_NONE,
		m_DmgRadius,
		m_flDamage );

//	int magnitude = 1.0;
//	int	colorRamp = random->RandomInt( 128, 255 );


	if ( m_nRocketTrailType == HOMER_SMOKE_TRAIL_ALIEN )
	{
		// Add a shockring
		CBroadcastRecipientFilter filter3;
		te->BeamRingPoint( filter3, 0, 
			GetAbsOrigin(),	//origin
			16,			//start radius
			1000,		//end radius
			m_spriteTexture, //texture
			0,			//halo index
			0,			//start frame
			2,			//framerate
			0.3f,		//life
			128,		//width
			16,			//spread
			0,			//amplitude
			100,		//r
			0,			//g
			200,		//b
			50,			//a
			128			//speed
			);


		// Add a shockring
		CBroadcastRecipientFilter filter4;
		te->BeamRingPoint( filter4, 0, 
			GetAbsOrigin(),	//origin
			16,			//start radius
			500,		//end radius
			m_spriteTexture, //texture
			0,			//halo index
			0,			//start frame
			2,			//framerate
			0.3f,		//life
			128,		//width
			16,			//spread
			0,			//amplitude
			200,		//r
			0,			//g
			100,		//b
			50,			//a
			128			//speed
			);



	}


	Vector vecForward = GetAbsVelocity();
	VectorNormalize(vecForward);
	trace_t		tr;
	UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward,  MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, & tr);

	UTIL_DecalTrace( &tr, "Scorch" );

	UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );

	RadiusDamage ( CTakeDamageInfo( this, GetOwnerEntity(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
	CPASAttenuationFilter filter2( this, "GrenadeHomer.StopSounds" );
	EmitSound( filter2, entindex(), "GrenadeHomer.StopSounds" );
	UTIL_Remove( this );
}
Esempio n. 19
0
void MakeUserDataRec(OpenUserDataRec    *myData , const wxString& filter )
{
    myData->menuitems = NULL ;
    myData->currentfilter = 0 ;
    myData->saveMode = false ;

    if ( filter && filter[0] )
    {
        wxString filter2(filter) ;
        int filterIndex = 0;
        bool isName = true ;
        wxString current ;
        for( unsigned int i = 0; i < filter2.Len() ; i++ )
        {
            if( filter2.GetChar(i) == wxT('|') )
            {
                if( isName ) {
                    myData->name.Add( current ) ;
                }
                else {
                    myData->extensions.Add( current.MakeUpper() ) ;
                    ++filterIndex ;
                }
                isName = !isName ;
                current = wxEmptyString ;
            }
            else
            {
                current += filter2.GetChar(i) ;
            }
        }
        // we allow for compatibility reason to have a single filter expression (like *.*) without
        // an explanatory text, in that case the first part is name and extension at the same time

        wxASSERT_MSG( filterIndex == 0 || !isName , wxT("incorrect format of format string") ) ;
        if ( current.IsEmpty() )
            myData->extensions.Add( myData->name[filterIndex] ) ;
        else
            myData->extensions.Add( current.MakeUpper() ) ;
        if ( filterIndex == 0 || isName )
            myData->name.Add( current.MakeUpper() ) ;

        ++filterIndex ;

        const size_t extCount = myData->extensions.GetCount();
        for ( size_t i = 0 ; i < extCount; i++ )
        {
            wxUint32 fileType;
            wxUint32 creator;
            wxString extension = myData->extensions[i];

            if (extension.GetChar(0) == '*')
                extension = extension.Mid(1);	// Remove leading *

            if (extension.GetChar(0) == '.')
            {
                extension = extension.Mid(1);	// Remove leading .
            }

            if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator ))
            {
                myData->filtermactypes.Add( (OSType)fileType );
            }
            else
            {
                myData->filtermactypes.Add( '****' ) ;		// We'll fail safe if it's not recognized
            }
        }
    }
}
Esempio n. 20
0
int main(void) {
  loggerInit();
  PortAudioClass pa;
  SignalBlock sb;  
  FilterBlock fb;
  fb.initialize();
  
  // Global setup
  int num_inputs = 2;
  int num_outputs = 2;
  EXEC_MODE mode = SWEEP;

  int num_taps = 4800;
  
  std::vector<float> filter1(num_taps,0.f);
  filter1.at(0) = 1.f;

  std::vector<float> filter2(num_taps,0.f);
  filter2.at(0) = 1.f;

  fb.setFilterLen(num_taps);
  fb.setNumInAndOutputs(num_inputs,num_outputs);
  
  //readFile("responseL.txt", filter1);
  //readFile("responseR.txt", filter2);
  
  for(int i = 0; i < num_taps; i++)
    std::cout<<filter1.at(i)<<std::endl;

  fb.setFilterTaps(0,0, filter1);
  fb.setFilterTaps(0,1, filter2);
  //fb.setFilterTaps(1,1, filter2);
  //fb.setFilterTaps(1,0, filter2);
  fb.setFrameLen(256);
  fb.setMode(mode);

  fb.initialize();
  
  pa.setFramesPerBuffer(256);
  pa.initialize();
  
  //for(int i = 0; i < pa.getNumberOfDevices(); i++)
  //  pa.printDeviceInfo(i);

  // Currently fastrack is at index 3
  // Soundflower 16 is index 5

  // port audio setup
  pa.setCurrentDevice(3);
  pa.setNumInputChannels(num_inputs);
  pa.setNumOutputChannels(num_outputs);

 
  pa.setFs(48e3);
  
  // sweep parameters  
  if(mode == SWEEP) {
    
    
     // this is for the sweep, one pair at a time
    pa.setCurrentOutputChannel(0);
    pa.setCurrentInputChannel(0);
    sb.setFs(48e3);
    sb.setFBegin(1);
    sb.setFEnd(20000);
    sb.setLength(6);
    pa.output_data_ = sb.getSweep();
    CallbackStruct sweep = pa.setupSweepCallbackBlock();
    pa.setCallbackData((void*)&sweep);
    pa.setCallback(playRecCallback);
  }
  if(mode < SWEEP) {
    log_msg<LOG_INFO>(L"main - Convoltuion processing: %s")%mode_texts[(int)mode];
    pa.setCallbackData((void*)(&fb));
    pa.setCallback(convolutionCallback);
  }


  pa.openStream();
  pa.startStream();
  sleep(sb.getLength());
  pa.closeStream();
  pa.terminate();

  if(mode == SWEEP) {
    std::vector<float> ir = sb.getRawIr(pa.getOutputData(),
                                        pa.getInputBuffer());  
    writeFile("response1.txt", pa.getOutputData(), pa.getInputBuffer(), ir);
  }
  return 0;
}
Esempio n. 21
0
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
void CNPC_AlienGrunt::HandleAnimEvent( animevent_t *pEvent )
{
	switch( pEvent->event )
	{
	case AGRUNT_AE_HORNET1:
	case AGRUNT_AE_HORNET2:
	case AGRUNT_AE_HORNET3:
	case AGRUNT_AE_HORNET4:
	case AGRUNT_AE_HORNET5:
		{
			// m_vecEnemyLKP should be center of enemy body
			Vector vecArmPos;
			QAngle angArmDir;
			Vector vecDirToEnemy;
			QAngle angDir;

			if (HasCondition( COND_SEE_ENEMY) && GetEnemy())
			{
				Vector vecEnemyLKP = GetEnemy()->GetAbsOrigin();

				vecDirToEnemy = ( ( vecEnemyLKP ) - GetAbsOrigin() );
				VectorAngles( vecDirToEnemy, angDir );
				VectorNormalize( vecDirToEnemy );
			}
			else
			{
				angDir = GetAbsAngles();
				angDir.x = -angDir.x;

				Vector vForward;
				AngleVectors( angDir, &vForward );
				vecDirToEnemy = vForward;
			}

			DoMuzzleFlash();

			// make angles +-180
			if (angDir.x > 180)
			{
				angDir.x = angDir.x - 360;
			}

		//	SetBlending( 0, angDir.x );
			GetAttachment( "0", vecArmPos, angArmDir );

			vecArmPos = vecArmPos + vecDirToEnemy * 32;
		
			CPVSFilter filter( GetAbsOrigin() );
			te->Sprite( filter, 0.0,
				&vecArmPos, iAgruntMuzzleFlash, random->RandomFloat( 0.4, 0.8 ), 128 );

			CBaseEntity *pHornet = CBaseEntity::Create( "hornet", vecArmPos, QAngle( 0, 0, 0 ), this );

			Vector vForward;
			AngleVectors( angDir, &vForward );
	
			pHornet->SetAbsVelocity( vForward * 300 );
			pHornet->SetOwnerEntity( this );
			
			EmitSound( "Weapon_Hornetgun.Single" );

			CHL1BaseNPC *pHornetMonster = (CHL1BaseNPC *)pHornet->MyNPCPointer();

			if ( pHornetMonster )
			{
				pHornetMonster->SetEnemy( GetEnemy() );
			}
		}
		break;

	case AGRUNT_AE_LEFT_FOOT:
		// left foot
		{
			CPASAttenuationFilter filter2( this );
			EmitSound( filter2, entindex(), "AlienGrunt.LeftFoot" );
		}
		break;
	case AGRUNT_AE_RIGHT_FOOT:
		// right foot
		{
			CPASAttenuationFilter filter3( this );
			EmitSound( filter3, entindex(), "AlienGrunt.RightFoot" );
		}
		break;

	case AGRUNT_AE_LEFT_PUNCH:
		{
			Vector vecMins = GetHullMins();
			Vector vecMaxs = GetHullMaxs();
			vecMins.z = vecMins.x;
			vecMaxs.z = vecMaxs.x;

			CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB );
			CPASAttenuationFilter filter4( this );
			
			if ( pHurt )
			{
				if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
					 pHurt->ViewPunch( QAngle( -25, 8, 0) );

				Vector vRight;
				AngleVectors( GetAbsAngles(), NULL, &vRight, NULL );

				// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
				if ( pHurt->IsPlayer() )
				{
					// this is a player. Knock him around.
					pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * 250 );
				}

				EmitSound(filter4, entindex(), "AlienGrunt.AttackHit" );

				Vector vecArmPos;
				QAngle angArmAng;
				GetAttachment( 0, vecArmPos, angArmAng );
				SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood.
			}
			else
			{
				// Play a random attack miss sound
				EmitSound(filter4, entindex(), "AlienGrunt.AttackMiss" );
			}
		}
		break;

	case AGRUNT_AE_RIGHT_PUNCH:
		{
			Vector vecMins = GetHullMins();
			Vector vecMaxs = GetHullMaxs();
			vecMins.z = vecMins.x;
			vecMaxs.z = vecMaxs.x;

			CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB );
			CPASAttenuationFilter filter5( this );
				
			if ( pHurt )
			{
				if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
					 pHurt->ViewPunch( QAngle( 25, 8, 0) );

				// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
				if ( pHurt->IsPlayer() )
				{
					// this is a player. Knock him around.
					Vector vRight;
					AngleVectors( GetAbsAngles(), NULL, &vRight, NULL );
					pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * -250 );
				}

				EmitSound( filter5, entindex(), "AlienGrunt.AttackHit" );

				Vector vecArmPos;
				QAngle angArmAng;
				GetAttachment( 0, vecArmPos, angArmAng );
				SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood.
			}
			else
			{
				// Play a random attack miss sound
				EmitSound( filter5, entindex(), "AlienGrunt.AttackMiss" );
			}
		}
		break;

	default:
		BaseClass::HandleAnimEvent( pEvent );
		break;
	}
}
Esempio n. 22
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pOther - 
//-----------------------------------------------------------------------------
void CFlare::FlareTouch( CBaseEntity *pOther )
{
	Assert( pOther );
	if ( !pOther->IsSolid() )
		return;

	if ( ( m_nBounces < 10 ) && ( GetWaterLevel() < 1 ) )
	{
		// Throw some real chunks here
		g_pEffects->Sparks( GetAbsOrigin() );
	}

	//If the flare hit a person or NPC, do damage here.
	if ( pOther && pOther->m_takedamage )
	{
		/*
			The Flare is the iRifle round right now. No damage, just ignite. (sjb)

		//Damage is a function of how fast the flare is flying.
		int iDamage = GetAbsVelocity().Length() / 50.0f;

		if ( iDamage < 5 )
		{
			//Clamp minimum damage
			iDamage = 5;
		}

		//Use m_pOwner, not GetOwnerEntity()
		pOther->TakeDamage( CTakeDamageInfo( this, m_pOwner, iDamage, (DMG_BULLET|DMG_BURN) ) );
		m_flNextDamage = gpGlobals->curtime + 1.0f;
		*/

		CBaseAnimating *pAnim;

		pAnim = dynamic_cast<CBaseAnimating*>(pOther);
		if( pAnim )
		{
			pAnim->Ignite( 30.0f );
		}

		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity	*= 0.1f;
		SetAbsVelocity( vecNewVelocity );

		SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
		SetGravity(1.0f);


		Die( 0.5 );

		return;
	}
	else
	{
		// hit the world, check the material type here, see if the flare should stick.
		trace_t tr;
		tr = CBaseEntity::GetTouchTrace();

		//Only do this on the first bounce
		if ( m_nBounces == 0 )
		{
			const surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps );	

			if ( pdata != NULL )
			{
				//Only embed into concrete and wood (jdw: too obscure for players?)
				//if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) )
				{
					Vector	impactDir = ( tr.endpos - tr.startpos );
					VectorNormalize( impactDir );

					float	surfDot = tr.plane.normal.Dot( impactDir );

					//Do not stick to ceilings or on shallow impacts
					if ( ( tr.plane.normal.z > -0.5f ) && ( surfDot < -0.9f ) )
					{
						RemoveSolidFlags( FSOLID_NOT_SOLID );
						AddSolidFlags( FSOLID_TRIGGER );
						UTIL_SetOrigin( this, tr.endpos + ( tr.plane.normal * 2.0f ) );
						SetAbsVelocity( vec3_origin );
						SetMoveType( MOVETYPE_NONE );
						
						SetTouch( &CFlare::FlareBurnTouch );
						
						int index = decalsystem->GetDecalIndexForName( "SmallScorch" );
						if ( index >= 0 )
						{
							CBroadcastRecipientFilter filter;
							te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index );
						}
						
						CPASAttenuationFilter filter2( this, "Flare.Touch" );
						EmitSound( filter2, entindex(), "Flare.Touch" );

						return;
					}
				}
			}
		}

		//Scorch decal
		if ( GetAbsVelocity().LengthSqr() > (250*250) )
		{
			int index = decalsystem->GetDecalIndexForName( "FadingScorch" );
			if ( index >= 0 )
			{
				CBroadcastRecipientFilter filter;
				te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index );
			}
		}

		// Change our flight characteristics
		SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
		SetGravity( UTIL_ScaleForGravity( 640 ) );
		
		m_nBounces++;

		//After the first bounce, smacking into whoever fired the flare is fair game
		SetOwnerEntity( this );	

		// Slow down
		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity.x *= 0.8f;
		vecNewVelocity.y *= 0.8f;
		SetAbsVelocity( vecNewVelocity );

		//Stopped?
		if ( GetAbsVelocity().Length() < 64.0f )
		{
			SetAbsVelocity( vec3_origin );
			SetMoveType( MOVETYPE_NONE );
			RemoveSolidFlags( FSOLID_NOT_SOLID );
			AddSolidFlags( FSOLID_TRIGGER );
			SetTouch( &CFlare::FlareBurnTouch );
		}
	}
}
Esempio n. 23
0
void run_filter_set(
        input_filter<t1>& i_filter,
        middle_filter<t1,t2>& m_filter,
        output_filter<t2>& o_filter,
        mode_array *filter_type,
        final_assert_type my_t) {
    tbb::filter_t<void, t1> filter1( filter_type[0], i_filter );
    tbb::filter_t<t1, t2> filter2( filter_type[1], m_filter );
    tbb::filter_t<t2, void> filter3( filter_type[2], o_filter );
    ASSERT(filter_node_count==3, "some filter nodes left after previous iteration?");
    resetCounters();
    // Create filters sequence when parallel_pipeline() is being run
    tbb::parallel_pipeline( n_tokens, filter1 & filter2 & filter3 );
    checkCounters(my_t);

    // Create filters sequence partially outside parallel_pipeline() and also when parallel_pipeline() is being run
    tbb::filter_t<void, t2> filter12;
    filter12 = filter1 & filter2;
    resetCounters();
    tbb::parallel_pipeline( n_tokens, filter12 & filter3 );
    checkCounters(my_t);

    tbb::filter_t<void, void> filter123 = filter12 & filter3;
    // Run pipeline twice with the same filter sequence
    for( unsigned i = 0; i<2; i++ ) {
        resetCounters();
        tbb::parallel_pipeline( n_tokens, filter123 );
        checkCounters(my_t);
    }

    // Now copy-construct another filter_t instance, and use it to run pipeline
    {
        tbb::filter_t<void, void> copy123( filter123 );
        resetCounters();
        tbb::parallel_pipeline( n_tokens, copy123 );
        checkCounters(my_t);
    }

    // Construct filters and create the sequence when parallel_pipeline() is being run
    resetCounters();
    tbb::parallel_pipeline( n_tokens,
               tbb::make_filter<void, t1>(filter_type[0], i_filter) &
               tbb::make_filter<t1, t2>(filter_type[1], m_filter) &
               tbb::make_filter<t2, void>(filter_type[2], o_filter) );
    checkCounters(my_t);

    // Construct filters, make a copy, destroy the original filters, and run with the copy
    int cnt = filter_node_count;
    {
        tbb::filter_t<void, void>* p123 = new tbb::filter_t<void,void> (
               tbb::make_filter<void, t1>(filter_type[0], i_filter) &
               tbb::make_filter<t1, t2>(filter_type[1], m_filter) &
               tbb::make_filter<t2, void>(filter_type[2], o_filter) );
        ASSERT(filter_node_count==cnt+5, "filter node accounting error?");
        tbb::filter_t<void, void> copy123( *p123 );
        delete p123;
        ASSERT(filter_node_count==cnt+5, "filter nodes deleted prematurely?");
        resetCounters();
        tbb::parallel_pipeline( n_tokens, copy123 );
        checkCounters(my_t);
    }

    // construct a filter with temporaries
    {
        tbb::filter_t<void, void> my_filter;
        fill_chain<t1,t2>( my_filter, filter_type, i_filter, m_filter, o_filter );
        resetCounters();
        tbb::parallel_pipeline( n_tokens, my_filter );
        checkCounters(my_t);
    }
    ASSERT(filter_node_count==cnt, "scope ended but filter nodes not deleted?");
}
Esempio n. 24
0
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
void CNPC_Vortigaunt::HandleAnimEvent( animevent_t *pEvent )
{
    // ALERT( at_console, "event %d : %f\n", pEvent->event, pev->frame );
    switch( pEvent->event )
    {
    case ISLAVE_AE_CLAW:
    {
        // SOUND HERE!
        CBaseEntity *pHurt = CheckTraceHullAttack( 40, Vector(-10,-10,-10), Vector(10,10,10), sk_islave_dmg_claw.GetFloat(), DMG_SLASH );
        CPASAttenuationFilter filter( this );
        if ( pHurt )
        {
            if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
                pHurt->ViewPunch( QAngle( 5, 0, -18 ) );

            // Play a random attack hit sound
            enginesound->EmitSound( filter, entindex(), CHAN_WEAPON, pAttackHitSounds[ random->RandomInt(0,ARRAYSIZE(pAttackHitSounds)-1) ], 1.0, ATTN_NORM, 0, m_iVoicePitch );
        }
        else
            // Play a random attack miss sound
            enginesound->EmitSound( filter, entindex(), CHAN_WEAPON, pAttackMissSounds[ random->RandomInt(0,ARRAYSIZE(pAttackMissSounds)-1) ], 1.0, ATTN_NORM, 0, m_iVoicePitch );
    }
    break;

    case ISLAVE_AE_CLAWRAKE:
    {
        CBaseEntity *pHurt = CheckTraceHullAttack( 40, Vector(-10,-10,-10), Vector(10,10,10), sk_islave_dmg_clawrake.GetFloat(), DMG_SLASH );
        CPASAttenuationFilter filter2( this );
        if ( pHurt )
        {
            if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
                pHurt->ViewPunch( QAngle( 5, 0, 18 ) );

            enginesound->EmitSound( filter2, entindex(), CHAN_WEAPON, pAttackHitSounds[ random->RandomInt(0,ARRAYSIZE(pAttackHitSounds)-1) ], 1.0, ATTN_NORM, 0, m_iVoicePitch );
        }
        else
            enginesound->EmitSound( filter2, entindex(), CHAN_WEAPON, pAttackMissSounds[ random->RandomInt(0,ARRAYSIZE(pAttackMissSounds)-1) ], 1.0, ATTN_NORM, 0, m_iVoicePitch );
    }
    break;

    case ISLAVE_AE_ZAP_POWERUP:
    {
        // speed up attack when on hard
        if ( g_iSkillLevel == SKILL_HARD )
            m_flPlaybackRate = 1.5;

        Vector v_forward;
        GetVectors( &v_forward, NULL, NULL );

        CBroadcastRecipientFilter filter;
        te->DynamicLight( filter, 0.0, &GetAbsOrigin(), 125, 200, 100, 2, 120, 0.2 / m_flPlaybackRate, 0 );

        if ( m_hDead != NULL )
        {
            WackBeam( -1, m_hDead );
            WackBeam( 1, m_hDead );
        }
        else
        {
            ArmBeam( -1 );
            ArmBeam( 1 );
            BeamGlow( );
        }

        CPASAttenuationFilter filter3( this );
        enginesound->EmitSound( filter3, entindex(), CHAN_WEAPON, "debris/zap4.wav", 1, ATTN_NORM, 0, 100 + m_iBeams * 10 );

// Huh?  Model doesn't have multiple texturegroups, commented this out.  -LH
//			m_nSkin = m_iBeams / 2;
    }
    break;

    case ISLAVE_AE_ZAP_SHOOT:
    {
        ClearBeams( );

        if ( m_hDead != NULL )
        {
            Vector vecDest = m_hDead->GetAbsOrigin() + Vector( 0, 0, 38 );
            trace_t trace;
            UTIL_TraceHull( vecDest, vecDest, GetHullMins(), GetHullMaxs(),MASK_SOLID, m_hDead, COLLISION_GROUP_NONE, &trace );

            if ( !trace.startsolid )
            {
                CBaseEntity *pNew = Create( "monster_alien_slave", m_hDead->GetAbsOrigin(), m_hDead->GetAbsAngles() );

                pNew->AddSpawnFlags( 1 );
                WackBeam( -1, pNew );
                WackBeam( 1, pNew );
                UTIL_Remove( m_hDead );
                break;
            }
        }

        ClearMultiDamage();

        ZapBeam( -1 );
        ZapBeam( 1 );

        CPASAttenuationFilter filter4( this );
        enginesound->EmitSound( filter4, entindex(), CHAN_WEAPON, "hassault/hw_shoot1.wav", 1, ATTN_NORM, 0, random->RandomInt( 130, 160 ) );
        ApplyMultiDamage();

        m_flNextAttack = gpGlobals->curtime + random->RandomFloat( 0.5, 4.0 );
    }
    break;

    case ISLAVE_AE_ZAP_DONE:
    {
        ClearBeams();
    }
    break;

    default:
        BaseClass::HandleAnimEvent( pEvent );
        break;
    }
}
Esempio n. 25
0
//-----------------------------------------------------------------------------
// Purpose: 
//
//
//-----------------------------------------------------------------------------
void CGrenade_Molotov::Detonate( void ) 
{
	SetModelName( NULL_STRING );		//invisible
	AddSolidFlags( FSOLID_NOT_SOLID );	// intangible

	m_takedamage = DAMAGE_NO;

	trace_t trace;
	UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + Vector ( 0, 0, -128 ),  MASK_SOLID_BRUSHONLY, 
		this, COLLISION_GROUP_NONE, &trace);

	// Pull out of the wall a bit
	if ( trace.fraction != 1.0 )
	{
		SetLocalOrigin( trace.endpos + (trace.plane.normal * (m_flDamage - 24) * 0.6) );
	}

	int contents = UTIL_PointContents ( GetAbsOrigin() );
	
	if ( (contents & MASK_WATER) )
	{
		UTIL_Remove( this );
		return;
	}

	EmitSound( "Grenade_Molotov.Detonate");

// Start some fires
	int i;
	QAngle vecTraceAngles;
	Vector vecTraceDir;
	trace_t firetrace;

	for( i = 0 ; i < 16 ; i++ )
	{
		// build a little ray
		vecTraceAngles[PITCH]	= random->RandomFloat(45, 135);
		vecTraceAngles[YAW]		= random->RandomFloat(0, 360);
		vecTraceAngles[ROLL]	= 0.0f;

		AngleVectors( vecTraceAngles, &vecTraceDir );

		Vector vecStart, vecEnd;

		vecStart = GetAbsOrigin() + ( trace.plane.normal * 128 );
		vecEnd = vecStart + vecTraceDir * 512;

		UTIL_TraceLine( vecStart, vecEnd, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &firetrace );

		Vector	ofsDir = ( firetrace.endpos - GetAbsOrigin() );
		float	offset = VectorNormalize( ofsDir );

		if ( offset > 128 )
			offset = 128;

		//Get our scale based on distance
		float scale	 = 0.1f + ( 0.75f * ( 1.0f - ( offset / 128.0f ) ) );
		float growth = 0.1f + ( 0.75f * ( offset / 128.0f ) );

		if( firetrace.fraction != 1.0 )
		{
			FireSystem_StartFire( firetrace.endpos, scale, growth, 30.0f, (SF_FIRE_START_ON|SF_FIRE_SMOKELESS|SF_FIRE_NO_GLOW), (CBaseEntity*) this, FIRE_NATURAL );
		}
	}
// End Start some fires
	
	CPASFilter filter2( trace.endpos );

	te->Explosion( filter2, 0.0,
		&trace.endpos, 
		g_sModelIndexFireball,
		2.0, 
		15,
		TE_EXPLFLAG_NOPARTICLES,
		m_DmgRadius,
		m_flDamage );

	CBaseEntity *pOwner;
	pOwner = GetOwnerEntity();
	SetOwnerEntity( NULL ); // can't traceline attack owner if this is set

	UTIL_DecalTrace( &trace, "Scorch" );

	UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );
	CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );

	RadiusDamage( CTakeDamageInfo( this, pOwner, m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );

	AddEffects( EF_NODRAW );
	SetAbsVelocity( vec3_origin );
	SetNextThink( gpGlobals->curtime + 0.2 );

	if ( m_pFireTrail )
	{
		UTIL_Remove( m_pFireTrail );
	}

	UTIL_Remove(this);
}
void CSnark::SuperBounceTouch( CBaseEntity *pOther )
{
	float	flpitch;
	trace_t tr = CBaseEntity::GetTouchTrace( );

	// don't hit the guy that launched this grenade
	if ( m_hOwner && ( pOther == m_hOwner ) )
		return;

	// at least until we've bounced once
	m_hOwner = NULL;

	QAngle angles = GetAbsAngles();
	angles.x = 0;
	angles.z = 0;
	SetAbsAngles( angles );

	// avoid bouncing too much
	if ( m_flNextHit > gpGlobals->curtime) 
		return;

	// higher pitch as squeeker gets closer to detonation time
	flpitch = 155.0 - 60.0 * ( ( m_flDie - gpGlobals->curtime ) / SQUEEK_DETONATE_DELAY );

	if ( pOther->m_takedamage && m_flNextAttack < gpGlobals->curtime )
	{
		// attack!

		// make sure it's me who has touched them
		if ( tr.m_pEnt == pOther )
		{
			// and it's not another squeakgrenade
			if ( tr.m_pEnt->GetModelIndex() != GetModelIndex() )
			{
				// ALERT( at_console, "hit enemy\n");
				ClearMultiDamage();

				Vector vecForward;
				AngleVectors( GetAbsAngles(), &vecForward );

				if ( m_hOwner != NULL )
				{
					CTakeDamageInfo info( this, m_hOwner, sk_snark_dmg_bite.GetFloat(), DMG_SLASH );
					CalculateMeleeDamageForce( &info, vecForward, tr.endpos );
					pOther->DispatchTraceAttack( info, vecForward, &tr );
				}
				else
				{
					CTakeDamageInfo info( this, this, sk_snark_dmg_bite.GetFloat(), DMG_SLASH );
					CalculateMeleeDamageForce( &info, vecForward, tr.endpos );
					pOther->DispatchTraceAttack( info, vecForward, &tr );
				}

				ApplyMultiDamage();

				SetDamage( GetDamage() + sk_snark_dmg_pop.GetFloat() ); // add more explosion damage
				// m_flDie += 2.0; // add more life

				// make bite sound
				CPASAttenuationFilter filter( this );
				enginesound->EmitSound( filter, entindex(), CHAN_WEAPON, "squeek/sqk_deploy1.wav", 1, ATTN_NORM, 0, (int)flpitch );
				m_flNextAttack = gpGlobals->curtime + 0.5;
			}
		}
		else
		{
			// ALERT( at_console, "been hit\n");
		}
	}

	m_flNextHit = gpGlobals->curtime + 0.1;
	m_flNextHunt = gpGlobals->curtime;

	if ( g_pGameRules->IsMultiplayer() )
	{
		// in multiplayer, we limit how often snarks can make their bounce sounds to prevent overflows.
		if ( gpGlobals->curtime < m_flNextBounceSoundTime )
		{
			// too soon!
			return;
		}
	}

	if ( !( GetFlags() & FL_ONGROUND ) )
	{
		// play bounce sound
		CPASAttenuationFilter filter2( this );
		switch ( random->RandomInt( 0, 2 ) )
		{
		case 0:
			enginesound->EmitSound( filter2, entindex(), CHAN_VOICE, "squeek/sqk_hunt1.wav", 1, ATTN_NORM, 0, (int)flpitch );	break;
		case 1:
			enginesound->EmitSound( filter2, entindex(), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, (int)flpitch );	break;
		case 2:
			enginesound->EmitSound( filter2, entindex(), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, (int)flpitch );	break;
		}

		CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 256, 0.25 );
	}
	else
	{
		// skittering sound
		CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 100, 0.1 );
	}

	m_flNextBounceSoundTime = gpGlobals->curtime + 0.5;// half second.
}
void CUnifiedCertStore::InitializeL()
	{
	AllocWorkingVarsL();
	
	// We want the list of all token types that support a readable or writable 
	// certstore interface
	RArray<TUid> uidArray;
	CleanupClosePushL(uidArray);
		
	User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceWritableCertStore)));
	
	TCTFindTokenTypesByInterface filter(uidArray.Array());
	CCTTokenTypeInfo::ListL(iWorkingVars->iWritableTokenTypes, filter);

	uidArray.Reset();

	User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceCertStore)));

	RCPointerArray<CCTTokenTypeInfo> tokenTypes;
	CleanupClosePushL(tokenTypes);

	TCTFindTokenTypesByInterface filter2(uidArray.Array());
	CCTTokenTypeInfo::ListL(tokenTypes, filter2);
	
  	// Check whether client specified order list has attributes in it
  	if(iOrderAttributes.Count() > 0)
  	    {
  	    ApplyOrderingL(tokenTypes);
  	    }

	// Make a note of all hardware token types
	TInt i = 0;
	TInt end = tokenTypes.Count();
	for (; i < end; i++)
		{
		TCTTokenTypeAttribute software;
		software.iUID = KCTSoftware;
		TInt find = tokenTypes[i]->Attributes().Find(software);
		// In the case (TInt)ETrue == KThirdPartyCertStore == 1  
		if (find != KErrNotFound && tokenTypes[i]->Attributes()[find].iVal != 
			(TInt)ETrue && tokenTypes[i]->Attributes()[find].iVal != KManufactureCertStore)
			{
			// This is a hardware type. Add its UID to the list.
			User::LeaveIfError(iHardwareTypeUids.Append(tokenTypes[i]->Type()));
			}
		}

	i = 0;
	while (i < end)
		{
		TInt j = 0;
		TInt jEnd = iWorkingVars->iWritableTokenTypes.Count();
		while (j < jEnd)
			{
			if (iWorkingVars->iWritableTokenTypes[j]->Type() == tokenTypes[i]->Type())
				{
				break;
				}
			j++;
			}
		if (j == jEnd)
			{
			User::LeaveIfError(iWorkingVars->iReadOnlyTokenTypes.Append(tokenTypes[i]));
			tokenTypes.Remove(i);
			end--;
			}
		else
			{
			i++;
			}
		}

	CleanupStack::PopAndDestroy(2);	// uidArray, tokenTypes
	
	iWorkingVars->iIndex = -1;

	TRequestStatus* status = &iStatus;
	User::RequestComplete(status, KErrNone);
	SetActive();
	}
Esempio n. 28
0
//-----------------------------------------------------------------------------
// Purpose: Breaks the breakable. m_hBreaker is the entity that caused us to break.
//-----------------------------------------------------------------------------
void CBreakable::Die( void )
{
	Vector vecVelocity;// shard velocity
	char cFlag = 0;
	int pitch;
	float fvol;
	
	pitch = 95 + random->RandomInt(0,29);

	if (pitch > 97 && pitch < 103)
	{
		pitch = 100;
	}

	// The more negative m_iHealth, the louder
	// the sound should be.

	fvol = random->RandomFloat(0.85, 1.0) + (abs(m_iHealth) / 100.0);
	if (fvol > 1.0)
	{
		fvol = 1.0;
	}

	const char *soundname = NULL;

	switch (m_Material)
	{
	default:
		break;

	case matGlass:
		soundname = "Breakable.Glass";
		cFlag = BREAK_GLASS;
		break;

	case matWood:
		soundname = "Breakable.Crate";
		cFlag = BREAK_WOOD;
		break;

	case matComputer:
		soundname = "Breakable.Computer";
		cFlag = BREAK_METAL;
		break;

	case matMetal:
		soundname = "Breakable.Metal";
		cFlag = BREAK_METAL;
		break;

	case matFlesh:
	case matWeb:
		soundname = "Breakable.Flesh";
		cFlag = BREAK_FLESH;
		break;

	case matRocks:
	case matCinderBlock:
		soundname = "Breakable.Concrete";
		cFlag = BREAK_CONCRETE;
		break;

	case matCeilingTile:
		soundname = "Breakable.Ceiling";
		break;
	}

	if ( soundname )
	{
		if ( m_hBreaker && m_hBreaker->IsPlayer() )
		{
			IGameEvent * event = gameeventmanager->CreateEvent( "break_breakable" );
			if ( event )
			{
				event->SetInt( "userid", ToBasePlayer( m_hBreaker )->GetUserID() );
				event->SetInt( "entindex", entindex() );
				event->SetInt( "material", cFlag );
				gameeventmanager->FireEvent( event );
			}
		}

		CSoundParameters params;
		if ( GetParametersForSound( soundname, params, NULL ) )
		{
			CPASAttenuationFilter filter( this );

			EmitSound_t ep;
			ep.m_nChannel = params.channel;
			ep.m_pSoundName = params.soundname;
			ep.m_flVolume = fvol;
			ep.m_SoundLevel = params.soundlevel;
			ep.m_nPitch = pitch;

			EmitSound( filter, entindex(), ep );	
		}
	}
		
	switch( m_Explosion )
	{
	case expDirected:
		vecVelocity = g_vecAttackDir * -200;
		break;

	case expUsePrecise:
		{
			AngleVectors( m_GibDir, &vecVelocity, NULL, NULL );
			vecVelocity *= 200;
		}
		break;

	case expRandom:
		vecVelocity.x = 0;
		vecVelocity.y = 0;
		vecVelocity.z = 0;
		break;

	default:
		DevMsg("**ERROR - Unspecified gib dir method in func_breakable!\n");
		break;
	}

	Vector vecSpot = WorldSpaceCenter();
	CPVSFilter filter2( vecSpot );

	int iModelIndex = 0;
	CCollisionProperty *pCollisionProp = CollisionProp();

	Vector vSize = pCollisionProp->OBBSize();
	int iCount = ( vSize[0] * vSize[1] + vSize[1] * vSize[2] + vSize[2] * vSize[0] ) / ( 3 * 12 * 12 );

	if ( iCount > func_break_max_pieces.GetInt() )
	{
		iCount = func_break_max_pieces.GetInt();
	}

	ConVarRef breakable_disable_gib_limit( "breakable_disable_gib_limit" );
	if ( !breakable_disable_gib_limit.GetBool() && iCount )
	{
		if ( m_PerformanceMode == PM_NO_GIBS )
		{
			iCount = 0;
		}
		else if ( m_PerformanceMode == PM_REDUCED_GIBS )
		{
			int iNewCount = iCount * func_break_reduction_factor.GetFloat();
			iCount = MAX( iNewCount, 1 );
		}
	}

	if ( m_iszModelName != NULL_STRING )
	{
		for ( int i = 0; i < iCount; i++ )
		{

	#ifdef HL1_DLL
			// Use the passed model instead of the propdata type
			const char *modelName = STRING( m_iszModelName );
			
			// if the map specifies a model by name
			if( strstr( modelName, ".mdl" ) != NULL )
			{
				iModelIndex = modelinfo->GetModelIndex( modelName );
			}
			else	// do the hl2 / normal way
	#endif

			iModelIndex = modelinfo->GetModelIndex( g_PropDataSystem.GetRandomChunkModel(  STRING( m_iszModelName ) ) );

			// All objects except the first one in this run are marked as slaves...
			int slaveFlag = 0;
			if ( i != 0 )
			{
				slaveFlag = BREAK_SLAVE;
			}

			te->BreakModel( filter2, 0.0, 
				vecSpot, pCollisionProp->GetCollisionAngles(), vSize, 
				vecVelocity, iModelIndex, 100, 1, 2.5, cFlag | slaveFlag );
		}
	}

	ResetOnGroundFlags();

	// Don't fire something that could fire myself
	SetName( NULL_STRING );

	AddSolidFlags( FSOLID_NOT_SOLID );
	
	// Fire targets on break
	m_OnBreak.FireOutput( m_hBreaker, this );

	VPhysicsDestroyObject();
	SetThink( &CBreakable::SUB_Remove );
	SetNextThink( gpGlobals->curtime + 0.1f );
	if ( m_iszSpawnObject != NULL_STRING )
	{
		CBaseEntity::Create( STRING(m_iszSpawnObject), vecSpot, pCollisionProp->GetCollisionAngles(), this );
	}

	if ( Explodable() )
	{
		ExplosionCreate( vecSpot, pCollisionProp->GetCollisionAngles(), this, GetExplosiveDamage(), GetExplosiveRadius(), true );
	}
}
Esempio n. 29
0
void OpenUserDataRec::MakeUserDataRec( const wxString& filter )
{
    if ( !filter.empty() )
    {
        wxString filter2(filter) ;
        int filterIndex = 0;
        bool isName = true ;
        wxString current ;

        for ( unsigned int i = 0; i < filter2.length() ; i++ )
        {
            if ( filter2.GetChar(i) == wxT('|') )
            {
                if ( isName )
                {
                    m_name.Add( current ) ;
                }
                else
                {
                    m_extensions.Add( current ) ;
                    ++filterIndex ;
                }

                isName = !isName ;
                current = wxEmptyString ;
            }
            else
            {
                current += filter2.GetChar(i) ;
            }
        }
        // we allow for compatibility reason to have a single filter expression (like *.*) without
        // an explanatory text, in that case the first part is name and extension at the same time

        wxASSERT_MSG( filterIndex == 0 || !isName , wxT("incorrect format of format string") ) ;
        if ( current.empty() )
            m_extensions.Add( m_name[filterIndex] ) ;
        else
            m_extensions.Add( current ) ;
        if ( filterIndex == 0 || isName )
            m_name.Add( current ) ;

        ++filterIndex ;

        const size_t extCount = m_extensions.GetCount();
        for ( size_t i = 0 ; i < extCount; i++ )
        {
            wxUint32 fileType, creator;
            wxString extension = m_extensions[i];

            // Remove leading '*'
            if ( !extension.empty() && (extension.GetChar(0) == '*') )
                extension = extension.Mid( 1 );

            // Remove leading '.'
            if ( !extension.empty() && (extension.GetChar(0) == '.') )
                extension = extension.Mid( 1 );

            if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator ))
                m_filtermactypes.Add( (OSType)fileType );
            else
                m_filtermactypes.Add( '****' ); // We'll fail safe if it's not recognized
        }
    }
}