Graphics::Surface *loadThumbnail(Common::SeekableReadStream &in) { ThumbnailHeader header; if (!loadHeader(in, header, true)) return 0; if (header.bpp != 2) { warning("trying to load thumbnail with unsupported bit depth %d", header.bpp); return 0; } Graphics::PixelFormat format = g_system->getOverlayFormat(); Graphics::Surface *const to = new Graphics::Surface(); to->create(header.width, header.height, format); OverlayColor *pixels = (OverlayColor *)to->pixels; for (int y = 0; y < to->h; ++y) { for (int x = 0; x < to->w; ++x) { uint8 r, g, b; colorToRGB<ColorMasks<565> >(in.readUint16BE(), r, g, b); // converting to current OSystem Color *pixels++ = format.RGBToColor(r, g, b); } } return to; }
int VMIFile::readData() { file_t f; vmi_hdr_t header; uint8 *raw; char tmp[13]; DreamcastFile *df; df=getDCFile(); if(df == NULL) { df=new DreamcastFile(); setDCFile(df); } if (!(f=fs_open(getFileName(), O_RDONLY))) { printf("ERROR: Can't open %s!\n", getFileName()); return(-1); } fs_read(f, &header, 0x6C); fs_close(f); loadHeader(&header); sprintf(tmp, "%s.VMS", getResourceName()); if (!(f=fs_open(tmp, O_RDONLY))) { printf("ERROR: Can't open %s!\n", tmp); return(-2); } // raw=(uint8*)malloc(df->getSize()); raw=new uint8[df->getSize()]; fs_read(f, raw, df->getSize()); df->setData(raw); // free(raw); fs_close(f); return(0); }
void UISubclassWizard::clicked() { switch ( swPages->currentIndex() ) { case 0: pbBackward->setEnabled( false ); pbForward->setText( tr ( "Next" ) ); break; case 1: pbBackward->setEnabled( true ); pbForward->setText( tr ( "Next" ) ); loadHeader(); break; case 2: pbBackward->setEnabled( true ); if ( pbForward->text() == tr( "Next" ) ) { pbForward->setText( tr ( "Finish" ) ); loadSource(); } else accept(); break; } lInformations->setText( swPages->currentWidget()->toolTip() ); }
void FoxPro::load(SeekableReadStream *dbf, SeekableReadStream *cdx, SeekableReadStream *fpt) { assert(dbf); // Read header uint32 recordSize, recordCount, firstRecordPos; loadHeader(*dbf, recordSize, recordCount, firstRecordPos); if (_hasIndex && !cdx) throw Exception("Index needed"); if (_hasMemo && !fpt) throw Exception("Memo needed"); // Read fields loadFields(*dbf, recordSize); if (_hasMemo && !fpt) throw Exception("Memo needed"); // Read records dbf->seek(firstRecordPos); loadRecords(*dbf, recordSize, recordCount); // Read memos if (fpt) loadMemos(*fpt); // TODO: Read the compound index (CDX) file }
// fileManager::loadMaskImage(): loads the full tractogram mask in memory void fileManager::loadMaskImage( std::string maskFilename) { std::vector<std::vector<std::vector<float> > > maskMatrix; ValueType maskValueType = readImage( maskFilename, &maskMatrix ); loadHeader(maskFilename); const size_t dimx = maskMatrix.size(); const size_t dimy = maskMatrix[0].size(); const size_t dimz = maskMatrix[0][0].size(); m_maskMatrix.clear(); { std::vector<bool> zvect(dimz,false); std::vector<std::vector<bool> >yzmatrix(dimy,zvect); m_maskMatrix.resize(dimx,yzmatrix); } size_t maskSum=0; for (int i=0 ; i<dimx ; ++i) { for (int j=0 ; j<dimy ; ++j) { for (int k=0 ; k<dimz ; ++k) { m_maskMatrix[i][j][k] = maskMatrix[i][j][k]; if(m_maskMatrix[i][j][k]) ++maskSum; } } } m_flipVector.clear(); m_flipVector.resize(maskSum,0); for (size_t i=0; i<maskSum; ++i) { m_flipVector[i]=i; } size_t indexer(0); for (int k=0 ; k<dimz ; ++k) { for (int j=0 ; j<dimy ; ++j) { size_t valuesPerRow(0); for (int i=0 ; i<dimx ; ++i) { if(m_maskMatrix[i][j][k]) { ++valuesPerRow; } } std::reverse(m_flipVector.begin()+indexer,m_flipVector.begin()+indexer+valuesPerRow); indexer+=valuesPerRow; } } return; }// end fileManager::loadMaskImage() -----------------------------------------------------------------
bool PEFormat::load(SharedPtr<DataSource> source, bool fromMemory) { size_t headerSize = loadHeader(source, fromMemory); if(headerSize == 0) return false; header_ = source->getView(0, headerSize); return true; }
void StreamedSnd::load(Common::SeekableReadStream *in) { loadHeader(in); // Start decoding the input stream Audio::AudioStream *as = makeDecoder(in, _size); // Start playing the decoded audio stream play(as); }
bool checkThumbnailHeader(Common::SeekableReadStream &in) { uint32 position = in.pos(); ThumbnailHeader header; bool hasHeader = loadHeader(in, header, false); in.seek(position, SEEK_SET); return hasHeader; }
bool IFFDecoder::loadStream(Common::SeekableReadStream &stream) { destroy(); const uint32 form = stream.readUint32BE(); if (form != ID_FORM) { warning("Failed reading IFF-file"); return false; } stream.skip(4); const uint32 type = stream.readUint32BE(); switch (type) { case ID_ILBM: _type = TYPE_ILBM; break; case ID_PBM: _type = TYPE_PBM; break; } if (type == TYPE_UNKNOWN) { warning("Failed reading IFF-file"); return false; } while (1) { const uint32 chunkType = stream.readUint32BE(); const uint32 chunkSize = stream.readUint32BE(); if (stream.eos()) break; switch (chunkType) { case ID_BMHD: loadHeader(stream); break; case ID_CMAP: loadPalette(stream, chunkSize); break; case ID_CRNG: loadPaletteRange(stream, chunkSize); break; case ID_BODY: loadBitmap(stream); break; default: stream.skip(chunkSize); } } return true; }
bool skipThumbnail(Common::SeekableReadStream &in) { uint32 position = in.pos(); ThumbnailHeader header; if (!loadHeader(in, header, false)) { in.seek(position, SEEK_SET); return false; } in.seek(header.size - (in.pos() - position), SEEK_CUR); return true; }
void GFF4File::load(uint32 type) { try { loadHeader(type); loadStructs(); loadStrings(); } catch (Common::Exception &e) { clear(); e.add("Failed reading GFF4 file"); throw; } }
void GFF3File::load(uint32 id) { try { loadHeader(id); loadStructs(); loadLists(); } catch (Common::Exception &e) { clear(); e.add("Failed reading GFF3 file"); throw; } }
// // beginLoadStream // bool kstream::beginLoadStream( const char * szFileName ) { // Wrong stream type if ( m_streamType == STREAM_OUTPUT ) return false; // Load a streaming file m_spStreamFile.reset( new SystemFile( szFileName, READ_ONLY, BINARY_FILE ) ); // Load the header information if ( !loadHeader() ) return false; return true; }
void KNPluginManager::loadPlugins() { //Initial the infrastructure; loadHeader(new KNMainWindowHeader); loadPreference(new KNPreference); #ifdef Q_OS_WIN loadPlatformExtras(new KNWindowsExtras); #endif #ifdef Q_OS_MACX loadPlatformExtras(new KNMacExtras); #endif //Load the category plugin. loadMusicPlugin(new KNMusicPlugin); }
TemplightProtobufReader::LastChunkType TemplightProtobufReader::next() { if ( buffer.empty() ) { if ( remainder_buffer.empty() ) { LastChunk = TemplightProtobufReader::EndOfFile; return LastChunk; } else { return startOnBuffer(remainder_buffer); } } unsigned int cur_wire = llvm::protobuf::loadVarInt(buffer); switch(cur_wire) { case llvm::protobuf::getStringWire<1>::value: { std::uint64_t cur_size = llvm::protobuf::loadVarInt(buffer); loadHeader(buffer.slice(0, cur_size)); buffer = buffer.drop_front(cur_size); return LastChunk; }; case llvm::protobuf::getStringWire<2>::value: { std::uint64_t cur_size = llvm::protobuf::loadVarInt(buffer); llvm::StringRef sub_buffer = buffer.slice(0, cur_size); buffer = buffer.drop_front(cur_size); cur_wire = llvm::protobuf::loadVarInt(sub_buffer); cur_size = llvm::protobuf::loadVarInt(sub_buffer); switch( cur_wire ) { case llvm::protobuf::getStringWire<1>::value: loadBeginEntry(sub_buffer); break; case llvm::protobuf::getStringWire<2>::value: loadEndEntry(sub_buffer); break; default: // ignore for fwd-compat. break; }; return LastChunk; }; case llvm::protobuf::getStringWire<3>::value: { std::uint64_t cur_size = llvm::protobuf::loadVarInt(buffer); loadDictionaryEntry(buffer.slice(0, cur_size)); buffer = buffer.drop_front(cur_size); LastChunk = TemplightProtobufReader::Other; return LastChunk; }; default: { // ignore for fwd-compat. llvm::protobuf::skipData(buffer, cur_wire); return next(); // tail-call }; } }
DataFileReader::DataFileReader(string& fileName) { try { inputFile = new BufferedFile(); inputFile->open(fileName); counter=0; loadHeader(); } catch(...) { #ifdef FATAL cout << "Cannot load InputFile" << endl; #endif exit(0); } }
int Map::load(std::string fname) { FileParser infile; maprow *cur_layer = NULL; clearEvents(); clearLayers(); clearQueues(); // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemies.push(Map_Enemy()); else if (infile.section == "enemygroup") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile, &cur_layer); else if (infile.section == "enemy") loadEnemy(infile); else if (infile.section == "enemygroup") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); return 0; }
/** * constructor * * @param filename name of BAM file * @param rranges range descriptor string * @param rputrank put ranks on alignments **/ BamRangeDecoder(std::string const & filename, std::string const & rranges, bool const rputrank = false) : libmaus2::bambam::BamAlignmentDecoder(rputrank), Pheader(loadHeader(filename)), header(*Pheader), Pindex(loadIndex(deriveBamIndexName(filename))), index(*Pindex), ranges(libmaus2::bambam::BamRangeParser::parse(rranges,header)), rangeidx(0), rangecur(0), wrapper(filename,header), chunks(), chunkidx(0), decoder(wrapper.getDecoder()), algn(decoder.getAlignment()), active(setup()) { }
bool RawVolumeModel::getVolumeInfo(VolumeInfo& info, const eq::Range& range) { if (!_headerLoaded && !loadHeader(1.0f, 1.0f)) return false; if (_preintName == 0) { LBLOG(eq::LOG_CUSTOM) << "Creating preint" << std::endl; _preintName = createPreintegrationTable(&_TF[0]); } VolumePart* volumePart = nullptr; const int32_t key = calcHashKey(range); if (_volumeHash.find(key) == _volumeHash.end()) { // new key volumePart = &_volumeHash[key]; if (!_createVolumeTexture(volumePart->volume, volumePart->TD, range)) return false; } else { // old key volumePart = &_volumeHash[key]; } info.volume = volumePart->volume; info.TD = volumePart->TD; info.preint = _preintName; info.volScaling = _volScaling; if (_hasDerivatives) { info.voxelSize.W = 1.f; info.voxelSize.H = 1.f; info.voxelSize.D = 1.f; } else { info.voxelSize.W = 1.f / _tW; info.voxelSize.H = 1.f / _tH; info.voxelSize.D = 1.f / _tD; } return true; }
void TransactionWidget::loadQuery() { ThreadControl *tc = qobject_cast<ThreadControl *>( sender() ); if( !tc ) return; int i = tc->getIndexOfLastQuery( qList ); if( i < 0 ) return; QString str = tc->getData(); switch(i) { case 0: { loadHeader( str ); break; } case 1: case 4: case 5: { loadTransactions( str ); break; } case 2: { clearTransaction( str ); break; } case 3: { loadAccount( str ); break; } case 6: case 7: { loadAccountSaldo( str ); break; } } }
PointCloudT PCDStream<PointCloudT>::loadData(std::istream& stream) { delete header; loadHeader(stream); int id = 0; if(PointCloudT::Point::RowsAtCompileTime != header->fieldCount + 1) { throw std::ios_base::failure("Field count does not match."); } typename PointCloudT::ScalarType data[PointCloudT::Point::RowsAtCompileTime]; PointCloudT pointCloud; pointCloud.reserve(header->points); std::string line; while(std::getline(stream, line)) { if(line.empty()) continue; char firstChar = line.at(0); if(firstChar == '#') continue; std::istringstream lineStream(line); for(std::size_t i = 0; i < header->fieldCount; i++) { lineStream >> data[i]; } data[header->fieldCount] = 1; pointCloud.emplace_back(data); auto& point = pointCloud.back(); point.setId(id++); point.realPoint = true; } return pointCloud; }
void PCDStream<PointCloudT>::saveData(const PointCloudT& pointCloud, std::ostream& stream) { loadHeader(pointCloud); header->save(stream); // TODO: Set precision based on header/point type. std::streamsize precision = stream.precision(); stream.precision(8); for(const auto& point : pointCloud) { stream << point[0]; for(std::size_t i = 1; i < header->fieldCount; i++) { stream << ' ' << point[i]; } stream << std::endl; } stream.precision(precision); }
gwMd2::gwMd2(const char *filePath){ FILE *fp = fopen(filePath,"r"); assert(fp); header = loadHeader(fp); assert(header); skin = loadSkins(fp); assert(skin); texCoord = loadTexCoords(fp); assert(texCoord); triangle = loadTriangles(fp); assert(triangle); frame = loadFrames(fp); assert(frame); glcmds = loadGlCommands(fp); assert(glcmds); tex = new gwTexture(skin[textureId].name); assert(tex); fclose(fp); }
/*AudioFile::AudioFile( shared_ptr<IStream> aStream ) : mStream( aStream ) { setup(); }*/ AudioFile::AudioFile( const std::string &aFilePath ) { #if defined( FLI_MAC ) FSRef fsref; OSStatus fileRefError = FSPathMakeRef( (const UInt8 *)aFilePath.c_str(), &fsref, NULL ); if( fileRefError ) { //handle error std::cout << "Input file not found" << std::endl; return; } OSStatus audioFileOpenError = AudioFileOpen(&fsref, fsRdPerm, 0, &mNativeFileRef); if( audioFileOpenError ) { //handle error std::cout << "AudioFileOpen failed" << std::endl; return; } loadHeader(); load(); #endif }
bool LokiFormat::loadImage(const unsigned char *data, std::size_t size) { // Make sure the file is large enough to contain the Loki header if (!isValid(data, size)) { return false; } std::size_t headerIndex; if (!findHeader(data, size, 32, &headerIndex)) { LOGE("Failed to find Android header in loki'd boot image"); return false; } LOGD("Found Android boot image header at: %" MB_PRIzu, headerIndex); if (!loadHeader(data, size, headerIndex)) { return false; } const LokiHeader *loki = reinterpret_cast<const LokiHeader *>(&data[0x400]); LOGD("Found Loki boot image header at 0x%x", 0x400); LOGD("- magic: %s", StringUtils::toMaxString( reinterpret_cast<const char *>(loki->magic), 4).c_str()); LOGD("- recovery: %u", loki->recovery); LOGD("- build: %s", StringUtils::toMaxString(loki->build, 128).c_str()); LOGD("- orig_kernel_size: %u", loki->orig_kernel_size); LOGD("- orig_ramdisk_size: %u", loki->orig_ramdisk_size); LOGD("- ramdisk_addr: 0x%08x", loki->ramdisk_addr); if (loki->orig_kernel_size != 0 && loki->orig_ramdisk_size != 0 && loki->ramdisk_addr != 0) { return loadLokiNewImage(data, size, loki); } else { return loadLokiOldImage(data, size, loki); } }
ImageSourcePng::ImageSourcePng( DataSourceRef dataSourceRef, ImageSource::Options /*options*/ ) : ImageSource(), mInfoPtr( 0 ), mPngPtr( 0 ) { mPngPtr = png_create_read_struct( PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL ); if( ! mPngPtr ) { throw ImageSourcePngException( "Could not create png struct." ); } mCiInfoPtr = shared_ptr<ci_png_info>( new ci_png_info ); mCiInfoPtr->srcStreamRef = dataSourceRef->createStream(); png_set_read_fn( mPngPtr, reinterpret_cast<void*>( mCiInfoPtr.get() ), ci_PNG_stream_reader ); mInfoPtr = png_create_info_struct( mPngPtr ); if( ! mInfoPtr ) { png_destroy_read_struct( &mPngPtr, (png_infopp)NULL, (png_infopp)NULL ); mPngPtr = 0; throw ImageSourcePngException( "Could not destroy png read struct." ); } if( ! loadHeader() ) throw ImageSourcePngException( "Could not load png header." ); }
bool AndroidFormat::loadImage(const unsigned char *data, std::size_t size) { std::size_t headerIndex; if (!findHeader(data, size, 512, &headerIndex)) { LOGE("Failed to find Android header in boot image"); return false; } LOGD("Found Android boot image header at: %" PRIzu, headerIndex); if (!loadHeader(data, size, headerIndex)) { return false; } uint32_t pos = 0; // Save kernel image pos += headerIndex; pos += sizeof(BootImageHeader); pos += skipPadding(sizeof(BootImageHeader), mI10e->pageSize); if (pos + mI10e->hdrKernelSize > size) { LOGE("Kernel image exceeds boot image size by %" PRIzu " bytes", pos + mI10e->hdrKernelSize - size); return false; } mI10e->kernelImage.assign(data + pos, data + pos + mI10e->hdrKernelSize); // Save ramdisk image pos += mI10e->hdrKernelSize; pos += skipPadding(mI10e->hdrKernelSize, mI10e->pageSize); if (pos + mI10e->hdrRamdiskSize > size) { LOGE("Ramdisk image exceeds boot image size by %" PRIzu " bytes", pos + mI10e->hdrRamdiskSize - size); return false; } mI10e->ramdiskImage.assign(data + pos, data + pos + mI10e->hdrRamdiskSize); // Save second bootloader image pos += mI10e->hdrRamdiskSize; pos += skipPadding(mI10e->hdrRamdiskSize, mI10e->pageSize); if (pos + mI10e->hdrSecondSize > size) { LOGE("Second bootloader image exceeds boot image size by %" PRIzu " bytes", pos + mI10e->hdrSecondSize - size); return false; } // The second bootloader may not exist if (mI10e->hdrSecondSize > 0) { mI10e->secondImage.assign(data + pos, data + pos + mI10e->hdrSecondSize); } else { mI10e->secondImage.clear(); } // Save device tree image pos += mI10e->hdrSecondSize; pos += skipPadding(mI10e->hdrSecondSize, mI10e->pageSize); if (pos + mI10e->hdrDtSize > size) { std::size_t diff = pos + mI10e->hdrDtSize - size; LOGE("WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING"); LOGE("THIS BOOT IMAGE MAY NO LONGER BE BOOTABLE. YOU HAVE BEEN WARNED"); LOGE("Device tree image exceeds boot image size by %" PRIzu " bytes and HAS BEEN TRUNCATED", diff); LOGE("WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING"); mI10e->dtImage.assign(data + pos, data + pos + mI10e->hdrDtSize - diff); } else { mI10e->dtImage.assign(data + pos, data + pos + mI10e->hdrDtSize); } // The device tree image may not exist as well if (mI10e->hdrDtSize == 0) { mI10e->dtImage.clear(); } pos += mI10e->hdrDtSize; pos += skipPadding(mI10e->hdrDtSize, mI10e->pageSize); return true; }
int main (void) { int WidthBack, HeightBack, i, j; bool quit = 0; //const Uint8 *kbState = SDL_GetKeyboardState(NULL); char **imgFromSrc; SDL_Event e; SDL_Window *win; SDL_Renderer *ren; SDL_Texture *background; if (SDL_Init(SDL_INIT_VIDEO) != 0 || (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG) { logSDLError("Init"); return 1; } win = SDL_CreateWindow( "Generic Title", WINDOW_OFFSET_X, WINDOW_OFFSET_Y, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_GRABBED ); if (win == NULL) { logSDLError("CreateWindow"); return 2; } ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (ren == NULL) { logSDLError("CreateRenderer"); return 3; } imgFromSrc = bmp_xpm; background = loadHeader(imgFromSrc, ren); //character = loadTexture("char.png", ren); if (background == NULL /*|| character == NULL*/) { logSDLError("loadTexture"); return 4; } SDL_RenderClear(ren); SDL_QueryTexture(background, NULL, NULL, &WidthBack, &HeightBack); WidthBack /= 2; HeightBack /= 2; for (i = 0; i < WINDOW_WIDTH / WidthBack; i++) { for (j = 0; j <= WINDOW_HEIGHT / HeightBack; j++) { renderTextureS(background, ren, i * WidthBack, j * HeightBack, WidthBack, HeightBack); } } SDL_RenderPresent(ren); while (!quit) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) quit = 1; //if (e.type == SDL_MOUSEBUTTONDOWN) quit = 1; } SDL_RenderClear(ren); for (i = 0; i < WINDOW_WIDTH / WidthBack; i++) { for (j = 0; j <= WINDOW_HEIGHT / HeightBack; j++) { renderTextureS(background, ren, i * WidthBack, j * HeightBack, WidthBack, HeightBack); } } SDL_RenderPresent(ren); } SDL_DestroyTexture(background); cleanUp(win, ren); return 0; }
int main (void) { //int argv, char **argc int x, y, i, j, bW, bH, fW, fH, sW, sH; int curClip = 0; bool quit = 0; const Uint8 *kbState = SDL_GetKeyboardState(NULL); char **imgFromSrc; SDL_Event e; SDL_Window *win; SDL_Renderer *ren; SDL_Texture *bg; SDL_Texture *fg; SDL_Rect wall; SDL_Rect clips[CLIPS_AMOUNT]; if (SDL_Init(SDL_INIT_VIDEO) != 0 || (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG) { logSDLError("Init"); return 1; } win = SDL_CreateWindow("Hello World!", WINDOW_OFFSET_X, WINDOW_OFFSET_Y, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN); if (win == NULL) { logSDLError("CreateWindow"); return 2; } ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (ren == NULL) { logSDLError("CreateRenderer"); return 3; } imgFromSrc = bmp_xpm; bg = loadHeader(imgFromSrc, ren); fg = loadTexture("../SDL/sprites/sprite.png", ren); if (bg == NULL || fg == NULL) { logSDLError("loadTexture"); return 4; } SDL_RenderClear(ren); SDL_QueryTexture(bg, NULL, NULL, &bW, &bH); bW /= 2; bH /= 2; for (i = 0; i < WINDOW_WIDTH / bW; i++) { for (j = 0; j <= WINDOW_HEIGHT / bH; j++) { renderTextureS(bg, ren, i * bW, j * bH, bW, bH); } } fW = 95; fH = 95; x = WINDOW_WIDTH / 2 - fW / 2; y = WINDOW_WIDTH / 2 - fH / 2; for (i = 0; i < CLIPS_AMOUNT; i++) { clips[i].x = i / 2 * fW; clips[i].y = i % 2 * fH; clips[i].w = fW; clips[i].h = fH; } SDL_QueryTexture(fg, NULL, NULL, &sW, &sH); renderTexture(fg, ren, x, y); SDL_RenderPresent(ren); SDL_Delay(2000); while (!quit) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) quit = 1; //if (e.type == SDL_MOUSEBUTTONDOWN) quit = 1; } if (kbState[SDL_SCANCODE_W] || kbState[SDL_SCANCODE_UP]) { x -= 5; curClip = 3; if (x < -sW) x = WINDOW_WIDTH - sW; } if (kbState[SDL_SCANCODE_A] || kbState[SDL_SCANCODE_LEFT]) { y -= 5; curClip = 0; if (y < -sH) y = WINDOW_HEIGHT + sH; } if (kbState[SDL_SCANCODE_S] || kbState[SDL_SCANCODE_DOWN]) { x += 5; curClip = 1; if (x > WINDOW_WIDTH - sW) x = 0 -sW; } if (kbState[SDL_SCANCODE_D] || kbState[SDL_SCANCODE_RIGHT]) { y += 5; curClip = 2; if (y > WINDOW_HEIGHT + sH) y = 0 -sH; } SDL_RenderClear(ren); for (i = 0; i < WINDOW_WIDTH / bW; i++) { for (j = 0; j <= WINDOW_HEIGHT / bH; j++) { renderTextureS(bg, ren, i * bW, j * bH, bW, bH); } } renderSprite(fg, ren, x, y, &clips[curClip]); SDL_RenderPresent(ren); } SDL_DestroyTexture(bg); SDL_DestroyTexture(fg); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); cleanUp(); return 0; }
int Map::load(const std::string& fname) { FileParser infile; clearEvents(); clearLayers(); clearQueues(); music_filename = ""; // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile); else if (infile.section == "enemy") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); // create a temporary EffectDef for immunity; will be used for map StatBlocks EffectDef immunity_effect; immunity_effect.id = "MAP_EVENT_IMMUNITY"; immunity_effect.type = "immunity"; // create StatBlocks for events that need powers for (unsigned i=0; i<events.size(); ++i) { Event_Component *ec_power = events[i].getComponent(EC_POWER); if (ec_power) { statblocks.push_back(StatBlock()); StatBlock *statb = &statblocks.back(); if (!statb) { logError("Map: Could not create StatBlock for Event."); continue; } // store the index of this StatBlock so that we can find it when the event is activated ec_power->y = static_cast<int>(statblocks.size())-1; statb->starting[STAT_ACCURACY] = 1000; // always hit the target Event_Component *ec_path = events[i].getComponent(EC_POWER_PATH); if (ec_path) { // source is power path start statb->pos.x = static_cast<float>(ec_path->x) + 0.5f; statb->pos.y = static_cast<float>(ec_path->y) + 0.5f; } else { // source is event location statb->pos.x = static_cast<float>(events[i].location.x) + 0.5f; statb->pos.y = static_cast<float>(events[i].location.y) + 0.5f; } Event_Component *ec_damage = events[i].getComponent(EC_POWER_DAMAGE); if (ec_damage) { statb->starting[STAT_DMG_MELEE_MIN] = statb->starting[STAT_DMG_RANGED_MIN] = statb->starting[STAT_DMG_MENT_MIN] = ec_damage->a; statb->starting[STAT_DMG_MELEE_MAX] = statb->starting[STAT_DMG_RANGED_MAX] = statb->starting[STAT_DMG_MENT_MAX] = ec_damage->b; } // this is used to store cooldown ticks for a map power // the power id, type, etc are not used statb->powers_ai.resize(1); // make this StatBlock immune to negative status effects // this is mostly to prevent a player with a damage return bonus from damaging this StatBlock statb->effects.addEffect(immunity_effect, 0, 0, false, -1, 0, SOURCE_TYPE_ENEMY); } } // ensure that our map contains a collison layer if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) { layernames.push_back("collision"); layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h, 0); } collision_layer = static_cast<int>(layers.size())-1; } return 0; }