/** * @function LoadBuffers * @brief loads buffers, from wav file to RAM (if necessary) * @param none * @return int8_t: -1: end of file / file not found, 0: ok */ static int8_t LoadBuffers(void) { int8_t res = 0; /*buffer 1*/ if(isBuffer1Empty == true) { if(LoadBuffer(buf1) < 0) { res = -1; } else { posBuf1 = 0; isBuffer1Empty = false; } } /*buffer 2 -- copy paste of buffer 1 procedure...*/ if(isBuffer2Empty == true) { if(LoadBuffer(buf2) < 0) { res = -1; } else { posBuf2 = 0; isBuffer2Empty = false; } } return res; }
bool CsAudioManager::Init(ALCchar *deviceName) { //initialize the audio library ALCdevice* pDevice; ALCcontext* pContext; const ALCchar* deviceSpecifier; // Get handle to device. pDevice = alcOpenDevice(deviceName); // Get the device specifier. deviceSpecifier = alcGetString(pDevice, ALC_DEVICE_SPECIFIER); // Create audio context. pContext = alcCreateContext(pDevice, NULL); // Set active context. alcMakeContextCurrent(pContext); // Check for an error. if (alcGetError(pDevice) != ALC_NO_ERROR) return false; alGenBuffers(NUM_SOUNDS, Buffer); LoadBuffer("../../sounds/0explosion.wav", EXPLOSION); LoadBuffer("../../sounds/0FIREMISSILE.wav",FIRE_MISSILE); LoadBuffer("../../sounds/0FIREMACHINEGUN.wav",FIRE_MACHINEGUN); LoadBuffer("../../sounds/0JETENGINE.wav", JET_ENGINE); LoadBuffer("../../sounds/0COLLISION.wav", COLLISION); LoadBuffer("../../sounds/0RICOCHET.wav", RICOCHET); LoadBuffer("../../sounds/game_music.wav", GAME_MUSIC); LoadBuffer("../../sounds/menu_music.wav", MENU_MUSIC); //LoadBuffer("wavdata/stereo.wav", MENU_SOUND); //LoadBuffer("wavdata/stereo.wav", EXPLOSION_SOUND); return true; }
bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding ) { // There was a really terrifying little bug here. The code: // value = filename // in the STL case, cause the assignment method of the std::string to // be called. What is strange, is that the std::string had the same // address as it's c_str() method, and so bad things happen. Looks // like a bug in the Microsoft STL implementation. // See STL_STRING_BUG above. // Fixed with the StringToBuffer class. value = filename; // reading in binary mode so that tinyxml can normalize the EOL IFile* file = g_OpenFile( value.c_str () ); if ( file ) { bool result = LoadBuffer( (LPCSTR)file->GetBuffer(), file->Size(), encoding ); file->Release(); return result; } else { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } }
/** * @brief * Constructor */ Buffer::Buffer(PLSound::SoundManager &cSoundManager, const String &sName, bool bStream) : PLSound::Buffer(cSoundManager, sName) { // Load the sound buffer if (sName.GetLength()) LoadBuffer(sName, bStream); }
void UpdateBuffer(){ if(!mDynamic) return; if(mBufferID == GL_INVALID_INDEX) LoadBuffer(); OpenGL::BindBuffer(GL_ARRAY_BUFFER, mBufferID); OpenGL::BufferData(GL_ARRAY_BUFFER, BufferSize(), Buffer(), GL_DYNAMIC_DRAW); }
int CLuaSVM::ExecuteFile(const char* path) //这里的path必须是经过luac -o test.out test.lua 之后的文件,不然它读进内存的都是不带转义的字符,导致编译出错..... { if( mbShutScript ) return 0; long len = File_Stream::GetSize(path); char *pBuff = new char[len+1]; memset(pBuff, 0, len+1); int iRet = File_Stream::Read(path,pBuff, len); if (iRet < 0) goto error; //load it first if(LoadBuffer(pBuff, len) != FR_OK) { ErrorInfoOut( mLS,"load script failed:%s, error msg :%s\n", path, lua_tostring(mLS, -1) ); goto error; } else { //ErrorInfoOut(NULL,"load script file:%s\n", Path ); } if(pBuff) delete pBuff; return 1; error: if(pBuff) delete pBuff; return 0; }
HRESULT CBSprite::LoadFile(char* Filename, int LifeTime, TSpriteCacheType CacheType) { CBFile* File = Game->m_FileManager->OpenFile(Filename); if(!File) { Game->LOG(0, "CBSprite::LoadFile failed for file '%s'", Filename); if(Game->m_DEBUG_DebugMode) return LoadFile("invalid_debug.bmp", LifeTime, CacheType); else return LoadFile("invalid.bmp", LifeTime, CacheType); } else { Game->m_FileManager->CloseFile(File); File = NULL; } HRESULT ret; AnsiString ext = PathUtil::GetExtension(Filename); if (StringUtil::StartsWith(Filename, "savegame:", true) || StringUtil::CompareNoCase(ext, ".bmp") || StringUtil::CompareNoCase(ext, ".tga") || StringUtil::CompareNoCase(ext, ".png") || StringUtil::CompareNoCase(ext, ".jpg")) { CBFrame* frame = new CBFrame(Game); CBSubFrame* subframe = new CBSubFrame(Game); subframe->SetSurface(Filename, true, 0, 0, 0, LifeTime, true); if(subframe->m_Surface==NULL) { Game->LOG(0, "Error loading simple sprite '%s'", Filename); ret = E_FAIL; delete frame; delete subframe; } else { CBPlatform::SetRect(&subframe->m_Rect, 0, 0, subframe->m_Surface->GetWidth(), subframe->m_Surface->GetHeight()); frame->m_Subframes.Add(subframe); m_Frames.Add(frame); m_CurrentFrame = 0; ret = S_OK; } } else { BYTE* Buffer = Game->m_FileManager->ReadWholeFile(Filename); if(Buffer) { if(FAILED(ret = LoadBuffer(Buffer, true, LifeTime, CacheType))) Game->LOG(0, "Error parsing SPRITE file '%s'", Filename); delete [] Buffer; } } m_Filename = new char [strlen(Filename)+1]; strcpy(m_Filename, Filename); return ret; }
ImageDetails::ImageDetails( const char * const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight ) : name( _name ), width( _width ), height( _height ), reportedWidth( _reportedWidth ), reportedHeight( _reportedHeight ), refBufferSize( _width * _height ), refBuffer( new Dali::PixelBuffer[ refBufferSize ] ) { LoadBuffer(); }
void TdfParser::LoadVirtualFile(std::string const& filename){ this->filename = filename; int size = G->cb->GetFileSize(filename.c_str()); if(size == -1){ G->L.print("file " + filename + " not found"); return; } char* c = new char[size]; G->cb->ReadFile(filename.c_str(),c,size); LoadBuffer(c,(std::size_t)size); return; }
wxString ScriptingManager::LoadBufferRedirectOutput(const wxString& buffer) { // wxCriticalSectionLocker c(cs); s_ScriptErrors.Clear(); ::capture.Clear(); sq_setprintfunc(SquirrelVM::GetVMPtr(), CaptureScriptOutput); bool res = LoadBuffer(buffer); sq_setprintfunc(SquirrelVM::GetVMPtr(), ScriptsPrintFunc); return res ? ::capture : (wxString) wxEmptyString; }
UInt32 Read(Byte* to,UInt32 s) { UInt32 rdd = 0; while (s && !eof) { if (readed==size) LoadBuffer(); UInt32 cpy = size - readed; if (cpy>s) cpy=s; if (cpy) ::memcpy(to+rdd,buffer+readed,cpy); s-=cpy; readed+=cpy; rdd+=cpy; } return rdd; }
static void FreeWidgetBuffer(Widget_t *pWidget) { unsigned QuadNum = Layout[LAYOUT_TYPE(pWidget->Layout)].QuadNum; unsigned char i; for (i = 0; i < QuadNum; ++i) { BufTag &= ~(1 << pWidget->Buffers[i]); // add "+" template to empty buffer LoadBuffer(pWidget->Buffers[i], pWidgetTemplate[TMPL_WGT_EMPTY]); } PrintF("-Tg:%04X", BufTag); }
HRESULT CBEvent::LoadFile(char *Filename) { byte *Buffer = Game->m_FileManager->ReadWholeFile(Filename); if (Buffer == NULL) { Game->LOG(0, "CBEvent::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; if (FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing EVENT file '%s'", Filename); delete [] Buffer; return ret; }
Buffer::Buffer(int currentUnitIndex, std::vector<int> currentBufferGenes) { //std::cout<<"Buffer creation begun"<<std::endl; unitIndex = currentUnitIndex; unitBufferTypeIndex = (unitIndex==0)? 0 : 1; bufferName = (unitBufferTypeIndex==0)? "FuelTank0" : "Battery0"; bufferGenes= currentBufferGenes; GetBufferIndex(); GetBufferFileName(); LoadBuffer(); UpdateBufferAvailabilityRatio(); minimumStateOfBuffer = 1; //bufferAvailabilityRatioOverMission.push_back(bufferAvailabilityRatio); //stateOfBufferOverMission.push_back(stateOfBuffer); }
HRESULT CAdSpriteSet::LoadFile(char * Filename, int LifeTime, TSpriteCacheType CacheType) { BYTE* Buffer = Game->m_FileManager->ReadWholeFile(Filename); if(Buffer==NULL) { Game->LOG(0, "CAdSpriteSet::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; if(FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing SPRITESET file '%s'", Filename); delete [] Buffer; return ret; }
size_t TextReader::GetLine(std::string &line) { line.clear(); bool isEnd = false; while (!isEnd) { while(pos_ < length_) { char & c = buf_[pos_++]; if (c == '\n') { isEnd = true; break; } else { line += c; } } if (isEnd || LoadBuffer() == 0) break; } return line.size(); }
HRESULT CAdTalkDef::LoadFile(const char *Filename) { byte *Buffer = Game->m_FileManager->ReadWholeFile(Filename); if (Buffer == NULL) { Game->LOG(0, "CAdTalkDef::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; CBUtils::SetString(&m_Filename, Filename); if (FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing TALK file '%s'", Filename); delete [] Buffer; return ret; }
void AnsiString::AddBuffer(const char *buffer, int len_value) { size_t len; if (!len_value) return; if ((Data) && (len_value)) { len = _LENGTH; _LENGTH = len + len_value; if (_DATA_SIZE < _LENGTH + 1) { _DATA_SIZE = ((_LENGTH + 1) / BLOCK_SIZE) * BLOCK_SIZE + BLOCK_SIZE; Data = (char *)realloc(Data, _DATA_SIZE); } MEMCPY(Data + len, buffer, len_value + 1); } else LoadBuffer(buffer, len_value); }
void Address::AttachedToWindow() { os::File* pcFile = new os::File( m_pcPlugin->GetPath() ); os::Resources cCol( pcFile ); os::ResStream* pcStream = cCol.GetResourceStream( "icon48x48.png" ); m_pcIcon = new os::BitmapImage( pcStream ); delete pcStream; delete pcFile; pcSettingsWindow = NULL; InitDefaultAddresses(); LoadAddresses(); LoadBuffer(); LoadSettings(); ExportHelpFile(); pcAddressDrop->SetTarget(this); }
HRESULT CBFontTT::LoadFile(char *Filename) { byte *Buffer = Game->m_FileManager->ReadWholeFile(Filename); if (Buffer == NULL) { Game->LOG(0, "CBFontTT::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; m_Filename = new char [strlen(Filename) + 1]; strcpy(m_Filename, Filename); if (FAILED(ret = LoadBuffer(Buffer))) Game->LOG(0, "Error parsing TTFONT file '%s'", Filename); delete [] Buffer; return ret; }
void AnsiString::AddBuffer(char *S_Data, int S_Len, int blocks) { char *newdata; size_t len; size_t len_value; if ((Data) && (S_Data)) { //len=strlen(Data); len = _LENGTH; len_value = S_Len; _LENGTH = len + len_value; if (_DATA_SIZE < _LENGTH + 1) { _DATA_SIZE = ((_LENGTH + 1) / BLOCK_SIZE) * BLOCK_SIZE * blocks + BLOCK_SIZE; Data = (char *)realloc(Data, _DATA_SIZE); } memcpy(Data + len, S_Data, len_value + 1); } else { LoadBuffer(S_Data, S_Len); } }
HRESULT CUIEntity::LoadFile(char *Filename) { byte *Buffer = Game->m_FileManager->ReadWholeFile(Filename); if (Buffer == NULL) { Game->LOG(0, "CUIEntity::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; m_Filename = new char [strlen(Filename) + 1]; strcpy(m_Filename, Filename); if (FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing ENTITY container file '%s'", Filename); delete [] Buffer; return ret; }
HRESULT CBEventSet::LoadFile(char * Filename) { BYTE* Buffer = Game->m_FileManager->ReadWholeFile(Filename); if(Buffer==NULL) { Game->LOG(0, "CBEventSet::LoadFile failed for file '%s'", Filename); return E_FAIL; } HRESULT ret; m_Filename = new char [strlen(Filename)+1]; strcpy(m_Filename, Filename); if(FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing EVENTS file '%s'", Filename); delete [] Buffer; return ret; }
static void AssignWidgetBuffer(Widget_t *pWidget) { unsigned QuadNum = Layout[LAYOUT_TYPE(pWidget->Layout)].QuadNum; unsigned char i; for (i = 0; i < QuadNum; ++i) { unsigned char Tag; for (Tag = 0; Tag < BUFFER_TAG_BITS; ++Tag) // go through 16 bufs { if ((BufTag & (1 << Tag)) == 0) // found empty buffer { pWidget->Buffers[i] = Tag; BufTag |= 1 << Tag; // add "..." template LoadBuffer(Tag, pWidgetTemplate[TMPL_WGT_LOADING]); break; } } } }
bool ScriptingManager::LoadScript(const wxString& filename) { // wxCriticalSectionLocker c(cs); wxLogNull ln; // own error checking implemented -> avoid debug warnings wxString fname(filename); wxFile f(fname); // try to open if (!f.IsOpened()) { bool found = false; // check in same dir as currently running script (if any) if (!m_CurrentlyRunningScriptFile.IsEmpty()) { fname = wxFileName(m_CurrentlyRunningScriptFile).GetPath() + _T('/') + filename; f.Open(fname); found = f.IsOpened(); } if (!found) { // check in standard script dirs fname = ConfigManager::LocateDataFile(filename, sdScriptsUser | sdScriptsGlobal); f.Open(fname); if (!f.IsOpened()) { Manager::Get()->GetLogManager()->DebugLog(_T("Can't open script ") + filename); return false; } } } // read file wxString contents = cbReadFileContents(f); m_CurrentlyRunningScriptFile = fname; bool ret = LoadBuffer(contents, fname); m_CurrentlyRunningScriptFile.Clear(); return ret; }
void AnsiString::AddBuffer(char *S_Data, int S_Len) { char *newdata; size_t len; size_t len_value; if ((Data) && (S_Data)) { //len=strlen(Data); len = _LENGTH; len_value = S_Len; _LENGTH = len + len_value; if (_DATA_SIZE < _LENGTH + 1) { _DATA_SIZE = ((_LENGTH + 1) / BLOCK_SIZE) * BLOCK_SIZE + BLOCK_SIZE; newdata = new char[_DATA_SIZE]; memcpy(newdata, Data, len); memcpy(newdata + len, S_Data, len_value + 1); delete[] Data; Data = newdata; } else memcpy(Data + len, S_Data, len_value + 1); } else { LoadBuffer(S_Data, S_Len); } //operator+=(S.Data); }
TdfParser::TdfParser(char const* buf, size_t size) { LoadBuffer(buf, size); }
void Bind(){ if(mBufferID == GL_INVALID_INDEX) LoadBuffer(); OpenGL::BindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferID); }
int BufferedFile::Read(uint8_t *pdestBuffer, int numBytes) { if ( (BufferMode==ReadBuffer) || SetBufferMode(ReadBuffer)) { // Data in buffer... copy it if ((int)(DataSize-Pos) >= numBytes) { memcpy(pdestBuffer, pBuffer+Pos, numBytes); Pos += numBytes; return numBytes; } // Not enough data in buffer, copy buffer int readBytes = DataSize-Pos; memcpy(pdestBuffer, pBuffer+Pos, readBytes); numBytes -= readBytes; pdestBuffer += readBytes; Pos = DataSize; // Don't reload buffer if more then tolerance // (No major advantage, and we don't want to write a loop) if (numBytes>FILEBUFFER_TOLERANCE) { numBytes = pFile->Read(pdestBuffer,numBytes); if (numBytes > 0) { FilePos += numBytes; Pos = DataSize = 0; } return readBytes + ((numBytes==-1) ? 0 : numBytes); } // Reload the buffer // WARNING: Right now LoadBuffer() assumes the buffer's empty LoadBuffer(); if ((int)(DataSize-Pos) < numBytes) numBytes = (int)DataSize-Pos; memcpy(pdestBuffer, pBuffer+Pos, numBytes); Pos += numBytes; return numBytes + readBytes; /* // Alternative Read implementation. The one above is probably better // due to FILEBUFFER_TOLERANCE. int total = 0; do { int bufferBytes = (int)(DataSize-Pos); int copyBytes = (bufferBytes > numBytes) ? numBytes : bufferBytes; memcpy(pdestBuffer, pBuffer+Pos, copyBytes); numBytes -= copyBytes; pdestBuffer += copyBytes; Pos += copyBytes; total += copyBytes; if (numBytes == 0) break; LoadBuffer(); } while (DataSize > 0); return total; */ } int sz = pFile->Read(pdestBuffer,numBytes); if (sz > 0) FilePos += sz; return sz; }
bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) { if ( !file ) { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Delete the existing data: Clear(); location.Clear(); // Get the file size, so we can pre-allocate the string. HUGE speed impact. long length = 0; fseek( file, 0, SEEK_END ); length = ftell( file ); fseek( file, 0, SEEK_SET ); if ( length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } char* buf = new char[ length+1 ]; buf[0] = 0; if ( fread( buf, length, 1, file ) != 1 ) { delete [] buf; SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } buf[length] = 0; bool state = LoadBuffer(buf, length, encoding); delete [] buf; return state; /* if ( !file ) { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Delete the existing data: Clear(); location.Clear(); // Get the file size, so we can pre-allocate the string. HUGE speed impact. long length = 0; fseek( file, 0, SEEK_END ); length = ftell( file ); fseek( file, 0, SEEK_SET ); // Strange case, but good to handle up front. if ( length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // If we have a file, assume it is all one big XML file, and read it in. // The document parser may decide the document ends sooner than the entire file, however. TIXML_STRING data; data.reserve( length ); char* buf = new char[ length+1 ]; buf[0] = 0; if ( fread( buf, length, 1, file ) != 1 ) { delete [] buf; SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } const char* lastPos = buf; const char* p = buf; buf[length] = 0; while( *p ) { assert( p < (buf+length) ); if ( *p == 0xa ) { // Newline character. No special rules for this. Append all the characters // since the last string, and include the newline. data.append( lastPos, (p-lastPos+1) ); // append, include the newline ++p; // move past the newline lastPos = p; // and point to the new buffer (may be 0) assert( p <= (buf+length) ); } else if ( *p == 0xd ) { // Carriage return. Append what we have so far, then // handle moving forward in the buffer. if ( (p-lastPos) > 0 ) { data.append( lastPos, p-lastPos ); // do not add the CR } data += (char)0xa; // a proper newline if ( *(p+1) == 0xa ) { // Carriage return - new line sequence p += 2; lastPos = p; assert( p <= (buf+length) ); } else { // it was followed by something else...that is presumably characters again. ++p; lastPos = p; assert( p <= (buf+length) ); } } else { ++p; } } // Handle any left over characters. if ( p-lastPos ) { data.append( lastPos, p-lastPos ); } delete [] buf; buf = 0; Parse( data.c_str(), 0, encoding ); if ( Error() ) return false; else return true; */ }