Esempio n. 1
0
int main(int argc, char **argv)
{
   int i;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   open_log_monospace();
   
   log_printf("%-36s %-6s %8s %8s %8s %8s\n",
      "name", "flags", "ctime", "mtime", "atime", "size");
   log_printf(
      "------------------------------------ "
      "------ "
      "-------- "
      "-------- "
      "-------- "
      "--------\n");

   if (argc == 1) {
      ALLEGRO_FS_ENTRY *entry = al_create_fs_entry("data");
      print_entry(entry);
      al_destroy_fs_entry(entry);
   }

   for (i = 1; i < argc; i++) {
      ALLEGRO_FS_ENTRY *entry = al_create_fs_entry(argv[i]);
      print_entry(entry);
      al_destroy_fs_entry(entry);
   }

   close_log(true);
   return 0;
}
Esempio n. 2
0
bool t3f_scan_files(const char * path, bool (*process_file)(const char * fn, bool isfolder, void * data), bool subdir, void * data)
{
	ALLEGRO_FS_ENTRY * dir;
	ALLEGRO_FS_ENTRY * fp;
	char cname[1024] = {0};

	/* ignore ./ and ../ path entries */
	strcpy(cname, path);
    if(strlen(cname) > 0)
    {
        if(cname[strlen(cname) - 1] == '/')
        {
            if(subdir)
            {
                if(cname[strlen(cname) - 2] == '.')
                {
                    return false;
                }
            }
            cname[strlen(cname) - 1] = 0;
        }
    }

//	printf("!Looking in %s\n", cname);
	dir = al_create_fs_entry(cname);
	if(!dir)
	{
		return false;
	}
	if(!al_open_directory(dir))
	{
		return false;
	}
//	printf("Looking in %s\n", cname);
	while(1)
	{
		fp = al_read_directory(dir);
		if(!fp)
		{
			break;
		}
//		name = al_path_to_string(al_get_entry_name(fp), '/');
		if(al_get_fs_entry_mode(fp) & ALLEGRO_FILEMODE_ISDIR)
		{
			if(process_file(al_get_fs_entry_name(fp), true, data))
			{
			}
			t3f_scan_files(al_get_fs_entry_name(fp), process_file, true, data);
		}
		else
		{
            if(process_file(al_get_fs_entry_name(fp), false, data))
			{
			}
		}
		al_destroy_fs_entry(fp);
	}
	al_destroy_fs_entry(dir);
    return true;
}
Esempio n. 3
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. 4
0
bool ScreenPlay::scan_save_files()
{
    //reduntant finction?
    if(gms == nullptr)
        gms = new GameSave();

    savefiles.clear();

    std::string dum;
    int a = 0;
    ALLEGRO_FS_ENTRY* dir = al_create_fs_entry("saves/");

    if(al_open_directory(dir) == false)
    {
        al_make_directory("saves/");
    }

    if(al_open_directory(dir))
    {
        ALLEGRO_FS_ENTRY* file;
        while(file = al_read_directory(dir))
        {
            dum = al_get_fs_entry_name(file);
            if( al_get_fs_entry_mode(file) == ALLEGRO_FILEMODE_ISDIR || dum.substr(dum.size()-4,4) != ".sav")
            {
                continue;
            }
            gms->Load(dum);
            savefiles.push_back(dum);

            scba->AddText(5, a * 100 +10, gms->Get_player_name(), al_map_rgb(255,215,0), &n_font);
            scba->AddButton("resources/fonts/Calibri.ttf", 400, a * 100 + 60, 75, 30, "Load", al_map_rgb(0,0,139));
            scba->AddRectangle(1,a * 100 , 500, 100, 2, al_map_rgb(10,10,10));
            scba->AddText(10, a * 100 + 60, "Mission: " + std::to_string(gms->Get_mission_number()), al_map_rgb(255,255,250), &m_font);
            a++;
            gms->Save();
        }
        al_destroy_fs_entry(file);
    }
    al_destroy_fs_entry(dir);

    return true;
}
Esempio n. 5
0
ScreenPlay::ScreenPlay(Button *ext_b) : but(ext_b)
{
    n_font = al_load_font("resources/fonts/Asimov.otf",40,0);
    m_font = al_load_font("resources/fonts/Calibri.ttf",30,0);

    std::string bnames[SCREENPLAY_NMB] = {"Back", "New game", "OK"};

    int bpoz[SCREENPLAY_NMB][4] = {  {1300, global::dHeight -70, 120, 50},
                                     {(global::dWidth-120)/2, global::dHeight -70, 120, 50},
                                     {(global::dWidth-120)/2, (global::dHeight-50)/2 +45, 120, 50}  };

    for(int a = 0;a < SCREENPLAY_NMB;a++)
    {
        buttons.push_back(new Button("resources/fonts/Calibri.ttf", bpoz[a][0], bpoz[a][1], bpoz[a][0] + bpoz[a][2],bpoz[a][1] + bpoz[a][3], bnames[a], al_map_rgb(0,0,128)));
    }
    buttons[OK]->Active(false);
    buttons[OK]->Print_active(false);

    scba = new ScrollableArea(((float)global::dWidth - 500.0f)/2.0f ,100, 500 ,global::dHeight-200);
    scba->background_col = al_map_rgba(50,50,50,120);

    //graphic background trash
    zemak_bitmpa = al_load_bitmap("resources/graphics/zemiacik.png");
    if(zemak_bitmpa == nullptr)
    {
        error_message("Could not load image : resources/graphics/zemiacik.png");
    }

    std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch().count());
    std::uniform_int_distribution<int> distribution(1,5);
    std::uniform_real_distribution<float> change(-10, 10);

    std::uniform_int_distribution<int> width(0,global::dWidth - ZEMIAK_SIZE);
    std::uniform_int_distribution<int> height(0,global::dHeight-ZEMIAK_SIZE);

    number_of_zemaky = distribution(generator);
    zemaky = new float[number_of_zemaky*4];

    for(int a = 0;a < number_of_zemaky*4;a+=4)
    {
        zemaky[a] = width(generator);
        zemaky[a+1] = height(generator);
        zemaky[a+2] = round(change(generator));
        zemaky[a+3] = round(change(generator));
    }
    //------------------------------------------


    //Saves loading
    gms = new GameSave();
    std::string dum;
    int a = 0;
    ALLEGRO_FS_ENTRY* dir = al_create_fs_entry("saves/");

    if(al_open_directory(dir) == false)
    {
        al_make_directory("saves/");
    }

    if(al_open_directory(dir))
    {
        ALLEGRO_FS_ENTRY* file;
        while(file = al_read_directory(dir))
        {
            dum = al_get_fs_entry_name(file);
            if( al_get_fs_entry_mode(file) == ALLEGRO_FILEMODE_ISDIR || dum.substr(dum.size()-4,4) != ".sav")
            {
                continue;
            }
            gms->Load(dum);
            savefiles.push_back(dum);

            scba->AddText(5, a * 100 +10, gms->Get_player_name(), al_map_rgb(255,215,0), &n_font);
            scba->AddButton("resources/fonts/Calibri.ttf", 400, a * 100 + 60, 75, 30, "Load", al_map_rgb(0,0,139));
            scba->AddRectangle(1,a * 100 , 500, 100, 2, al_map_rgb(10,10,10));
            scba->AddText(10, a * 100 + 60, "Mission: " + std::to_string(gms->Get_mission_number()), al_map_rgb(255,255,250), &m_font);
            a++;
            gms->Save();
        }
        al_destroy_fs_entry(file);
    }
    al_destroy_fs_entry(dir);
}
  virtual Skybox			*load(const File &file, bool force = false)
  {

    //
    // A terminer
    // http://raptor.developpez.com/tutorial/opengl/skybox/

    ALLEGRO_FS_ENTRY			*fs;
    ALLEGRO_FS_ENTRY			*content;
    ALLEGRO_BITMAP			**bmps = new ALLEGRO_BITMAP*[6];
    int					fileCnt = 0;
    GLuint				cube_map_texture_ID;
    GLenum				cube_map_target[6] = {
      GL_TEXTURE_CUBE_MAP_POSITIVE_X,
      GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
      GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
      GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
      GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
      GL_TEXTURE_CUBE_MAP_POSITIVE_Z
    };
    std::map<std::string, ALLEGRO_LOCKED_REGION*> texture_image;

    fs = al_create_fs_entry(file.getFullName().c_str());
    if (!fs)
      {
	throw LoadingFailed(file.getFullName(), "SkyboxLoader failed to find or open skybox folder.");
      }
    if (!al_open_directory(fs))
      {
	throw LoadingFailed(file.getFullName(), "SkyboxLoader failed to open skybox folder.");
      }
    if (!al_fs_entry_exists(fs))
      {
	throw LoadingFailed(file.getFullName(), "SkyboxLoader can't find folder.");
      }

    al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

    while ((content = al_read_directory(fs)))
      {
	const char *name = al_get_fs_entry_name(content);
	ALLEGRO_LOCKED_REGION *r;
	std::cout << name << std::endl;
	bmps[fileCnt] = al_load_bitmap(name);
	if (!bmps[fileCnt])
	  throw LoadingFailed(name, "SkyboxLoader can't load image.");
	r = al_lock_bitmap(bmps[fileCnt], ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
	if (!r)
	  throw LoadingFailed(name, "SkyboxLoader can't lock bitmap.");
	texture_image.insert(std::pair<std::string, ALLEGRO_LOCKED_REGION*>(std::string(name), r));
	al_destroy_fs_entry(content);
	++fileCnt;
      }

    al_destroy_fs_entry(fs);

    al_set_new_bitmap_flags(~ALLEGRO_MEMORY_BITMAP);

    // Génération d'une texture CubeMap
    glGenTextures(1, &cube_map_texture_ID);

    if (cube_map_texture_ID == 0)
      throw LoadingFailed(file.getFullName(), "SkyboxLoader error generating a texture.");

    // Configuration de la texture
    glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID);

    std::map<std::string, ALLEGRO_LOCKED_REGION*>::iterator it = texture_image.begin();
    int i = 0;
    while (it != texture_image.end())
      {
	glTexImage2D(cube_map_target[i], 0, it->second->pixel_size,
		     al_get_bitmap_width(bmps[i]),
		     al_get_bitmap_height(bmps[i]),
		     0, GL_BGRA, GL_UNSIGNED_BYTE,
		     it->second->data);
	al_unlock_bitmap(bmps[i]);
	++i;
	++it;
      }

    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP);

    return new Skybox(cube_map_texture_ID, bmps, file.getFileName(), force);
  }
Esempio n. 7
0
ALLEGRO_PATH *_al_unix_get_path(int id)
{
   switch (id) {
      case ALLEGRO_TEMP_PATH: {
         /* Check: TMP, TMPDIR, TEMP or TEMPDIR */
         char *envs[] = { "TMP", "TMPDIR", "TEMP", "TEMPDIR", NULL};
         uint32_t i = 0;
         for (; envs[i] != NULL; ++i) {
            char *tmp = getenv(envs[i]);
            if (tmp) {
               return al_create_path(tmp);
            }
         }

         /* next try: /tmp /var/tmp /usr/tmp */
         char *paths[] = { "/tmp/", "/var/tmp/", "/usr/tmp/", NULL };
         for (i=0; paths[i] != NULL; ++i) {
            ALLEGRO_FS_ENTRY *fse = al_create_fs_entry(paths[i]);
            bool found = al_fs_entry_is_directory(fse);
            al_destroy_fs_entry(fse);
            if (found) {
               return al_create_path(paths[i]);
            }
         }

         /* Give up? */
         return NULL;
      } break;

      case ALLEGRO_PROGRAM_PATH: {

         ALLEGRO_PATH *exe = get_executable_name();
         al_set_path_filename(exe, NULL);
         return exe;

      } break;

      case ALLEGRO_SYSTEM_DATA_PATH: {
         ALLEGRO_PATH *sys_data_path = NULL;

         /* FIXME: make this a compile time define, or a allegro cfg option? or both */
         sys_data_path = al_create_path("/usr/share/");
         al_append_path_component(sys_data_path, al_get_orgname());
         al_append_path_component(sys_data_path, al_get_appname());

         return sys_data_path;
      } break;

#if 0
      case ALLEGRO_USER_DATA_PATH: {
         int32_t ret = 0;
         uint32_t path_len = 0, ptr_len = 0, prog_len = 0;
         char path[PATH_MAX] = "", *ptr = NULL;
         char prog[PATH_MAX] = "";

         if (_unix_find_home(path, PATH_MAX) != 0) {
            return NULL;
         }

         strncat(path, "/.", 2);

         path_len = strlen(path);

         /* get exe name */
         /* FIXME:
            This really aught to get the "Program" name from somewhere, say a config var? Or a function al_set_program_name()?
            making a ~/.test_program dir for a exe named "test_program" might not be what people have in mind.
         */

         get_executable_name(prog, PATH_MAX);

         ptr = strrchr(prog, '/');
         if (!ptr) {
            al_set_errno(EINVAL);
            return NULL;
         }

         *ptr = '\0';
         ptr++;
         ptr_len = strlen(ptr);
         //
         strncat(path, ptr, ptr_len+1);
         //*(ptr-1) = '/';
         do_uconvert(path, U_ASCII, dir, U_UTF8, strlen(path)+1);

      } break;
#endif

      case ALLEGRO_USER_SETTINGS_PATH:
      case ALLEGRO_USER_DATA_PATH: {
         ALLEGRO_PATH *local_path = NULL;

         local_path = _unix_find_home();
         if (!local_path)
            return NULL;

         al_append_path_component(local_path, ".config");
         al_append_path_component(local_path, al_get_orgname());
         al_append_path_component(local_path, al_get_appname());

        return local_path;
      } break;

      case ALLEGRO_USER_HOME_PATH:
         return _unix_find_home();

      case ALLEGRO_SYSTEM_SETTINGS_PATH: {
         ALLEGRO_PATH *sys_path;

         /* FIXME: make this a compile time define, or something */
         sys_path = al_create_path("/etc/");
         al_append_path_component(sys_path, al_get_orgname());
         al_append_path_component(sys_path, al_get_appname());

         return sys_path;
      } break;

      case ALLEGRO_EXENAME_PATH:
         return get_executable_name();
         break;

      default:
         return NULL;
   }

   return NULL;
}
ALLEGRO_PATH *_al_unix_get_path(int id)
{
   switch (id) {
      case ALLEGRO_TEMP_PATH: {
         /* Check: TMP, TMPDIR, TEMP or TEMPDIR */
         char *envs[] = { "TMP", "TMPDIR", "TEMP", "TEMPDIR", NULL};
         uint32_t i = 0;
         for (; envs[i] != NULL; ++i) {
            char *tmp = getenv(envs[i]);
            if (tmp) {
               return al_create_path_for_directory(tmp);
            }
         }

         /* next try: /tmp /var/tmp /usr/tmp */
         char *paths[] = { "/tmp/", "/var/tmp/", "/usr/tmp/", NULL };
         for (i=0; paths[i] != NULL; ++i) {
            ALLEGRO_FS_ENTRY *fse = al_create_fs_entry(paths[i]);
            bool found = (al_get_fs_entry_mode(fse) & ALLEGRO_FILEMODE_ISDIR) != 0;
            al_destroy_fs_entry(fse);
            if (found) {
               return al_create_path_for_directory(paths[i]);
            }
         }

         /* Give up? */
         return NULL;
      } break;

      case ALLEGRO_RESOURCES_PATH: {
         ALLEGRO_PATH *exe = get_executable_name();
         exe = follow_symlinks(exe);
         al_set_path_filename(exe, NULL);
         return exe;

      } break;

      case ALLEGRO_USER_DATA_PATH:
      case ALLEGRO_USER_SETTINGS_PATH: {
         ALLEGRO_PATH *local_path = NULL;
         const char *org_name = al_get_org_name();
         const char *app_name = al_get_app_name();
         
         /* to avoid writing directly into the user's directory, require at least an app name */
         if (!app_name)
            return NULL;
         
         /* find the appropriate path from the xdg environment variables, if possible */
         if (id == ALLEGRO_USER_DATA_PATH) {
            const char *xdg_data_home = getenv("XDG_DATA_HOME");
            local_path = al_create_path_for_directory(xdg_data_home ? xdg_data_home : ".local/share");
         }
         else {
            const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
            local_path = al_create_path_for_directory(xdg_config_home ? xdg_config_home : ".config");
         }
         
         if (!local_path) 
            return NULL;
         
         /* if the path is relative, prepend the user's home directory */
         if (al_path_cstr(local_path, '/')[0] != '/') {
            ALLEGRO_PATH *home_path = _unix_find_home();
            if (!home_path)
               return NULL;
            
            al_rebase_path(home_path, local_path);
            al_destroy_path(home_path);
         }

         /* only add org name if not blank */
         if (org_name && org_name[0]) {              
            al_append_path_component(local_path, al_get_org_name());
         }
         
         al_append_path_component(local_path, al_get_app_name());

        return local_path;
      } break;

      case ALLEGRO_USER_HOME_PATH:
         return _unix_find_home();
         
      case ALLEGRO_USER_DOCUMENTS_PATH: {
         ALLEGRO_PATH *local_path = _get_xdg_path("DOCUMENTS");
         return local_path ? local_path : _unix_find_home();
      } break;

      case ALLEGRO_EXENAME_PATH:
         return get_executable_name();
         break;

      default:
         return NULL;
   }

   return NULL;
}