Esempio n. 1
0
char* GetDataFilePath(char* filename) {

	char *result = 0;

	if (al_filename_exists(filename)) {
		return strdup(filename);
	}

	char origfn[255] = "data/";
	strcat(origfn, filename);

	if (al_filename_exists(origfn)) {
		return strdup(origfn);
	}

	void TestPath(char* subpath) {
		ALLEGRO_PATH *tail = al_create_path(filename);
		ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
		ALLEGRO_PATH *data = al_create_path(subpath);
		al_join_paths(path, data);
		al_join_paths(path, tail);
		//printf("Testing for %s\n", al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
		if (al_filename_exists(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP))) {
			result = strdup(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
		}
		al_destroy_path(tail);
		al_destroy_path(data);
		al_destroy_path(path);
	}
Esempio n. 2
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);
}
Esempio n. 3
0
bool Windows::LoadProfile()
{
#ifdef WIN32
	char szPath[MAX_PATH];
	ALLEGRO_PATH* alPath;
	bool res;

	if( al_filename_exists( "c4a-prof" ) )
		return ParseProfileFile( "c4a-prof" );

	if( SHGetFolderPathA( 0, CSIDL_PERSONAL, 0, 0, (char*)&szPath ) == S_OK )
	{
		alPath = al_create_path( (char*)&szPath );
		al_append_path_component( alPath, "c4a-prof" );

		if( al_filename_exists( al_path_cstr( alPath, '/' ) ) )
			res = ParseProfileFile( (char*)al_path_cstr( alPath, '/' ) );

		al_destroy_path( alPath );
		return res;
	}
	return false;

#else
	return false;
#endif
}
Esempio n. 4
0
void DeinitConfig(void) {
	ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
	al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	al_join_paths(path, data);
	al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), config);
	al_destroy_path(path);
	al_destroy_path(data);
	al_destroy_config(config);
}
Esempio n. 5
0
SYMBOL_EXPORT void DeinitConfig(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_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	al_join_paths(path, data);
	al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), game->_priv.config);
	al_destroy_path(path);
	al_destroy_path(data);
	al_destroy_config(game->_priv.config);
	al_set_new_file_interface(iface);
}
Esempio n. 6
0
/*
 * Calling LoadLibrary with a relative file name is a security risk:
 * see e.g. Microsoft Security Advisory (2269637)
 * "Insecure Library Loading Could Allow Remote Code Execution"
 */
HMODULE _al_win_safe_load_library(const char *filename)
{
    ALLEGRO_PATH *path1 = NULL;
    ALLEGRO_PATH *path2 = NULL;
    char buf[MAX_PATH];
    const char *other_dirs[3];
    HMODULE lib = NULL;
    bool msvc_only = false;

    /* MSVC only: if the executable is in the build configuration directory,
     * which is also just under the current directory, then also try to load the
     * library from the current directory.  This leads to less surprises when
     * running example programs.
     */
#if defined(ALLEGRO_MSVC)
    msvc_only = true;
#endif

    /* Try to load the library from the directory containing the running
     * executable, the Windows system directories, or directories on the PATH.
     * Do NOT try to load the library from the current directory.
     */

    if (al_is_system_installed()) {
        path1 = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    }
    else if (GetModuleFileName(NULL, buf, sizeof(buf)) < sizeof(buf)) {
        path1 = al_create_path(buf);
    }
    if (msvc_only) {
        path2 = maybe_parent_dir(path1);
    }

    other_dirs[0] = path1 ? al_path_cstr(path1, '\\') : NULL;
    other_dirs[1] = path2 ? al_path_cstr(path2, '\\') : NULL;
    other_dirs[2] = NULL; /* sentinel */

    _al_sane_strncpy(buf, filename, sizeof(buf));
    if (PathFindOnPath(buf, other_dirs)) {
        ALLEGRO_DEBUG("PathFindOnPath found: %s\n", buf);
        lib = load_library_at_path(buf);
    }
    else {
        ALLEGRO_WARN("PathFindOnPath failed to find %s\n", filename);
    }

    al_destroy_path(path1);
    al_destroy_path(path2);

    return lib;
}
Esempio n. 7
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);
}
Esempio n. 8
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();
}
Esempio n. 9
0
void SoundInterface::commandPlaySound(void) {
	int32_t freg = cb->popValue().toInt();
	float balance = cb->popValue().toFloat();
	float volume = cb->popValue().toFloat();
	Any any = cb->popValue();
	
	// If passed parameter is integer, the sound is preloaded. Otherwise load it.
	if (any.type() == Any::Int) {
		CBChannel* channel = new CBChannel;
		channel->setMixer(al_get_default_mixer());
		int32_t id = any.toInt();
		channel->playSound((*sounds[id]), volume, balance, freg);
		int32_t nextChannel = nextChannelId();
		channels[nextChannel] = channel;
	}
	else {
		CBChannel* channel = new CBChannel;
		channel->setMixer(al_get_default_mixer());
		ALLEGRO_PATH *path = any.toString().getPath();
		const char *cpath = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
		channel->playSound(cpath, volume, balance, freg);
		int32_t nextChannel = nextChannelId();
		channels[nextChannel] = channel;
	}
}
Esempio n. 10
0
/** Creates filedialog and returns filepath(s) on succes, empty string on failure.*/
void cbeFileDialog(CBEnchanted * cb) {
	int mode = cb->popValue().getInt();
	string patterns = cb->popValue().toString().getRef();
#ifdef _WIN32
	string title = cb->popValue().toString().getRef();
#else
	string title = cb->popValue().toString().getUtf8Encoded();
#endif
	ALLEGRO_PATH * path = cb->popValue().toString().getPath();

	ALLEGRO_FILECHOOSER * fC = al_create_native_file_dialog(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), title.c_str(), patterns.c_str(), mode);
	al_destroy_path(path);

	if(fC == NULL) {
		cb->errors->createError("Can't create FileDialog!");
		cb->pushValue(0);
		return;
	}
	bool retVal = al_show_native_file_dialog(cb->gfxInterface->getWindow(), fC);

	if(retVal) {
		string filePaths = "";
		for(int count = 0; count < al_get_native_file_dialog_count(fC); count++) {
			filePaths += string(al_get_native_file_dialog_path(fC, count)) + string("|");
		}
		cb->pushValue(filePaths.substr(0, filePaths.length()-1));
	} else {
		cb->pushValue(string(""));
	}

	al_destroy_native_file_dialog(fC);

}
Esempio n. 11
0
bool Message::Init()
{
	ALLEGRO_PATH * pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
	al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Avatar");

    for (int i=0;i<7;i++)
	{
		char szFileName[255];
		sprintf(szFileName,"av%03d.png",i);
		al_set_path_filename(pPath,szFileName);
        ALLEGRO_BITMAP * pBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	    if (pBitmap!=NULL)
	    {
	        g_lstAvatar.push_back(pBitmap);
	    }
	    else
	    {
            al_destroy_path(pPath);
            return false;
	    }
	}

	al_destroy_path(pPath);
	return true;
}
Esempio n. 12
0
File: main.c Progetto: beoran/eruta
/* Testing function for al_get_standard_path */
void puts_standard_path(int path, char * name) {
  ALLEGRO_PATH * testpath;
  testpath =  al_get_standard_path(path);
  puts(name);
  puts(al_path_cstr(testpath, ALLEGRO_NATIVE_PATH_SEP));
  al_destroy_path(testpath);
}
Esempio n. 13
0
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where bitmaps are
// supposed to be stored.
MAS::Error MAS::Skin::LoadData(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir) || !al_get_path_filename(dir)) {
      return Error(Error::SKIN_DAT);
   }

   // load the datafile
   int i;
   char tmp[256];
   const char *str;

   // Look for each bitmap inside and load it if it exists
   for (i=0; i<nBitmaps; i++) {
      al_set_path_filename(dir, bitmapName[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) {
         bmpList[i]->Set(bmp, true, MAS::Settings::useVideoMemory ? Bitmap::VIDEO : Bitmap::MEMORY);

         snprintf(tmp, 256, "%s_TCKX", bitmapName[i]);
         bmpList[i]->ThickX((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
         snprintf(tmp, 256, "%s_TCKY", bitmapName[i]);
         bmpList[i]->ThickY((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
      }
   }

   al_set_path_filename(dir, "");

   return Error(Error::NONE);
}
Esempio n. 14
0
const char* getResource(const char* fmt, ...)
{
   va_list ap;
   static char res[512];
   static ALLEGRO_PATH *dir;
   static ALLEGRO_PATH *path;

   va_start(ap, fmt);
   memset(res, 0, 512);
   snprintf(res, 511, fmt, ap);

   if (!dir) {
      dir = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
#ifdef ALLEGRO_MSVC
      {
         /* Hack to cope automatically with MSVC workspaces. */
         const char *last = al_get_path_component(dir, -1);
         if (0 == strcmp(last, "Debug")
            || 0 == strcmp(last, "RelWithDebInfo")
            || 0 == strcmp(last, "Release")
            || 0 == strcmp(last, "Profile")) {
            al_remove_path_component(dir, -1);
         }
      }
#endif
      al_append_path_component(dir, "data");
   }

   if (path)
      al_destroy_path(path);

   path = al_create_path(res);
   al_rebase_path(dir, path);
   return al_path_cstr(path, '/');
}
Esempio n. 15
0
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where samples are
// supposed to be stored.
MAS::Error MAS::Skin::LoadSamples(ALLEGRO_PATH *dir) {
   if (!dir || !al_is_path_present(dir))
      return Error(Error::NO_FILE);

   int i;

   const char *sampleName[] = {
      "SAMPLE_ACTIVATE",
      "SAMPLE_CLOSE",
      "SAMPLE_GOTFOCUS",
      "SAMPLE_KEY",
      "SAMPLE_LOSTFOCUS",
      "SAMPLE_OPEN",
      "SAMPLE_SCROLL"
   };

   // Look for each sample inside the dat file and load it if it exists
   for (i=0; i<nSamples; i++) {
      al_set_path_filename(dir, sampleName[i]);
	  al_set_path_extension(dir, ".wav");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Sample spl;
      if (spl.Load(fullPath) == Error::NONE) {
         smpList[i]->Set(spl, true);
      }
   }

   al_set_path_filename(dir, "");

   return Error(Error::NONE);
}
static ALLEGRO_PATH *follow_symlinks(ALLEGRO_PATH *path)
{
   for (;;) {
      const char *path_str = al_path_cstr(path, '/');
      char buf[PATH_MAX];
      int len;

      len = readlink(path_str, buf, sizeof(buf) - 1);
      if (len <= 0)
         break;
      buf[len] = '\0';
      al_destroy_path(path);
      path = al_create_path(buf);
   }

   /* Make absolute path. */
   {
      const char *cwd = al_get_current_directory();
      ALLEGRO_PATH *cwd_path = al_create_path_for_directory(cwd);
      if (al_rebase_path(cwd_path, path))
         al_make_path_canonical(path);
      al_destroy_path(cwd_path);
      al_free((void *) cwd);
   }

   return path;
}
Esempio n. 17
0
SlotManager::SlotManager(bool a_blLoading,  ALLEGRO_PATH * a_pSearchpath,void (* a_pCallBack)(string))

{
    m_ColorInner     = al_map_rgb(0,0,0);
    m_ColorOuter     = al_map_rgb(100,100,255);
    m_ColorHighlight = al_map_rgb(0,0,255);
    m_pActiveSlot    = NULL;
    m_blLoading      = a_blLoading;
    m_pCallBack      = a_pCallBack;
    m_nIndex         = 1;

    if (a_pSearchpath!=NULL)
    {
        ALLEGRO_FS_ENTRY * pDir = al_create_fs_entry(al_path_cstr(a_pSearchpath,ALLEGRO_NATIVE_PATH_SEP));
        if (al_open_directory(pDir))
        {
            ALLEGRO_FS_ENTRY * pFile;
            while (pFile = al_read_directory(pDir))
            {
                ALLEGRO_PATH * pPath = al_create_path(al_get_fs_entry_name(pFile));

                AddSlot(al_get_path_basename(pPath));

                al_destroy_path(pPath);
                al_destroy_fs_entry(pFile);
            }
        }
        al_destroy_fs_entry(pDir);
    }

    if (!a_blLoading)
    {
        AddSlot("NEW SAVE...");
    }
}
Esempio n. 18
0
File: path.c Progetto: trezker/allua
static int allua_Path_get_string(lua_State * L)
{
   ALLUA_path path = allua_check_path(L, 1);
   lua_pushstring(L, al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));

   return 1;
}
Esempio n. 19
0
s_sprite c_tile::get_from_ini(ALLEGRO_CONFIG *config, const char * section, ALLEGRO_PATH * base_path)
{
    s_sprite temp;

    const char * buffer_file = al_get_config_value(config, section, "image_file");
    if(!buffer_file)
    {
        temp.index = -1;
        return temp;
    }
    ALLEGRO_PATH * imagepath = al_create_path(buffer_file);
    al_rebase_path(base_path, imagepath);
    temp.index = imagelist.load_image(al_path_cstr(imagepath, ALLEGRO_NATIVE_PATH_SEP));

    temp.x = get_config_int(config, section, "x");
    temp.y = get_config_int(config, section, "y");

    temp.width = get_config_int(config, section, "width");
    temp.height = get_config_int(config, section, "height");

    temp.origin_x = get_config_int(config, section, "origin_x");
    temp.origin_y = get_config_int(config, section, "origin_y");

    temp.origin_x = 0 - temp.origin_x;
    temp.origin_y = 0 - temp.origin_y;

    temp.palette_number = get_config_int(config, section, "palette_index");

    temp.column_height = get_config_int(config, section, "column_height");

    const char * color_selection = al_get_config_value(config, section, "color_source");
    if(color_selection)
        temp.color_by = get_color_selector(color_selection);

    const char * pal_source = al_get_config_value(config, section, "palette_source");
    if(pal_source)
        temp.color_source = get_color_source(pal_source);

    const char * color = al_get_config_value(config, section, "color_html");
    if(color)
        temp.color = color_html(color);

    const char * off = al_get_config_value(config, section, "offset_type");
    if(off)
        temp.offset_type = get_offset_type(off);

    const char * neigh = al_get_config_value(config, section, "border_terrain");
    if(neigh)
        temp.border_terrain = get_terrain_type(neigh);

    const char * neighbobj = al_get_config_value(config, section, "border_structure");
    if(neighbobj)
        temp.border_structure = get_structure_type(neighbobj);

    temp.offset_amount = get_config_int(config, section, "offset_amount");

    al_destroy_path(imagepath);
    return temp;
}
Esempio n. 20
0
/* Function: al_get_native_file_dialog_path
 */
const char *al_get_native_file_dialog_path(
   const ALLEGRO_FILECHOOSER *dialog, size_t i)
{
   const ALLEGRO_NATIVE_DIALOG *fc = (const ALLEGRO_NATIVE_DIALOG *)dialog;
   if (i < fc->fc_path_count)
      return al_path_cstr(fc->fc_paths[i], ALLEGRO_NATIVE_PATH_SEP);
   return NULL;
}
Esempio n. 21
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);
}
Esempio n. 22
0
bool Framework::initialize(std::string config_filename)
{
   if (initialized) return initialized;

   if (!al_init()) std::cerr << "al_init() failed" << std::endl;

   ALLEGRO_PATH *resource_path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
   al_change_directory(al_path_cstr(resource_path, ALLEGRO_NATIVE_PATH_SEP));
   al_destroy_path(resource_path);

   if (!al_install_mouse()) std::cerr << "al_install_mouse() failed" << std::endl;
   if (!al_install_keyboard()) std::cerr << "al_install_keyboard() failed" << std::endl;
   if (!al_install_joystick()) std::cerr << "al_install_joystick() failed" << std::endl;
   if (!al_install_audio()) std::cerr << "al_install_audio() failed" << std::endl;

   if (!al_init_native_dialog_addon()) std::cerr << "al_init_native_dialog_addon() failed" << std::endl;
   if (!al_init_primitives_addon()) std::cerr << "al_init_primitives_addon() failed" << std::endl;
   if (!al_init_image_addon()) std::cerr << "al_init_image_addon() failed" << std::endl;
   if (!al_init_font_addon()) std::cerr << "al_init_font_addon() failed" << std::endl;
   if (!al_init_ttf_addon()) std::cerr << "al_init_ttf_addon() failed" << std::endl;
   if (!al_init_acodec_addon()) std::cerr << "al_init_acodec_addon() failed" << std::endl;

   if (!al_reserve_samples(32)) std::cerr << "al_reserve_samples() failed" << std::endl;

   srand(time(NULL));

   primary_timer = al_create_timer(ALLEGRO_BPS_TO_SECS(60));

   al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
   //	al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP);

   builtin_font = al_create_builtin_font();

   event_queue = al_create_event_queue();
   al_register_event_source(event_queue, al_get_keyboard_event_source());
   al_register_event_source(event_queue, al_get_mouse_event_source());
   al_register_event_source(event_queue, al_get_joystick_event_source());
   al_register_event_source(event_queue, al_get_timer_event_source(primary_timer));
   al_register_event_source(event_queue, al_get_joystick_event_source());
   al_register_event_source(event_queue, al_get_default_menu_event_source());

   if (al_get_num_joysticks()) joystick = al_get_joystick(0); // make this better eventually
   else std::cerr << "no joystick(s) detected" << std::endl;

   instance = new Framework(config_filename);

   Attributes::create_datatype_definition(
      AllegroColorAttributeDatatype::IDENTIFIER,
      AllegroColorAttributeDatatype::to_val_func,
      AllegroColorAttributeDatatype::to_str_func
   );

   initialized = true;

   return true;
}
Esempio n. 23
0
int dot_menu_proc_upload_no(void * data, int i, void * pp)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;

	app->upload_scores = false;
	al_set_config_value(t3f_config, "Game Data", "Upload Scores", "false");
	al_save_config_file(al_path_cstr(t3f_config_path, '/'), t3f_config);
	app->current_menu = DOT_MENU_MUSIC;
	return 1;
}
Esempio n. 24
0
static void show_path(int id, const char *label)
{
   ALLEGRO_PATH *path;
   const char *path_str;

   path = al_get_standard_path(id);
   path_str = (path) ? al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP) : "<none>";
   log_printf("%s: %s\n", label, path_str);
   al_destroy_path(path);
}
Esempio n. 25
0
void mapEditor::saveMap() {
	ALLEGRO_FILECHOOSER* fC = al_create_native_file_dialog(al_create_path(""),"Select Location..","*.map",ALLEGRO_FILECHOOSER_SAVE);
	al_show_native_file_dialog(this->display,fC);
	const ALLEGRO_PATH* savePath = al_get_native_file_dialog_path(fC,0);
	const char* pathName = al_path_cstr(savePath, ALLEGRO_NATIVE_PATH_SEP);
	ALLEGRO_FILE* fHandle = al_fopen(pathName,"wb");
	mapSaver* newSaver = new mapSaver(*this->mHandler->mData);
	newSaver->writeData(fHandle);
	al_fclose(fHandle);
}
Esempio n. 26
0
File: map.cpp Progetto: faod/ld33
Tileset::Tileset(const char* filename)
{
    ALLEGRO_PATH *path;

    path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(path, RESOURCES_DIR);
    al_set_path_filename(path, filename);
    spritesheet_ = al_load_bitmap(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));

    al_destroy_path(path);
}
Esempio n. 27
0
void dot_menu_proc_profile_name_callback(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;

	if(strlen(app->user_name) <= 0)
	{
		strcpy(app->user_name, "Anonymous");
	}
	al_set_config_value(t3f_config, "Game Data", "User Name", app->user_name);
	al_save_config_file(al_path_cstr(t3f_config_path, '/'), t3f_config);
}
Esempio n. 28
0
/* _find_executable_file:
 *  Helper function: searches path and current directory for executable.
 *  Returns 1 on succes, 0 on failure.
 */
static ALLEGRO_PATH *_find_executable_file(const char *filename)
{
   char *env;

   /* If filename has an explicit path, search current directory */
   if (strchr(filename, '/')) {
      if (filename[0] == '/') {
         /* Full path; done */
         return al_create_path(filename);
      }
      else {
         struct stat finfo;
         char pathname[1024];
    
         /* Prepend current directory */
         ALLEGRO_PATH *path = al_get_current_directory();
         al_append_path_component(path, filename);

         if ((stat(pathname, &finfo)==0) &&
            (!S_ISDIR (finfo.st_mode))) {
            return path;
         }
      }
   }
   /* If filename has no explicit path, but we do have $PATH, search
    * there
    */
   else if ((env = getenv("PATH"))) {
      struct stat finfo;
      ALLEGRO_USTR *us = al_ustr_new(env);
      int start_pos = 0;
      while (start_pos >= 0) {
         int next_start_pos = al_ustr_find_chr(us, start_pos + 1, ':');
         int end_pos = next_start_pos;
         if (next_start_pos < 0)
            end_pos = al_ustr_size(us);
         ALLEGRO_USTR_INFO info;
         ALLEGRO_USTR *sub = al_ref_ustr(&info, us, start_pos, end_pos);

         ALLEGRO_PATH *path = al_create_path_for_directory(al_cstr(sub));
         al_append_path_component(path, filename);

         if (stat(al_path_cstr(path, '/'), &finfo) == 0 &&
            !S_ISDIR (finfo.st_mode)) {
            return path;
         }
         start_pos = next_start_pos;
      }
   }

   return NULL;
}
int main(int argc, const char *argv[])
{
   ALLEGRO_FILE *master, *slice;
   ALLEGRO_PATH *tmp_path;

   const char *first_string = "Hello, World!";
   const char *second_string = "The quick brown fox jumps over the lazy dog.";
   char buffer[BUFFER_SIZE];

   (void) argc, (void) argv;

   al_init();

   master = al_make_temp_file("ex_file_slice_XXXX", &tmp_path);
   if (!master) {
      abort_example("Unable to create temporary file\n");
   }

   /* Pack both strings into the master file. */
   pack_object(master, first_string, strlen(first_string));
   pack_object(master, second_string, strlen(second_string));

   /* Seek back to the beginning of the file, as if we had just opened it */
   al_fseek(master, 0, ALLEGRO_SEEK_SET);

   /* Loop through the main file, opening a slice for each object */
   while ((slice = get_next_chunk(master))) {
      /* Note: While the slice is open, we must avoid using the master file!
         If you were dealing with packed images, this is where you would pass 'slice'
         to al_load_bitmap_f(). */

      if (al_fsize(slice) < BUFFER_SIZE) {
         /* We could have used al_fgets(), but just to show that the file slice
            is constrained to the string object, we'll read the entire slice. */
         al_fread(slice, buffer, al_fsize(slice));
         buffer[al_fsize(slice)] = 0;
         printf("Chunk of size %d: '%s'\n", (int) al_fsize(slice), buffer);
      }

      /* The slice must be closed before the next slice is opened. Closing
         the slice will advanced the master file to the end of the slice. */
      al_fclose(slice);
   }

   al_fclose(master);

   al_remove_filename(al_path_cstr(tmp_path, '/'));

   return 0;
}
Esempio n. 30
0
ALLEGRO_MAP *al_open_map_from(const char *root_dir, const char *dir, const char *filename)
{
    // get cwd, and create path to specified directory
    ALLEGRO_PATH *cwd = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    const char *cwdstr = al_path_cstr(cwd, ALLEGRO_NATIVE_PATH_SEP);
    const char *build_path = strstr(cwdstr, root_dir);
    char *new_path = al_path_to_root(build_path);
    strcat(new_path, dir);

    // get map, and return to specified directory
    ALLEGRO_MAP *map = al_open_map(new_path, filename);
    al_change_directory(al_path_to_root(build_path));
    return map;
}