Beispiel #1
0
static void read_allegro_cfg(void)
{
   /* We assume that the stdio file interface is in effect. */

   ALLEGRO_PATH *path;
   ALLEGRO_CONFIG *temp;

   if (!sys_config)
      sys_config = al_create_config();

#if defined(ALLEGRO_UNIX) && !defined(ALLEGRO_IPHONE)
   temp = al_load_config_file("/etc/allegro5rc");
   if (temp) {
      al_merge_config_into(sys_config, temp);
      al_destroy_config(temp);
   }

   path = _al_unix_get_path(ALLEGRO_USER_HOME_PATH);
   if (path) {
      al_set_path_filename(path, "allegro5rc");
      temp = al_load_config_file(al_path_cstr(path, '/'));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_set_path_filename(path, ".allegro5rc");
      temp = al_load_config_file(al_path_cstr(path, '/'));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_destroy_path(path);
   }
#endif

   path = early_get_exename_path();
   if (path) {
      al_set_path_filename(path, "allegro5.cfg");
      temp = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_destroy_path(path);
   }
   /* Reconfigure logging in case something changed. */
   _al_configure_logging();
}
Beispiel #2
0
/* read_config:
 * Load settings from the configuration file, providing default values
 */
void read_global_config(const char *config)
{
   ALLEGRO_CONFIG *c = al_load_config_file(config);
   if (!c) c = al_create_config();

   fullscreen = get_config_int(c, "GFX", "fullscreen", fullscreen);
   bit_depth = get_config_int(c, "GFX", "bit_depth", bit_depth);
   screen_width = get_config_int(c, "GFX", "screen_width", screen_width);
   screen_height = get_config_int(c, "GFX", "screen_height", screen_height);
   window_width = get_config_int(c, "GFX", "window_width", window_height);
   window_height = get_config_int(c, "GFX", "window_height", screen_height);
   screen_samples = get_config_int(c, "GFX", "samples", screen_samples);
   use_vsync = get_config_int(c, "GFX", "vsync", use_vsync);

   logic_framerate =
      get_config_int(c, "TIMING", "logic_framerate", logic_framerate);
   limit_framerate =
      get_config_int(c, "TIMING", "limit_framerate", limit_framerate);
   max_frame_skip =
      get_config_int(c, "TIMING", "max_frame_skip", max_frame_skip);
   display_framerate =
      get_config_int(c, "TIMING", "display_framerate", display_framerate);
   reduce_cpu_usage =
      get_config_int(c, "TIMING", "reduce_cpu_usage", reduce_cpu_usage);

   sound_volume = get_config_int(c, "SOUND", "sound_volume", sound_volume);
   music_volume = get_config_int(c, "SOUND", "music_volume", music_volume);
   
   set_sound_volume(sound_volume / 10.0);
   set_music_volume(music_volume / 10.0);

   controller_id = get_config_int(c, "CONTROLS", "controller_id", controller_id);
   
   al_destroy_config(c);
}
Beispiel #3
0
static void read_scores(void)
{
   ALLEGRO_PATH *fn = userResourcePath();

   if (al_make_directory(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP))) {
      al_set_path_filename(fn, "scores.cfg");
      ALLEGRO_CONFIG *cfg = al_load_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP));
      if (cfg) {
         for (int i = 0; i < NUM_SCORES; i++) {
            char name[]  = {'n', (char)('0'+i), '\0'};
            char score[] = {'s', (char)('0'+i), '\0'};
            const char *v;

            v = al_get_config_value(cfg, "scores", name);
            if (v && strlen(v) <= 3) {
               strcpy(highScores[i].name, v);
            }
            v = al_get_config_value(cfg, "scores", score);
            if (v) {
               highScores[i].score = atoi(v);
            }
         }

         al_destroy_config(cfg);
      }
   }

   al_destroy_path(fn);
}
Beispiel #4
0
int main(int argc, char * argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;

   initialize();

   if (argc < 2) {
      log_printf("This example needs to be run from the command line.\nUsage: %s {audio_files}\n", argv[0]);
      goto done;
   }

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   stream_filename = argv[1];
   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      abort_example("Stream error!\n");
   }

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

done:
   myexit();
   al_destroy_display(display);
   close_log(true);
   return 0;
}
int main(int argc, char * argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;

   if (argc < 2) {
      printf("Usage: ex_stream_seek <filename>\n");
      return -1;
   }

   if (!initialize())
      return 1;

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   stream_filename = argv[1];
   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      printf("Stream error!\n");
      return 1;
   }

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

   myexit();
   return 0;
}
Beispiel #6
0
void GameGui::LoadGui(BuildingManager& manager)
{
	// more gross allegro config file stuff
	// it might be fine to just hardcode this stuff

	auto buildingMenu = new Gwen::Controls::TabControl(m_canvas.get(), "Buildings");
	buildingMenu->SetBounds(SCREEN_WIDTH - 262 - 150,SCREEN_HEIGHT - 135,262,135);

	auto mapBox = new Gwen::Controls::ImagePanel(m_canvas.get(), "Map");
	mapBox->SetBounds(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 150, 150, 150);

	ALLEGRO_CONFIG *uiConfig = al_load_config_file("ui/building_ui.cfg");

	ALLEGRO_CONFIG_SECTION *iter;
	// this first section is the 'global' section, we ignore it
	const char * cfgSection = al_get_first_config_section(uiConfig, &iter);

	const char * cfgEntry;
	ALLEGRO_CONFIG_ENTRY *eIter;

	// load tab pages from building_ui.cfg
	while(true)
	{
		cfgSection = al_get_next_config_section(&iter);

		// did we pass by the last section in the file?
		if(!cfgSection)
			break;

		auto section = std::string(cfgSection);
		Gwen::Controls::TabButton* resExtractors = buildingMenu->AddPage(section);

		cfgEntry = al_get_first_config_entry(uiConfig, cfgSection, &eIter);
		for(int i = 0; cfgEntry; i++)
		{
			auto entry = std::string(cfgEntry);
			CommandButton* but;
			if (section == "Terraform")
				but = CommandButton::CreateTerraformButton(resExtractors->GetPage());
			else if (section == "Transportation")
				but = CommandButton::CreatePathwayButton(resExtractors->GetPage());
			else
				but = CommandButton::CreateBuildingButton(resExtractors->GetPage(), manager.GetTemplateByName(entry));

			but->SetImage(al_get_config_value(uiConfig, cfgSection, cfgEntry));
			but->SetToolTip(cfgEntry);
			but->SetShouldDrawBackground(false);
			but->SetBounds((i/2) * 50, 0, 50, 50);
			but->onPress.Add(&m_iHandler, &InputHandler::OnBuildingButton);
			if(i%2)
				but->SetPos((i/2) * 50, 52);

			cfgEntry = al_get_next_config_entry(&eIter);
		}
	}

	al_destroy_config(uiConfig);
}
Beispiel #7
0
void InitConfig(void) {
	ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
	al_join_paths(path, data);
	config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	if (!config) config=al_create_config();
	al_destroy_path(path);
	al_destroy_path(data);
}
Beispiel #8
0
void ConfigfileLoadConfig(char *filename)
{
    if (Configfile.config != NULL)
    {
        al_destroy_config(Configfile.config);
        Configfile.config = NULL;
    }
    Configfile.config = al_load_config_file((const char *)filename);
}
Beispiel #9
0
ALLEGRO_CONFIG *
load_config_file (const char *filename)
{
  ALLEGRO_CONFIG *config = al_load_config_file (filename);

  if (! config)
    error (0, 0, "%s (%s): failed to load configuration file",
           __func__, filename);

  return config;
}
Beispiel #10
0
SYMBOL_EXPORT void InitConfig(struct Game* game) {
	const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface();
	al_set_standard_file_interface();
	ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini");
	al_join_paths(path, data);
	game->_priv.config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	if (!game->_priv.config) {
		game->_priv.config = al_create_config();
	}
	al_destroy_path(path);
	al_destroy_path(data);
	al_set_new_file_interface(iface);
}
Beispiel #11
0
list* load_all_generator_data() {
  list *names = list_new();
  ALLEGRO_CONFIG *cfg = al_load_config_file(DATA_PATH); // open config file
  ALLEGRO_CONFIG_SECTION *section = NULL;
  al_get_first_config_section(cfg, &section);
  char const *name = al_get_next_config_section(&section);
  while (name != NULL) {
    load_generator_data(name, cfg);
    list_push(names, strdup(name));
    name = al_get_next_config_section(&section);
  }
  al_destroy_config(cfg);
  return names;
}
Beispiel #12
0
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where cursors are
// supposed to be stored.
MAS::Error MAS::Skin::LoadCursors(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir)) {
      return Error(Error::NO_FILE);
   }

   MAS::Cursor::ReadSkinData(config);

   al_set_path_filename(dir, al_get_path_component(dir, -1));
   al_set_path_extension(dir, ".ini");
   const char *config_path_t = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
   ALLEGRO_CONFIG *mouse_config = al_load_config_file(config_path_t);

   int i;
   char tmp[256];
   char *config_path = strdup(config_path_t);
   int x, y, frames, interval;
   const char *str;

   // Look for each bitmap inside the dat file and load it if it exists
   for (i=0; i<nCursors; i++) {
      al_set_path_filename(dir, cursorName[i]);
      al_set_path_extension(dir, ".png");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Bitmap bmp;
      if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) {
         snprintf(tmp, 256, "%s_FCSX", cursorName[i]);
         x = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FCSY", cursorName[i]);
         y = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FRMS", cursorName[i]);
         frames = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 1;

         snprintf(tmp, 256, "%s_FDUR", cursorName[i]);
         interval = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 20;

         curList[i]->Create(bmp, frames);
         curList[i]->SetFocus(x, y);
         curList[i]->SetAnimationInterval(interval);
      }
   }

   al_set_path_filename(dir, "");
   free(config_path);
   al_destroy_config(mouse_config);

   return Error(Error::NONE);
}
Beispiel #13
0
static mrb_value
config_load_file(mrb_state *mrb, mrb_value self)
{
  char *filename;
  ALLEGRO_CONFIG *cfg;
  struct RData *data;

  mrb_get_args(mrb, "z", &filename);
  cfg = al_load_config_file(filename);
  if (!cfg) {
    mrb_raise(mrb, E_ALLEGRO_ERROR, "could not load config");
  }
  data = mrb_data_object_alloc(mrb, mrb_class_ptr(self), cfg, &mrbal_config_data_type);
  return mrb_obj_value(data);
}
Beispiel #14
0
ship *ship_init(const point start) {
  ALLEGRO_CONFIG *config = al_load_config_file(CONFIG_FILE_PATH);
  if (config != NULL) {
    ship *s = (ship *) malloc(sizeof(ship));
    s->center.x = start.x;
    s->center.y = start.y;
    s->v.dx = 0;
    s->v.dy = 0;
    s->a.ax = SHIP_FORCE;
    s->a.ay = SHIP_FORCE;
    s->direction = velocity_compute_direction(s->v);
    s->speed = velocity_compute_speed(s->v);
    s->bullets = NULL;
    s->bullet_count = 0;
    s->m.movement[UP] = false;
    s->m.movement[DOWN] = false;
    s->m.movement[LEFT] = false;
    s->m.movement[RIGHT] = false;

    const char *bitmap_path = al_get_config_value(config,
                                                  CONFIG_SHIP_SECTION,
                                                  CONFIG_SHIP_BITMAP_KEY);

    s->bitmap = al_load_bitmap(bitmap_path);
    if (!s->bitmap) {
      error_message("fail to load ship bitmap");
      return NULL;
    }

    // ship attributes
    s->attr.lives = SHIP_STARTING_LIVES;
    s->attr.mana = SHIP_MAX_MANA;
    s->attr.level = atoi(al_get_config_value(config,
                                             CONFIG_SHIP_SECTION,
                                             CONFIG_SHIP_LEVEL_KEY));
    s->attr.damage = SHIP_STARTING_DAMAGE;
    s->attr.is_buffed = false;
    s->attr.is_immune = false;
    s->attr.time_stamp = 0;

    al_destroy_config(config);
    return s;
  } else {
    error_message("fail to load ship config file");
    return NULL;
  }
}
Beispiel #15
0
particle_generator get_particle_generator(char *name) {
  list_node *p = data_list->head;
  generator_data *dat = NULL;
  while (p != NULL && strcmp(((generator_data*)p->value)->name, name) != 0) {
    p = p->next; // search for data matching the given name
  }
  if (p == NULL) {                                        // did not find data
    ALLEGRO_CONFIG *cfg = al_load_config_file(DATA_PATH); // open config file
    dat = load_generator_data(name, cfg);                 // load data from file
    list_push(data_list, dat);                            // cache data in list
    al_destroy_config(cfg);
  }
  else { // found data
    dat = (generator_data*)p->value;
  }
  return (particle_generator) {
    .data = dat, .position = {0,0}, .angle = 0, ._spawn_counter = 0
  };
}
Beispiel #16
0
void EngineConfig::load(std::string filename)
{
	if (m_Config != NULL)
	{
		al_destroy_config(m_Config);
	}

	m_Config = al_load_config_file(filename.c_str());

	if (m_Config == NULL)
	{
		THROW_GAME_EXCEPTION(EXCEP_CONFIG_FILE_MISSING);
	}

	loadResolutionWidth();
	loadResolutionHeight();
	loadFullscreen();
	loadFrameSpeed();
}
Beispiel #17
0
bool initialize_allegro(al_defs* al){
  if(!al_init()){
    fprintf(stderr, "[Sokoban] Failed to initialize graphics. \n");
    return 0;
  }
  
  al->conf = al_load_config_file("res/config.ini");
  if(!al->conf){
    al->conf = al_create_config();
    al_save_config_file("res/config.ini", al->conf);
  }

  al->width = atoi(al_get_config_value(al->conf, "window", "width"));
  al->height = atoi(al_get_config_value(al->conf, "window", "height"));
  
  al->disp = al_create_display(al->width, al->height);
  if(!al->disp){
    fprintf(stderr, "[Sokoban] Failed to create display. \n");
    return 0;
  }

  if(!al_init_image_addon()){
    fprintf(stderr, "[Sokoban] Cannot initialize image addon. \n");
    return 0;
  }

  if(!al_install_keyboard()){
    fprintf(stderr, "[Sokoban] Cannot install keyboard. \n");
    return 0;
  }

  al_init_font_addon();
  if(!al_init_ttf_addon()){
    fprintf(stderr, "[Sokoban] Cannot initialize fonts.");
    return 0;
  }

  load_resources(al);

  return 1;
}
Beispiel #18
0
/** loads a skin from disk.
    @param skin skin to load.
    @param filename filename of the skin's config file (UTF-8 string).
    @return the skin or NULL if the skin could not be loaded.
 */
ALGUI_SKIN *algui_load_skin(const char *filename) {
    ALLEGRO_CONFIG *config;
    ALGUI_SKIN *skin;
    
    assert(filename);
    
    //load config
    config = al_load_config_file(filename);
    if (!config) return NULL;
    
    //create a skin
    skin = (ALGUI_SKIN *)al_malloc(sizeof(ALGUI_SKIN));
    assert(skin);
    
    //copy the filename
    skin->filename = al_ustr_new(filename);
    
    //set the config
    skin->config = config;
    
    return skin;
}
Beispiel #19
0
void reset_billiard_balls(billiard_ball *balls)
{
	int i;
	const int key_size = 256;
	char key[key_size];
	ALLEGRO_CONFIG *config = al_load_config_file(BCONFIG_FPATH);

	/* DEBUG */
#ifdef DEBUG
	if(balls == NULL)
	{
		perror("billiard_ball null pointer");
		return;
	}
#endif

	if(!config)
	{
		perror("fail to load billiard_ball.config");
		return;
	}

	for(i = 0 ; i < BALL_COUNT ; i ++)
	{
		balls[i].number = i;
		balls[i].is_on_table = 1;
		balls[i].dx = 0;
		balls[i].dy = 0;

		// prepare the key for reading config file
		memset(key, '\0', key_size);
		sprintf(key, "ball%d", i);

		// read the initial position
		balls[i].cx = atof(al_get_config_value(config, key, "start_x"));
		balls[i].cy = atof(al_get_config_value(config, key, "start_y"));
	}
	al_destroy_config(config);
}
Beispiel #20
0
void ship_reset(ship *s, const size window_size) {
  if (s != NULL) {
    ALLEGRO_CONFIG *config = al_load_config_file(CONFIG_FILE_PATH);
    if (config != NULL) {
      // reset ship attributes
      s->attr.lives = SHIP_STARTING_LIVES;
      s->attr.mana = SHIP_MAX_MANA;
      s->attr.level = atoi(al_get_config_value(config,
                                                CONFIG_SHIP_SECTION,
                                                CONFIG_SHIP_LEVEL_KEY));
      s->attr.damage = SHIP_STARTING_DAMAGE;
      s->attr.is_buffed = false;
      s->attr.is_immune = false;
      s->attr.time_stamp = 0;
      al_destroy_config(config);
    }

    s->center.x = window_size.w / 2;
    s->center.y = window_size.h / 2;
    s->v.dx = 0;
    s->v.dy = 0;
    s->direction = velocity_compute_direction(s->v);
    s->speed = velocity_compute_speed(s->v);

    // destroy bullets
    bullet_destroy(s->bullets);
    s->bullets = NULL;
    s->bullet_count = 0;

    // reset movement
    s->m.movement[UP] = false;
    s->m.movement[DOWN] = false;
    s->m.movement[LEFT] = false;
    s->m.movement[RIGHT] = false;
  } else {
    error_message("ship object null pointer");
  }
}
Beispiel #21
0
int c_engine::init_engine()
{
	if (!al_init())
	{
		error_abort("al_init() - Failed!");
	}

	/// Load the config file
	ALLEGRO_CONFIG *al_config = NULL; 
	al_config = al_load_config_file(m_config_file.c_str());
	if (!al_config)
		error_abort("Couldn't open config file!");
	else 
	{
		std::stringstream ss; 
		const char *value = NULL; 
		value = al_get_config_value(al_config, "Display", "width"); 
		ss << value; 
		ss >> m_display_width; 
		value = al_get_config_value(al_config, "Display", "height");
		ss.clear(); 
		ss << value; 
		ss >> m_display_height;
	}


	/// Initialize the display
	m_al_display = al_create_display(m_display_width, m_display_height);
	if (!m_al_display)
	{
		error_abort("al_create_display() - Failed!"); 
	}
	
	
	return 0; 
}
Beispiel #22
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display;
    ALLEGRO_TIMER *timer;
    ALLEGRO_EVENT_QUEUE *queue;
    int redraw = 0;
    double t = 0;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    open_log_monospace();

    al_init_primitives_addon();
    al_install_mouse();
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_image_addon();
    init_platform_specific();

#ifdef ALLEGRO_IPHONE
    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
#endif
    display = al_create_display(640, 480);
    if (!display) {
        abort_example("Could not create display.\n");
    }
    al_install_keyboard();

    if (argc >= 2) {
        font_file = argv[1];
    }

    ex.f1 = al_load_font(font_file, 48, 0);
    ex.f2 = al_load_font(font_file, 48, ALLEGRO_TTF_NO_KERNING);
    ex.f3 = al_load_font(font_file, 12, 0);
    /* Specifying negative values means we specify the glyph height
     * in pixels, not the usual font size.
     */
    ex.f4 = al_load_font(font_file, -140, 0);
    ex.f5 = al_load_font(font_file, 12, ALLEGRO_TTF_MONOCHROME);

    {
        int ranges[] = {0x1F40A, 0x1F40A};
        ALLEGRO_BITMAP *icon = al_load_bitmap("data/icon.png");
		if (!icon) {
			abort_example("Couldn't load data/icon.png.\n");
		}
        ALLEGRO_BITMAP *glyph = al_create_bitmap(50, 50);
        al_set_target_bitmap(glyph);
        al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));
        al_draw_rectangle(0.5, 0.5, 49.5, 49.5, al_map_rgb_f(1, 1, 0),
         1);
        al_draw_bitmap(icon, 1, 1, 0);
        al_set_target_backbuffer(display);
        ex.f_alex = al_grab_font_from_bitmap(glyph, 1, ranges);
    }

    if (!ex.f1 || !ex.f2 || !ex.f3 || !ex.f4 || !ex.f_alex) {
        abort_example("Could not load font: %s\n", font_file);
    }

    al_set_fallback_font(ex.f3, ex.f_alex);

    ex.ranges_count = al_get_font_ranges(ex.f1, 0, NULL);
    print_ranges(ex.f1);

    ex.config = al_load_config_file("data/ex_ttf.ini");
    if (!ex.config) {
        abort_example("Could not data/ex_ttf.ini\n");
    }

    timer = al_create_timer(1.0 / 60);

    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);
    while (true) {
        ALLEGRO_EVENT event;
        al_wait_for_event(queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            break;
        if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
                event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            break;
        }
        if (event.type == ALLEGRO_EVENT_TIMER)
            redraw++;

        while (redraw > 0 && al_is_event_queue_empty(queue)) {
            double dt;
            redraw--;

            dt = al_get_time();
            render();
            dt = al_get_time() - dt;

            t = 0.99 * t + 0.01 * dt;

            ex.fps = 1.0 / t;
            al_flip_display();
        }
    }

    al_destroy_font(ex.f1);
    al_destroy_font(ex.f2);
    al_destroy_font(ex.f3);
    al_destroy_font(ex.f4);
    al_destroy_font(ex.f5);
    al_destroy_config(ex.config);

    close_log(false);

    return 0;
}
Beispiel #23
0
GAME * game_init ()
{
    if (!al_init ()) {
        fprintf (stderr, "Failed to initialize Allegro.\n");
        return NULL;
    }

    if (!al_init_image_addon ()) {
        fprintf (stderr, "Failed to initialize image addon.\n");
        return NULL;
    }

    if (!al_install_keyboard ()) {
        fprintf (stderr, "Failed to install keyboard.\n");
        return NULL;
    }

    al_init_font_addon ();

    if (!al_init_ttf_addon ()) {
        fprintf (stderr, "Failed to initialize ttf addon.\n");
        return NULL;
    }

    if (!al_init_primitives_addon ()) {
        fprintf (stderr, "Failed to initialize primitives addon.\n");
        return NULL;
    }

    GAME *game = al_malloc (sizeof (GAME));
    if (!game)
        return NULL;

    srand (time (NULL));

    game->running = true;
    game->paused = false;

    game->fullscreen = 1;
    game->windowed = 1;
    game->rrate = 60;
    game->suggest_vsync = 1;
    game->force_vsync = 0;

    game->current_npc = NULL;

    game->screen = screen_new ();

    char *filename;
    const char *str;

    filename = get_resource_path_str ("data/game.ini");
    ALLEGRO_CONFIG *game_config = al_load_config_file (filename);
    al_free (filename);

    str = al_get_config_value (game_config, "", "org");
    al_set_org_name (str);
    str = al_get_config_value (game_config, "", "app");
    al_set_app_name (str);

    ALLEGRO_PATH *settpath = al_get_standard_path (ALLEGRO_USER_SETTINGS_PATH);
    ALLEGRO_PATH *gcpath = al_clone_path (settpath);

    al_set_path_filename (gcpath, "general.ini");
    const char * gcpath_str = al_path_cstr (gcpath, ALLEGRO_NATIVE_PATH_SEP);

    ALLEGRO_CONFIG *gconfig = al_load_config_file (gcpath_str);

    if (!gconfig) {
        gconfig = al_create_config ();
        al_make_directory (al_path_cstr (settpath, ALLEGRO_NATIVE_PATH_SEP));

        set_config_i (gconfig, "display", "width", game->screen.width);
        set_config_i (gconfig, "display", "height", game->screen.height);
        set_config_i (gconfig, "display", "fullscreen", game->fullscreen);
        set_config_i (gconfig, "display", "windowed", game->windowed);
        set_config_i (gconfig, "display", "refreshrate", game->rrate);
        set_config_i (gconfig, "display", "suggest_vsync", game->suggest_vsync);
        set_config_i (gconfig, "display", "force_vsync", game->force_vsync);
    } else {
        get_config_i (gconfig, "display", "width", &game->screen.width);
        get_config_i (gconfig, "display", "height", &game->screen.height);
        get_config_i (gconfig, "display", "fullscreen", &game->fullscreen);
        get_config_i (gconfig, "display", "windowed", &game->windowed);
        get_config_i (gconfig, "display", "refreshrate", &game->rrate);
        get_config_i (gconfig, "display", "suggest_vsync", &game->suggest_vsync);
        get_config_i (gconfig, "display", "force_vsync", &game->force_vsync);
    }

    al_save_config_file (gcpath_str, gconfig);

    al_destroy_path (settpath);
    al_destroy_path (gcpath);
    al_destroy_config (gconfig);

    int flags = 0;

    if (game->fullscreen == game->windowed)
        flags |= ALLEGRO_FULLSCREEN_WINDOW;
    else if (game->fullscreen)
        flags |= ALLEGRO_FULLSCREEN;
    else
        flags |= ALLEGRO_WINDOWED;

    al_set_new_display_option (ALLEGRO_VSYNC, game->suggest_vsync, ALLEGRO_SUGGEST);
    al_set_new_display_option (ALLEGRO_DEPTH_SIZE, 8, ALLEGRO_SUGGEST);

    al_set_new_display_flags (flags);
    al_set_new_display_refresh_rate (game->rrate);
    game->display = al_create_display (game->screen.width, game->screen.height);
    if (!game->display) {
        fprintf (stderr, "Failed to create display.\n");
        al_free (game);
        return NULL;
    }

    al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);

    game->timer = al_create_timer (1.0 / FPS);
    if (!game->timer) {
        fprintf (stderr, "Failed to create timer.\n");
        al_free (game);
        return NULL;
    }

    game->screen.width = al_get_display_width (game->display);
    game->screen.height = al_get_display_height (game->display);
    screen_update_size (&game->screen, game->screen.width, game->screen.height);

    game->rrate = al_get_display_refresh_rate (game->display);

    game->event_queue = al_create_event_queue ();
    if (!game->event_queue) {
        fprintf (stderr, "Failed to create event queue.\n");
        al_free (game);
        return NULL;
    }

    al_register_event_source (game->event_queue, al_get_display_event_source (game->display));
    al_register_event_source (game->event_queue, al_get_timer_event_source (game->timer));

    al_set_render_state (ALLEGRO_ALPHA_FUNCTION, ALLEGRO_RENDER_EQUAL);
    al_set_render_state (ALLEGRO_ALPHA_TEST_VALUE, 1);

    filename = get_resource_path_str ("data/sprites.ini");
    game->sprites = sprite_load_sprites (filename);
    al_free (filename);

    filename = get_resource_path_str ("data/scenes.ini");
    game->scenes = scene_load_file (filename);
    scene_load_scenes (game->scenes, game->sprites);
    al_free (filename);

    str = al_get_config_value (game_config, "", "scene");
    game->current_scene = scene_get (game->scenes, str);

    str = al_get_config_value (game_config, "", "actor");
    game->current_actor = sprite_new_actor (game->sprites, str);
    str = al_get_config_value (game_config, "", "portal");
    SCENE_PORTAL *portal = scene_get_portal (game->scenes, str);

    al_destroy_config (game_config);

    filename = get_resource_path_str ("data/ui.ini");
    game->ui = ui_load_file (filename);
    al_free (filename);

    sprite_center (game->current_actor, &portal->position);
    screen_center (&game->screen, portal->position, game->current_scene->map);

    return game;
}
Beispiel #24
0
void _al_raspberrypi_get_screen_info(int *dx, int *dy,
                                     int *screen_width, int *screen_height)
{
    graphics_get_display_size(0 /* LCD */, (uint32_t *)screen_width, (uint32_t *)screen_height);

    /* On TV-out the visible area (area used by X and console)
     * is different from that reported by the bcm functions. We
     * have to 1) read fbwidth and fbheight from /proc/cmdline
     * and also overscan parameters from /boot/config.txt so our
     * displays are the same size and overlap perfectly.
     */
    *dx = 0;
    *dy = 0;
    FILE *cmdline = fopen("/proc/cmdline", "r");
    if (cmdline) {
        char line[1000];
        int i;
        for (i = 0; i < 999; i++) {
            int c = fgetc(cmdline);
            if (c == EOF) break;
            line[i] = c;
        }
        line[i] = 0;
        const char *p = strstr(line, "fbwidth=");
        if (p) {
            const char *p2 = strstr(line, "fbheight=");
            if (p2) {
                p += strlen("fbwidth=");
                p2 += strlen("fbheight=");
                int w = atoi(p);
                int h = atoi(p2);
                ALLEGRO_CONFIG *cfg = al_load_config_file("/boot/config.txt");
                if (cfg) {
                    const char *disable_overscan =
                        al_get_config_value(
                            cfg, "", "disable_overscan"
                        );
                    // If overscan parameters are disabled don't process
                    if (!disable_overscan ||
                            (disable_overscan &&
                             (!strcasecmp(disable_overscan, "false") ||
                              atoi(disable_overscan) == 0))) {
                        const char *left = al_get_config_value(
                                               cfg, "", "overscan_left");
                        const char *right = al_get_config_value(
                                                cfg, "", "overscan_right");
                        const char *top = al_get_config_value(
                                              cfg, "", "overscan_top");
                        const char *bottom = al_get_config_value(
                                                 cfg, "", "overscan_bottom");
                        int xx = left ? atoi(left) : 0;
                        xx -= right ? atoi(right) : 0;
                        int yy = top ? atoi(top) : 0;
                        yy -= bottom ? atoi(bottom) : 0;
                        *dx = (*screen_width - w + xx) / 2;
                        *dy = (*screen_height - h + yy) / 2;
                        *screen_width = w;
                        *screen_height = h;
                    }
                    else {
                        *dx = (*screen_width - w) / 2;
                        *dy = (*screen_height - h) / 2;
                        *screen_width = w;
                        *screen_height = h;
                    }
                    al_destroy_config(cfg);
                }
                else {
                    printf("Couldn't open /boot/config.txt\n");
                }
            }
        }
        fclose(cmdline);
    }
}
Beispiel #25
0
ALLEGRO_CONFIG *carregar_configuracao(const char *name) {
	return al_load_config_file(name);
}
Beispiel #26
0
////////////////////////////////////////////////////////////////////////////////
// Loads and processes the skin description file which is in fact a regular
// Allegro configuration file
MAS::Error MAS::Skin::Load(const char *file) {
   int i = 0;
   lastError = MAS::Error(MAS::Error::NONE);
   ALLEGRO_CONFIG *config;
   const char *str;
   ALLEGRO_PATH *sdp;

   if (!file) {
      lastError =  MAS::Error(MAS::Error::SKIN_INI);
      return lastError;
   }

   // Try to open the skin description file
   sdp = al_create_path(file);
   if (!al_is_path_present(sdp)) {
      al_destroy_path(sdp);
      lastError = MAS::Error(MAS::Error::SKIN_INI);
      return lastError;
   }

   config = al_load_config_file(file);

   if (skinFilePath != file) {
      delete [] skinFilePath;
      skinFilePath = new char[1+strlen(file)];
      strcpy(skinFilePath, file);
   }

   Reset();

   // Get the path to the skin configuration file (drop the filename)
   al_set_path_filename(sdp, "");

   ////////////////////////////////////////////////////////////////////////////////
   // Read the name of the dir and load the bitmap data
   bool default_bitmaps = false;

   str = al_get_config_value(config, "Skin", "main_data");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadData(sdp, config);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }
   else {
      default_bitmaps = true;
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the default colors
#define GET_COLOR_STR(val, def) ((str = al_get_config_value(config, "COLORS", val)) ? str : def)
   c_face     = MAS::Color(GET_COLOR_STR("face",     "210,210,210"));
   c_font     = MAS::Color(GET_COLOR_STR("fontface", " 16, 16, 16"));
   c_shad1    = MAS::Color(GET_COLOR_STR("shad1",    "255,255,255"));
   c_shad2    = MAS::Color(GET_COLOR_STR("shad2",    " 80, 80, 80"));
   c_disable  = MAS::Color(GET_COLOR_STR("disable",  "128,128,128"));
   c_select   = MAS::Color(GET_COLOR_STR("select",   "128,192,128"));
   c_deselect = MAS::Color(GET_COLOR_STR("deselect", "224,224,224"));
   c_focus    = MAS::Color(GET_COLOR_STR("focus",    "128,192,128"));
   c_sunken   = MAS::Color(GET_COLOR_STR("sunken",   "232,232,232"));
   c_back     = MAS::Color(GET_COLOR_STR("back",     "180,180,180"));
#undef GET_COLOR_STR

   if (default_bitmaps) {
      GenerateDefaultBitmaps();
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the cursors from another datafile
   str = al_get_config_value(config, "Skin", "cursors");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadCursors(sdp, config);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the samples from another datafile
   str = al_get_config_value(config, "Skin", "sounds");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadSamples(sdp);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }

#define GET_CONFIG_STR(section, key, def) \
   (str = al_get_config_value(config, section, key)) ? strtol(str, NULL, 10) : def

   ////////////////////////////////////////////////////////////////////////////////
   // Now load the fonts
   const char *fonts[] = { "FONT0", "FONT1", "FONT2", "FONT3",
                           "FONT4", "FONT5", "FONT6", "FONT7" };
   const char *ttfont;
   int size;
   for (i=0; i<nFonts; i++)   {
      size = GET_CONFIG_STR(fonts[i], "size", 10);
      ttfont = al_get_config_value(config, fonts[i], "file");   // the filename of the font
      al_set_path_filename(sdp, ttfont);
	  const char *filename = al_path_cstr(sdp, ALLEGRO_NATIVE_PATH_SEP);
      fntList[i]->Load(filename, size, false);
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the object specific data:
   //----------------------------------------------
   const char *fnames[] = { "font1", "font2", "font3", "font4" };
   const char *cnames[] = { "f_col1", "f_col2", "f_col3", "f_col4" };
   const char *snames[] = { "s_col1", "s_col2", "s_col3", "s_col4" };
   const char *def_col[] = { "0,0,0", "0,0,0", "128,128,128", "0,0,0" };
   const char *def_shd[] = { "-1", "-1", "-1", "-1" };

   // button, checkbox, radio button, etc.
   const char *info_name[] = {
      "BOX",
      "BUTTON",
      "CHECKBOX",
      "RADIO",
      "LIST",
      "WINDOW",
      "MENU",
      "TEXT",
      "EDITBOX",
      "PROGRESS",
      "HYPER",
      "TAB",
      "TOOLTIP"
   };

   for (int j=0; j<nInfoItems; j++)   {
      for (i=0; i<4; i++)   {
         fnt[j][i] = GET_CONFIG_STR(info_name[i], fnames[i], 10);
         fcol[j][i] = Color((str = al_get_config_value(config, info_name[j], cnames[i])) ? str : def_col[i]);
         scol[j][i] = Color((str = al_get_config_value(config, info_name[j], snames[i])) ? str : def_shd[i]);
      }
   }

   // wallpaper style
   wallpaperStyle = GET_CONFIG_STR("WALLPAPER", "style", 3);

   // buttons animation
   buttonDisplacement    = GET_CONFIG_STR("BUTTON", "displacement", 1);
   buttonAnimationType   = GET_CONFIG_STR("BUTTON", "animationType", 0);
   buttonAnimationLength = GET_CONFIG_STR("BUTTON", "animationLength", 0);

   // group box info
   boxX =      GET_CONFIG_STR("BOX", "offX", 6);
   boxY =      GET_CONFIG_STR("BOX", "offY", 1);
   boxAlign =  GET_CONFIG_STR("BOX", "alignment", 0);
   boxBack =   (str = al_get_config_value(config, "BOX", "backColor")) ? str : "222,222,222";

   // window
   winTextPos.x(  GET_CONFIG_STR("WINDOW", "textX", 10));
   winTextPos.y(  GET_CONFIG_STR("WINDOW", "textY", 18));
   winTextAlign = GET_CONFIG_STR("WINDOW", "alignment", 0);
   winTextBack  = GET_CONFIG_STR("WINDOW", "textBack", 0);
   winExitPos.x(  GET_CONFIG_STR("WINDOW", "exitX", -22));
   winExitPos.y(  GET_CONFIG_STR("WINDOW", "exitY", 6));
   winMaxPos.x(   GET_CONFIG_STR("WINDOW", "manX", -40));
   winMaxPos.y(   GET_CONFIG_STR("WINDOW", "manY", 6));
   winMinPos.x(   GET_CONFIG_STR("WINDOW", "minX", -56));
   winMinPos.y(   GET_CONFIG_STR("WINDOW", "minY", 6));
   winAnimationType = GET_CONFIG_STR("WINDOW", "animationType", 0);
   winAnimationLength = GET_CONFIG_STR("WINDOW", "animationLength", 0);

   // combo box
   comboAnimationType = GET_CONFIG_STR("COMBOBOX", "animationType", 0);
   comboAnimationLength = GET_CONFIG_STR("COMBOBOX", "animationLength", 0);

   // menu
   menuHeight = GET_CONFIG_STR("MENU", "height", 16);
   menuDelay =  GET_CONFIG_STR("MENU", "delay", 300);
   menuAnimationType = GET_CONFIG_STR("MENU", "animationType", 0);
   menuAnimationLength = GET_CONFIG_STR("MENU", "animationLength", 0);

   // tooltip info
   tooltipAnimationType =   GET_CONFIG_STR("TOOLTIP", "animationType", 0);
   tooltipAnimationLength = GET_CONFIG_STR("TOOLTIP", "animationLength", 0);
   tooltipBack = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "255,255,192");
   tooltipBorder = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "0,0,0");

   // dialog popup animation
   // ...

   // should the GUI draw dotted rectangles?
   drawDots = (str = al_get_config_value(config, "Skin", "dottedRect")) ? *str != '0' : false;

   // how the focus follows the mouse
   focus = GET_CONFIG_STR("Skin", "focus", 1);

#undef GET_CONFIG_STR

   al_destroy_path(sdp);

   return MAS::Error(MAS::Error::NONE);
}
Beispiel #27
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_TIMER *timer;
   ALLEGRO_EVENT_QUEUE *queue;
   int redraw = 0, i;
   bool quit = false;

   if (!al_init()) {
      abort_example("Could not initialise Allegro\n");
      return 1;
   }
   al_init_primitives_addon();
   al_install_mouse();
   al_init_image_addon();
   al_init_font_addon();
   al_init_ttf_addon();
   srand(time(NULL));

   white = al_map_rgba_f(1, 1, 1, 1);

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Could not create display\n");
      return 1;
   }
   al_set_window_title(display, "Allegro Logo Generator");
   al_install_keyboard();

   /* Read logo parameters from logo.ini (if it exists). */
   config = al_load_config_file("logo.ini");
   if (!config)
      config = al_create_config();
   for (i = 0; param_names[i]; i++) {
      char const *value = al_get_config_value(config, "logo", param_names[i]);
      if (value)
         strncpy(param_values[i], value, sizeof(param_values[i]));
   }

   font = al_load_font("data/DejaVuSans.ttf", 12, 0);
   if (!font) {
      abort_example("Could not load font\n");
      return 1;
   }

   timer = al_create_timer(1.0 / 60);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_mouse_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_timer_event_source(timer));

   al_start_timer(timer);
   while (!quit) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
         break;
      if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
         if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            quit = true;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_ENTER) {
            if (editing) {
               regenerate = true;
               editing = false;
            }
            else {
               cursor = 0;
               editing = true;
            }
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_UP) {
            if (selection > 0) {
               selection--;
               cursor = 0;
               editing = false;
            }
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) {
            if (param_names[selection + 1]) {
               selection++;
               cursor = 0;
               editing = false;
            }
         }
         else {
            int c = event.keyboard.unichar;
            if (editing) {
               if (c >= 32) {
                  ALLEGRO_USTR *u = al_ustr_new(param_values[selection]);
                  al_ustr_set_chr(u, cursor, c);
                  cursor++;
                  al_ustr_set_chr(u, cursor, 0);
                  strncpy(param_values[selection], al_cstr(u),
                     sizeof param_values[selection]);
                  al_ustr_free(u);
               }
            }
            else {
               if (c == 'r')
                  randomize();
               if (c == 's')
                  save();
            }
         }
      }
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         if (event.mouse.button == 1) {
            mouse_click(event.mouse.x, event.mouse.y);
         }
      }
      if (event.type == ALLEGRO_EVENT_TIMER)
         redraw++;

      if (redraw && al_is_event_queue_empty(queue)) {
         redraw = 0;

         render();

         al_flip_display();
      }
   }

   /* Write modified parameters back to logo.ini. */
   for (i = 0; param_names[i]; i++) {
      al_set_config_value(config, "logo", param_names[i],
         param_values[i]);
   }
   al_save_config_file("logo.ini", config);
   al_destroy_config(config);

   return 0;
}
Beispiel #28
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_FONT *font;
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT_QUEUE *queue;
   bool write = false;
   bool flip = false;
   bool quit;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_init_font_addon();
   al_init_image_addon();
   al_install_keyboard();
   al_install_mouse();

   /* Read parameters from ex_vsync.ini. */
   config = al_load_config_file("ex_vsync.ini");
   if (!config) {
      config = al_create_config();
      write = true;
   }

   /* 0 -> Driver chooses.
    * 1 -> Force vsync on.
    * 2 -> Force vsync off.
    */
   vsync = option(config, "vsync", 0);

   fullscreen = option(config, "fullscreen", 0);
   frequency = option(config, "frequency", 0);

   /* Write the file back (so a template is generated on first run). */
   if (write) {
      al_save_config_file("ex_vsync.ini", config);
   }
   al_destroy_config(config);

   /* Vsync 1 means force on, 2 means forced off. */
   if (vsync)
      al_set_new_display_option(ALLEGRO_VSYNC, vsync, ALLEGRO_SUGGEST);
   
   /* Force fullscreen mode. */
   if (fullscreen) {
      al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
      /* Set a monitor frequency. */
      if (frequency)
         al_set_new_display_refresh_rate(frequency);
   }

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display.\n");
   }

   font = al_load_font("data/a4_font.tga", 0, 0);
   if (!font) {
      abort_example("Failed to load a4_font.tga\n");
   }

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_mouse_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   quit = display_warning(queue, font);
   al_flush_event_queue(queue);

   while (!quit) {
      ALLEGRO_EVENT event;

      /* With vsync, this will appear as a 50% gray screen (maybe
       * flickering a bit depending on monitor frequency).
       * Without vsync, there will be black/white shearing all over.
       */
      if (flip)
         al_clear_to_color(al_map_rgb_f(1, 1, 1));
      else
         al_clear_to_color(al_map_rgb_f(0, 0, 0));
      
      al_flip_display();

      flip = !flip;

      while (al_get_next_event(queue, &event)) {
         switch (event.type) {
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
               quit = true;

            case ALLEGRO_EVENT_KEY_DOWN:
               if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                  quit = true;
         }
      }
      /* Let's not go overboard and limit flipping at 1000 Hz. Without
       * this my system locks up and requires a hard reboot :P
       */
      al_rest(0.001);
   }

   al_destroy_font(font);
   al_destroy_event_queue(queue);  

   return 0;
}
Beispiel #29
0
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_TIMER *timer;
   ALLEGRO_CONFIG *config;
   char const *value;
   char str[256];

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   
   al_init_primitives_addon();
   al_install_keyboard();
   al_install_mouse();
   al_init_image_addon();
   al_init_font_addon();
   init_platform_specific();

   /* Read supersampling info from ex_draw.ini. */
   ex.samples = 0;
   config = al_load_config_file("ex_draw.ini");
   if (!config)
      config = al_create_config();
   value = al_get_config_value(config, "settings", "samples");
   if (value)
      ex.samples = strtol(value, NULL, 0);
   sprintf(str, "%d", ex.samples);
   al_set_config_value(config, "settings", "samples", str);
   al_save_config_file("ex_draw.ini", config);
   al_destroy_config(config);

   if (ex.samples) {
      al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
      al_set_new_display_option(ALLEGRO_SAMPLES, ex.samples, ALLEGRO_SUGGEST);
   }
   display = al_create_display(640, 640);
   if (!display) {
      abort_example("Unable to create display.\n");
   }

   init();

   timer = al_create_timer(1.0 / ex.FPS);

   ex.queue = al_create_event_queue();
   al_register_event_source(ex.queue, al_get_keyboard_event_source());
   al_register_event_source(ex.queue, al_get_mouse_event_source());
   al_register_event_source(ex.queue, al_get_display_event_source(display));
   al_register_event_source(ex.queue, al_get_timer_event_source(timer));

   al_start_timer(timer);
   run();

   al_destroy_event_queue(ex.queue);  

   return 0;
}
Beispiel #30
0
int main(int argc, char* argv [])
{
    al_init();
    al_init_primitives_addon();
    al_install_keyboard();
    al_init_image_addon();

	ALLEGRO_CONFIG *configFile = al_load_config_file("data/config/config.ini");
	if (configFile == NULL)
	{
		al_show_native_message_box(NULL, "A fatal error has ocurred!",
			"The configuration file has not been found!", 
			"Be sure to always have a valid conf.ini in /data/config/ for the program to work...", "Understood", ALLEGRO_MESSAGEBOX_ERROR);
		return 0;
	}

	std::string dispW = al_get_config_value(configFile, "DISPLAY", "RESX");
	std::string dispH = al_get_config_value(configFile, "DISPLAY", "RESY");
	std::string fullscreenMode = al_get_config_value(configFile, "DISPLAY", "FULLSCREEN");

	int iDispW = stoi(dispW);
	int iDispH = stoi(dispH);
	bool bfullscreenMode = stoi(fullscreenMode);

	assert(iDispW < 5000 && iDispW > 0);
	assert(iDispH < 5000 && iDispH > 0);

	if (bfullscreenMode == true)
		al_set_new_display_flags(ALLEGRO_FULLSCREEN);

	ALLEGRO_DISPLAY *display = al_create_display(iDispW, iDispH);
	if (display == NULL)
	{
		al_show_native_message_box(NULL, "A fatal error has ocurred!",
			"Display creation failed!",
			"The resolution selected is not supported by your screen/video card...", "Understood", ALLEGRO_MESSAGEBOX_ERROR);
		return 0;
	}

    al_clear_to_color(al_map_rgb(255, 0, 0));
    al_flip_display();

    bool done = false;
    bool redraw = false;

    ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60.0);

    ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();

    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    //**********************
    ALLEGRO_BITMAP *test = al_load_bitmap("data/background.png");

    int x = 320, y = 240;

	Vec2D size(40.0f, 40.0f);

	TestObject gameObject(Vec2D(10.0f, 10.0f));
	gameObject.AddComponent(new RenderComponent());
    gameObject.AddComponent(new PhysicsComponent(size, size, size, true));
    //*********************

    al_start_timer(timer);

	//newManager.AddComponent(new PhysicsComponent(Vec2D(), Vec2D(), Vec2D(5.0f, 10.0f), false));

    while (!done)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(queue, &ev);

        switch (ev.type)
        {
            case ALLEGRO_EVENT_TIMER:
                redraw = true;
                gameObject.Update();
                break;
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                done = true;
                break;
            case ALLEGRO_EVENT_KEY_DOWN:
                if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                {
                    done = true;
                }
                //************
                else
                {
					// NOTHING
                }
                //************
                break;
            default:
                break;
        }

        if (redraw && al_is_event_queue_empty(queue))
        {
            redraw = false;

            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_bitmap(test, 0, 0, NULL);

			//PhysicsComponent *test = (PhysicsComponent*) newManager.GetComponentByType(COMP_PHYSICS);
			//Vec2D pos = test->GetPosition();

            al_draw_filled_circle(x, y, 89, al_map_rgb(255, 0, 255));

            al_flip_display();
        }
    }

	al_destroy_config(configFile);
    al_destroy_display(display);
    al_destroy_event_queue(queue);
    al_destroy_timer(timer);
}