예제 #1
0
int MPGetVolume(TMediaPlayer* mp)
{
        MCI_STATUS_PARMS p;
        p.dwCallback = 0;
        p.dwItem = MCI_DGV_STATUS_VOLUME;
        mciSendCommand(mp->DeviceID, MCI_STATUS, MCI_STATUS_ITEM, __int32(&p)) ;
        return p.dwReturn;
}
예제 #2
0
/* Gets previous Huffman tree item (?) */
struct huffman_tree_item *libmpq_huff_get_prev_item(struct huffman_tree_item *hi, __int32 value) {
    if (PTR_INT(hi->prev) < 0) {
        return PTR_NOT(hi->prev);
    }
    if (value < 0) {
        value = __int32(hi - hi->next->prev);
    }
    return hi->prev + value;
}
예제 #3
0
파일: shader.cpp 프로젝트: Lamorna/engine
/*
==================
==================
*/
void Vertex_Lighting_REM(

	const __int32 n_triangles,
	const vertex_light_manager_& vertex_light_manager,
	const float4_ positions[4][3],
	float4_ colour[4][3]

) {

	//const __int32 VERTEX_COLOUR = FIRST_ATTRIBUTE + 0;

	static const float r_screen_scale_x = 1.0f / screen_scale_x;
	static const float r_screen_scale_y = 1.0f / screen_scale_y;
	//const __m128 attenuation_factor = set_all(200.0f);
	//const __m128 attenuation_factor = set_all(800.0f);
	//const __m128 specular_scale = set_all(100.0f);
	//const __m128 diffuse_scale = set_all(20.0f);

	__m128 r_screen_scale[2];
	r_screen_scale[X] = set_all(r_screen_scale_x);
	r_screen_scale[Y] = set_all(r_screen_scale_y);
	__m128 screen_shift[2];
	screen_shift[X] = set_all(screen_shift_x);
	screen_shift[Y] = set_all(screen_shift_y);

	__m128 clip_space_position[3][4];
	//__m128 vertex_colour[3][4];

	float4_ new_position[4][3];
	for (__int32 i_vertex = 0; i_vertex < 3; i_vertex++) {

		__m128 vertex_position[4];
		for (__int32 i_triangle = 0; i_triangle < n_triangles; i_triangle++) {
			vertex_position[i_triangle] = load_u(positions[i_triangle][i_vertex].f);
			//vertex_colour[i_vertex][i_triangle] = load_u(colour[i_triangle][i_vertex].f);
		}
		Transpose(vertex_position);
		//Transpose(vertex_colour[i_vertex]);

		__m128 depth = reciprocal(vertex_position[Z]);
		clip_space_position[i_vertex][X] = ((vertex_position[X] - screen_shift[X]) * r_screen_scale[X]) * depth;
		clip_space_position[i_vertex][Y] = ((vertex_position[Y] - screen_shift[Y]) * r_screen_scale[Y]) * depth;
		clip_space_position[i_vertex][Z] = depth;


	}

	__m128 a[3];
	a[X] = clip_space_position[1][X] - clip_space_position[0][X];
	a[Y] = clip_space_position[1][Y] - clip_space_position[0][Y];
	a[Z] = clip_space_position[1][Z] - clip_space_position[0][Z];

	__m128 b[3];
	b[X] = clip_space_position[2][X] - clip_space_position[0][X];
	b[Y] = clip_space_position[2][Y] - clip_space_position[0][Y];
	b[Z] = clip_space_position[2][Z] - clip_space_position[0][Z];


	__m128 normal[4];
	normal[X] = (a[Y] * b[Z]) - (a[Z] * b[Y]);
	normal[Y] = (a[Z] * b[X]) - (a[X] * b[Z]);
	normal[Z] = (a[X] * b[Y]) - (a[Y] * b[X]);

	__m128 mag = (normal[X] * normal[X]) + (normal[Y] * normal[Y]) + (normal[Z] * normal[Z]);
	mag = _mm_rsqrt_ps(mag);
	normal[X] *= mag;
	normal[Y] *= mag;
	normal[Z] *= mag;

	float normal_4[3][4];
	store_u(normal[X], normal_4[X]);
	store_u(normal[Y], normal_4[Y]);
	store_u(normal[Z], normal_4[Z]);

	float centre_4[3][4];
	float extent_4[3][4];
	const __m128 half = set_all(0.5f);
	for (__int32 i_axis = X; i_axis < W; i_axis++) {

		__m128 max;
		__m128 min;
		max = min = clip_space_position[0][i_axis];
		max = max_vec(max_vec(max, clip_space_position[1][i_axis]), clip_space_position[2][i_axis]);
		min = min_vec(min_vec(min, clip_space_position[1][i_axis]), clip_space_position[2][i_axis]);
		store_u((max + min) * half, centre_4[i_axis]);
		store_u((max - min) * half, extent_4[i_axis]);
	}

	for (__int32 i_vertex = 0; i_vertex < 3; i_vertex++) {

		Transpose(clip_space_position[i_vertex]);
		for (__int32 i_triangle = 0; i_triangle < n_triangles; i_triangle++) {
			store_u(clip_space_position[i_vertex][i_triangle], new_position[i_triangle][i_vertex].f);
		}
	}

	const __m128 zero = set_all(0.0f);
	const __m128 one = set_all(1.0f);

	enum {
		MAX_LIGHTS_PER_VERTEX = 128,
	};

	for (__int32 i_triangle = 0; i_triangle < n_triangles; i_triangle++) {

		__m128 centre[3];
		__m128 extent[3];
		for (__int32 i_axis = X; i_axis < W; i_axis++) {
			centre[i_axis] = set_all(centre_4[i_axis][i_triangle]);
			extent[i_axis] = set_all(extent_4[i_axis][i_triangle]);
		}

		float z_min = centre_4[Z][i_triangle] - extent_4[Z][i_triangle];
		float z_max = centre_4[Z][i_triangle] + extent_4[Z][i_triangle];
		__int32 bin_min = __int32(z_min / vertex_light_manager.bin_interval);
		__int32 bin_max = __int32(z_max / vertex_light_manager.bin_interval);
		bin_min = min(bin_min, vertex_light_manager_::NUM_BINS - 1);
		bin_max = min(bin_max, vertex_light_manager_::NUM_BINS - 1);
		bin_min = max(bin_min, 0);
		bin_max = max(bin_max, 0);

		//bin_max = bin_max >= 10 ? 0 : bin_max;
		//printf_s(" %i , %i \n", bin_min, bin_max);

		__int32 i_lights[MAX_LIGHTS_PER_VERTEX];
		__int32 n_lights = 0;
		{
			for (__int32 i_bin = bin_min; i_bin <= bin_max; i_bin++) {

				const vertex_light_manager_::bin_& bin = vertex_light_manager.bin[i_bin];

				for (__int32 i_light_4 = 0; i_light_4 < bin.n_lights; i_light_4 += 4) {

					const __int32 n = min(bin.n_lights - i_light_4, 4);

					__m128 light_position[4];
					for (__int32 i_light = 0; i_light < n; i_light++) {
						__int32 index = vertex_light_manager.i_light[bin.i_start + i_light_4 + i_light];
						light_position[i_light] = load_u(vertex_light_manager.light_sources[index].position.f);
					}
					Transpose(light_position);

					const __m128 light_extent = set_all(100.0f);
					__m128i is_valid = set_all(-1);
					is_valid &= abs(centre[X] - light_position[X]) < (extent[X] + light_extent);
					is_valid &= abs(centre[Y] - light_position[Y]) < (extent[Y] + light_extent);
					is_valid &= abs(centre[Z] - light_position[Z]) < (extent[Z] + light_extent);

					unsigned __int32 result_mask = store_mask(is_valid);

					for (__int32 i_light = 0; i_light < n; i_light++) {

						__int32 index = vertex_light_manager.i_light[bin.i_start + i_light_4 + i_light];
						i_lights[n_lights] = index;
						n_lights += (result_mask >> i_light) & 0x1;
					}

					if (n_lights > MAX_LIGHTS_PER_VERTEX) {

						n_lights = MAX_LIGHTS_PER_VERTEX;
						break;
					}
				}
			}
		}

		for (__int32 i_vertex = 0; i_vertex < 3; i_vertex++) {

			__m128 vertex_position[3];
			vertex_position[X] = set_all(new_position[i_triangle][i_vertex].x);
			vertex_position[Y] = set_all(new_position[i_triangle][i_vertex].y);
			vertex_position[Z] = set_all(new_position[i_triangle][i_vertex].z);

			__m128 vertex_colour[4];
			vertex_colour[R] = set_all(0.0f);
			vertex_colour[G] = set_all(0.0f);
			vertex_colour[B] = set_all(0.0f);

			__m128 normal[3];
			normal[X] = set_all(normal_4[X][i_triangle]);
			normal[Y] = set_all(normal_4[Y][i_triangle]);
			normal[Z] = set_all(normal_4[Z][i_triangle]);

			for (__int32 i_light_4 = 0; i_light_4 < n_lights; i_light_4 += 4) {

				const __int32 n = min(n_lights - i_light_4, 4);

				__m128 light_position[4];
				__m128 light_colour[4];
				unsigned __int32 mask = 0x0;
				float intensity_4[4];
				for (__int32 i_light = 0; i_light < n; i_light++) {

					mask |= 0x1 << i_light;
					const __int32 index = i_lights[i_light_4 + i_light];
					intensity_4[i_light] = vertex_light_manager.light_sources[index].intensity;
					light_position[i_light] = load_u(vertex_light_manager.light_sources[index].position.f);
					light_colour[i_light] = load_u(vertex_light_manager.light_sources[index].colour.f);
				}
				Transpose(light_position);
				Transpose(light_colour);
				__m128 light_intensity = load_u(intensity_4);

				__m128 light_ray[3];
				light_ray[X] = vertex_position[X] - light_position[X];
				light_ray[Y] = vertex_position[Y] - light_position[Y];
				light_ray[Z] = vertex_position[Z] - light_position[Z];

				__m128 mag = (light_ray[X] * light_ray[X]) + (light_ray[Y] * light_ray[Y]) + (light_ray[Z] * light_ray[Z]);
				__m128 r_mag = _mm_rsqrt_ps(mag);
				light_ray[X] *= r_mag;
				light_ray[Y] *= r_mag;
				light_ray[Z] *= r_mag;

				__m128 dot = (normal[X] * light_ray[X]) + (normal[Y] * light_ray[Y]) + (normal[Z] * light_ray[Z]);
				dot &= dot > zero;

				__m128 r_distance = reciprocal(one + mag);
				__m128 spec = (dot * dot) * r_distance;

				static const __m128 specular_coefficient = set_all(2000.0f);
				static const __m128 diffuse_coefficient = set_all(200.0f);

				//printf_s(" %f ", dot);
				__m128i loop_mask = load_mask[mask];

				for (__int32 i_channel = R; i_channel < A; i_channel++) {
					__m128 final = spec * specular_coefficient * light_colour[i_channel] * light_intensity;
					final += r_distance * diffuse_coefficient * light_colour[i_channel] * light_intensity;
					vertex_colour[i_channel] += final & loop_mask;
				}
			}

			Transpose(vertex_colour);
			vertex_colour[0] += vertex_colour[1] + vertex_colour[2] + vertex_colour[3];
			float4_ temp;
			store_u(vertex_colour[0], temp.f);
			colour[i_triangle][i_vertex].x += temp.x;
			colour[i_triangle][i_vertex].y += temp.y;
			colour[i_triangle][i_vertex].z += temp.z;
		}
	}
예제 #4
0
void MPSetVolume(TMediaPlayer* mp, int vol, int channel)
{
        MCI_DGV_SETAUDIO_PARMS p;
        p.dwCallback = 0;
        p.dwItem = MCI_DGV_SETAUDIO_VOLUME;
        p.dwValue = vol;
        p.dwOver = 0;
        p.lpstrAlgorithm=0;
        p.lpstrQuality=0;

        mciSendCommand(mp->DeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE | channel | MCI_DGV_SETAUDIO_ITEM,  __int32(&p));
}
예제 #5
0
void get_results_after_sorting(const char * name, __int32 param_offset,__int32 hist_offset, sort_class * sorter,Det_struct * det, double  parameter[], double tdc_ns[][NUM_IONS], Histo * Hist, Ueberstruct &Ueber)
{
	std::string det_name = name;
	if ((parameter[param_offset] > 0.5) && (parameter[param_offset] < 2.5)) {
		bool isDLD = true;
		if((parameter[param_offset] > 1.5) && (parameter[param_offset] < 2.5)) isDLD = false;
		
		// write results to detector struct.
		//
		// The sort_and_write_NTuple function will be able to access for each hit:
		//		x position [mm]
		//		y position [mm]
		//		MCP time [ns]
		//		reconstruction method
		//		number of hits on detector
		
		for (__int32 i=0;i<det->number_of_reconstructed_hits;++i) {
			det->x[i] = sorter->output_hit_array[i]->x;
			det->y[i] = sorter->output_hit_array[i]->y;
			det->method[i] = sorter->output_hit_array[i]->method;
			det->time[i] = sorter->output_hit_array[i]->time;		 
		}

		if (!Ueber.fast_mode) {

			if (det->number_of_reconstructed_hits > 0) {
				if (Hist->is_defined(hist_offset+3))
					Hist->fill2(hist_offset+3,det->x[0],det->y[0],1.);
				else
					Hist->fill2(hist_offset+3,add(det_name,std::string("_xy_mm_sorted")),det->x[0],det->y[0],1.,"",200,-100.,100.,"",200,-100.,+100,"",det_name.c_str()); 
			}

			if (det->number_of_reconstructed_hits > 0) {
				if (Hist->is_defined(hist_offset+0)) Hist->fill1(hist_offset+0,det->method[0]); else Hist->fill1(hist_offset+0,add(det_name,std::string("_method_hit_1")),det->method[0],1.,add(std::string("method_hit_1 "),det_name,std::string(" method_hit_1")),25,-0.5,24.5,add(det_name,std::string("_method_hit_1")),det_name.c_str());
			}
			if (det->number_of_reconstructed_hits > 1) {
				if (Hist->is_defined(hist_offset+1)) Hist->fill1(hist_offset+1,det->method[1]); else Hist->fill1(hist_offset+1,add(det_name,std::string("_method_hit_2")),det->method[1],1.,add(std::string("method_hit_2 "),det_name,std::string(" method_hit_2")),25,-0.5,24.5,add(det_name,std::string("_method_hit_2")),det_name.c_str());
			}
		}

		if(!isDLD && (!Ueber.fast_mode || det->auto_calibration)) {
			// create map of desaster
			double sumu_ns = -1.e60;
			double sumv_ns = -2.e60;
			double sumw_ns = -3.e60;
			__int32 * cnt = Ueber.cnt;
			if (cnt[sorter->Cu1]>0 && cnt[sorter->Cu2]>0) sumu_ns = tdc_ns[sorter->Cu1][0] + tdc_ns[sorter->Cu2][0];
			if (cnt[sorter->Cv1]>0 && cnt[sorter->Cv2]>0) sumv_ns = tdc_ns[sorter->Cv1][0] + tdc_ns[sorter->Cv2][0];
			if (cnt[sorter->Cw1]>0 && cnt[sorter->Cw2]>0) sumw_ns = tdc_ns[sorter->Cw1][0] + tdc_ns[sorter->Cw2][0];
			if (sorter->use_MCP) {
				double mcp_signal = -1.e100;
				if (cnt[sorter->Cmcp]>0) mcp_signal = tdc_ns[sorter->Cmcp][0];
				sumu_ns -= 2.*mcp_signal;
				sumv_ns -= 2.*mcp_signal;
				sumw_ns -= 2.*mcp_signal;
			}
//			if (det->auto_calibration) {
				if (fabs(sumu_ns)<10. && fabs(sumv_ns)<10. && fabs(sumw_ns)<10.) {
//					if (!det->use_reconstruction) {
						double tu1_ns = tdc_ns[sorter->Cu1][0];
						double tu2_ns = tdc_ns[sorter->Cu2][0];
						double tv1_ns = tdc_ns[sorter->Cv1][0];
						double tv2_ns = tdc_ns[sorter->Cv2][0];
						double tw1_ns = tdc_ns[sorter->Cw1][0];
						double tw2_ns = tdc_ns[sorter->Cw2][0];

						double u_ns = tu1_ns - tu2_ns;
						double v_ns = tv1_ns - tv2_ns;
						double w_ns = tw1_ns - tw2_ns;

						if (!det->use_reconstruction && !det->auto_calibration && sorter->use_pos_correction) {
							u_ns = sorter->signal_corrector->correct_pos(tu1_ns,tu2_ns,0);
							v_ns = sorter->signal_corrector->correct_pos(tv1_ns,tv2_ns,1);
							w_ns = sorter->signal_corrector->correct_pos(tw1_ns,tw2_ns,2);
						}

						bool feed = false;
						if (!det->use_reconstruction) feed = true;
						if (det->use_reconstruction && det->number_of_reconstructed_hits>0) {
							if (det->method[0] == 0) feed = true;
						}
						if (feed) {
							det->scalefactors_calibrator->feed_calibration_data(u_ns,v_ns,w_ns, w_ns - det->hex_offset_w);
							if (det->auto_calibration == 1) {
								if (det->scalefactors_calibrator->map_is_full_enough()) {
									++det->auto_calibration;
									printf("\nCalibration finished on detector \"%s\"\n",name);
									Ueber.stop_reading_files = true;
								}
							}

							__int32 n = __int32(det->scalefactors_calibrator->detector_map_size * 0.5 + 0.1);
							if (Hist->is_defined(hist_offset+2))
								Hist->fill2(hist_offset+2,det->scalefactors_calibrator->binx,det->scalefactors_calibrator->biny,det->scalefactors_calibrator->detector_map_fill);
							else
								Hist->fill2(hist_offset+2,add(det_name,std::string("_non_linearity")),det->scalefactors_calibrator->binx,det->scalefactors_calibrator->biny,det->scalefactors_calibrator->detector_map_fill,"",2*n,-n-0.5,+n-0.5,"",2*n,-n-0.5,+n-0.5,"",det_name.c_str()); 
						}
					//}
				}
			//}
		}
	}
}