void CDisplay::UpdateHighScores() { for(int i = 0; i < numHighScores; i++) { long tempScore = atol(highScores[i]); if(score > tempScore) { for(int j = numHighScores - 1; j > i; j--) highScores[j] = highScores[j - 1]; highScores[i] = ltoa(score, new char[16], 10); break; } } ALLEGRO_FILE* file; file = al_fopen("C:\\Users\\Chase\\Documents\\Visual Studio 2010\\Projects\\Tetris\\scores.scr", "w+b"); if(!file) { printf("File scores.scr could not be opened\n"); return; } for(int i = 0; i < numHighScores; i++) { long tempScore = atol(highScores[i]); al_fwrite(file, &tempScore, 8); } al_fclose(file); printf("File written to"); }
characterImageCache* characterImageManager::cacheImage(std::string imageName, std::string dataName) { if (characterImageManager::cacheList.find(imageName)==characterImageManager::cacheList.end()) { //Cache was not previously generated, so generate it characterImageCache* newCache = new characterImageCache(); //int oldFlags = al_get_new_bitmap_flags(); //al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR); newCache->image = al_load_bitmap_f(gameEngine::resources::graphics.openSubFile(imageName),".png"); //Load the image to cache //al_set_new_bitmap_flags(oldFlags); ALLEGRO_FILE * imageData = gameEngine::resources::graphics.openSubFile(dataName,false); al_fread(imageData,&newCache->imageOriginX,sizeof(unsigned short)); al_fread(imageData,&newCache->imageOriginY,sizeof(unsigned short)); al_fread(imageData,&newCache->imageRelativeX,sizeof(short)); al_fread(imageData,&newCache->imageRelativeY,sizeof(short)); al_fclose(imageData); newCache->usageCount = 1; //One person is now using it.. cacheList[imageName] = newCache; //Add the cache to the map to.. cache it :p //std::cout << "Loaded image and cached it for first time.." << std::endl; return newCache; }else{ //Cache already exists, so return the existing one //std::cout << "Using previously cached image..." << std::endl; characterImageManager::cacheList[imageName]->usageCount ++; //A new renderer is using this cache return characterImageManager::cacheList[imageName]; } }
/* This has to load bitmaps from CPA and disk (for skeled) */ ALLEGRO_BITMAP *my_load_bitmap(std::string filename) { CPA *cpa; ALLEGRO_FILE *f; if (engine) { cpa = engine->get_cpa(); } else { cpa = NULL; } if (cpa) { f = cpa->load(filename); } else { f = al_fopen(filename.c_str(), "rb"); } if (!f) { return NULL; } ALLEGRO_BITMAP *bmp; //#if defined ANDROID || defined ALLEGRO_IPHONE || defined ALLEGRO_RASPBERRYPI bmp = al_load_bitmap_f(f, ".png"); /*#else if (!engine || !cpa) { bmp = al_load_bitmap_f(f, ".png"); } else { bmp = al_load_bitmap_f(f, ".png"); } #endif*/ al_fclose(f); return bmp; }
/* Function: al_fopen_fd */ ALLEGRO_FILE *al_fopen_fd(int fd, const char *mode) { ALLEGRO_FILE *f; USERDATA *userdata; FILE *fp; userdata = al_malloc(sizeof(USERDATA)); if (!userdata) return NULL; /* The fd should remain open if this function fails in any way, * so delay the fdopen() call to last. */ userdata->fp = NULL; userdata->errnum = 0; f = al_create_file_handle(&_al_file_interface_stdio, userdata); if (!f) { al_free(userdata); return NULL; } fp = fdopen(fd, mode); if (!fp) { al_set_errno(errno); al_fclose(f); return NULL; } userdata->fp = fp; return f; }
void WorldStage::SaveMapToFile(RegionalMap *map) { std::stringstream ss; const int MAP_WIDTH=80, MAP_HEIGHT=80; //Open a file based on map position ss << "region." << map->startX/MAP_WIDTH << "." << map->startY/MAP_HEIGHT; ALLEGRO_FILE *file = al_fopen(ss.str().c_str(), "w"); if(file) { //Write magic number to it and newline al_fputs(file, "b272bda9bf0c1cdcba614b5ed99c4d62"); al_fputs(file, "\n"); //Write version number and newline al_fputs(file, "0\n"); //Write each tile as a 32le for(int y = 0; y < MAP_HEIGHT; y++) for(int x = 0; x < MAP_WIDTH; x++) { al_fwrite32le(file, map->tile[x][y].materialTypeIndex); } //Write each actor id as a 32le for(auto actorId = map->actorIDs.begin(); actorId != map->actorIDs.end(); actorId++) { al_fwrite32le(file, (*actorId)); } //Close a file al_fclose(file); } }
void Sound::loadFromMemory(const char * data, int length){ ALLEGRO_FILE * memory = al_open_memfile((void*) data, length, "r"); this->data.sample = al_load_sample_f(memory, ".wav"); al_fclose(memory); own = new int; *own = 1; }
static bool fs_apk_entry_exists(ALLEGRO_FS_ENTRY *fse) { ALLEGRO_FILE *f = fs_apk_open_file(fse, "r"); if (f) { al_fclose(f); return true; } return false; }
bool File::close() { if(isOpen()) { al_fclose(m_file); m_file = NULL; return true; } return false; }
static void modaudio_stream_close(ALLEGRO_AUDIO_STREAM *stream) { MOD_FILE *const df = stream->extra; _al_acodec_stop_feed_thread(stream); lib.duh_end_sigrenderer(df->sig); lib.unload_duh(df->duh); if (df->fh) al_fclose(df->fh); }
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); }
/* To be called when stream is destroyed */ static void ogg_stream_close(ALLEGRO_AUDIO_STREAM *stream) { AL_OP_DATA *extra = (AL_OP_DATA *) stream->extra; _al_acodec_stop_feed_thread(stream); al_fclose(extra->file); lib.op_free(extra->of); al_free(extra); stream->extra = NULL; }
ALLEGRO_BITMAP * load_packed_bitmap(unsigned char *mem, int mem_size) { /* fail nicely :) */ if (mem == NULL) return NULL; ALLEGRO_FILE *mem_file = al_open_memfile(mem, mem_size, "r"); /* file type determined by second arg */ ALLEGRO_BITMAP *bm = al_load_bitmap_f(mem_file, ".png"); al_fclose(mem_file); return bm; }
int t3f_save_tilemap(T3F_TILEMAP * tmp, const char * fn) { ALLEGRO_FILE * fp; fp = al_fopen(fn, "wb"); if(!fp) { return 0; } t3f_save_tilemap_f(tmp, fp); al_fclose(fp); return 1; }
int t3f_save_tileset(T3F_TILESET * tsp, const char * fn) { ALLEGRO_FILE * fp; fp = al_fopen(fn, "wb"); if(!fp) { return 0; } t3f_save_tileset_f(tsp, fp); al_fclose(fp); return 1; }
gameMap gameMap::loadMapFromID(int id, mapType type) { gameMap newMap; newMap.m_dataID =id; newMap.m_type = type; std::stringstream buf; buf << GAME_MAP_DATA << id << ".map"; ALLEGRO_FILE *mapFile = al_fopen(buf.str().c_str(),"rb"); newMap.getCollisionData().loadMapData(mapFile); al_fclose(mapFile); return newMap; }
int t3f_save_animation(T3F_ANIMATION * ap, const char * fn) { ALLEGRO_FILE * fp; fp = al_fopen(fn, "wb"); if(!fp) { return 0; } t3f_save_animation_f(ap, fp); al_fclose(fp); return 1; }
bool t3f_save_vector_font(T3F_VECTOR_FONT * vfp, const char * fn) { ALLEGRO_FILE * fp; bool ret; fp = al_fopen(fn, "wb"); if(!fp) { return false; } ret = t3f_save_vector_font_f(vfp, fp); al_fclose(fp); return ret; }
T3F_TILESET * t3f_load_tileset(const char * fn) { ALLEGRO_FILE * fp; T3F_TILESET * tsp; fp = al_fopen(fn, "rb"); if(!fp) { return NULL; } tsp = t3f_load_tileset_f(fp, fn); al_fclose(fp); return tsp; }
T3F_ANIMATION * t3f_load_animation(const char * fn) { T3F_ANIMATION * ap; ALLEGRO_FILE * fp; fp = al_fopen(fn, "rb"); if(!fp) { return NULL; } ap = t3f_load_animation_f(fp, fn); al_fclose(fp); return ap; }
T3F_TILEMAP * t3f_load_tilemap(const char * fn) { ALLEGRO_FILE * fp; T3F_TILEMAP * tmp; fp = al_fopen(fn, "rb"); if(!fp) { return NULL; } tmp = t3f_load_tilemap_f(fp); al_fclose(fp); return tmp; }
T3F_VECTOR_FONT * t3f_load_vector_font(const char * fn) { ALLEGRO_FILE * fp; T3F_VECTOR_FONT * vfp = NULL; fp = al_fopen(fn, "rb"); if(!fp) { return NULL; } vfp = t3f_load_vector_font_f(fp); al_fclose(fp); return vfp; }
T3F_VECTOR_OBJECT * t3f_load_vector_object(const char * fn) { ALLEGRO_FILE * fp; T3F_VECTOR_OBJECT * vp = NULL; fp = al_fopen(fn, "rb"); if(!fp) { return NULL; } vp = t3f_load_vector_object_f(fp); al_fclose(fp); return vp; }
/* Function: al_load_jpg */ ALLEGRO_BITMAP *al_load_jpg(char const *filename) { ALLEGRO_FILE *fp; ALLEGRO_BITMAP *bmp; ASSERT(filename); fp = al_fopen(filename, "rb"); if (!fp) return NULL; bmp = al_load_jpg_f(fp); al_fclose(fp); return bmp; }
ALLEGRO_BITMAP *_al_load_png(const char *filename, int flags) { ALLEGRO_FILE *fp; ALLEGRO_BITMAP *bmp; ALLEGRO_ASSERT(filename); fp = al_fopen(filename, "rb"); if (!fp) return NULL; bmp = _al_load_png_f(fp, flags); al_fclose(fp); return bmp; }
ALLEGRO_SAMPLE *_al_load_ogg_opus(const char *filename) { ALLEGRO_FILE *f; ALLEGRO_SAMPLE *spl; ASSERT(filename); ALLEGRO_INFO("Loading sample %s.\n", filename); f = al_fopen(filename, "rb"); if (!f) { ALLEGRO_WARN("Failed reading %s.\n", filename); return NULL; } spl = _al_load_ogg_opus_f(f); al_fclose(f); return spl; }
ALLEGRO_SAMPLE *_al_load_voc(const char *filename) { ALLEGRO_FILE *f; ALLEGRO_SAMPLE *spl; ASSERT(filename); ALLEGRO_INFO("Loading VOC sample %s.\n", filename); f = al_fopen(filename, "rb"); if (!f) { ALLEGRO_ERROR("Unable to open %s for reading.\n", filename); return NULL; } spl = _al_load_voc_f(f); al_fclose(f); return spl; }
/* Function: al_save_jpg */ bool al_save_jpg(char const *filename, ALLEGRO_BITMAP *bmp) { ALLEGRO_FILE *fp; bool result; ASSERT(filename); ASSERT(bmp); fp = al_fopen(filename, "wb"); if (!fp) { TRACE("Unable to open file %s for writing\n", filename); return false; } result = al_save_jpg_f(fp, bmp); al_fclose(fp); return result; }
bool _al_save_png(const char *filename, ALLEGRO_BITMAP *bmp) { ALLEGRO_FILE *fp; bool retsave; bool retclose; ALLEGRO_ASSERT(filename); ALLEGRO_ASSERT(bmp); fp = al_fopen(filename, "wb"); if (!fp) { ALLEGRO_ERROR("Unable to open file %s for writing\n", filename); return false; } retsave = _al_save_png_f(fp, bmp); retclose = al_fclose(fp); return retsave && retclose; }
void CDisplay::ReadFile() { ALLEGRO_FILE* file; file = al_fopen("C:\\Users\\Chase\\Documents\\Visual Studio 2010\\Projects\\Tetris\\scores.scr", "rb"); if(!file) printf("File scores.scr could not be opened\n"); numHighScores = al_fsize(file) / 8; highScores = new char*[numHighScores]; for(int i = 0; i < numHighScores; i++) { long* temp = new long; al_fread(file, temp, 8); highScores[i] = ltoa(*temp, new char[16], 10); } al_fclose(file); printf("File read from, scores: %d\n",numHighScores); }
ConfigFile::ConfigFile( std::string Filename ) { ALLEGRO_FILE* fileHnd; std::string document; char buf[1024]; fileHnd = al_fopen( Filename.c_str(), "r" ); if( fileHnd != 0 ) { document.clear(); while( !al_feof( fileHnd ) ) { al_fgets( fileHnd, (char*)&buf, 1024 ); document.append( (char*)&buf ); memset( (void*)buf, 0, 1024 ); } ParseFile( document ); al_fclose( fileHnd ); } }