void Database::ExecSongTablesCommands(QSqlDatabase& db, const QStringList& song_tables, const QStringList& commands) { for (const QString& command : commands) { // There are now lots of "songs" tables that need to have the same schema: // songs, magnatune_songs, and device_*_songs. We allow a magic value // in the schema files to update all songs tables at once. if (command.contains(kMagicAllSongsTables)) { for (const QString& table : song_tables) { // Another horrible hack: device songs tables don't have matching _fts // tables, so if this command tries to touch one, ignore it. if (table.startsWith("device_") && command.contains(QString(kMagicAllSongsTables) + "_fts")) { continue; } qLog(Info) << "Updating" << table << "for" << kMagicAllSongsTables; QString new_command(command); new_command.replace(kMagicAllSongsTables, table); QSqlQuery query(db.exec(new_command)); if (CheckErrors(query)) qFatal("Unable to update music library database"); } } else { QSqlQuery query(db.exec(command)); if (CheckErrors(query)) qFatal("Unable to update music library database"); } } }
void Draw(const std::vector<DrawObject>& drawObjects, std::vector<tinyobj::material_t>& materials, std::map<std::string, GLuint>& textures) { glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_FILL); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 1.0); GLsizei stride = (3 + 3 + 3 + 2) * sizeof(float); for (size_t i = 0; i < drawObjects.size(); i++) { DrawObject o = drawObjects[i]; if (o.vb < 1) { continue; } glBindBuffer(GL_ARRAY_BUFFER, o.vb); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); std::string diffuse_texname = materials[o.material_id].diffuse_texname; if (diffuse_texname.length() > 0) { glBindTexture(GL_TEXTURE_2D, textures[diffuse_texname]); } glVertexPointer(3, GL_FLOAT, stride, (const void*)0); glNormalPointer(GL_FLOAT, stride, (const void*)(sizeof(float) * 3)); glColorPointer(3, GL_FLOAT, stride, (const void*)(sizeof(float) * 6)); glTexCoordPointer(2, GL_FLOAT, stride, (const void*)(sizeof(float) * 9)); glDrawArrays(GL_TRIANGLES, 0, 3 * o.numTriangles); CheckErrors("drawarrays"); glBindTexture(GL_TEXTURE_2D, 0); } // draw wireframe glDisable(GL_POLYGON_OFFSET_FILL); glPolygonMode(GL_FRONT, GL_LINE); glPolygonMode(GL_BACK, GL_LINE); glColor3f(0.0f, 0.0f, 0.4f); for (size_t i = 0; i < drawObjects.size(); i++) { DrawObject o = drawObjects[i]; if (o.vb < 1) { continue; } glBindBuffer(GL_ARRAY_BUFFER, o.vb); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, stride, (const void*)0); glNormalPointer(GL_FLOAT, stride, (const void*)(sizeof(float) * 3)); glColorPointer(3, GL_FLOAT, stride, (const void*)(sizeof(float) * 6)); glTexCoordPointer(2, GL_FLOAT, stride, (const void*)(sizeof(float) * 9)); glDrawArrays(GL_TRIANGLES, 0, 3 * o.numTriangles); CheckErrors("drawarrays"); } }
// open an Ogg stream from a given file and start playing it void COggStream::Play(const std::string& path, const float3& pos, float volume) { if (!stopped) { // we're already playing another stream return; } int result = 0; if (!(oggFile = fopen(path.c_str(), "rb"))) { logOutput.Print("Could not open Ogg file."); return; } if ((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0) { fclose(oggFile); logOutput.Print("Could not open Ogg stream (reason: %s).", ErrorString(result).c_str()); return; } vorbisInfo = ov_info(&oggStream, -1); vorbisComment = ov_comment(&oggStream, -1); // DisplayInfo(); if (vorbisInfo->channels == 1) { format = AL_FORMAT_MONO16; } else { format = AL_FORMAT_STEREO16; } alGenBuffers(2, buffers); CheckErrors(); alGenSources(1, &source); CheckErrors(); SetVolume(volume, true); alSource3f(source, AL_POSITION, pos.x, pos.y, pos.z); alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f ); alSource3f(source, AL_DIRECTION, 0.0f, 0.0f, 0.0f ); alSourcef( source, AL_ROLLOFF_FACTOR, 0.0f ); alSourcei( source, AL_SOURCE_RELATIVE, false ); if (!StartPlaying()) { ReleaseBuffers(); } else { secsPlayed = 0; lastTick = SDL_GetTicks(); stopped = false; paused = false; } }
// clean up the OpenAL resources void COggStream::ReleaseBuffers() { stopped = true; paused = false; alSourceStop(source); EmptyBuffers(); alDeleteBuffers(2, buffers); CheckErrors(); alDeleteSources(1, &source); CheckErrors(); ov_clear(&oggStream); }
int main(int argc, char *argv[]) { char *way_to_file; char *parent_catalog = NULL; int catalog_counter = 1, file_counter = 0; TFile *file_list = NULL; //check for errors, if found - exit program if (CheckErrors(argc, argv)) return 1; //edit parent path(if the last letter = '/' - delete it parent_catalog = EditArgv(parent_catalog, argv[1]); //recursive function of searching file. if file wasn`t found - exit if ((file_list = SearchFile(parent_catalog, argv[2], &catalog_counter, &file_counter, file_list)) == NULL) { fprintf(stderr, "%s: Such file not found...\n", argv[1]); return 0; } //print the information about file PrintFile(way_to_file, argv[2], catalog_counter, file_counter); while(file_list != NULL) { printf("\n%s\n", file_list->path); file_list = file_list->next; } return 0; }
void TestCommonData::Wait( bool& work, bool& done) { work = false; done = false; bool started = false; while( !done || !started ) { if (work) started = true; UpdateData(); if ( IsStopped() ) { mCommand.Start_Oper = false; mCommand.Stop_Oper = true; mCommand.Nasos_M2 = app::Settings::Instance().MainPupm() == "M2"; mCommand.OP15_25_Continum = false; mCommand.Next_Amp = false; mCommand.Write(); Log( "Испытание прервано" ); return; } } TestingTime = StartTime.elapsed()/1000; *mStopMarker = !CheckErrors(); }
bool Shader::AddShader(const std::string &a_file, const ShaderType &a_type){ // Load shader file bool loadFail = false; std::string fileString = LoadFile(a_file, loadFail); const char* file = fileString.c_str(); if (loadFail) return false;// Load error // Create shader unsigned int shader = 0; switch (a_type) { case ShaderType::VERTEX: shader = glCreateShader(GL_VERTEX_SHADER); break; case ShaderType::FRAGMENT: shader = glCreateShader(GL_FRAGMENT_SHADER); break; } // Pass shader to GL and compile glShaderSource(shader, 1, &file, NULL); glCompileShader(shader); if (CheckErrors(shader)) { glDeleteShader(shader); // Compilation error... return false; } // Link to program glAttachShader(m_program, shader); }
void LuaEnvironment::DoFile(const char* filename) { Utility::Println(3, "Beginning ", filename, "..."); int errorCode = luaL_dofile(L_, filename); CheckErrors(errorCode); Utility::Println(3, "Finishing ", filename, "..."); }
// read decoded data from audio stream into PCM buffer bool COggStream::DecodeStream(ALuint buffer) { char pcm[BUFFER_SIZE]; int size = 0; int section = 0; int result = 0; while (size < BUFFER_SIZE) { result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, §ion); if (result > 0) { size += result; } else { if (result < 0) { logOutput.Print("Error reading Ogg stream (%s)", ErrorString(result).c_str()); } else { break; } } } if (size == 0) { return false; } alBufferData(buffer, format, pcm, size, vorbisInfo->rate); CheckErrors(); return true; }
void ColorGradient::GetColors(Vector4f* outColors, const float* inValues, unsigned int numbElements) const { CheckErrors(); for (unsigned int i = 0; i < numbElements; ++i) { outColors[i] = GetColorWOErrorChecking(inValues[i]); } }
void MythXDisplay::CheckOrphanedErrors(void) { if (xerrors.size() < 1) return; std::map<Display*, XErrorVectorType>::iterator errors = xerrors.begin(); for (; errors != xerrors.end(); ++errors) if (!xerror_handlers.count(errors->first)) CheckErrors(errors->first); }
// dequeue any buffers pending on source void COggStream::EmptyBuffers() { int queued = 0; alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); while (queued-- > 0) { ALuint buffer; alSourceUnqueueBuffers(source, 1, &buffer); CheckErrors(); } }
unsigned int rglGetUniformBlockIndex(unsigned int programBuffer, char* name) { #if _DEBUG unsigned int buff = glGetUniformBlockIndex(programBuffer, name); CheckErrors(); return buff; #else return glGetUniformBlockIndex(programBuffer, name); #endif }
bool MythXDisplay::StopLog(void) { if (!(m_disp && xerror_handlers.count(m_disp))) return false; Sync(); XErrorCallbackType old_handler = xerror_handlers[m_disp]; XLOCK(this, XSetErrorHandler(old_handler)); xerror_handlers.erase(m_disp); return CheckErrors(); }
OpenGLPixelBuffer::OpenGLPixelBuffer( const unsigned int numBytes ) : mPixelBufferID( 0 ) { // pixel buffer glGenBuffersARB( 1, &mPixelBufferID ); glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, mPixelBufferID ); glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, numBytes, 0, GL_STATIC_DRAW_ARB ); glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 ); CheckErrors(); }
// pop the processed buffers from the queue, // refill them, and push them back in line bool COggStream::UpdateBuffers() { int processed = 0; bool active = true; alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); while (processed-- > 0) { ALuint buffer; alSourceUnqueueBuffers(source, 1, &buffer); CheckErrors(); // false if we've reached end of stream active = DecodeStream(buffer); alSourceQueueBuffers(source, 1, &buffer); CheckErrors(); } return active; }
void Shader::Compile() { if(vertex.empty() || fragment.empty()) { return; } uint32 vert = -1; uint32 frag = -1; id = glCreateProgram(); if(!vertex.empty()) { vert = Compile(GL_VERTEX_SHADER, vertex); glAttachShader(id, vert); } if(!fragment.empty()) { frag = Compile(GL_FRAGMENT_SHADER, fragment); glAttachShader(id, frag); } #if !LFANT_GLES uint32 geom = -1; uint32 comp = -1; if(!geometry.empty()) { geom = Compile(GL_GEOMETRY_SHADER, geometry); glAttachShader(id, geom); } if(!compute.empty()) { comp = Compile(GL_COMPUTE_SHADER, compute); glAttachShader(id, comp); } #endif glLinkProgram(id); CheckErrors(); if(vert) glDeleteShader(vert); if(frag) glDeleteShader(frag); #if !LFANT_GLES if(geom != -1) glDeleteShader(geom); if(comp != -1) glDeleteShader(comp); #endif Unbind(); // GetGame()->Log(glGetError()); }
void Database::UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db) { QSqlQuery select(QString("SELECT ROWID, filename FROM %1").arg(table), db); QSqlQuery update( QString("UPDATE %1 SET filename=:filename WHERE ROWID=:id").arg(table), db); select.exec(); if (CheckErrors(select)) return; while (select.next()) { const int rowid = select.value(0).toInt(); const QString filename = select.value(1).toString(); if (filename.isEmpty() || filename.contains("://")) { continue; } const QUrl url = QUrl::fromLocalFile(filename); update.bindValue(":filename", url.toEncoded()); update.bindValue(":id", rowid); update.exec(); CheckErrors(update); } }
EffectShader::EffectShader( std::vector<const char*> shader_blocks, std::vector<int> shader_sizes, EffectShaderType shader_type, const std::string& shader_debug_desc) { assert(shader_type != EffectShaderType::EST_GEOMETRY); // Not supported yet assert(shader_blocks.size() > 2 && shader_sizes.size() == shader_blocks.size()); // faulty data given m_type = shader_type == EffectShaderType::EST_VERTEX? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; m_shader = glCreateShader(m_type); glShaderSource(m_shader, shader_blocks.size(), &shader_blocks[0], &shader_sizes[0]); glCompileShader(m_shader); if (!CheckErrors(shader_debug_desc.c_str(), m_shader)) { throw EffectShaderException(); } }
int main(void) { fitsfile *fptr; int status = 0; char* file_name = "!mybintab.fits"; //create a fits file CheckErrors( fits_create_file(&fptr,file_name, &status) ); // specify what is in each column, see the link for more details //http://heasarc.gsfc.nasa.gov/docs/software/fitsio/quick/node10.html const long nrows=1025; const int tfields=2; char *ttype[tfields], *tform[tfields], *tunit[tfields]; for (int ii = 0; ii < tfields; ii++) { ttype[ii] = (char *) malloc(20); tform[ii] = (char *) malloc(20); tunit[ii] = (char *) malloc(20); } // name for the column strcpy(ttype[0], "l"); strcpy(ttype[1], "C_l"); // data format strcpy(tform[0], "I11"); strcpy(tform[1], "E13.5"); // units strcpy(tunit[0], ""); strcpy(tunit[1], "mK^2"); // name of the HDU extension char *extname ="POWER SPECTRUM"; //insert an empy table first CheckErrors(fits_create_tbl(fptr, BINARY_TBL, nrows, tfields, ttype,tform, tunit,extname,&status) ); //note that everything here starts with 1 rather than 0 (unlike the C arryas) long firstrow =1; long firstelem = 1; long nelements = nrows; int* ell = malloc(nrows*sizeof(int)); double* c_ell=malloc(nrows*sizeof(double)); // create data for(long i=0;i<nrows;++i) { ell[i] = (int) i; c_ell[i] = (double) i*100; } //first column datatype TINT int colnum = 1; CheckErrors( fits_write_col(fptr, TINT, colnum, firstrow, firstelem, nelements, ell,&status) ); //second column datatype is TDOUBLE colnum = 2 ; CheckErrors( fits_write_col(fptr, TDOUBLE, colnum, firstrow, firstelem, nelements, c_ell,&status) ); //free memory for (int ii = 0; ii < tfields; ii++) { free(ttype[ii]); free(tform[ii]); free(tunit[ii]); } free(ell); free(c_ell); //close fits file CheckErrors( fits_close_file(fptr, &status) ); return 0; }
void CShader::Compile() { CompileShader(); CheckErrors(); }
void OpenGLPixelBuffer::Unbind() const { glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 ); CheckErrors(); }
OpenGLPixelBuffer::~OpenGLPixelBuffer() { glDeleteBuffersARB( 1, &mPixelBufferID ); CheckErrors(); }
void CDirectSerial::handleUpperEvent(Bit16u type) { switch(type) { case SERIAL_POLLING_EVENT: { DWORD dwRead = 0; Bit8u chRead = 0; setEvent(SERIAL_POLLING_EVENT, 1); if(!receiveblock) { if(((!(LSR&LSR_RX_DATA_READY_MASK)) || rx_retry>=rx_retry_max )) { rx_retry=0; if (ReadFile (hCom, &chRead, 1, &dwRead, NULL)) { if (dwRead) { receiveByte (chRead); setEvent(40, bytetime-0.03f); // receive timing receiveblock=true; } } } else rx_retry++; } // check for errors CheckErrors(); // update Modem input line states updateMSR (); break; } case 40: { // receive time is up DWORD dwRead = 0; Bit8u chRead = 0; receiveblock=false; // check if there is something to receive if(((!(LSR&LSR_RX_DATA_READY_MASK)) || rx_retry>=rx_retry_max )) { rx_retry=0; if (ReadFile (hCom, &chRead, 1, &dwRead, NULL)) { if (dwRead) { receiveByte (chRead); setEvent(40, bytetime-0.03f); // receive timing receiveblock=true; } } } else rx_retry++; break; } case SERIAL_TX_EVENT: { DWORD dwRead = 0; Bit8u chRead = 0; if(!receiveblock) { if(((!(LSR&LSR_RX_DATA_READY_MASK)) || rx_retry>=rx_retry_max )) { rx_retry=0; if (ReadFile (hCom, &chRead, 1, &dwRead, NULL)) { if (dwRead) { receiveByte (chRead); setEvent(40, bytetime-0.03f); // receive timing receiveblock=true; } } } else rx_retry++; } ByteTransmitted(); break; } case SERIAL_THR_EVENT: { ByteTransmitting(); setEvent(SERIAL_TX_EVENT,bytetime+0.03f); break; } } }