void ReadALConfig(void) { al_string ppath = AL_STRING_INIT_STATIC(); WCHAR buffer[MAX_PATH]; const WCHAR *str; FILE *f; if(SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE) { al_string filepath = AL_STRING_INIT_STATIC(); alstr_copy_wcstr(&filepath, buffer); alstr_append_cstr(&filepath, "\\alsoft.ini"); TRACE("Loading config %s...\n", alstr_get_cstr(filepath)); f = al_fopen(alstr_get_cstr(filepath), "rt"); if(f) { LoadConfigFromFile(f); fclose(f); } alstr_reset(&filepath); } GetProcBinary(&ppath, NULL); if(!alstr_empty(ppath)) { alstr_append_cstr(&ppath, "\\alsoft.ini"); TRACE("Loading config %s...\n", alstr_get_cstr(ppath)); f = al_fopen(alstr_get_cstr(ppath), "r"); if(f) { LoadConfigFromFile(f); fclose(f); } } if((str=_wgetenv(L"ALSOFT_CONF")) != NULL && *str) { al_string filepath = AL_STRING_INIT_STATIC(); alstr_copy_wcstr(&filepath, str); TRACE("Loading config %s...\n", alstr_get_cstr(filepath)); f = al_fopen(alstr_get_cstr(filepath), "rt"); if(f) { LoadConfigFromFile(f); fclose(f); } alstr_reset(&filepath); } alstr_reset(&ppath); }
Cursor::Cursor( Palette* ColourPalette ) { ALLEGRO_FILE* f = al_fopen( "data/TACDATA/MOUSE.DAT", "rb" ); while( images.size() < al_fsize( f ) / 576 ) { ALLEGRO_BITMAP* b = al_create_bitmap( 24, 24 ); ALLEGRO_LOCKED_REGION* r = al_lock_bitmap( b, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 ); for( int y = 0; y < 24; y++ ) { for( int x = 0; x < 24; x++ ) { int palidx = al_fgetc( f ); Colour* rowptr = (Colour*)(&((char*)r->data)[ (y * r->pitch) + (x * 4) ]); Colour* palcol = ColourPalette->GetColour( palidx ); rowptr->a = palcol->a; rowptr->r = palcol->r; rowptr->g = palcol->g; rowptr->b = palcol->b; } } al_unlock_bitmap( b ); images.push_back( b ); } CurrentType = CursorType::Normal; cursorx = 0; cursory = 0; }
/* 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; }
SolarSystem *solsys_load(const char *filename) { SolarSystem *ret; ALLEGRO_FILE *file; ALLEGRO_CONFIG *cfg; file = al_fopen(filename, "rb"); if (file == NULL) { log_err("Error opening file %s\n", filename); return NULL; } cfg = al_load_config_file_f(file); if (cfg == NULL) { al_fclose(file); log_err("Not a valid config file\n"); return NULL; } ret = load_from_config(cfg); if (ret == NULL) log_err("Couldn't load solarsystem from file: %s\n", filename); else log_dbg("Loaded a solarsystem with %d bodies\n", ret->num_bodies); al_destroy_config(cfg); al_fclose(file); return ret; }
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"); }
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 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); }
bool File::open( const std::string& fileName, const std::string& openMode ) { if(isOpen()) { close(); } m_file = al_fopen(fileName.c_str(),openMode.c_str()); return m_file != NULL; }
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; }
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; }
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_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; }
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_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; }
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_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_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; }
void SaveButton::on_click(int, int) { if (saving) { log_printf("Stopped saving waveform.\n"); saving = false; return; } if (!save_fp) { save_fp = al_fopen("ex_synth.raw", "wb"); } if (save_fp) { log_printf("Started saving waveform.\n"); saving = true; } }
ALLEGRO_FILE* Data::load_file(const std::string path, const char *mode) { std::string fullPath = this->GetActualFilename(path); if (fullPath == "") { std::cerr << "Failed to find file \"" + path +"\"\n"; return nullptr; } ALLEGRO_FILE *file = al_fopen(fullPath.c_str(), mode); if (file == nullptr) { std::cerr << "Failed to open file \"" + fullPath +"\"\n"; return nullptr; } return file; }
/* Function: al_load_ogg_vorbis */ ALLEGRO_SAMPLE *al_load_ogg_vorbis(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_vorbis_f(f); return spl; }
/* 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; }
/* Function: al_load_ogg_vorbis_audio_stream */ ALLEGRO_AUDIO_STREAM *al_load_ogg_vorbis_audio_stream(const char *filename, size_t buffer_count, unsigned int samples) { ALLEGRO_FILE *f; ALLEGRO_AUDIO_STREAM *stream; ASSERT(filename); ALLEGRO_INFO("Loading stream %s.\n", filename); f = al_fopen(filename, "rb"); if (!f) { ALLEGRO_WARN("Failed reading %s.\n", filename); return NULL; } stream = al_load_ogg_vorbis_audio_stream_f(f, buffer_count, samples); return stream; }
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_WARN("Failed reading %s.\n", filename); return NULL; } spl = _al_load_voc_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; }
// Method to Initialize Level void level1() { Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet Pacman.X = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen Pacman.Y = SCREEN_H / 2; // Starting y-coordinate of pacman on the screen Pacman.S = 2.0; // Movement S of pacman Pacman.NumbOfFrames = 2; // Total number of pacman animation frames in the sprite sheet Pacman.frameDelay = 7; // S of pacman animation Pacman.InitObject(); // Initialize pacman gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)]; gameObjectCount = 0; Food = al_load_bitmap("food.png"); Block = al_load_bitmap("block.png"); Level = al_fopen("level_1.data", "r"); // Loading and initializing Level & Game Objects for (int R = 0; R < SCREEN_H / TILE_SIZE; R++) { for (int C = 0; C < SCREEN_W / TILE_SIZE; C++) { levelGrid[R][C] = al_fgetc(Level); switch (levelGrid[R][C]) { case 10: C--; break; case 49: gameObject[gameObjectCount].InitObject(Block, C * TILE_SIZE, R * TILE_SIZE, BLOCK); gameObjectCount++; break; case 48: gameObject[gameObjectCount].InitObject(Food, C * TILE_SIZE, R * TILE_SIZE, FOOD); gameObjectCount++; break; } } } }
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); }
/* 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; }
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 ); } }