コード例 #1
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
/* We're in samples - try to convert the random xml value to something useful */
static void try_to_fill_sample(struct sample *sample, const char *name, char *buf)
{
	int len = strlen(name);
	int in_deco;

	start_match("sample", name, buf);
	if (MATCH(".sample.pressure", pressure, &sample->cylinderpressure))
		return;
	if (MATCH(".sample.cylpress", pressure, &sample->cylinderpressure))
		return;
	if (MATCH(".sample.cylinderindex", get_cylinderindex, &sample->sensor))
		return;
	if (MATCH(".sample.sensor", get_sensor, &sample->sensor))
		return;
	if (MATCH(".sample.depth", depth, &sample->depth))
		return;
	if (MATCH(".sample.temp", temperature, &sample->temperature))
		return;
	if (MATCH(".sample.temperature", temperature, &sample->temperature))
		return;
	if (MATCH(".sample.sampletime", sampletime, &sample->time))
		return;
	if (MATCH(".sample.time", sampletime, &sample->time))
		return;
	if (MATCH(".sample.ndl", sampletime, &sample->ndl))
		return;
	if (MATCH(".sample.in_deco", get_index, &in_deco)) {
		sample->in_deco = (in_deco == 1);
		return;
	}
	if (MATCH(".sample.stoptime", sampletime, &sample->stoptime))
		return;
	if (MATCH(".sample.stopdepth", depth, &sample->stopdepth))
		return;
	if (MATCH(".sample.cns", get_index, &sample->cns))
		return;
	if (MATCH(".sample.po2", double_to_permil, &sample->po2))
		return;

	switch (import_source) {
	case DIVINGLOG:
		if (divinglog_fill_sample(sample, name, len, buf))
			return;
		break;

	case UDDF:
		if (uddf_fill_sample(sample, name, len, buf))
			return;
		break;

	default:
		break;
	}

	nonmatch("sample", name, buf);
}
コード例 #2
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
static void try_to_match_autogroup(const char *name, char *buf)
{
	int len = strlen(name);
	int autogroupvalue;

	start_match("autogroup", name, buf);
	if (MATCH(".autogroup.state", get_index, &autogroupvalue)) {
		set_autogroup(autogroupvalue);
		return;
	}
	nonmatch("autogroup", name, buf);
}
コード例 #3
0
ファイル: parse-xml.c プロジェクト: draco003/subsurface
static void try_to_fill_event(const char *name, char *buf)
{
	int len = strlen(name);

	start_match("event", name, buf);
	if (MATCH(".event", utf8_string, &event.name))
		return;
	if (MATCH(".name", utf8_string, &event.name))
		return;
	if (MATCH(".time", eventtime, &event.time))
		return;
	if (MATCH(".type", get_index, &event.type))
		return;
	if (MATCH(".flags", get_index, &event.flags))
		return;
	nonmatch("event", name, buf);
}
コード例 #4
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
static void try_to_fill_dc_settings(const char *name, char *buf)
{
	int len = strlen(name);

	start_match("divecomputerid", name, buf);
	if (MATCH("divecomputerid.model", utf8_string, &cur_settings.dc.model))
		return;
	if (MATCH("divecomputerid.deviceid", hex_value, &cur_settings.dc.deviceid))
		return;
	if (MATCH("divecomputerid.nickname", utf8_string, &cur_settings.dc.nickname))
		return;
	if (MATCH("divecomputerid.serial", utf8_string, &cur_settings.dc.serial_nr))
		return;
	if (MATCH("divecomputerid.firmware", utf8_string, &cur_settings.dc.firmware))
		return;

	nonmatch("divecomputerid", name, buf);
}
コード例 #5
0
ファイル: parse-xml.c プロジェクト: denghuancong/subsurface
/* We're in samples - try to convert the random xml value to something useful */
static void try_to_fill_sample(struct sample *sample, const char *name, char *buf)
{
	int len = strlen(name);

	start_match("sample", name, buf);
	if (MATCH(".sample.pressure", pressure, &sample->cylinderpressure))
		return;
	if (MATCH(".sample.cylpress", pressure, &sample->cylinderpressure))
		return;
	if (MATCH(".sample.cylinderindex", get_index, &sample->cylinderindex))
		return;
	if (MATCH(".sample.depth", depth, &sample->depth))
		return;
	if (MATCH(".sample.temp", temperature, &sample->temperature))
		return;
	if (MATCH(".sample.temperature", temperature, &sample->temperature))
		return;
	if (MATCH(".sample.sampletime", sampletime, &sample->time))
		return;
	if (MATCH(".sample.time", sampletime, &sample->time))
		return;

	switch (import_source) {
	case UEMIS:
		if (uemis_fill_sample(sample, name, len, buf))
			return;
		break;

	case DIVINGLOG:
		if (divinglog_fill_sample(sample, name, len, buf))
			return;
		break;

	case UDDF:
		if (uddf_fill_sample(sample, name, len, buf))
			return;
		break;

	default:
		break;
	}

	nonmatch("sample", name, buf);
}
コード例 #6
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
/* We're in the top-level trip xml. Try to convert whatever value to a trip value */
static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char *buf)
{
	int len = strlen(name);

	start_match("trip", name, buf);

	dive_trip_t *dive_trip = *dive_trip_p;

	if (MATCH(".date", divedate, &dive_trip->when))
		return;
	if (MATCH(".time", divetime, &dive_trip->when))
		return;
	if (MATCH(".location", utf8_string, &dive_trip->location))
		return;
	if (MATCH(".notes", utf8_string, &dive_trip->notes))
		return;

	nonmatch("trip", name, buf);
}
コード例 #7
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
{
	int len = strlen(name);

	start_match("divecomputer", name, buf);

	if (MATCH(".date", divedate, &dc->when))
		return;
	if (MATCH(".time", divetime, &dc->when))
		return;
	if (MATCH(".model", utf8_string, &dc->model))
		return;
	if (MATCH(".deviceid", hex_value, &dc->deviceid))
		return;
	if (MATCH(".diveid", hex_value, &dc->diveid))
		return;

	if (match_dc_data_fields(dc, name, len, buf))
		return;

	nonmatch("divecomputer", name, buf);
}
コード例 #8
0
ファイル: PingPong.c プロジェクト: Arles/PebblePingPong
void handle_init(AppContextRef ctx) {
  window_init(&window, TXT_TITLE);
  window_stack_push(&window, true /* Animated */);

  start_match();

  window_set_click_config_provider(&window, (ClickConfigProvider) config_provider);

  layer_init(&score_layer_me, window.layer.frame);
  score_layer_me.update_proc = update_score_layer_me_callback;
  layer_add_child(&window.layer, &score_layer_me);
  layer_mark_dirty(&score_layer_me);

  layer_init(&score_layer_opponent, window.layer.frame);
  score_layer_opponent.update_proc = update_score_layer_opponent_callback;
  layer_add_child(&window.layer, &score_layer_opponent);
  layer_mark_dirty(&score_layer_opponent);

  layer_init(&match_layer, window.layer.frame);
  match_layer.update_proc = update_match_layer_callback;
  layer_add_child(&window.layer, &match_layer);
  layer_mark_dirty(&match_layer);

  layer_init(&duration_layer, window.layer.frame);
  duration_layer.update_proc = update_duration_layer_callback;
  layer_add_child(&window.layer, &duration_layer);
  layer_mark_dirty(&duration_layer);

  text_layer_init(&layer_notification, FRAME_NOTIFICATION);
  text_layer_set_background_color(&layer_notification, GColorBlack);
  text_layer_set_text_color(&layer_notification, GColorWhite);
  text_layer_set_font(&layer_notification, fonts_get_system_font(FONT_KEY_GOTHIC_28));
  text_layer_set_text_alignment(&layer_notification, GTextAlignmentCenter);
  text_layer_set_overflow_mode(&layer_notification, GTextOverflowModeWordWrap);

}
コード例 #9
0
ファイル: PingPong.c プロジェクト: Arles/PebblePingPong
void select_long_click_handler(ClickRecognizerRef recognizer, Window *window) {
  start_match();
  layer_mark_dirty(&duration_layer);
}
コード例 #10
0
ファイル: main.c プロジェクト: DaveTCode/2dUltimateFrisbee
/**
 * 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);
}
コード例 #11
0
ファイル: parse-xml.c プロジェクト: syuxue/subsurface
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
{
	int len = strlen(name);

	start_match("dive", name, buf);

	switch (import_source) {
	case DIVINGLOG:
		if (divinglog_dive_match(dive, name, len, buf))
			return;
		break;

	case UDDF:
		if (uddf_dive_match(dive, name, len, buf))
			return;
		break;

	default:
		break;
	}

	if (MATCH(".number", get_index, &dive->number))
		return;
	if (MATCH(".tripflag", get_tripflag, &dive->tripflag))
		return;
	if (MATCH(".date", divedate, &dive->when))
		return;
	if (MATCH(".time", divetime, &dive->when))
		return;
	if (MATCH(".datetime", divedatetime, &dive->when))
		return;
	/*
	 * Legacy format note: per-dive depths and duration get saved
	 * in the first dive computer entry
	 */
	if (match_dc_data_fields(&dive->dc, name, len, buf))
		return;

	if (MATCH(".cylinderstartpressure", pressure, &dive->cylinder[0].start))
		return;
	if (MATCH(".cylinderendpressure", pressure, &dive->cylinder[0].end))
		return;
	if (MATCH(".gps", gps_location, dive))
		return;
	if (MATCH(".Place", gps_location, dive))
		return;
	if (MATCH(".latitude", gps_lat, dive))
		return;
	if (MATCH(".sitelat", gps_lat, dive))
		return;
	if (MATCH(".lat", gps_lat, dive))
		return;
	if (MATCH(".longitude", gps_long, dive))
		return;
	if (MATCH(".sitelon", gps_long, dive))
		return;
	if (MATCH(".lon", gps_long, dive))
		return;
	if (MATCH(".location", utf8_string, &dive->location))
		return;
	if (MATCH("dive.name", utf8_string, &dive->location))
		return;
	if (MATCH(".suit", utf8_string, &dive->suit))
		return;
	if (MATCH(".divesuit", utf8_string, &dive->suit))
		return;
	if (MATCH(".notes", utf8_string, &dive->notes))
		return;
	if (MATCH(".divemaster", utf8_string, &dive->divemaster))
		return;
	if (MATCH(".buddy", utf8_string, &dive->buddy))
		return;
	if (MATCH("dive.rating", get_rating, &dive->rating))
		return;
	if (MATCH("dive.visibility", get_rating, &dive->visibility))
		return;
	if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cur_cylinder_index].type.size))
		return;
	if (MATCH(".cylinder.workpressure", pressure, &dive->cylinder[cur_cylinder_index].type.workingpressure))
		return;
	if (MATCH(".cylinder.description", utf8_string, &dive->cylinder[cur_cylinder_index].type.description))
		return;
	if (MATCH(".cylinder.start", pressure, &dive->cylinder[cur_cylinder_index].start))
		return;
	if (MATCH(".cylinder.end", pressure, &dive->cylinder[cur_cylinder_index].end))
		return;
	if (MATCH(".weightsystem.description", utf8_string, &dive->weightsystem[cur_ws_index].description))
		return;
	if (MATCH(".weightsystem.weight", weight, &dive->weightsystem[cur_ws_index].weight))
		return;
	if (MATCH("weight", weight, &dive->weightsystem[cur_ws_index].weight))
		return;
	if (MATCH(".o2", gasmix, &dive->cylinder[cur_cylinder_index].gasmix.o2))
		return;
	if (MATCH(".o2percent", gasmix, &dive->cylinder[cur_cylinder_index].gasmix.o2))
		return;
	if (MATCH(".n2", gasmix_nitrogen, &dive->cylinder[cur_cylinder_index].gasmix))
		return;
	if (MATCH(".he", gasmix, &dive->cylinder[cur_cylinder_index].gasmix.he))
		return;
	if (MATCH(".divetemperature.air", temperature, &dive->airtemp))
		return;

	nonmatch("dive", name, buf);
}