Пример #1
0
void GameScreen::render_default()
{
	game::engine::active_stage->setup_lights();

	camera = game::engine::active_stage->get_camera_matrix();
	camera->reset_identity();
	camera->rotate(Vector3(1, 0, 0), DEG_TO_RAD(phi));
	camera->rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));
	set_view_matrix(*camera);

	Matrix4x4 cockpit_loc_mat;

	XFormNode *gun_ctrl = game::engine::active_stage->get_gun_ctrl_node_ptr();
	XFormNode *cockpit_ctrl = game::engine::active_stage->get_cockpit_ctrl_node_ptr();
	Object *crosshair = game::engine::active_stage->get_crosshair();

	crosshair->set_matrix((*camera).inverse());

	cockpit_loc_mat.rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));
	cockpit_ctrl->set_matrix(cockpit_loc_mat.inverse());

	gun_ctrl->set_matrix((*camera).inverse());

	shadow_render_pass(false, get_msec());
	//draw_shad_tex();
	color_render_pass(get_msec());
    game::utils::display_to_rendering_quad();
}
Пример #2
0
int main(int argc, char **argv) {
    int i, vcount = 1000000;
    void *kd, *set;
    unsigned int msec, start;

    if (argc > 1 && isdigit(argv[1][0])) {
        vcount = atoi(argv[1]);
    }
    printf("inserting %d random vectors... ", vcount);
    fflush(stdout);

    kd = kd_create(3);

    start = get_msec();
    for (i = 0; i < vcount; i++) {
        float x, y, z;
        x = ((float) rand() / RAND_MAX) * 200.0 - 100.0;
        y = ((float) rand() / RAND_MAX) * 200.0 - 100.0;
        z = ((float) rand() / RAND_MAX) * 200.0 - 100.0;

        assert(kd_insert3(kd, x, y, z, 0) == 0);
    }
    msec = get_msec() - start;
    printf("%.3f sec\n", (float) msec / 1000.0);

    start = get_msec();
    set = kd_nearest_range3(kd, 0, 0, 0, 40);
    msec = get_msec() - start;
    printf("range query returned %d items in %.5f sec\n", kd_res_size(set), (float) msec / 1000.0);
    kd_res_free(set);

    kd_free(kd);
    return 0;
}
Пример #3
0
void test_perf_hec_fp_2e127m1_g2i(char *s)
{
	unsigned char pk[PUBLICKEY_BYTES], sk[SECRETKEY_BYTES], ss[SHAREDSECRET_BYTES];
	struct timeval t_start, t_end, t_diff;
	long long st, fn, count;

	printf("\n//%s\n", s); fflush(stdout);
	gettimeofday(&t_start, NULL);
	st = cpucycles();
	for(count = 0; count < TRIAL; count++){
		crypto_dh_keypair(pk, sk);
	}
	fn = cpucycles();
	gettimeofday(&t_end, NULL);
	timersub(&t_end, &t_start, &t_diff);
	printf("Key pair generation cycles: %lld\n", (fn - st)/TRIAL);
	printf("Key pair generation time: %.3f msec\n", get_msec(t_diff, TRIAL, 1)); fflush(stdout);
	gettimeofday(&t_start, NULL);
	st = cpucycles();
	for(count = 0; count < TRIAL; count++){
		crypto_dh(ss, pk, sk);
	}
	fn = cpucycles();
	gettimeofday(&t_end, NULL);
	timersub(&t_end, &t_start, &t_diff);
	printf("Secret sharing cycles: %lld\n", (fn - st)/TRIAL);
	printf("Secret sharing time: %.3f msec\n", get_msec(t_diff, TRIAL, 1)); fflush(stdout);
}
Пример #4
0
void idle_func(void) {
	/* Check if we are going faster than the FRAME_TIME */
	long current_time = get_msec();
	long delta = next_frame_time - current_time;
	if(delta > 0 && delta < FRAME_TIME) {
		usleep(delta * 1000l);
		next_frame_time += FRAME_TIME;
	} else {
		/* Seems we are too late or we just started. Just sync. */
		next_frame_time = current_time + FRAME_TIME;
	}
	glutPostRedisplay();

	/* Check if we should go to the next shader or if we are transitioning */
	if(transition_offset_x) {
		transition_offset_x += transition_direction;
		if(transition_offset_x >= SCREEN_WIDTH) {
			/* Old shader is now shifted out. Switch shader and shift it in */
			current_shader = (current_shader+1) % shader_count;
			set_shader(shaders[current_shader].prog);
			shader_activated_time = current_time;

			transition_offset_x = SCREEN_WIDTH;
			transition_direction = -1;
		} else if(transition_offset_x <= 0) {
			transition_direction = 0;
		}
	} else if(shaders[current_shader].time + shader_activated_time < current_time) {
		transition_offset_x = 1;
		transition_direction = 1;
	}
}
Пример #5
0
int main(int argc, char **argv) {
	if(init_socket() < 0) {
		perror("failed to init socket");
		return -1;
	}
	
	glutInitWindowSize(64, 60);
	
	/* initialize glut */
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutCreateWindow("Raadhus Shader");

	glutDisplayFunc(draw);
	glutIdleFunc(idle_func);
	glutKeyboardFunc(key_handler);
	glutMotionFunc(mouse_handler);
	
	if(read_shaders("shaders.conf")) {
		return EXIT_FAILURE;
	}

	set_shader(shaders[current_shader].prog);
	shader_activated_time = get_msec();

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_DEPTH_TEST);

	init_osaa();

	glutMainLoop();
	return 0;
}
Пример #6
0
int do_decoding()
{
    System sys;
    Graph graph(sys);
    graph.propagate_system();

    graph.get_kalman_path();
    
    double start = get_msec();

    graph.put_init_samples();

    tic();
    clock_t start_time = clock();
    bool time_finished = false;
    
    for(int i=0; i < 500; i++)
    {
        graph.add_sample();
       
        /*
        int num_vert = graph.get_num_vert();
        int max_async_updates = min((double)num_vert, 100*log(num_vert));
        for(int j=0; j< max_async_updates; j++)
        {
            int which = RANDF*num_vert;
            Vertex *v = graph.vlist[which];
            graph.propagate_viterbi(v);
        }
        */

        if( graph.num_vert % 10 == 0)
        {
            cout<< graph.num_vert <<" ";
            toc();
        }

    }

    graph.get_best_path();
    cout<<"time: "<< get_msec() - start << " [ms]" << endl;

    graph.plot_trajectory();
    graph.plot_graph();

    return 0;
}
Пример #7
0
void draw(void) {
	unsigned char pixels[SCREEN_WIDTH * 60 * 3];
	unsigned int prog = shaders[current_shader].prog;

	iGlobalTime = get_msec() / 1000.0f;

	glDisable(GL_BLEND);		

	switch(shaders[current_shader].type) {
	case GL_CODE:
		switch(prog) {
		case 1:
			draw_osaa();
			break;
		}
		break;
	case REAL_SHADER:
		set_shader(prog);

		set_uniform1f(prog, "iGlobalTime", iGlobalTime);

		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(-1, -1);
		glTexCoord2f(1, 0);
		glVertex2f(1, -1);
		glTexCoord2f(1, 1);
		glVertex2f(1, 1);
		glTexCoord2f(0, 1);
		glVertex2f(-1, 1);
		glEnd();
		
		break;
	}

	set_shader(0);
	glEnable(GL_BLEND);

	glColor4f(0.0f, 0.0f, 0.0f, transition_offset_x / (float)SCREEN_WIDTH);

	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex2f(-1, -1);
	glTexCoord2f(1, 0);
	glVertex2f(1, -1);
	glTexCoord2f(1, 1);
	glVertex2f(1, 1);
	glTexCoord2f(0, 1);
	glVertex2f(-1, 1);
	glEnd();

	glutSwapBuffers();

	memset(pixels, 0, SCREEN_WIDTH*60*3);
	glReadPixels(0, 0, SCREEN_WIDTH, 60, GL_RGB, GL_UNSIGNED_BYTE, pixels);

	send_packet(pixels, sizeof(pixels));
}
Пример #8
0
void set_mouse(int x, int y)
{
	SDL_ShowCursor(0);
	last_mouse_hide_time = get_msec();

	SDL_WarpMouse(x * scale, y * scale);
	mousex = x;
	mousey = y;
}
Пример #9
0
int graph_sanity_check()
{
    System sys;
    Graph graph(sys);
    graph.propagate_system();
    graph.get_kalman_path();
    graph.plot_trajectory();
    
    double start = get_msec();

    graph.put_init_samples();
    
    tic();
    for(int i=0; i < 1000; i++)
    {
        graph.add_sample();
        if(i % 100 == 0)
        {
            cout<< i <<" ";
            toc();
            cout<<"\r";
        }
    }

    graph.plot_graph();
    cout<<"added samples: "<< graph.num_vert << endl;

    //cout<<"pruned: "<< graph.prune_graph() << endl;
    //graph.print_rrg();
    cout<<"finished putting samples"<<endl;
    assert(graph.is_everything_normalized());
    //cout<<"graph is correct"<<endl;
    
    for(int i=0; i< 100; i++)
    {
        graph.simulate_trajectory();
        //cout<<i<<endl;
    }
    graph.plot_monte_carlo_trajectories();
    
    cout<<"time: "<< get_msec() - start << " [ms]" << endl;
}
Пример #10
0
int main(int argc, char * argv[])
{
    Mtime newtime, oldtime;
    char ch;
    int type = GAMETYPE_ALONE_SINGLE;
    const char * addr = NULL;

    while ((ch = getopt(argc, argv, "sc:ow")) != -1)
    switch (ch) {
        case 'o':
            type = GAMETYPE_ALONE_SINGLE;
            break;

        case 'w':
            type = GAMETYPE_ALONE_MATCH;
            break;

        case 's':
            type = GAMETYPE_ONLINE_SERVER;
            addr = NULL;
            break;

        case 'c':
            type = GAMETYPE_ONLINE_CLIENT;
            addr = optarg;
            break;
    }

    if (!(russia_block = new_game(type, (void *)addr)))
        return 1;

    oldtime = get_msec();
    while (!(russia_block->status & STATUS_EXIT)) {
        newtime = get_msec();

        clock_frame(newtime - oldtime);

        oldtime = newtime;
    }

    return 0;
}
Пример #11
0
void draw_text_box(char *txt,int w,int h,int x,int y,rgb c1,rgb c2){
	long t0=get_msec(),t1;
	int txt_w=0;
	txt_w=XTextWidth(sfont,txt,strlen(txt));

	int xpos=0;

	int paddingX=w*0.1;
	int innerW=w*0.8;
	int innerH=h*0.8;

	if( txt_w <= innerW ) {
		xpos=(innerW-txt_w)/2;	
	}else{
		xpos=0;
	}


	XRectangle rects[]={ {0,0,w+1,h+1} };
	XSetClipRectangles(dpy,gc,x,y,rects,1,Unsorted);

	XColor fg=_rgb2XColor(c1.r,c1.g,c1.b);
	XColor bg=_rgb2XColor(c2.r,c2.g,c2.b);
	XColor white=_rgb2XColor(255,255,255);
	assert(txt);

	int x0,y0,w0,h0;

/*	GC fg_gc=XCreateGC(dpy,d,0,0);
	GC bg_gc=XCreateGC(dpy,d,0,0);
	GC white_gc=XCreateGC(dpy,d,0,0);
	*/

	d=double_buffer;

	XAllocColor(dpy,attr.colormap,&white);
	XAllocColor(dpy,attr.colormap,&bg);
	
	XSetForeground(dpy,gc,bg.pixel);
	XSetFillStyle(dpy,gc,FillSolid);
	XFillRectangle(dpy,d,gc,x,y,w,h);

	XSetForeground(dpy,gc,white.pixel);
	XSetBackground(dpy,gc,white.pixel);
	XDrawRectangle(dpy,d,gc,x,y,w,h);

	XSetForeground(dpy,gc,white.pixel);
	XDrawString(dpy,d,gc,x+paddingX+xpos,y+((h-10)/2),txt,strlen(txt));

}
Пример #12
0
void copy_frame(void *pixels)
{
	unsigned char *frame = (unsigned char*)pixels;

	if(SDL_MUSTLOCK(fbsurf)) {
		SDL_LockSurface(fbsurf);
	}

	if(scale > 1) {
		int i, j, xsz, ysz;
		unsigned char *dest = fbsurf->pixels;

		xsz = 320 * scale;
		ysz = 200 * scale;

		for(i=0; i<ysz; i++) {
			for(j=0; j<xsz; j++) {
				*dest++ = frame[(i / scale) * 320 + (j / scale)];
			}
		}
	} else {
		memcpy(fbsurf->pixels, frame, 64000);
	}

	if(SDL_MUSTLOCK(fbsurf)) {
		SDL_UnlockSurface(fbsurf);
	}
	SDL_Flip(fbsurf);


	/* also print fps every second ... */
	{
		static long prev_fps, num_frames;
		long msec, dt;

		msec = get_msec();
		dt = msec - prev_fps;
		if(dt >= 1000) {
			float fps = (float)num_frames / ((float)dt / 1000.0f);
			printf("framerate: %.1f      \r", fps);
			fflush(stdout);
			num_frames = 0;
			prev_fps = msec;
		} else {
			num_frames++;
		}
	}
}
Пример #13
0
int main (int argc, char **argv)
{
    progname = *argv;
    for (;;) {
        switch (getopt (argc, argv, "d")) {
        case EOF:
            break;
        case 'd':
            ++paddle_debug;
            continue;
        default:
            usage ();
        }
        break;
    }
    argc -= optind;
    argv += optind;

    if (argc != 0)
        usage ();

    paddle_open();
    atexit (paddle_close);
    signal (SIGINT, sigint);

    int old_daah = -1, old_dit = -1;
    struct timeval tv = {0};
    for (;;) {
        int daah, dit;

        paddle_poll (&daah, &dit);
        if (daah != old_daah || dit != old_dit) {
            int msec = get_msec (&tv);

            printf ("%d - %s\n", msec,
                daah ? "Daah" : dit ? "Dit" : "Idle");
            fflush (stdout);
            old_daah = daah;
            old_dit = dit;
        }
        usleep (10000);
    }
    paddle_close();
    return (0);
}
Пример #14
0
Файл: test.c Проект: mdurrer/cgd
static void print_perf(void)
{
	unsigned long msec, avg_frame_time;
	float sec, fps;

	msec = get_msec();
	if(!num_frm || msec < 1000) {
		printf("leaving so soon? (%lu ms)\n", msec);
		return;
	}

	sec = msec / 1000.0f;
	fps = (float)num_frm / sec;
	avg_frame_time = msec / num_frm;

	printf("%lu frames in %.2f seconds\n", num_frm, sec);
	printf("  avg. frame time: %lu ms\n", avg_frame_time);
	printf("  avg. framerate: %.2f fps\n", fps);
}
Пример #15
0
Файл: test.c Проект: mdurrer/cgd
static void redraw(void)
{
	float angle = get_msec() / 10.0;
	mgl_clear(0);
	mgl_clear_depth();

	mgl_matrix_mode(MGL_MODELVIEW);
	mgl_load_identity();
	mgl_translate(0, 0, -cam_zoom);
	if(auto_rotate) {
		mgl_rotate(angle * 0.5, 1, 0, 0);
		mgl_rotate(angle, 0, 0, 1);
	} else {
		mgl_rotate(cam_phi, 1, 0, 0);
		mgl_rotate(cam_theta, 0, 1, 0);
	}

	switch(prim) {
	case TORUS:
		mgl_index(green_base);
		mgl_torus(1.0, 0.25, 16, 8);
		break;
	case SPHERE:
		mgl_index(blue_base);
		mgl_sphere(1.0, 16, 8);
		break;
	case CUBE:
		mgl_index(red_base);
		mgl_cube(1.0);
	}

	if(!auto_rotate) {
		draw_cursor(fbuf, 320, 200, mx, my, white_base + grad_range - 1);
	}

    copy_frame(fbuf);
	if(use_vsync) {
		wait_vsync();
	}
	num_frm++;
}
Пример #16
0
static void proc_events(void)
{
	static SDL_Event ev;

	if(last_mouse_hide_time > 0 && get_msec() - last_mouse_hide_time > 3000) {
		last_mouse_hide_time = 0;
		SDL_ShowCursor(1);
	}

	while(SDL_PollEvent(&ev)) {
		switch(ev.type) {
		case SDL_KEYDOWN:
			{
				int key = ev.key.keysym.sym;

				if(!keybev) {
					keybev = &ev;
				}

				if(!keystate[key]) {
					keystate[key] = 1;
					num_pressed++;
				}
			}
			break;

		case SDL_KEYUP:
			{
				int key = ev.key.keysym.sym;

				if(keystate[key]) {
					keystate[key] = 0;
					if(--num_pressed < 0) {
						num_pressed = 0;
					}
				}
			}
			break;

		case SDL_MOUSEMOTION:
			mousex = ev.motion.x / scale;
			mousey = ev.motion.y / scale;
			break;

		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			{
				int mask = 0;
				switch(ev.button.button) {
				case SDL_BUTTON_LEFT:
					mask = MOUSE_LEFT;
					break;
				case SDL_BUTTON_MIDDLE:
					mask = MOUSE_MIDDLE;
					break;
				case SDL_BUTTON_RIGHT:
					mask = MOUSE_RIGHT;
				default:
					break;
				}
				if(!mask) {
					break;
				}

				if(ev.button.state == SDL_PRESSED) {
					bnmask |= mask;
				} else {
					bnmask &= ~mask;
				}
			}
			break;

		default:
			break;
		}
	}
}
Пример #17
0
bool Engine::render(void)
{
	std::ofstream debugfile;
	debugfile.open("E:\\code\\debug2.txt", std::ios_base::app);
	debugfile << "Starting currLine = " << currLine << std::endl;
	// render scene
	Vector3 o(0.0, 0.0, -5.0);

	// initialize timer
	unsigned int msecs = get_msec();

	// reset last found primitive pointer
	Primitive *lastprim = nullptr;

	// render remaining lines
	for (unsigned int y = currLine; y < (height - 20); y++)
	{
		SX = WX1;
		// render pixels for current line
		for (unsigned int x = 0; x < width; x++)
		{
			// fire primary ray
			Color acc(0.0, 0.0, 0.0);
			Vector3 dir = Vector3(SX, SY, 0) - o;
			dir.normalize();
			Ray r(o, dir);
			double dist;
			unsigned int prev = get_msec();
			Primitive *prim = raytrace(r, acc, 1, 1.0, dist);
			unsigned int post = get_msec();
			if (post - prev != 0) {
				if (prim)
					debugfile << prim->getName() << " @ ";
				debugfile << x << ", " << y << ": ";
				debugfile << post - prev << std::endl;
			}
			int red = (int)(acc.R() * 256);
			int green = (int)(acc.G() * 256);
			int blue = (int)(acc.B() * 256);
			if (red > 255) red = 255;
			if (green > 255) green = 255;
			if (blue > 255) blue = 255;
			dest[ppos++] = RGBA_to_Pixel(red, green, blue);
			SX += DX;
		}
		SY += DY;
		
		// see if we've been working to long already
		// TODO
		if ((get_msec() - msecs) > 100)
		{
			// return control to windows so the screen gets updated
			currLine = y + 1;
			debugfile << "exiting currLine = " << currLine << std::endl;
			debugfile.close();
			return false;
		}
	}

	// all done
	debugfile.close();
	return true;
}
Пример #18
0
void reset_timer(void)
{
	start_time = SDL_GetTicks();
	printf("resetting timer: %u, %lu\n", start_time, get_msec());
}
Пример #19
0
int main(int argc, char **argv)
{
	int i, count = 128;
	struct dtx_font *font;
	struct image img;
	unsigned int start_msec, dur;

	for(i=1; i<argc; i++) {
		if(argv[i][0] == '-') {
			if(strcmp(argv[i], "-opaque") == 0) {
				printf("using opaque rendering\n");
				dtx_set(DTX_RASTER_THRESHOLD, -1);
				dtx_set(DTX_RASTER_BLEND, 0);
			} else if(strcmp(argv[i], "-threshold") == 0) {
				int thres = atoi(argv[++i]);
				dtx_set(DTX_RASTER_THRESHOLD, thres);
				printf("using threshold rendering with threshold: %d\n", thres);
			} else if(strcmp(argv[i], "-blend") == 0) {
				printf("using alpha blended rendering\n");
				dtx_set(DTX_RASTER_BLEND, 1);	/* enable alpha blended drawing */
			} else {
				printf("usage: [-opaque|-threshold <n>|-blend] [num hello worlds]\n");
				return 0;
			}
		} else {
			count = atoi(argv[i]);
		}
	}

	if(!(font = dtx_open_font("serif.ttf", 32))) {
		fprintf(stderr, "failed to open font\n");
		return 1;
	}
	dtx_use_font(font, 32);

	/* create the raster image we'll draw into */
	img.width = 640;
	img.height = 480;
	if(!(img.pixels = malloc(img.width * img.height * 4))) {
		perror("failed to allocate image memory");
		return 1;
	}
	memset(img.pixels, 0x20, img.width * img.height * 4);	/* clear fb */

	/* set the render target to libdrawtext and enable raster drawing */
	dtx_target_raster(img.pixels, img.width, img.height);

	printf("printing %d hello worlds\n", count);
	start_msec = get_msec();

	for(i=0; i<count; i++) {
		dtx_color(frand(), frand(), frand(), 1);
		dtx_position((frand() * 1.25 - 0.25) * img.width,
				(frand() * 1.25 - 0.25) * img.height);
		dtx_printf("hello world!");
	}

	dur = get_msec() - start_msec;
	printf("printed %d hello worlds in %u milliseconds\n", i, dur);

	if(save_image(&img, "output.ppm") == -1) {
		return 1;
	}
	printf("output.ppm saved\n");
	return 0;
}
Пример #20
0
int main(int argc, char **argv)
{
	int i,j, vcount = 10;
	int tot_count = 101;
	void *kd[tot_count], *set[tot_count];
	unsigned int msec, start;
/*
	if(argc > 1 && isdigit(argv[1][0])) {
		vcount = atoi(argv[1]);
	}
*/
	printf("inserting  random vectors... ");

	/* Creating Trees correspinding to each age group */
	for (i=0;i<tot_count;i++)
		kd[i]=kd_create(3);

	start = get_msec();

	/* Reading Input File */
	FILE *file;
	char *line = NULL;
	size_t len = 0;
	char read;
	file=fopen(argv[1], "r");

	if (file == NULL)
		return 1;

	int a;
	double b;
	double c;
	double d;

	/* Inseting the person's co-ordinates and age in the respective trees */
	while ((read = getline(&line, &len, file)) != -1) {
		convert(line, &a, &b, &c, &d);
		assert(kd_insert3(kd[a], b, c, d, 0) == 0);	 
	}

	if (line)
		free(line);

	msec = get_msec() - start;
	printf("%.3f sec\n", (float)msec / 1000.0);

	start = get_msec();
	double lat, longitude, latitude;
	/**
	  printf("range query returned %d items in %.5f sec\n", kd_res_size(set[0]), (float)msec / 1000.0);
	 **/
	int reqd_dist,index , ind;
	while(1){
		printf("Enter How many top places you want\n");
		scanf("%d",&reqd_dist);
		int counter = 0;
		int initial_radius = 100;
		printf("Enter the age of the person\n");
		scanf("%d",&index);
		printf("Enter the co-ordinates of a person \n");
		scanf("%f %f",&longitude,&latitude);
		double a_x, a_y,a_z;
		coordinates_to_lat(longitude, latitude, &a_x,&a_y,&a_z);
		int starting_index[101] ={0};
		/* Copmuter Science   */
		int loop_break = 0;
		int end_index =  index + sqrt(reqd_dist);
		if(end_index >= 101)
			end_index = 100;
		while(counter <= reqd_dist){
			for (i=index ; i<= end_index ; i++){
				set[i] = kd_nearest_range3(kd[i], a_x, a_y,a_z, initial_radius);
				/*printf("After %d\n",kd_res_size(set[i]));
				*/
			}

			/* TODO :: change sqrt(reqd_dist) to something else...... */	
			for(ind = index; ind <= end_index; ind++){
				double x = 1, y = 1, z = 1;
				a = 1;
				while(starting_index[ind]){
					kd_res_next(set[ind]);
					starting_index[ind]-=1;
				}
				while(a){
					kd_res_item3(set[ind], &x, &y, &z);
					/*printf("%f %f %f\n",x,y,z);*/
					lat_to_coordinates(x, y, z, &lat, &longitude);
					printf("%d %0.2f %0.2f\n",ind,lat, longitude);
					counter += 1;
					int val = kd_res_end(set[ind]);
					if(val == 1){
						a = 0;
						break;
					}
					else{
						a = kd_res_next(set[ind]);
						/*printf("%d\n",a);*/
					}
					if(counter >= reqd_dist){
						loop_break = 1;
						break;
					}
				}
				if(loop_break ==1)
					break;
			}

			for (i=index ; i<= end_index;i++){
				starting_index[i] = kd_res_size(set[i]);
			}

			if(loop_break ==1)
				break;
			initial_radius += initial_radius;
		}
	}
	msec = get_msec() - start;
	/*	for(i=1;i<tot_count;i++){
		kd_res_free(set[i]);
		kd_free(kd[i]);
		}
	 */
	/**
	  printf("range query returned %d items in %.5f sec\n", kd_res_size(set[i]), (float)msec / 1000.0);
	 **/
	/*
	   printf("range query returned %d items in %.5f sec\n", kd_res_size(set), (float)msec / 1000.0);
	   kd_res_free(set);
	   kd_free(kd);
	 */
	return 0;
}
Пример #21
0
int main(int argc, char **argv)
{
	unsigned long prev_msec = 0, frame_time;
	unsigned int sdl_flags = SDL_HWPALETTE | SDL_HWSURFACE;

	char *env = getenv("FULLSCREEN");
	if(env && atoi(env)) {
		sdl_flags |= SDL_FULLSCREEN;
	}

	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
		fprintf(stderr, "failed to initialize SDL\n");
		return 1;
	}
	if(!(fbsurf = SDL_SetVideoMode(640, 480, 8, sdl_flags))) {
		fprintf(stderr, "failed to set video mode\n");
		SDL_Quit();
		return 1;
	}
	SDL_WM_SetCaption("colcycle/SDL", 0);

	SDL_LockSurface(fbsurf);
	fbwidth = fbsurf->w;
	fbheight = fbsurf->h;
	fbpixels = fbsurf->pixels;

	if(app_init(argc, argv) == -1) {
		SDL_Quit();
		return 1;
	}
	SDL_UnlockSurface(fbsurf);
	SDL_UpdateRect(fbsurf, 0, 0, 0, 0);

	if(sdl_flags & SDL_FULLSCREEN) {
		SDL_ShowCursor(0);
	}

	start_msec = SDL_GetTicks();

	while(!quit) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
			case SDL_QUIT:
				quit = 1;
				break;
			case SDL_KEYDOWN:
				app_keyboard(ev.key.keysym.sym, 1);
				break;
			case SDL_KEYUP:
				app_keyboard(ev.key.keysym.sym, 0);
				break;

			default:
				break;
			}
			if(quit) goto break_evloop;
		}

		if(SDL_MUSTLOCK(fbsurf)) {
			SDL_LockSurface(fbsurf);
		}
		fbpixels = fbsurf->pixels;

		time_msec = get_msec();
		app_draw();
		if(SDL_MUSTLOCK(fbsurf)) {
			SDL_UnlockSurface(fbsurf);
		}

		time_msec = get_msec();
		frame_time = time_msec - prev_msec;
		prev_msec = time_msec;
		if(frame_time < 16) {
			SDL_Delay(16 - frame_time);
		}
	}

break_evloop:
	app_cleanup();
	SDL_ShowCursor(1);
	SDL_Quit();
	return 0;
}
Пример #22
0
void GameScreen::update()
{
	game::engine::active_stage->update(get_msec(), dt);
}
Пример #23
0
void ui_loop(int full_throttle){
	Window root_return,*children_return,parent;
	unsigned int n_children;
	XEvent ev;
	event_t *v_event;
	int i;
	XWindowAttributes winattr,wa;
	int x,y;
	int propagate;
	char keydown[16];
	KeySym keysym_ret;
	XComposeStatus status_in_out;

	symbol_x11 data;

	vkey key=ANY;

	if(full_throttle){
		send_empty_event(win);
	}

	XColor reds,redx;

	XAllocNamedColor(dpy,
                     DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
	                     "red", &reds, &redx);

	while(running){
		XNextEvent(dpy,&ev);

		switch(ev.type){
			case ButtonRelease:
				lastMX=ev.xbutton.x;
				lastMY=ev.xbutton.y;

				onclick(lastMX,lastMY);
				refresh();
				break;
			case KeyRelease:
				uk_log("KeyRelease %i",ev.xkey.keycode);

	// FIXME what should index be? currently at 0, also this function is deprecated
				data.ks=XKeycodeToKeysym(dpy,ev.xkey.keycode,0);
				data.modifier=0;
				data.keycode=ev.xkey.keycode;

				log_platformspecific(&data);
				
				if(ev.xkey.keycode==22) key=BACKSPACE;
				else if(ev.xkey.keycode==36) key=ENTER;
				else key=ANY;

				XLookupString(&ev,keydown,16,&keysym_ret,&status_in_out);
				onrelease(keydown,&propagate,key,(void *)&data);
				uk_log("propagate = %i",propagate);
				if(!propagate) break;

				uk_log("event propagated");
				v_event=_get_event_from_keycode(ev.xkey.keycode);
				onevent(v_event);

				refresh();
				XFlush(dpy);
				break;
			case DestroyNotify:
				uk_log("destroy window");
				//  Destroy notify here makes the program close whenever you open 
				// A new window on my machine. Wonder why?
//				running=0;
				break;
			case ClientMessage:
				if(ev.xclient.data.l[0]!=0x42 || ! full_throttle) break;
				send_empty_event(win);
			case Expose:
				exposes++;	
				if((exposes%10)==0)
					uk_log("eps=%i",1000*exposes/(get_msec()-start_time));
				onrender();

				reset_clip();
				__x11_frame++;
				XCopyArea(dpy,double_buffer,win,gc,0,0,WIDTH,HEIGHT,0,0);
//				XFlush(dpy);
				break;
			case ReparentNotify:
				uk_log("Reparent win=%x par=%x",ev.xreparent.window,ev.xreparent.parent);
				if(ev.xreparent.parent!=0){	
					win_parent=ev.xreparent.parent;
				}
				break;
			case ConfigureNotify:
				get_win_pos(win,&lastX,&lastY);
				// Let's start out with window
/*				i=0;	
				for(Window cwin=win; cwin != 0; cwin=parent){
				// I'm sure this is cheating!
					winX=ev.xconfigure.x;
					winY=ev.xconfigure.y;
					XQueryTree(dpy,cwin,&root_return,&parent,&children_return,&n_children);


					// Don't ask. This is pure magic!
					// Probably it only works on Ubuntu
					// there are for some 2 windows around my window 
					// until I can see the  actual position of the window. 
					// Milage may vary. 
					if(i ==  2){
						XWindowAttributes attr;
						XGetWindowAttributes(dpy,cwin,&attr);
						lastX=attr.x; lastY=attr.y;
						uk_log("windows moved to (%i,%i)",lastX,lastY);
					}
					i++;
				}
				*/
				break;
		}
	}	
	uk_log("ui_loop end!");
//	writestate(STATE_FILE,lastX,lastY);
	veta_exit();
}
Пример #24
0
void ui_init(int w,int h,int x,int y){
	start_time=get_msec();
	setup_modifiers();

	_w=w;
	_h=h;
	winX=x;
	winY=y;
	
	dpy=XOpenDisplay("");
	screen=DefaultScreen(dpy);
	root=DefaultRootWindow(dpy);

	XMatchVisualInfo(dpy, screen, 32, TrueColor, &visualinfo);

	uk_log("Iniitializing UI");
	uk_log("Win @ (%i,%i,%i,%i)",x,y,w,h);
	
	 attr.colormap   = XCreateColormap( dpy, root, visualinfo.visual, AllocNone) ;
	 attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask;
	 attr.background_pixmap = None ;
	 attr.border_pixel      = 0 ;

	uk_log("root=%x\n",root);
	uk_log("%i %i %i %i\n",x,y,w,h);
	win=XCreateWindow(dpy,root,
		x,y,w,h,
		0,
		visualinfo.depth,
		InputOutput,
		visualinfo.visual,
		CWColormap|CWEventMask|CWBackPixmap|CWBorderPixel,
		&attr);

	XWindowAttributes wa;

	XGetWindowAttributes(dpy,win,&wa);

	gc = XCreateGC(dpy,win,0,0);
	double_buffer=XCreatePixmap(dpy,win,wa.width,wa.height,wa.depth);

	XColor black=_rgb2XColor(255,255,255);
	XAllocColor(dpy,attr.colormap,&black);
	XSetForeground(dpy,gc,black.pixel);
	XFillRectangle(dpy,double_buffer,gc,0,0,wa.width,wa.height);

	d=double_buffer;

	uk_log("Created pixmap = %x",double_buffer);

	XGetWindowAttributes(dpy,win,&wa);

	load_font();

	uk_log("window = %x root = %x",win,root);

	_set_on_top(dpy,win);
	_set_sticky(dpy,win);

	_set_alpha(dpy,win,conf_get_float("alpha",ALPHA));

	XMapWindow(dpy,win);
	XMoveWindow(dpy,win,x,y);

	// Try to make borderless
	_make_borderless(dpy,win);

	// Bind to what stuff?
	unsigned long eventmask;
	eventmask=StructureNotifyMask|SubstructureNotifyMask;
	uk_log("event mask = x%x",eventmask);
	XSelectInput(dpy,root,eventmask);

	XFlush(dpy);

	kbio.start=kbio.stop=kbio.n=0;
	_setupkeymap();

	grabkeys();
//	grabkeyboard();
}
Пример #25
0
void GameScreen::render_ovr()
{
	static bool is_visible = true;

	if (!game::engine::ovr_initialized){
		std::cout << "Ovr HMD not initialized!" << std::endl;
		return;
	}

	game::engine::active_stage->setup_lights();
	camera = game::engine::active_stage->get_camera_matrix();

	set_unistate("st_light_intensity", (float)1.0);

	

	Matrix4x4 gun_loc_mat;
	Matrix4x4 cockpit_loc_mat;
	Matrix4x4 crosshair_loc_mat;

	/*Gun and Cokcpit tranformations*/
	XFormNode *gun_ctrl = game::engine::active_stage->get_gun_ctrl_node_ptr();
	XFormNode *cockpit_ctrl = game::engine::active_stage->get_cockpit_ctrl_node_ptr();
	XFormNode *crosshair_crtl = (XFormNode*)game::engine::active_stage->get_crosshair();

	cockpit_loc_mat.rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));
	cockpit_ctrl->set_matrix(cockpit_loc_mat.inverse());

	gun_loc_mat.rotate(Vector3(1, 0, 0), DEG_TO_RAD(phi));
	gun_loc_mat.rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));
	gun_ctrl->set_matrix(gun_loc_mat.inverse());

	crosshair_loc_mat.rotate(Vector3(1, 0, 0), DEG_TO_RAD(phi));
	crosshair_loc_mat.rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));
	crosshair_crtl->set_matrix(crosshair_loc_mat.inverse());
	/*---------------------------------------------------------------------------*/

	//Shadow render pass.
	shadow_render_pass(true, get_msec());

	/*Render the textures of the cockpits front screens.*/
	game::engine::active_stage->render(STAGE_RENDER_COCKPIT_SCRN_TEXTURES, get_msec());

	if (is_visible) {


		game::engine::ovr_manager.calculate_eye_poses();

		game::engine::ovr_manager.begin_ovr_frame();

		//Update the particles.
		game::engine::nuc_manager->update(dt, get_msec());

		game::engine::rndr_pass_type = RNDR_PASS_COLOR;

		for (int eye = 0; eye < 2; eye++) {

			OvrTransformationData xform_data = game::engine::ovr_manager.get_ovr_transformation_data_per_eye(eye);

			glViewport(xform_data.viewport.position.x, xform_data.viewport.position.y, xform_data.viewport.size.x, xform_data.viewport.size.y);
			
			//Send the Viewport size to the shader.
			set_unistate("st_screen_size", Vector2(xform_data.viewport.size.x, xform_data.viewport.size.y));

			set_projection_matrix(xform_data.projection);

			camera->reset_identity();

			camera->rotate(Vector3(0, 1, 0), DEG_TO_RAD(theta));

			set_view_matrix(xform_data.view * (*camera));

			/*Render calls*/
			glActiveTexture(GL_TEXTURE0 + 3);
			glBindTexture(GL_TEXTURE_2D, game::engine::ovr_manager.get_ovr_render_target().get_depth_attachment());
			glActiveTexture(GL_TEXTURE0);
			set_unistate("st_shadow2D_tex", 3);
			set_unistate("st_shadow_matrix", shad_mat);
			game::engine::active_stage->render(STAGE_RENDER_SKY | STAGE_RENDER_SCENES |
				STAGE_RENDER_ENEMIES | STAGE_RENDER_PROJECTILES, get_msec());

			glActiveTexture(GL_TEXTURE0 + 3);
			glBindTexture(GL_TEXTURE_2D, game::engine::rtarg2.get_depth_attachment());
			glActiveTexture(GL_TEXTURE0);
			set_unistate("st_shadow2D_tex", 3);
			set_unistate("st_shadow_matrix", shad_mat2);

			game::engine::active_stage->render(STAGE_RENDER_GUNS, get_msec());
			game::engine::nuc_manager->render(RENDER_PSYS, get_msec());
			game::engine::active_stage->render(STAGE_RENDER_COCKPIT | STAGE_RENDER_HOLOMAP | STAGE_RENDER_CROSSHAIR, get_msec());
			/*-----------------------------------------------------------------------------------------*/
		}
	}

	is_visible = game::engine::ovr_manager.submit_ovr_frame();

	game::engine::ovr_manager.draw_ovr_mirror_texture(game::options::win_width, game::options::win_height);
}