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; }
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..."); } }
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; }
static void print_file(ALLEGRO_FS_ENTRY *entry) { int mode = al_get_fs_entry_mode(entry); time_t now = time(NULL); time_t atime = al_get_fs_entry_atime(entry); time_t ctime = al_get_fs_entry_ctime(entry); time_t mtime = al_get_fs_entry_mtime(entry); off_t size = al_get_fs_entry_size(entry); const char *name = al_get_fs_entry_name(entry); log_printf("%-36s %s%s%s%s%s%s %8u %8u %8u %8u\n", name, mode & ALLEGRO_FILEMODE_READ ? "r" : ".", mode & ALLEGRO_FILEMODE_WRITE ? "w" : ".", mode & ALLEGRO_FILEMODE_EXECUTE ? "x" : ".", mode & ALLEGRO_FILEMODE_HIDDEN ? "h" : ".", mode & ALLEGRO_FILEMODE_ISFILE ? "f" : ".", mode & ALLEGRO_FILEMODE_ISDIR ? "d" : ".", (unsigned)(now - ctime), (unsigned)(now - mtime), (unsigned)(now - atime), (unsigned)size); }
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); }