Beispiel #1
0
/**
 * Runs a single iteration of the event loop, by capturing an X event and
 * acting upon it.
 *
 * @return true if more events can be processed, false otherwise.
 */
bool XEvents::step()
{
    // Grab the next event from X, and then dispatch upon its type
    m_xdata.next_event(m_event);

    if (m_event.type == m_randroffset + RRNotify)
        handle_rrnotify();
    
    if (m_event.type == KeyPress)
        handle_keypress();

    if (m_event.type == ButtonPress)
        handle_buttonpress();

    if (m_event.type == ButtonRelease)
        handle_buttonrelease();

    if (m_event.type == MotionNotify)
        handle_motionnotify();

    if (m_event.type == MapNotify)
        handle_mapnotify();

    if (m_event.type == Expose)
        handle_expose();

    if (m_event.type == DestroyNotify)
        handle_destroynotify();

    return !m_done;
}
Beispiel #2
0
static void handle_host_interrupt(struct hw_trapframe *hw_tf)
{
	uintptr_t fh = mtpcr(PCR_FROMHOST, 0);
	switch (fh >> 56)
	{
	  case 0x00: return;
	  case 0x01: handle_keypress(fh); return;
	  default: assert(0);
	}
}
Beispiel #3
0
void default_keyboard_handler(XEvent *ev)
{
	if(call_grab_handler(ev))
		return;
		
	if(ev->type==KeyPress)
		handle_keypress(&(ev->xkey));
	
	/*skip_focusenter();*/
}
Beispiel #4
0
static void __serial_rx(char c, struct cpu_user_regs *regs)
{
    if ( xen_rx )
        return handle_keypress(c, regs);

    /* Deliver input to guest buffer, unless it is already full. */
    if ( (serial_rx_prod-serial_rx_cons) != SERIAL_RX_SIZE )
        serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c;
    /* Always notify the guest: prevents receive path from getting stuck. */
    send_global_virq(VIRQ_CONSOLE);
}
Beispiel #5
0
void game_handle_event(SDL_Event event, camera *camera, PLAYERS *players) {
  if(paused) {
    paused_state.handle_event(event, camera, players);
    return;
  }

  switch(event.type) {
    case SDL_MOUSEBUTTONDOWN:
      handle_mousedown(event.button, camera, players);
      break;
    case SDL_MOUSEMOTION:
      mouse_x = event.motion.x;
      mouse_y = event.motion.y;
      break;
    case SDL_KEYDOWN:
      handle_keypress(event.key.keysym.sym, camera);
  }
}
Beispiel #6
0
void update_input()
{
    if (SDL_PollEvent(&event)) {
        switch(event.type) {
            case SDL_QUIT:
                quit = true;
                break;
            case SDL_KEYDOWN:
                handle_keypress(event.key.keysym.sym);
                break;
            case SDL_KEYUP:
                handle_keyup(event.key.keysym.sym);
                break;
        }
    }

    if (accel->up > 0) accel->up--;
    if (accel->down > 0) accel->down--;
    if (accel->left > 0) accel->left--;
    if (accel->right > 0) accel->right--;

    if (speed->up > 0) speed->up--;
    if (speed->down > 0) speed->down--;
    if (speed->left > 0) speed->left--;
    if (speed->right > 0) speed->right--;

    if (pressed_keys->up) accel->up = 2;
    if (pressed_keys->down) accel->down = 2;
    if (pressed_keys->left) accel->left = 2;
    if (pressed_keys->right) accel->right = 2;

    speed->up += accel->up;
    speed->down += accel->down;
    speed->left += accel->left;
    speed->right += accel->right;

    if (speed->up > max_speed) speed->up = max_speed;
    if (speed->down > max_speed) speed->down = max_speed;
    if (speed->left > max_speed) speed->left = max_speed;
    if (speed->right > max_speed) speed->right = max_speed;

    ship->rect.x += (speed->right - speed->left);
    ship->rect.y += (speed->down - speed->up);
}
Beispiel #7
0
void handle_event(){
  SDL_Event event;
  while(SDL_PollEvent(&event)){
    switch(event.type){
    case SDL_ACTIVEEVENT:
      //lost focus
      if(event.active.gain == 0)
	Active = true;
      else
	Active = true;
      break;
    case SDL_VIDEORESIZE:
      surface = SDL_SetVideoMode(event.resize.w,
				 event.resize.h,
				 SCREEN_BPP, videoFlags);
    case SDL_KEYDOWN: handle_keypress(&event.key.keysym); break;
    case SDL_MOUSEMOTION: handle_mouse_motion(event.motion); break;
    case SDL_MOUSEBUTTONDOWN: handle_mouse_button(event.button); break;
    case SDL_QUIT: Running = false; break;
    default: break;
    }
  }
}
Beispiel #8
0
/*
 * edit_char: handles each character for an input stream.  Not too difficult
 * to work out.
 */
void	edit_char (u_char key)
{
	u_char		extended_key;
	WaitPrompt *	oldprompt;
	u_char		dummy[2];
	int		xxx_return = 0;		/* XXXX Need i say more? */

	if (dumb_mode)
	{
#ifdef TIOCSTI
		ioctl(0, TIOCSTI, &key);
#else
		say("Sorry, your system doesnt support 'faking' user input...");
#endif
		return;
	}

	/* were we waiting for a keypress? */
	if (last_input_screen->promptlist && 
		last_input_screen->promptlist->type == WAIT_PROMPT_KEY)
	{
		dummy[0] = key, dummy[1] = 0;
		oldprompt = last_input_screen->promptlist;
		last_input_screen->promptlist = oldprompt->next;
		(*oldprompt->func)(oldprompt->data, dummy);
		new_free(&oldprompt->data);
		new_free(&oldprompt->prompt);
		new_free((char **)&oldprompt);

		set_input(empty_string);
		change_input_prompt(-1);
		xxx_return = 1;
	}

	/* 
	 * This is only used by /pause to see when a keypress event occurs,
	 * but not to impact how that keypress is handled at all.
	 */
	if (last_input_screen->promptlist && 
		last_input_screen->promptlist->type == WAIT_PROMPT_DUMMY)
	{
		oldprompt = last_input_screen->promptlist;
		last_input_screen->promptlist = oldprompt->next;
		(*oldprompt->func)(oldprompt->data, NULL);
		new_free(&oldprompt->data);
		new_free(&oldprompt->prompt);
		new_free((char **)&oldprompt);
	}

	if (xxx_return)
		return;

	/* If the high bit is set, mangle it as neccesary. */
	if (key & 0x80)
	{
		if (current_term->TI_meta_mode)
		{
			edit_char('\033');
			key &= ~0x80;
		}
		else if (!term_eight_bit())
			key &= ~0x80;
	}

	extended_key = key;

	/* If we just hit the quote character, add this character literally */
	if (last_input_screen->quote_hit)
	{
		last_input_screen->quote_hit = 0;
		input_add_character(extended_key, empty_string);
	}

	/* Otherwise, let the keybinding system take care of the work. */
	else {
		last_input_screen->last_key = handle_keypress(
			last_input_screen->last_key,
			last_input_screen->last_press, key);
		get_time(&last_input_screen->last_press);
	}
}
Beispiel #9
0
void Engine::main_loop() {
    setup_curses();

    map->update_visibility_from(player->get_pos());
    render();

    main_loop_done = false;
    while(!main_loop_done) {

        switch (state) {
            case NEUTRAL:
                if (detect_player_and_mob_turns())
                    break;

                if (detect_modal_messages())
                    break;

                tick();

                break;
            case PLAYER_TURN:
                render();
                if(handle_keypress(getch())) {
                    state = NEUTRAL;
                    player->turn_taken();
                }
                map->update_visibility_from(player->get_pos());
                break;

            case MOB_TURN:
                do_ai();
                state = NEUTRAL;
                break;

            case VIEW_INVENTORY:
                render();
                render_inv();
                doupdate();
                getch();
                state = NEUTRAL;
                break;
            case WIELD:
                do_wield();
                state = NEUTRAL;
                player->turn_taken();
                break;
            case FIRE:
                if (fire_weapon()) {
                    player->turn_taken();
                }
                state = NEUTRAL;
                break;
            case MODAL_MSG:
                render();
                render_modal_messages();
                doupdate();
                while(getch() != ' ') {}
                state = NEUTRAL;
                break;

        }

        if (player->is_dead()) {
            game_over_lost();
        }


    }

    teardown_curses();
}
Beispiel #10
0
static int play_song(char *filename) {

	int i,j,f,length_seconds;
	double s,n,hz,diff;

	int result;
	int frame_num=0,frames_elapsed=0;

	struct timeval start,next;

	struct pt3_song_t pt3;
	struct display_stats ds;
	char string[13];

	unsigned char frame[16];

#define TIMING_DEBUG	0

#if TIMING_DEBUG==1
	struct timeval before,after;
	double b,a;
	FILE *debug_file;
	debug_file=fopen("timing.debug","w");
#endif

	printf("\nPlaying song %s\n",filename);

	result=pt3_load_song(filename,&pt3);
	if (result<0) {
		return -1;
	}

	gettimeofday(&start,NULL);

	/**********************/
	/* Print song summary */
	/**********************/

	length_seconds=60;
	printf("\tSong name: %s\n",pt3.name);
	printf("\tAuthor name: %s\n",pt3.author);

	sprintf(display_text,"VMW CHIPTUNE");
	display_14seg_string(display_type,display_text);

	/******************/
	/* Play the song! */
	/******************/

	frame_num=0;

	for(i=0;i < pt3.music_len;i++) {

		pt3_set_pattern(i,&pt3);

		for(j=0;j<64;j++) {

			/* decode line. 1 if done early */
			if (pt3_decode_line(&pt3)) break;

                        /* Dump out subframes of line */
                        for(f=0;f<pt3.speed;f++) {

				pt3_make_frame(&pt3,frame);

				ym_play_frame(frame,shift_size,
					&ds, diff_mode,play_music,mute_channel);

				if (visualize) {
					if (display_type&DISPLAY_TEXT) {
						printf("\033[H\033[2J");
					}

					display_update(display_type,
							&ds,
							frame_num,
							100,
							filename,0,
							current_mode);
				}

				result=handle_keypress();
				if (result) return result;

				frames_elapsed++;
				frame_num++;

				sprintf(string,"%s %s %s",
					pt3_current_note('A',&pt3),
					pt3_current_note('B',&pt3),
					pt3_current_note('C',&pt3));

				music_visualize(frames_elapsed,frame_num,
					filename,
					length_seconds,pt3.name,pt3.author,
					string);

				/* Calculate time it took to play/visualize */
				gettimeofday(&next,NULL);
				s=start.tv_sec+(start.tv_usec/1000000.0);
				n=next.tv_sec+(next.tv_usec/1000000.0);
				diff=(n-s)*1000000.0;

				/* Delay until time for next update (often 50Hz) */
				if (play_music) {
					if (diff>0) bcm2835_delayMicroseconds(20000-diff);
					/* often 50Hz = 20000 */
					/* TODO: calculate correctly */

				}
				else {
					if (visualize) usleep(1000000/frame_rate);
				}

				/* Calculate time it actually took, and print		*/
				/* so we can see if things are going horribly wrong	*/
				gettimeofday(&next,NULL);
				n=next.tv_sec+(next.tv_usec/1000000.0);

				if (frame_num%100==0) {
					hz=1/(n-s);
					printf("Done frame %d/%d, %.1lfHz\n",
						frame_num,1,hz);
				}
				start.tv_sec=next.tv_sec;
				start.tv_usec=next.tv_usec;
			}
		}
	}

	return 0;
}
Beispiel #11
0
void tasklist_window() /* {{{ */
{
	/* ncurses main function */
	int c;
	task *cur;
	char *uuid = NULL;

	/* get field lengths */
	cfg.fieldlengths.project = max_project_length();
	cfg.fieldlengths.date = DATELENGTH;

	/* create windows */
	rows = LINES;
	cols = COLS;
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "rows: %d, columns: %d", rows, cols);
	header = newwin(1, cols, 0, 0);
	tasklist = newwin(rows-2, cols, 1, 0);
	statusbar = newwin(1, cols, rows-1, 0);
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "ncurses windows: h:%p, t:%p, s:%p (%d,%d)", header, tasklist, statusbar, rows, cols);
	if (statusbar==NULL || tasklist==NULL || header==NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "window creation failed (rows:%d, cols:%d)", rows, cols);
		ncurses_end(-1);
	}

	/* set curses settings */
	set_curses_mode(NCURSES_MODE_STD);

	/* print task list */
	check_screen_size();
	cfg.fieldlengths.description = COLS-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
	task_count();
	print_header();
	tasklist_print_task_list();

	/* main loop */
	while (1)
	{
		/* set variables for determining actions */
		done = false;
		redraw = false;
		reload = false;

		/* check for an empty task list */
		if (head == NULL)
		{
			if (strcmp(active_filter,"") == 0){
				tnc_fprintf(logfp, LOG_ERROR, "it appears that your task list is empty. %s does not yet support empty task lists.", PROGNAME);
				ncurses_end(-1);
			}
			active_filter = strdup("");
			reload = true;
		}

		/* get the screen size */
		rows = LINES;
		cols = COLS;

		/* check for a screen thats too small */
		check_screen_size();

		/* check for size changes */
		check_resize();

		/* apply staged window updates */
		doupdate();

		/* get a character */
		c = wgetch(statusbar);

		/* handle the character */
		handle_keypress(c, MODE_TASKLIST);

		/* exit */
		if (done)
			break;
		/* reload task list */
		if (reload)
		{
			cur = get_task_by_position(selline);
			if (cur != NULL)
				uuid = strdup(cur->uuid);
			wipe_tasklist();
			reload_tasks();
			task_count();
			redraw = true;
			if (cfg.follow_task)
				set_position_by_uuid(uuid);
			check_free(uuid);
			uuid = NULL;
			tasklist_check_curs_pos();
		}
		/* redraw all windows */
		if (redraw)
		{
			cfg.fieldlengths.project = max_project_length();
			cfg.fieldlengths.description = cols-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
			print_header();
			tasklist_print_task_list();
			tasklist_check_curs_pos();
			touchwin(tasklist);
			touchwin(header);
			touchwin(statusbar);
			wnoutrefresh(tasklist);
			wnoutrefresh(header);
			wnoutrefresh(statusbar);
			doupdate();
		}

		statusbar_timeout();
	}
} /* }}} */
Beispiel #12
0
int main(int argc, char **argv)
{
    int i, c, *w, down;
    gamestr g;
    player players[5];
    char names[5 * 9], *p;
    int belts[5];
    g.villain = players;

    SDL_Renderer *screen;
    SDL_Event event;
    Tbox t;
    Chatbox out;

    if (argc == 3)
        screen = init_sdl(atoi(argv[1]), atoi(argv[2]), 0, FONT);
    else if (argc == 2)
        screen = init_sdl(W, H, argv[1], FONT);
    else
        screen = init_sdl(W, H, 0, FONT);

    for (i = 0; i < 5; i++) {
        sprintf(&names[9 * i], "Player %1d", i + 1);
        g.villain[i].name = &names[9 * i];
        g.villain[i].water_level = i;
        g.villain[i].points = i;
        g.villain[i].lifebelts = i;
        g.villain[i].played = i + 1;
        g.villain[i].dead = i == 4 ? 1 : 0;
        belts[i] = 6;
    }

    belts[0] = 10;

    for (i = 0; i < 12; i++)
        g.player.weathercards[i] = i + 1;

    g.w_card[0] = 5;
    g.w_card[1] = 12;

    t = create_textbox(screen, getfont(), 36, 532);
    out = create_chatbox(screen, getfont(), 36, 410, 10);

    g.count = 5;

    render(screen, &g, 0, belts);
    textbox_set(t, strdup(""));
    chatbox_append(out, strdup("foobar"));
    chatbox_append(out, strdup("baaz"));
    chatbox_append(out, strdup("quux"));
    chatbox_render(out);
    SDL_RenderPresent(screen);

    down = 0;
    for (i = 9; i; i--) {
        do {
            SDL_WaitEvent(&event);
            c = SDL_GetModState();

            if (event.type == SDL_QUIT)
                exit(0);
            if (event.type == SDL_KEYUP || event.type == SDL_MOUSEBUTTONUP)
                belts[0] = 0;
            if (event.type == SDL_KEYDOWN)
                down = 1;
        } while (belts[0]);
        belts[0] = 10;

        if (down && event.type == SDL_KEYUP) {
            if ((p = handle_keypress(event.key.keysym.sym, c, t, out))) {
                chatbox_append(out, p);
            }
#if 0
            if ((c = getprintkey(event.key.keysym.sym, SDL_GetModState()))) {
                /* append to message */
                p = malloc(strlen(textbox_get(t)) + 2);
                sprintf(p, "%s%c", textbox_get(t), c);

                /* fprintf(stderr, "text is now %s\n", p); */

                free(textbox_get(t));
                textbox_set(t, p);
            }

            switch(event.key.keysym.sym) {
            case SDLK_q:
                exit(0);
            case SDLK_PAGEUP:
                chatbox_scrollup(out);
                break;
            case SDLK_PAGEDOWN:
                chatbox_scrolldown(out);
                break;
            case SDLK_RETURN:
                chatbox_append(out, textbox_get(t));
                textbox_set(t, strdup(""));
                break;
            default:
                break;
            }
#endif /* 0 */
        } else if (event.type == SDL_MOUSEBUTTONUP) {
            w = g.player.weathercards;

            c = card_select(event.button.x, event.button.y, w);

            if (c != -1) {
                g.villain[0].played = w[c];
                w[c] = 0;
            }
        }

    	g.villain[0].lifebelts = i;
        if (i == 1) i = 2;

        render(screen, &g, 0, belts);
        textbox_update(t);
        chatbox_render(out);
        game_over(screen, &g, 0, 0, 0);

        SDL_RenderPresent(screen);
    }

    return 0;
}
Beispiel #13
0
void loop(char key) {
  handle_keypress(key);
  draw();
}
Beispiel #14
0
int main(int argc, char** argv)
{
	if(argc != 2)
		usage(argv[0]);

	FILE* infile = fopen(argv[1], "r");
	if(infile == NULL)
	{
		perror("Error opening input file");
		return EXIT_FAILURE;
	}
	System* sys = load_system(infile);
	if(sys == NULL)
	{
		printf("Loading input file failed\n");
		return EXIT_FAILURE;
	}
	init_simulation(sys);
	state.sys = sys;
	state.views = malloc(sys->nplanets * sizeof(PlanetView));
	for(int i = 0; i < sys->nplanets; i++)
		state.views[i].radius = pow(sys->planets[i].mass / DENSITY_FACTOR, 1.0f/3.0f);
	state.scale = 1.0f;
	Vector* fst_pos = &sys->planets[0].position;
	vector_copy(state.pos, *fst_pos);
	state.pos[1] += 1.1f*get_planet_radius(0);
	state.pos[0] -= get_planet_radius(0);
	state.rot_x = 90.0f;
	state.locked_planet = -1;
	state.hours_per_sec = DEFAULT_SIMULATION_SPEED;
	state.time_step = sys->time_step;
	state.paused = true;
	state.trails_enabled = true;

	if(SDL_Init(SDL_INIT_VIDEO) < 0)
		die("SDL initialization failed");
	atexit(SDL_Quit);
	const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
	if(!videoInfo)
		die("Could not get video information");
	int videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_HWSURFACE | SDL_HWACCEL;

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
	surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
	if(!surface)
	{
		printf("Surface creation failed, trying to disable anti-aliasing...\n");
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
	}
	if(!surface)
		die("Changing video mode failed");

	init_gl();
	init_viewport();
	SDL_ShowCursor(0);
	SDL_WM_GrabInput(SDL_GRAB_ON);

	SDL_Event event;
	while(SDL_PollEvent(&event))
		;  /* ignore spurious mouse events at startup */

	bool window_is_active = true;
	int step = 0;
	while (true)
	{
		Uint32 next_update = SDL_GetTicks() + FRAME_INTERVAL;
		while (SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_ACTIVEEVENT:
					window_is_active = event.active.gain;
					break;			    
				case SDL_VIDEORESIZE:
					surface = SDL_SetVideoMode(event.resize.w,
							event.resize.h,
							SCREEN_BPP, videoFlags);
					if(!surface)
						die("Lost video surface during resize");
					init_viewport();
					break;
				case SDL_KEYDOWN:
					handle_keypress(&event.key.keysym);
					break;
				case SDL_MOUSEMOTION:
					handle_mouse(&event.motion);
					break;
				case SDL_QUIT:
					goto out;
				default:
					break;
			}
		}
		update();
		if(window_is_active)
		{
			draw_scene();
			glFlush();
			SDL_GL_SwapBuffers();
		}
		if(!state.paused)
		{
			for(int i = 0; i < (state.hours_per_sec * 3600.0f / FRAME_INTERVAL) / state.time_step; i++)
			{
				if((step % TRAILS_INTERVAL) == 0)
					update_trails();
				simulate_one_step(sys, step++, state.time_step);
			}
		}
		Sint32 delta = next_update - SDL_GetTicks();
		if(delta > 0)
			SDL_Delay(delta);
	}
out:

	return 0;
}