Ejemplo n.º 1
0
SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) {
    SkTypeface* face;
    if (FLAGS_portableFonts) {
        face = create_font(name, style);
    } else if (FLAGS_resourceFonts) {
        face = resource_font(name, style);
    } else {
        face = SkTypeface::CreateFromName(name, style);
    }
    return face;
}
Ejemplo n.º 2
0
static bool create_xcom_large_font()
{
    int fh = open(F("$(xcom)/geodata/biglets.dat"), O_RDONLY | O_BINARY);
    if (fh == -1) return false;
    int fl = filelength(fh);
    unsigned char *dat_lat = new unsigned char[fl];
    unsigned char *dat_cyr = (unsigned char *)datafile[DAT_BIGLETS_CYR].dat;
    read(fh, dat_lat, fl);
    close(fh);
    large = create_font(dat_lat, dat_cyr, 16, 16, 1);
    delete []dat_lat;
    return true;
}
Ejemplo n.º 3
0
static bool create_xcom_small_font()
{
    int fh = open(F("$(xcom)/geodata/smallset.dat"), O_RDONLY | O_BINARY);
    if (fh == -1) return false;
    int fl = filelength(fh);
    unsigned char *dat_lat = new unsigned char[fl];
    unsigned char *dat_cyr = (unsigned char *)datafile[DAT_SMALLSET_CYR].dat;
    read(fh, dat_lat, fl);
    close(fh);
    g_small_font = create_font(dat_lat, dat_cyr, 8, 9, 1);
    delete []dat_lat;
    return true;
}
Ejemplo n.º 4
0
 // font_size is in units of tenths of point size. i.e. 100 is a 10 point font
 FontPtr create_font(DevicePtr device, const tstring & font_name, int font_size) {
   HDC dc = GetDC(NULL);
   if (!dc) WIN_EXCEPT("Failed call to GetDC(NULL).");
   int log_pixels_y = GetDeviceCaps(dc, LOGPIXELSY);
   ReleaseDC(NULL, dc);
 
   FontPtr font;
   HRESULT hr = E_FAIL;
   if (is_fixed_width(font_name)) {
     LOGFONT lf;
     // Try filling the logfont with GDI+ first since it gives more natural font
     //   proportions than passing 0 as the width. However since GDI+ doesn't handle
     //   some fonts like Terminal properly, if GDI+ fails, try creating the font
     //   directly.
     if (get_logfont(font_name, font_size, &lf))
       return create_font(device, lf);
     hr = D3DXCreateFont(device,
                         -MulDiv(font_size, log_pixels_y, 72 * POINT_SIZE_SCALE),
                         0,
                         FW_NORMAL,
                         D3DX_DEFAULT,
                         FALSE,
                         DEFAULT_CHARSET,
                         OUT_DEFAULT_PRECIS,
                         QUALITY,
                         FIXED_PITCH | FF_DONTCARE,
                         font_name.c_str(),
                         &font);
   }
   if (FAILED(hr)) {
     tstringstream sstr;
     sstr << _T("Unable to use the font ") << font_name << ".";
     MessageBox(NULL, sstr.str().c_str(), _T("Font error"), MB_OK);
     hr = D3DXCreateFont(device,
                         -MulDiv(font_size, log_pixels_y, 72 * POINT_SIZE_SCALE),
                         0,
                         FW_NORMAL,
                         D3DX_DEFAULT,
                         FALSE,
                         DEFAULT_CHARSET,
                         OUT_DEFAULT_PRECIS,
                         QUALITY,
                         FIXED_PITCH | FF_DONTCARE,
                         _T("Lucida Console"),
                         &font);
     if (FAILED(hr)) DX_EXCEPT("Failed call to D3DXCreateFont(). ", hr);
   }
   return font;
 }
Ejemplo n.º 5
0
int
CKLBLuaLibFONT::luaFontCreate(lua_State * L)
{
	CLuaState lua(L);
	int argc = lua.numArgs();
	if(argc != 2) {
		lua.retBoolean(false);
		return 1;
	}
	
	int size = lua.getInt(1);
	const char * fontname = lua.getString(2);
	FONTOBJ * fontobj = create_font(size, fontname);

	lua.retPointer(fontobj);
	return 1;
}
Ejemplo n.º 6
0
/* **level\_data** is created and populated with
 * level specific entities. Some entities require further
 * initialization, such as the timeline.
 * A timeline allows creating a sequence of events
 * on a, well.. time line. Each event has a start time,
 * duration and callback function the will get called
 * each time the timeline is updated and if the event
 * is active.
 * We use a timeline to animate the title, creating 3
 * events: (1) slide the title into the screen (2)
 * make the title "bling" and (3) slide the title out
 * of the screen.
 * Using the SECOND and SECONDS constant is for
 * the sake of readability only.
 */
static struct level_data* create_level_data(void)
{
    struct level_data* ldata = calloc(1, sizeof(*ldata));
    if (ldata == NULL) goto error;

    ldata->wizard = create_wizard();
    if (ldata->wizard == NULL) goto cleanup_level_data;

    if (prepare_title(&ldata->title) != 0) goto cleanup_level_data;
    if (prepare_tree(&ldata->tree) != 0) goto cleanup_level_data;

    ldata->grass_tile = create_image("res/grass_tile.png");
    if (ldata->grass_tile == NULL) goto cleanup_level_data;

    ldata->earth_tile = create_image("res/earth_tile.png");
    if (ldata->earth_tile == NULL) goto cleanup_level_data;

    play_animation(ldata->tree.sprite, ldata->tree.windblow);

    ldata->timeline = create_timeline();
    if (ldata->timeline == NULL) goto cleanup_level_data;
    append_event(ldata->timeline, 0, 1 * SECOND, before_title_in);
    append_event(ldata->timeline, 0, 1 * SECOND, slide_title_in);
    append_event(ldata->timeline, 0, 4 * SECONDS, bling_title);
    append_event(ldata->timeline, 0, 1 * SECOND, slide_title_out);

    ldata->font = create_font("res/font.png", 32, 4);
    if (ldata->font == NULL) goto cleanup_level_data;

    ldata->music = create_sound("res/wizard.ogg");
    play_sound(ldata->music, -1);
    return ldata;

cleanup_level_data:
    destroy_level_data(ldata);

error:
    ERROR("Unable to create level data");
    return NULL;
}
Ejemplo n.º 7
0
void set_portable_typeface(SkPaint* paint, const char* name, SkFontStyle style) {
    paint->setTypeface(create_font(name, style));
}
Ejemplo n.º 8
0
sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) {
    return create_font(name, style);
}
Ejemplo n.º 9
0
static INT_PTR CALLBACK win_sectorview_dialog_proc(HWND dialog, UINT message,
	WPARAM wparam, LPARAM lparam)
{
	imgtoolerr_t err;
	INT_PTR rc = 0;
	struct sectorview_info *info;
	RECT dialog_rect;

	switch(message)
	{
		case WM_INITDIALOG:
			info = (struct sectorview_info *) lparam;
			info->font = create_font();

			GetWindowRect(dialog, &dialog_rect);
			info->old_width = dialog_rect.right - dialog_rect.left;
			info->old_height = dialog_rect.bottom - dialog_rect.top;
			info->track = ~0;
			info->head = ~0;
			info->sector = ~0;

			SendMessage(GetDlgItem(dialog, IDC_HEXVIEW), WM_SETFONT, (WPARAM) info->font, (LPARAM) TRUE);
			SetWindowLongPtr(dialog, GWLP_USERDATA, lparam);

			setup_spin_control(dialog, IDC_TRACKSPIN, IDC_TRACKEDIT);
			setup_spin_control(dialog, IDC_HEADSPIN, IDC_HEADEDIT);
			setup_spin_control(dialog, IDC_SECTORSPIN, IDC_SECTOREDIT);

			err = read_sector_data(dialog, 0, 0, 0);
			if (err == IMGTOOLERR_SEEKERROR)
				err = read_sector_data(dialog, 0, 0, 1);
			if (!err)
				set_sector_text(dialog);
			break;

		case WM_DESTROY:
			info = get_sectorview_info(dialog);
			if (info->font)
			{
				DeleteObject(info->font);
				info->font = NULL;
			}
			break;

		case WM_SYSCOMMAND:
			if (wparam == SC_CLOSE)
				EndDialog(dialog, 0);
			break;

		case WM_COMMAND:
			switch(HIWORD(wparam))
			{
				case BN_CLICKED:
					switch(LOWORD(wparam))
					{
						case IDOK:
						case IDCANCEL:
							EndDialog(dialog, 0);
							break;
					}
					break;

				case EN_CHANGE:
					change_sector(dialog);
					break;
			}
			break;

		case WM_SIZE:
			info = get_sectorview_info(dialog);

			GetWindowRect(dialog, &dialog_rect);
			size_dialog(dialog, sectorview_anchor,
				(dialog_rect.right - dialog_rect.left) - info->old_width,
				(dialog_rect.bottom - dialog_rect.top) - info->old_height);

			info->old_width = dialog_rect.right - dialog_rect.left;
			info->old_height = dialog_rect.bottom - dialog_rect.top;
			break;

		case WM_MOUSEWHEEL:
			if (HIWORD(wparam) & 0x8000)
				SendMessage(GetDlgItem(dialog, IDC_HEXVIEW), WM_VSCROLL, SB_LINEDOWN, 0);
			else
				SendMessage(GetDlgItem(dialog, IDC_HEXVIEW), WM_VSCROLL, SB_LINEUP, 0);
			break;
	}

	return rc;
}
Ejemplo n.º 10
0
void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style style) {
    SkTypeface* face = create_font(name, style);
    SkSafeUnref(paint->setTypeface(face));
}
Ejemplo n.º 11
0
/****************************************************************************
 *
 *  ROUTINE       : xprintf
 *
 *  INPUTS        : const PB_INSTANCE *ppbi : Pointer to decoder instance.
 *                  long n_pixel             : Offset into buffer to write text.
 *                  const char *format      : Format string for print.
 *                  ...                     : Variable length argument list.
 *
 *  OUTPUTS       : None.
 *
 *  RETURNS       : int: Size (in bytes) of the formatted text.
 *
 *  FUNCTION      : Display a printf style message on the current video frame.
 *
 *  SPECIAL NOTES : None.
 *
 ****************************************************************************/
int onyx_xprintf(unsigned char *ppbuffer, long n_pixel, long n_size, long n_stride, const char *format, ...)
{
    BOOL b_rc;
    va_list arglist;
    HFONT hfont, hfonto;

    int rc = 0;
    char sz_formatted[256] = "";
    unsigned char *p_dest = &ppbuffer[n_pixel];

#ifdef _WIN32_WCE
    //  Set up temporary bitmap
    HDC hdc_memory   = NULL;
    HBITMAP hbm_temp = NULL;
    HBITMAP hbm_orig = NULL;

    RECT rect;

    //  Copy bitmap to video frame
    long x;
    long y;

    //  Format text
    va_start(arglist, format);
    _vsnprintf(sz_formatted, sizeof(sz_formatted), format, arglist);
    va_end(arglist);

    rect.left   = 0;
    rect.top    = 0;
    rect.right  = 8 * strlen(sz_formatted);
    rect.bottom = 8;

    hdc_memory = create_compatible_dc(NULL);

    if (hdc_memory == NULL)
        goto Exit;

    hbm_temp = create_bitmap(rect.right, rect.bottom, 1, 1, NULL);

    if (hbm_temp == NULL)
        goto Exit;

    hbm_orig = (HBITMAP)(select_object(hdc_memory, hbm_temp));

    if (!hbm_orig)
        goto Exit;

    //  Write text into bitmap
    //  font?
    hfont = create_font(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, "");

    if (hfont == NULL)
        goto Exit;

    hfonto = (HFONT)(select_object(hdc_memory, hbm_temp));

    if (!hfonto)
        goto Exit;

    select_object(hdc_memory, hfont);
    set_text_color(hdc_memory, 1);
    set_bk_color(hdc_memory, 0);
    set_bk_mode(hdc_memory, TRANSPARENT);

    b_rc = bit_blt(hdc_memory, rect.left, rect.top, rect.right, rect.bottom, hdc_memory, rect.left, rect.top, BLACKNESS);

    if (!b_rc)
        goto Exit;

    b_rc = ext_text_out(hdc_memory, 0, 0, ETO_CLIPPED, &rect, sz_formatted, strlen(sz_formatted), NULL);

    if (!b_rc)
        goto Exit;

    for (y = rect.top; y < rect.bottom; ++y)
    {
        for (x = rect.left; x < rect.right; ++x)
        {
            if (get_pixel(hdc_memory, x, rect.bottom - 1 - y))
                p_dest[x] = 255;
        }

        p_dest += n_stride;
    }

    rc = strlen(sz_formatted);

Exit:

    if (hbm_temp != NULL)
    {
        if (hbm_orig != NULL)
        {
            select_object(hdc_memory, hbm_orig);
        }

        delete_object(hbm_temp);
    }

    if (hfont != NULL)
    {
        if (hfonto != NULL)
            select_object(hdc_memory, hfonto);

        delete_object(hfont);
    }

    if (hdc_memory != NULL)
        delete_dc(hdc_memory);

    hdc_memory = 0;

#endif

    return rc;
}
Ejemplo n.º 12
0
SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) {
    return create_font(name, style);
}
Ejemplo n.º 13
0
Archivo: P_MAIN.C Proyecto: cepa/pong
void install()
{
  if(!load_pal("data/game.pal",game_pal))
  {
    printf("Error - Couldn't load game palette !\n");
    exit(-1);
  }

  if(!(font = create_font()))
  {
    printf("Error - Couldn't create FONT structure !\n");
    exit(-1);
  }

  if(!load_fnt("data/font.fnt",font))
  {
    printf("Error - Couldn't load game font !\n");
    exit(-1);
  }

  if(!(screen_buffer = create_bitmap(320,200)))
  {
    printf("Error - Couldn't create screen buffer !\n");
    exit(-1);
  }

  if(!(court = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/court.gfx",court))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(logo = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/pong.gfx",logo))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(logo_c = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/pong_c.gfx",logo_c))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(bar_left = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/bar_l.gfx",bar_left))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(bar_right = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/bar_r.gfx",bar_right))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(ball[0] = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/ball1.gfx",ball[0]))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  if(!(ball[1] = create_bitmap(1,1)))
  {
    close13h();
    printf("Error - Couldn't create bitmap !\n");
    exit(-1);
  }

  if(!load_gfx("data/ball2.gfx",ball[1]))
  {
    close13h();
    printf("Error - Couldn't load bitmap !\n");
    exit(-1);
  }

  init13h();
  install_keyboard();
  install_timer(MS2D(10),timer);
  set_palette(game_pal);
  clear_bitmap(screen_buffer,0);
  draw_screen_buffer(screen_buffer);
}
Ejemplo n.º 14
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);
}
Ejemplo n.º 15
0
int
main(int argc, char** argv)
{
  /* Window manager data structures. */
  struct wm_device* dev = NULL;
  struct wm_window* win = NULL;
  const struct wm_window_desc win_desc = { 800, 600, 0 };
  /* Renderer data structure. */
  struct rdr_glyph_desc glyph_desc_list[NB_CHARS];
  struct rdr_font* font = NULL;
  struct rdr_frame* frame = NULL;
  struct rdr_system* sys = NULL;
  struct rdr_term* term = NULL;
  /* Resources data structure. */
  struct rsrc_context* ctxt = NULL;
  struct rsrc_font* rfont = NULL;
  /* Miscellaneous data. */
  const char* driver_name = NULL;
  const char* font_name = NULL;
  size_t line_space = 0;
  size_t i = 0;
  bool b = false;

  if(argc != 3) {
    printf("usage: %s RB_DRIVER FONT\n", argv[0]);
    return -1;
  }
  driver_name = argv[1];
  font_name = argv[2];

  /* Setup the render font. */
  RSRC(create_context(NULL, &ctxt));
  RSRC(create_font(ctxt, font_name, &rfont));
  if(RSRC(is_font_scalable(rfont, &b)), b)
    RSRC(font_size(rfont, 18, 18));

  for(i = 0; i < NB_CHARS; ++i) {
    struct rsrc_glyph* glyph = NULL;
    struct rsrc_glyph_desc glyph_desc;
    size_t width = 0;
    size_t height = 0;
    size_t Bpp = 0;
    size_t size = 0;

    RSRC(font_glyph(rfont, (wchar_t)(i + FIRST_CHAR), &glyph));

    /* Get glyph desc. */
    RSRC(glyph_desc(glyph, &glyph_desc));
    glyph_desc_list[i].width = glyph_desc.width;
    glyph_desc_list[i].character = glyph_desc.character;
    glyph_desc_list[i].bitmap_left = glyph_desc.bbox.x_min;
    glyph_desc_list[i].bitmap_top = glyph_desc.bbox.y_min;

    /* Get glyph bitmap. */
    RSRC(glyph_bitmap(glyph, true, &width, &height, &Bpp, NULL));
    glyph_desc_list[i].bitmap.width = width;
    glyph_desc_list[i].bitmap.height = height;
    glyph_desc_list[i].bitmap.bytes_per_pixel = Bpp;
    glyph_desc_list[i].bitmap.buffer = NULL;
    size = width * height * Bpp;
    if(0 != size) {
      unsigned char* buffer = MEM_CALLOC(&mem_default_allocator, 1, size);
      RSRC(glyph_bitmap(glyph, true, NULL, NULL, NULL, buffer));
      glyph_desc_list[i].bitmap.buffer = buffer;
    }

    RSRC(glyph_ref_put(glyph));
  }

  RSRC(font_line_space(rfont, &line_space));
  RSRC(font_ref_put(rfont));
  RSRC(context_ref_put(ctxt));

  WM(create_device(NULL, &dev));
  WM(create_window(dev, &win_desc, &win));

  RDR(create_system(driver_name, NULL, &sys));
  RDR(create_frame
    (sys, (struct rdr_frame_desc[]){{win_desc.width,win_desc.height}}, &frame));
Ejemplo n.º 16
0
    RSRC(glyph_ref_put(glyph));
  }

  RSRC(font_line_space(rfont, &line_space));
  RSRC(font_ref_put(rfont));
  RSRC(context_ref_put(ctxt));

  WM(create_device(NULL, &dev));
  WM(create_window(dev, &win_desc, &win));

  RDR(create_system(driver_name, NULL, &sys));
  RDR(create_frame
    (sys, (struct rdr_frame_desc[]){{win_desc.width,win_desc.height}}, &frame));

  RDR(background_color(frame, (float[]){0.05f, 0.05f, 0.05f}));
  RDR(create_font(sys, &font));
  RDR(font_data(font, line_space, NB_CHARS, glyph_desc_list));
  for(i = 0; i < NB_CHARS; ++i) {
    MEM_FREE(&mem_default_allocator, glyph_desc_list[i].bitmap.buffer);
  }

  {
    /* DEBUG. */
    size_t w, h, Bpp;
    const unsigned char* buffer = NULL;
    RDR(font_bitmap_cache(font, &w, &h, &Bpp, &buffer));
    RSRC(write_ppm(ctxt, "/tmp/debug.ppm", w, h, Bpp, buffer));
  }

  RDR(create_term(sys, font, win_desc.width, win_desc.height, &term));
  RDR(term_print_wstring