예제 #1
0
/*
 * This reads the keyboard status port, and does the
 * appropriate action.
 *
 * It requires that we hold the keyboard controller
 * spinlock.
 */
static void handle_kbd_event(void)
{
	unsigned int status = KBDSTAT;
	unsigned int work = 10000;
	unsigned char scancode;

	while (status & KBD_STAT_RXF) {
		while (status & KBD_STAT_RXF) {
			scancode = KBDDATA & 0xff;
			if (!(status & KBD_STAT_STP))
				handle_keyboard_event(scancode);
			if (!--work) {
				printk(KERN_ERR
				       "pc_keyb: keyboard controller jammed (0x%02X).\n",
				       status);
				return;
			}
			status = KBDSTAT;
		}
		work = 10000;
	}

	if (status & KBD_STAT_STP)
		KBDSTAT = KBD_STAT_STP;
}
예제 #2
0
/*
 * This reads the keyboard status port, and does the
 * appropriate action.
 *
 * It requires that we hold the keyboard controller
 * spinlock.
 */
static unsigned char handle_kbd_event(void)
{
	unsigned char status = kbd_read_status();
	unsigned int work = 10000;

	while ((--work > 0) && (status & KBD_STAT_OBF)) {
		unsigned char scancode;

		scancode = kbd_read_input();

		/* Error bytes must be ignored to make the 
		   Synaptics touchpads compaq use work */
#if 1
		/* Ignore error bytes */
		if (!(status & (KBD_STAT_GTO | KBD_STAT_PERR)))
#endif
		{
			if (status & KBD_STAT_MOUSE_OBF)
				handle_mouse_event(scancode);
			else
				handle_keyboard_event(scancode);
		}

		status = kbd_read_status();
	}
		
	if (!work)
		printk(KERN_ERR "pc_keyb: controller jammed (0x%02X).\n", status);

	return status;
}
예제 #3
0
static unsigned char handle_kbd_event(void)
{
   unsigned char scancode;

   scancode = kbd_read_input();
   handle_keyboard_event(scancode);

   return 0;
}
예제 #4
0
static void e5_receive(struct e5_struct *k)
{
	k->packet[k->pos++] = ctrl_inb(EC3104_SER4_DATA);

	if (k->pos == 1) {
		switch(k->packet[0]) {
		case 0x80:
			k->length = 3;
			break;
			
		case 0x87: /* PS2 ext */
			k->length = 6;
			break;

		case 0x88: /* keyboard */
			k->length = 3;
			break;

		default:
			k->length = 1;
			printk(KERN_WARNING "unknown E5 packet %02x\n",
			       k->packet[0]);
		}
	}

	if (k->pos == k->length) {
		int i;

		if (e5_checksum(k->packet, k->length) != 0)
			printk(KERN_WARNING "E5: wrong checksum\n");

#if 0
		printk("E5 packet [");
		for(i=0; i<k->length; i++) {
			printk("%02x ", k->packet[i]);
		}

		printk("(%02x)]\n", e5_checksum(k->packet, k->length-1));
#endif

		switch(k->packet[0]) {
		case 0x80:
		case 0x88:
			handle_keyboard_event(k->packet[1]);
			break;
		}

		k->pos = k->length = 0;
	}
}
예제 #5
0
void handle_event(nstate *state)
{
	switch(state->event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			handle_exposure_event(state);
			break;
		case GR_EVENT_TYPE_BUTTON_DOWN:
			handle_mouse_event(state);
			break;
		case GR_EVENT_TYPE_KEY_DOWN:
			handle_keyboard_event(state);
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			state->state = STATE_EXIT;
			break;
		case GR_EVENT_TYPE_TIMEOUT:
			break;
		default:
			fprintf(stderr, "Unhandled event type %d\n",
							state->event.type);
			break;
	}
}
예제 #6
0
파일: Gameview.cpp 프로젝트: knied/LD27
void GameView::keyReleaseEvent(QKeyEvent *event) {
    handle_keyboard_event(event, KEY_RELEASE_EVENT);
}
예제 #7
0
파일: Gameview.cpp 프로젝트: knied/LD27
void GameView::keyPressEvent(QKeyEvent *event)
{
    handle_keyboard_event(event, KEY_PRESS_EVENT);
}
예제 #8
0
/**
 * main
 *
 * TODO: Write function block once this is cleaned up.
 */
int main(int argc, char** argv)
{
  /*
   * Local Variables.
   */
  SDL_Event transient_event;
  SCREEN *screen;
  MATCH_STATE *match_state;
  Uint32 frame_start_time;
  Uint32 frame_time_taken_ms;
  Uint32 physics_time_delta;
  Uint32 last_physics_update;
  Uint32 ai_time_delta;
  Uint32 last_ai_update;
  Uint32 ms_per_frame;
  int rc;
  StrMap *config_table;
  Uint32 last_animation_update = 0;
  Uint32 animation_ms_per_frame;
  int max_fps;
  FONT *font;
  char disc_graphic_file[MAX_CONFIG_VALUE_LEN + 1];
  char grass_tile_file[MAX_CONFIG_VALUE_LEN + 1];
  char o_xml_file[MAX_CONFIG_VALUE_LEN + 1];
  char d_xml_file[MAX_CONFIG_VALUE_LEN + 1];
  int ii;
  SDL_Color white = {0xFF, 0xFF, 0xFF, 0x00};

  /*
   * Begin logging.
   */
  DT_INIT_LOG;

  /*
   * TODO: Move loading and retrieving constants using defaults from the config
   * file to a different folder, code file. Simple api.
   */
  load_config_to_str_map("config.txt", &config_table);
  if (!get_config_value_int(config_table,
                            cv_animation_ms_per_frame,
                            (int *)&animation_ms_per_frame))
  {
    game_exit("Programmer error: animation ms per frame not handled in cfg.");
  }
  if (!get_config_value_int(config_table, cv_max_fps, &max_fps))
  {
    game_exit("Programmer error: max fps not handled in cfg.");
  }
  ms_per_frame = (int) MILLISECONDS_PER_SECOND / max_fps;
  if (!get_config_value_str(config_table, cv_disc_graphic, (char *)disc_graphic_file))
  {
    game_exit("Programmer error: disc graphic not handled in cfg.");
  }
  if (!get_config_value_str(config_table, cv_grass_tile_filename, (char *)grass_tile_file))
  {
    game_exit("Programmer error: grass tile graphic not handled in cfg.");
  }
  if (!get_config_value_str(config_table, cv_o_xml_file, (char *)o_xml_file))
  {
    game_exit("Programmer error: O XML file not handled in cfg.");
  }
  if (!get_config_value_str(config_table, cv_d_xml_file, (char *)d_xml_file))
  {
    game_exit("Programmer error: D XML file not handled in cfg.");
  }
  DT_DEBUG_LOG("Config file loaded\n");

  /*
   * Create the screen object and use it to initialise the window system.
   */
  screen = create_screen();
  rc = init_window_system(screen, SCREEN_WIDTH, SCREEN_HEIGHT, BPP);
  if (INIT_OK != rc)
  {
    game_exit("Window system could not be initialised.");
  }
  DT_DEBUG_LOG("Graphics subsystem created and initialized\n");

  /*
   * Initialise Audio subsystem
   */
  rc = init_audio_subsystem(config_table);
  if (INIT_AUDIO_SYSTEM_OK != rc)
  {
    /*
     * Don't exit just because we can't output audio. The audio code will
     * handle this case.
     */
    DT_DEBUG_LOG("Audio subsystem could not be initialised\n");
  }
  else
  {
    DT_DEBUG_LOG("Audio subsystem created and initialized\n");
  }

  /*
   * Initialise the opengl components of the screen.
   */
  rc = init_gl(screen);
  if (GL_INIT_OK != rc)
  {
    game_exit("Could not do opengl initialisation.");
  }
  DT_DEBUG_LOG("OpenGL setup complete\n");

  /*
   * TODO: Proper font management system where more than one font can be loaded
   *
   * Create the font object that is going to be used to write text throughout
   * the game.
   */
  rc = create_font("..\\..\\resources\\Fonts\\LucidaSansRegular.ttf",
                   &font,
                   30,
                   TTF_STYLE_NORMAL,
                   white);
  if (BUILD_FONT_OK != rc)
  {
    game_exit("Could not load up LucidaSansRegular font.");
  }
  DT_DEBUG_LOG("Lucida sans regular font loaded\n");

  /*
   * TODO: Constants to move from here.
   *
   * Create a new match state object before starting the game loop.
   */
  match_state = create_match_state(15,
                                   60 * 60,
                                   disc_graphic_file,
                                   grass_tile_file,
                                   o_xml_file,
                                   d_xml_file,
                                   create_o_automaton_states,
                                   create_automaton_events);
  if (NULL == match_state)
  {
    game_exit("Failed to create match state.");
  }
  init_pitch(match_state->pitch);
  DT_DEBUG_LOG("Match state created and initialized\n");

  /*
   * Scale the pitch by an arbitrary amount to account for the otherwise small
   * scaling.
   */
  scale_camera(match_state->camera_handler, 10.0f);

  /*
   * Load the animation data.
   */
  rc = load_animation_data(match_state->animation_handler);
  if (LOAD_ANIMATION_DATA_OK != rc)
  {
    game_exit("Failed to load animation data.");
  }
  DT_DEBUG_LOG("Animation data loaded\n");

  /*
   * Initialise the timings
   */
  last_physics_update = SDL_GetTicks();
  last_ai_update = SDL_GetTicks();

  /*
   * Initialise and start a new match.
   */
  start_match(match_state);

  // @@@DAT testing
  throw_multi_player_ai_event_by_name(match_state->teams,
                                      match_state->players_per_team,
                                      match_state->teams[0]->players[0]->automaton,
                                      AUTOMATON_EVENT_PULL_THROWN);

  /*
   * Game loop
   */
  while(true)
  {
    /*
     * Frame time is tracked so that we can determine how long to wait before
     * displaying the next frame. i.e. to fix the FPS.
     */
    frame_start_time = SDL_GetTicks();

    /*
     * Look at disc
     */
    look_at_location(match_state->camera_handler,
                     match_state->disc->position.x,
                     match_state->disc->position.y,
                     screen);

    /*
     * While there are events to process, do so.
     */
    while(SDL_PollEvent(&transient_event))
    {
      /*
       * First check whether it is an SDL_QUIT event. If so then exit with
       * message.
       */
      if (transient_event.type == SDL_QUIT)
      {
        destroy_match_state(match_state);
        game_exit("User requested exit via SDL_QUIT event.");
      }
      else if ((transient_event.type == SDL_KEYDOWN) ||
               (transient_event.type == SDL_KEYUP))
      {
        /*
         * The event was the user either depressing or releasing a key so call
         * to the keyboard event handler to deal with the event.
         */
        handle_keyboard_event(&(transient_event.key),
                              transient_event.type,
                              match_state,
                              screen);
      }
      else if ((transient_event.type == SDL_MOUSEBUTTONDOWN) ||
               (transient_event.type == SDL_MOUSEBUTTONUP))
      {
        /*
         * The event was the user either depressing or releasing a mouse button
         * so pass to the mouse button event handler to deal with it. This
         * includes the mouse wheel moving.
         */
        handle_mousebutton_event(&(transient_event.button), match_state);
      }
    }

    /*
     * Perform an update on all the ai objects.
     */
    ai_time_delta = SDL_GetTicks() - last_ai_update;
    process_all_player_ai(match_state->teams,
                          match_state->players_per_team,
                          ai_time_delta);
    last_ai_update = SDL_GetTicks();

    /*
     * Process the automaton timed event queue to see if any events need to be
     * popped.
     */
    pop_all_timed_events(match_state->automaton_handler->timed_event_queue,
                         SDL_GetTicks(),
                         match_state);

    /*
     * Do physics processing. This updates the positions of all moving entities
     * in the game.
     *
     * WARNING - If this takes longer than the amount of time allocated per
     * frame then there might be 'interesting' problems in the frame refresh.
     */
    physics_time_delta = SDL_GetTicks() - last_physics_update;
    calculate_positions(match_state,
                        physics_time_delta);
    last_physics_update = SDL_GetTicks();

    /*
     * Having moved all of the objects to their new positions we need to
     * detect collisions and verify the new locations.
     *
     * At the end of this function the positions of all objects will have been
     * updated.
     */
    detect_and_handle_collisions(match_state->teams,
                                 match_state->players_per_team,
                                 match_state->disc);

    /*
     * Update the camera object.
     */
    update_camera_position(match_state);

    /*
     * TODO: Is this management of animations sufficient?
     *
     * Update the animation frame counters.
     */
    if (SDL_GetTicks() - last_animation_update >= animation_ms_per_frame)
    {
      last_animation_update = SDL_GetTicks();
      for (ii = 0; ii < match_state->players_per_team; ii++)
      {
        increment_animation_frame_counter(match_state->teams[0]->players[ii],
                                          match_state->animation_handler);
        increment_animation_frame_counter(match_state->teams[1]->players[ii],
                                          match_state->animation_handler);
      }
    }

    /*
     * If the frame has taken less than the maximum allowed amount of time to
     * render then delay the screen update.
     */
    frame_time_taken_ms = SDL_GetTicks() - frame_start_time;
    if (frame_time_taken_ms < ms_per_frame)
    {
      SDL_Delay(ms_per_frame - frame_time_taken_ms);
    }

    /*
     * Redraw the screen.
     */
    redraw_screen(screen, match_state, font);
  }

  return(0);
}