void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices) { // tmp arrays used to store the sorted data: float *tmpVertices; unsigned *tmpIndices; Chronometer chrono; // Sort data chrono.start(); GeomCleaner::SortIndexedVertexArray(iVertices, iVSize, iIndices, iISize, &tmpVertices, &tmpIndices); if (G.debug & G_DEBUG_FREESTYLE) { printf("Sorting: %lf sec.\n", chrono.stop()); } // compress data chrono.start(); GeomCleaner::CompressIndexedVertexArray(tmpVertices, iVSize, tmpIndices, iISize, oVertices, oVSize, oIndices); real duration = chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { printf("Merging: %lf sec.\n", duration); } // deallocates memory: delete [] tmpVertices; delete [] tmpIndices; }
int main(int argc, char *argv[]) { Chronometer total; total.start(); try { Util::check(argv[1] == NULL, "You must specify an output directory."); ChronoPlotter plotter(argv[1], new RangeLoop(Population::NUM_SELECTION, 50, 301, 50), "Tiempo (ms)"); plotter.parameters.putNumber(Population::NUM_CROSSOVER, 0); plotter.parameters.putNumber(Dummy::WEIGHS_RANGE, 5); JoinEnumLoop linesLoop(ET_SELECTION_ALGORITHM); linesLoop.addInnerLoop(new RangeLoop(Population::SIZE, 400, 501, 100)); linesLoop.addEnumLoop(SA_ROULETTE_WHEEL, NULL); linesLoop.addEnumLoop(SA_RANKING, NULL); linesLoop.addEnumLoop(SA_TOURNAMENT, new RangeLoop(Population::TOURNAMENT_SIZE, 5, 30, 10)); linesLoop.addEnumLoop(SA_TRUNCATION, NULL); plotter.plotChrono(chronoSelection, "chronoGen_Selection", &linesLoop, 50); printf("Exit success.\n"); } catch (std::string& error) { cout << "Error: " << error << endl; } MemoryManagement::printTotalAllocated(); MemoryManagement::printTotalPointers(); MemoryManagement::printListOfPointers(); total.stop(); printf("Total time spent: %f \n", total.getSeconds()); return EXIT_SUCCESS; }
CIF::CIF(istream &is, const bool interpret,const bool verbose) { string s; (*fpObjCrystInformUser)("CIF: Opening CIF"); Chronometer chrono; chrono.start(); //Copy to an iostream so that we can put back characters if necessary stringstream in; char c; while(is.get(c))in.put(c); const float t0read=chrono.seconds(); s=(boost::format("CIF: Parsing CIF (reading dt=%5.3fs)")%t0read).str(); (*fpObjCrystInformUser)(s); this->Parse(in); const float t1parse=chrono.seconds(); s=(boost::format("CIF: Finished Parsing, Extracting...(parsing dt=%5.3fs)") % (t1parse-t0read)).str(); (*fpObjCrystInformUser)(s); // Extract structure from blocks if(interpret) for(map<string,CIFData>::iterator posd=mvData.begin();posd!=mvData.end();++posd) posd->second.ExtractAll(verbose); const float t2interpret=chrono.seconds(); s=(boost::format("CIF: Finished Import...(interpret dt=%5.3fs, total CIF import=%5.3fs)")%(t2interpret-t1parse)%t2interpret).str(); (*fpObjCrystInformUser)(s); }
int main(int argc, char *argv[]) { Chronometer total; total.start(); try { Util::check(argv[1] == NULL, "You must specify an output directory."); ChronoPlotter plotter(argv[1], new RangeLoop(Dummy::SIZE, 50, 301, 50), "Tiempo (ms)"); plotter.parameters.putNumber(PROBABILITY, 0); plotter.parameters.putNumber(NUM_TIMES, 0); plotter.parameters.putNumber(Dummy::WEIGHS_RANGE, 20); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_IMPLEMENTATION), IT_C); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_FUNCTION), FT_IDENTITY); plotter.parameters.putNumber(Dummy::NUM_INPUTS, 2); EnumLoop averageLoop(ET_BUFFER, 2, BT_FLOAT, BT_BIT); averageLoop.addInnerLoop(new RangeLoop(Dummy::NUM_LAYERS, 1, 2, 1)); EnumLoop crossLoop(ET_CROSS_LEVEL); JoinEnumLoop* crossAlgLoop = new JoinEnumLoop(ET_CROSS_ALG); crossLoop.addInnerLoop(crossAlgLoop); crossAlgLoop->addEnumLoop(CA_UNIFORM, new RangeLoop(PROBABILITY, 0.2, 0.5, 0.2)); crossAlgLoop->addEnumLoop(CA_MULTIPOINT, new RangeLoop(NUM_TIMES, 1, 10, 5)); crossAlgLoop->addEnumLoop(CA_PROPORTIONAL, NULL); plotter.plotChronoAveraged(chronoCrossover, "chronoGen_crossover", &crossLoop, &averageLoop, 50); EnumLoop mutatAlgLoop(ET_MUTATION_ALG, 2, MA_PER_INDIVIDUAL, MA_PROBABILISTIC); mutatAlgLoop.addInnerLoop(new RangeLoop(PROBABILITY, 0.0025, 0.011, 0.0025)); plotter.plotChronoAveraged(chronoMutations, "chronoGen_mutate", &mutatAlgLoop, &averageLoop, 100); EnumLoop resetAlgLoop(ET_RESET_ALG, 2, RA_PER_INDIVIDUAL, RA_PROBABILISTIC); resetAlgLoop.addInnerLoop(new RangeLoop(PROBABILITY, 0.0025, 0.011, 0.0025)); plotter.plotChronoAveraged(chronoReset, "chronoGen_reset", &resetAlgLoop, &averageLoop, 100); // // separated files // // EnumLoop filesLoop(ET_BUFFER, 3, BT_FLOAT, BT_BIT, BT_SIGN); // // plotter.plotChronoFiles(chronoCrossover, "Individual_crossover", &crossLoop, &filesLoop, 5); // plotter.plotChronoAveraged(chronoMutations, "Individual_mutate", &mutatAlgLoop, &filesLoop, 10); // plotter.plotChronoAveraged(chronoReset, "Individual_reset", &resetAlgLoop, &filesLoop, 10); printf("Exit success.\n"); } catch (std::string& error) { cout << "Error: " << error << endl; } MemoryManagement::printTotalAllocated(); MemoryManagement::printTotalPointers(); MemoryManagement::printListOfPointers(); total.stop(); printf("Total time spent: %f \n", total.getSeconds()); return EXIT_SUCCESS; }
void ThreadPool::job_worker(ThreadPool* th, uint32_t index) { setTLSSys(th->m_sys); ThreadProfile* profile=th->m_sys->allocateProfiler(RGB(200,200,0)); char buf[16]; snprintf(buf,16,"Thread %u",index); profile->setTag(buf); Chronometer chronometer; while(1) { th->num_jobs.wait(); if(th->stopFlag) return; Locker l(th->mutex); IThreadJob* myJob=th->jobs.front(); th->jobs.pop_front(); th->curJobs[index]=myJob; l.release(); chronometer.checkpoint(); try { // it's possible that a job was added and will be executed while forcestop() has been called if(th->stopFlag) return; myJob->execute(); } catch(JobTerminationException& ex) { LOG(LOG_NOT_IMPLEMENTED,"Job terminated"); } catch(LightsparkException& e) { LOG(LOG_ERROR,_("Exception in ThreadPool ") << e.what()); th->m_sys->setError(e.cause); } catch(std::exception& e) { LOG(LOG_ERROR,"std Exception in ThreadPool:"<<myJob<<" "<<e.what()); th->m_sys->setError(e.what()); } profile->accountTime(chronometer.checkpoint()); l.acquire(); th->curJobs[index]=NULL; l.release(); //jobFencing is allowed to happen outside the mutex myJob->jobFence(); } }
int main(int argc, char *argv[]) { Chronometer total; total.start(); try { Util::check(argv[1] == NULL, "You must specify an output directory."); ChronoPlotter plotter(argv[1], new RangeLoop(Dummy::SIZE, 512, 8193, 512), "Tiempo (ms)"); unsigned repetitions = 500; plotter.parameters.putNumber(Dummy::WEIGHS_RANGE, 20); plotter.parameters.putNumber(Dummy::NUM_INPUTS, 2); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_FUNCTION), FT_IDENTITY); EnumLoop linesLoop(ET_IMPLEMENTATION); linesLoop.addInnerLoop(new EnumLoop(ET_BUFFER, 3, BT_FLOAT, BT_BIT, BT_SIGN)); RangeLoop averageLoop(Dummy::OUTPUT_SIZE, 512, 1025, 512); plotter.plotChronoAveraged(chronoCalculateAndAddTo, "impl_calculate_inputSize", &linesLoop, &averageLoop, repetitions); repetitions = 1000; plotter.resetRangeX(Dummy::OUTPUT_SIZE, 128, 2049, 128); averageLoop.setKey(Dummy::SIZE); plotter.plotChronoAveraged(chronoCalculateAndAddTo, "impl_calculate_outputSize", &linesLoop, &averageLoop, repetitions); EnumLoop filesLoop(ET_BUFFER, 3, BT_FLOAT, BT_BIT, BT_SIGN); EnumLoop cudaLinesLoop(ET_IMPLEMENTATION, 4, IT_CUDA_REDUC0, IT_CUDA_REDUC, IT_CUDA_OUT, IT_CUDA_INV); cudaLinesLoop.addInnerLoop(new ExpLoop(CUDA_BLOCK_SIZE, 16, 513, 2)); plotter.plotChronoFilesAveraged(chronoCalculateAndAddTo, "impl_calculate_outputSize_blockSize", &cudaLinesLoop, &filesLoop, &averageLoop, repetitions); repetitions = 500; plotter.resetRangeX(Dummy::SIZE, 512, 8193, 512); averageLoop.setKey(Dummy::OUTPUT_SIZE); plotter.plotChronoFilesAveraged(chronoCalculateAndAddTo, "impl_calculate_inputSize_blockSize", &cudaLinesLoop, &filesLoop, &averageLoop, repetitions); printf("Exit success.\n"); } catch (std::string error) { cout << "Error: " << error << endl; } MemoryManagement::printTotalAllocated(); MemoryManagement::printTotalPointers(); //MemoryManagement::mem_printListOfPointers(); total.stop(); printf("Total time spent: %f \n", total.getSeconds()); return EXIT_SUCCESS; }
void perform_logic() { const float time_passed = m_chrono.seconds(); const float time_step = time_passed - m_time_passed; m_time_passed = time_passed; // without a multiplier, this will rotate a full turn after ~6.28s // this rotates clockwise of c-clockwise depending on m_turn_???? //m_tank.turn_left((m_turn_left - m_turn_right) * time_step); m_tank.move_lr((m_turn_left - m_turn_right) * time_step * 100.0f); // without the '100.0f', it would move at ~1px/s m_tank.move_ud((m_forward - m_backward) * time_step * 100.0f); if(m_fire) { m_fire = false; m_bullets.push_back(m_tank.fire()); } // move bullets for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end(); ++it) (*it)->move_ud(time_step * 200.0f); // remove off screen bullets for perfrmance boost for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end();) { const Point2f &p = (*it)->get_position(); if(p.x < -10.0f || p.x > 10.0f + get_Window().get_width() || p.y < -10.0f || p.y > 10.0f + get_Window().get_height()) { delete *it; it = m_bullets.erase(it); } else ++it; } }
int main(int argc, const char **argv){ if( argc<5 ){ usage(cerr); return 1; } try{ Params params; set_params( argc, argv, params ); params.check(); K_Clust c( ¶ms ); if (params.profile_query){ std::cerr << "Preprocessing...\n"; c.prepare(); std::cerr << "done.\n"; } Chronometer chron; chron.start(); c.cluster(); // c.kDP_benchmark_scop_tpfp(); float cl_seconds = chron.getSnapShotSeconds(); cerr << "Runtime for representatives: " << cl_seconds << " seconds" << endl; c.write_representatives_db(); float wrep_seconds = chron.getSnapShotSeconds(); cerr << "Runtime for write representatives: " << wrep_seconds - cl_seconds << " seconds" << endl; c.write_dmp_files(); float wdmp_seconds = chron.getSnapShotSeconds(); cerr << "Runtime for write dmp files: " << wdmp_seconds - wrep_seconds << " seconds" << endl; // c.write_debug_files((params.get_working_dir() +"debug.dat").c_str()); // float wdebug_seconds = chron.getSnapShotSeconds(); // cerr << "Runtime for write debug files: " << wdebug_seconds - wdmp_seconds << " seconds" << endl; if( params.refinement ){ cerr << "Perform refinement" << endl; c.refine(); cerr << "Runtime for refinement: " << chron.getSnapShotSeconds()-wdmp_seconds << " seconds" << endl; } //cerr << "After refinement - before free tables" << endl; c.free_tables_seedlists_kmeraln(); if( params.refinement ){ //cerr << "Write refined nodes" << endl; c.write_refined_nodes_dmp(); } //cerr << "write debug files" << endl; // c.write_debug_files( (params.get_working_dir() +"debug_refined.dat").c_str() ); //cerr << "cleanup tmp-files" << endl; c.cleanup_tmp_files(); //cerr << "Print time" << endl; chron.stop(); chron.print_time( std::cerr ); }catch(const std::exception &e){ std::cerr << std::endl << ">" << std::endl; std::cerr << "ERROR: " << e.what() << std::endl; std::cerr << ">" << std::endl; return 3; } return 0; }
void UpdateCameraView::operator()( osg::Node* node, osg::NodeVisitor* nv ) { Chronometer timer; timer.tic(); cv::Mat currentImg; videoStream >> currentImg; if (!currentImg.empty()) { if ((!augEnvironment->posFound)&&(augEnvironment->synchroniser.tac() > 200)) //wait 1s to match { cvImg = augEnvironment->match(currentImg); augEnvironment->posFound = true; } else if ((augEnvironment->hasProjected)&&(augEnvironment->synchroniser.tac() > 300)&&(!imageCaptured)) { static int count = 0; int lastindex = augEnvironment->parameterFileName.find_last_of("/"); string dir = augEnvironment->parameterFileName.substr(0, lastindex); string errFilename = dir + "/" + augEnvironment->errorFileNameBase + "err.png"; imwrite(errFilename, currentImg); if (augEnvironment->calculateErr) { double meanErr, maxErr; augEnvironment->calculateReprojectionErr(augEnvironment->groundTruthFileName, currentImg); cout<<meanErr<<" "<<maxErr<<endl; } cvImg = currentImg.clone(); imageCaptured = true; } else { cvImg = currentImg.clone(); } osg::ref_ptr<osg::Group> backgroundCameraNode = dynamic_cast<osg::Group*>(node); for (unsigned int i = 0 ; i < backgroundCameraNode->getNumChildren() ; i++) { if (backgroundCameraNode->getChild(i)->getName() == string("Background texture")) { updateBackgroundTexture(backgroundCameraNode->getChild(i)); } } if (augEnvironment->recordVideo) { if (! vWriter.isOpened()) { vWriter.open("recordedStream.mpg", CV_FOURCC('P','I','M','1'), 20.0f, currentImg.size(), true); } vWriter << currentImg; if (! vWriter2.isOpened()) { vWriter2.open("outStream.mpg", CV_FOURCC('P','I','M','1'), 20.0f, currentImg.size(), true); } vWriter2 << cvImg; } traverse( node, nv ); } }
void* RenderThread::sdl_worker(RenderThread* th) { sys=th->m_sys; rt=th; SemaphoreLighter lighter(th->initialized); RECT size=sys->getFrameSize(); int initialWidth=size.Xmax/20; int initialHeight=size.Ymax/20; th->windowWidth=initialWidth; th->windowHeight=initialHeight; SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); SDL_SetVideoMode(th->windowWidth, th->windowHeight, 24, SDL_OPENGL|SDL_RESIZABLE); th->commonGLInit(th->windowWidth, th->windowHeight); th->commonGLResize(th->windowWidth, th->windowHeight); lighter.light(); ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0)); profile->setTag("Render"); FTTextureFont font(th->fontPath.c_str()); if(font.Error()) throw RunTimeException("Unable to load font"); font.FaceSize(12); try { Chronometer chronometer; while(1) { sem_wait(&th->event); if(th->m_sys->isShuttingDown()) break; chronometer.checkpoint(); if(th->resizeNeeded) { if(th->windowWidth!=th->newWidth || th->windowHeight!=th->newHeight) { th->windowWidth=th->newWidth; th->windowHeight=th->newHeight; SDL_SetVideoMode(th->windowWidth, th->windowHeight, 24, SDL_OPENGL|SDL_RESIZABLE); } th->newWidth=0; th->newHeight=0; th->resizeNeeded=false; th->commonGLResize(th->windowWidth, th->windowHeight); profile->accountTime(chronometer.checkpoint()); continue; } if(th->newTextureNeeded) th->handleNewTexture(); if(th->prevUploadJob) th->finalizeUpload(); if(th->uploadNeeded) { th->handleUpload(); profile->accountTime(chronometer.checkpoint()); continue; } assert(th->renderNeeded); SDL_PumpEvents(); if(th->m_sys->isOnError()) { glLoadIdentity(); glScalef(1.0f/th->scaleX,-1.0f/th->scaleY,1); glTranslatef(-th->offsetX,(th->offsetY+th->windowHeight)*(-1.0f),0); glUseProgram(0); glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDrawBuffer(GL_BACK); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8,0.8,0.8); font.Render("We're sorry, Lightspark encountered a yet unsupported Flash file", -1,FTPoint(0,th->windowHeight/2)); stringstream errorMsg; errorMsg << "SWF file: " << th->m_sys->getOrigin().getParsedURL(); font.Render(errorMsg.str().c_str(), -1,FTPoint(0,th->windowHeight/2-20)); errorMsg.str(""); errorMsg << "Cause: " << th->m_sys->errorCause; font.Render(errorMsg.str().c_str(), -1,FTPoint(0,th->windowHeight/2-40)); font.Render("Press 'Q' to exit",-1,FTPoint(0,th->windowHeight/2-60)); glFlush(); SDL_GL_SwapBuffers( ); } else { SDL_GL_SwapBuffers( ); th->coreRendering(font, true); //Call glFlush to offload work on the GPU glFlush(); } profile->accountTime(chronometer.checkpoint()); th->renderNeeded=false; } } catch(LightsparkException& e) { LOG(LOG_ERROR,_("Exception in RenderThread ") << e.cause); sys->setError(e.cause); } th->commonGLDeinit(); return NULL; }
void NetStream::execute() { if(downloader->hasFailed()) { sys->currentVm->addEvent(this,Class<Event>::getInstanceS("ioError")); sys->downloadManager->destroy(downloader); return; } //The downloader hasn't failed yet at this point //mutex access to downloader istream s(downloader); s.exceptions ( istream::eofbit | istream::failbit | istream::badbit ); ThreadProfile* profile=sys->allocateProfiler(RGB(0,0,200)); profile->setTag("NetStream"); //We need to catch possible EOF and other error condition in the non reliable stream uint32_t decodedAudioBytes=0; uint32_t decodedVideoFrames=0; //The decoded time is computed from the decodedAudioBytes to avoid drifts uint32_t decodedTime=0; bool waitForFlush=true; try { ScriptDataTag tag; Chronometer chronometer; STREAM_TYPE t=classifyStream(s); if(t==FLV_STREAM) { FLV_HEADER h(s); if(!h.isValid()) throw ParseException("FLV is not valid"); unsigned int prevSize=0; bool done=false; do { //Check if threadAbort has been called, if so, stop this loop if(closed) done = true; UI32 PreviousTagSize; s >> PreviousTagSize; PreviousTagSize.bswap(); assert_and_throw(PreviousTagSize==prevSize); //Check tag type and read it UI8 TagType; s >> TagType; switch(TagType) { case 8: { AudioDataTag tag(s); prevSize=tag.getTotalLen(); if(audioDecoder==NULL) { audioCodec=tag.SoundFormat; switch(tag.SoundFormat) { case AAC: assert_and_throw(tag.isHeader()) #ifdef ENABLE_LIBAVCODEC audioDecoder=new FFMpegAudioDecoder(tag.SoundFormat, tag.packetData, tag.packetLen); #else audioDecoder=new NullAudioDecoder(); #endif tag.releaseBuffer(); break; case MP3: #ifdef ENABLE_LIBAVCODEC audioDecoder=new FFMpegAudioDecoder(tag.SoundFormat,NULL,0); #else audioDecoder=new NullAudioDecoder(); #endif decodedAudioBytes+= audioDecoder->decodeData(tag.packetData,tag.packetLen,decodedTime); //Adjust timing decodedTime=decodedAudioBytes/audioDecoder->getBytesPerMSec(); break; default: throw RunTimeException("Unsupported SoundFormat"); } if(audioDecoder->isValid() && sys->audioManager->pluginLoaded()) audioStream=sys->audioManager->createStreamPlugin(audioDecoder); } else { assert_and_throw(audioCodec==tag.SoundFormat); decodedAudioBytes+= audioDecoder->decodeData(tag.packetData,tag.packetLen,decodedTime); if(audioStream==0 && audioDecoder->isValid() && sys->audioManager->pluginLoaded()) audioStream=sys->audioManager->createStreamPlugin(audioDecoder); //Adjust timing decodedTime=decodedAudioBytes/audioDecoder->getBytesPerMSec(); } break; } case 9: { VideoDataTag tag(s); prevSize=tag.getTotalLen(); //If the framerate is known give the right timing, otherwise use decodedTime from audio uint32_t frameTime=(frameRate!=0.0)?(decodedVideoFrames*1000/frameRate):decodedTime; if(videoDecoder==NULL) { //If the isHeader flag is on then the decoder becomes the owner of the data if(tag.isHeader()) { //The tag is the header, initialize decoding #ifdef ENABLE_LIBAVCODEC videoDecoder= new FFMpegVideoDecoder(tag.codec,tag.packetData,tag.packetLen, frameRate); #else videoDecoder=new NullVideoDecoder(); #endif tag.releaseBuffer(); } else if(videoDecoder==NULL) { //First packet but no special handling #ifdef ENABLE_LIBAVCODEC videoDecoder=new FFMpegVideoDecoder(tag.codec,NULL,0,frameRate); #else videoDecoder=new NullVideoDecoder(); #endif videoDecoder->decodeData(tag.packetData,tag.packetLen, frameTime); decodedVideoFrames++; } Event* status=Class<NetStatusEvent>::getInstanceS("status", "NetStream.Play.Start"); getVm()->addEvent(this, status); status->decRef(); status=Class<NetStatusEvent>::getInstanceS("status", "NetStream.Buffer.Full"); getVm()->addEvent(this, status); status->decRef(); } else { videoDecoder->decodeData(tag.packetData,tag.packetLen, frameTime); decodedVideoFrames++; } break; } case 18: { tag = ScriptDataTag(s); prevSize=tag.getTotalLen(); //The frameRate of the container overrides the stream if(tag.metadataDouble.find("framerate") != tag.metadataDouble.end()) frameRate=tag.metadataDouble["framerate"]; break; } default: LOG(LOG_ERROR,_("Unexpected tag type ") << (int)TagType << _(" in FLV")); threadAbort(); } if(!tickStarted && isReady()) { { multiname onMetaDataName; onMetaDataName.name_type=multiname::NAME_STRING; onMetaDataName.name_s="onMetaData"; onMetaDataName.ns.push_back(nsNameAndKind("",NAMESPACE)); ASObject* callback = client->getVariableByMultiname(onMetaDataName); if(callback && callback->getObjectType() == T_FUNCTION) { ASObject* callbackArgs[1]; ASObject* metadata = Class<ASObject>::getInstanceS(); if(tag.metadataDouble.find("width") != tag.metadataDouble.end()) metadata->setVariableByQName("width", "", abstract_d(tag.metadataDouble["width"])); else metadata->setVariableByQName("width", "", abstract_d(getVideoWidth())); if(tag.metadataDouble.find("height") != tag.metadataDouble.end()) metadata->setVariableByQName("height", "", abstract_d(tag.metadataDouble["height"])); else metadata->setVariableByQName("height", "", abstract_d(getVideoHeight())); if(tag.metadataDouble.find("framerate") != tag.metadataDouble.end()) metadata->setVariableByQName("framerate", "", abstract_d(tag.metadataDouble["framerate"])); if(tag.metadataDouble.find("duration") != tag.metadataDouble.end()) metadata->setVariableByQName("duration", "", abstract_d(tag.metadataDouble["duration"])); if(tag.metadataInteger.find("canseekontime") != tag.metadataInteger.end()) metadata->setVariableByQName("canSeekToEnd", "", abstract_b(tag.metadataInteger["canseekontime"] == 1)); if(tag.metadataDouble.find("audiodatarate") != tag.metadataDouble.end()) metadata->setVariableByQName("audiodatarate", "", abstract_d(tag.metadataDouble["audiodatarate"])); if(tag.metadataDouble.find("videodatarate") != tag.metadataDouble.end()) metadata->setVariableByQName("videodatarate", "", abstract_d(tag.metadataDouble["videodatarate"])); //TODO: missing: audiocodecid (Number), cuePoints (Object[]), //videocodecid (Number), custommetadata's callbackArgs[0] = metadata; client->incRef(); metadata->incRef(); FunctionEvent* event = new FunctionEvent(static_cast<IFunction*>(callback), client, callbackArgs, 1); getVm()->addEvent(NULL,event); event->decRef(); } } tickStarted=true; if(frameRate==0) { assert(videoDecoder->frameRate); frameRate=videoDecoder->frameRate; } sys->addTick(1000/frameRate,this); //Also ask for a render rate equal to the video one (capped at 24) float localRenderRate=dmin(frameRate,24); sys->setRenderRate(localRenderRate); } profile->accountTime(chronometer.checkpoint()); if(aborting) { throw JobTerminationException(); } } while(!done); } else threadAbort(); }
void NetStream::execute() { //mutex access to downloader istream s(downloader); s.exceptions ( istream::eofbit | istream::failbit | istream::badbit ); ThreadProfile* profile=sys->allocateProfiler(RGB(0,0,200)); profile->setTag("NetStream"); //We need to catch possible EOF and other error condition in the non reliable stream try { Chronometer chronometer; STREAM_TYPE t=classifyStream(s); if(t==FLV_STREAM) { FLV_HEADER h(s); if(!h.isValid()) threadAbort(); unsigned int prevSize=0; bool done=false; do { UI32 PreviousTagSize; s >> PreviousTagSize; PreviousTagSize.bswap(); assert(PreviousTagSize==prevSize); //Check tag type and read it UI8 TagType; s >> TagType; switch(TagType) { case 8: { AudioDataTag tag(s); prevSize=tag.getTotalLen(); break; } case 9: { VideoDataTag tag(s); prevSize=tag.getTotalLen(); assert(tag.codecId==7); if(tag.isHeader()) { //The tag is the header, initialize decoding assert(decoder==NULL); //The decoder can be set only once //NOTE: there is not need to mutex the decoder, as an async transition from NULL to //valid is not critical decoder=new FFMpegDecoder(tag.packetData,tag.packetLen); assert(decoder); assert(frameRate!=0); //Now that the decoder is valid, let's start the ticking sys->addTick(1000/frameRate,this); //sys->setRenderRate(frameRate); tag.releaseBuffer(); } else decoder->decodeData(tag.packetData,tag.packetLen); break; } case 18: { ScriptDataTag tag(s); prevSize=tag.getTotalLen(); //HACK: initialize frameRate from the container frameRate=tag.frameRate; break; } default: cout << (int)TagType << endl; threadAbort(); } profile->accountTime(chronometer.checkpoint()); if(aborting) throw JobTerminationException(); } while(!done); } else threadAbort(); }
void* RenderThread::gtkplug_worker(RenderThread* th) { sys=th->m_sys; rt=th; NPAPI_params* p=th->npapi_params; SemaphoreLighter lighter(th->initialized); th->windowWidth=p->width; th->windowHeight=p->height; Display* d=XOpenDisplay(NULL); int a,b; Bool glx_present=glXQueryVersion(d,&a,&b); if(!glx_present) { LOG(LOG_ERROR,_("glX not present")); return NULL; } int attrib[10]={GLX_BUFFER_SIZE,24,GLX_DOUBLEBUFFER,True,None}; GLXFBConfig* fb=glXChooseFBConfig(d, 0, attrib, &a); if(!fb) { attrib[2]=None; fb=glXChooseFBConfig(d, 0, attrib, &a); LOG(LOG_ERROR,_("Falling back to no double buffering")); } if(!fb) { LOG(LOG_ERROR,_("Could not find any GLX configuration")); ::abort(); } int i; for(i=0;i<a;i++) { int id; glXGetFBConfigAttrib(d,fb[i],GLX_VISUAL_ID,&id); if(id==(int)p->visual) break; } if(i==a) { //No suitable id found LOG(LOG_ERROR,_("No suitable graphics configuration available")); return NULL; } th->mFBConfig=fb[i]; cout << "Chosen config " << hex << fb[i] << dec << endl; XFree(fb); th->mContext = glXCreateNewContext(d,th->mFBConfig,GLX_RGBA_TYPE ,NULL,1); GLXWindow glxWin=p->window; glXMakeCurrent(d, glxWin,th->mContext); if(!glXIsDirect(d,th->mContext)) cout << "Indirect!!" << endl; th->commonGLInit(th->windowWidth, th->windowHeight); th->commonGLResize(th->windowWidth, th->windowHeight); lighter.light(); ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0)); profile->setTag("Render"); FTTextureFont font(th->fontPath.c_str()); if(font.Error()) { LOG(LOG_ERROR,_("Unable to load serif font")); throw RunTimeException("Unable to load font"); } font.FaceSize(12); glEnable(GL_TEXTURE_2D); try { Chronometer chronometer; while(1) { sem_wait(&th->event); if(th->m_sys->isShuttingDown()) break; chronometer.checkpoint(); if(th->resizeNeeded) { if(th->windowWidth!=th->newWidth || th->windowHeight!=th->newHeight) { th->windowWidth=th->newWidth; th->windowHeight=th->newHeight; LOG(LOG_ERROR,_("Window resize not supported in plugin")); } th->newWidth=0; th->newHeight=0; th->resizeNeeded=false; th->commonGLResize(th->windowWidth, th->windowHeight); profile->accountTime(chronometer.checkpoint()); continue; } if(th->newTextureNeeded) th->handleNewTexture(); if(th->prevUploadJob) th->finalizeUpload(); if(th->uploadNeeded) { th->handleUpload(); profile->accountTime(chronometer.checkpoint()); continue; } assert(th->renderNeeded); if(th->m_sys->isOnError()) { glLoadIdentity(); glScalef(1.0f/th->scaleX,-1.0f/th->scaleY,1); glTranslatef(-th->offsetX,(th->offsetY+th->windowHeight)*(-1.0f),0); glUseProgram(0); glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDrawBuffer(GL_BACK); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8,0.8,0.8); font.Render("We're sorry, Lightspark encountered a yet unsupported Flash file", -1,FTPoint(0,th->windowHeight/2)); stringstream errorMsg; errorMsg << "SWF file: " << th->m_sys->getOrigin().getParsedURL(); font.Render(errorMsg.str().c_str(), -1,FTPoint(0,th->windowHeight/2-20)); errorMsg.str(""); errorMsg << "Cause: " << th->m_sys->errorCause; font.Render(errorMsg.str().c_str(), -1,FTPoint(0,th->windowHeight/2-40)); glFlush(); glXSwapBuffers(d,glxWin); } else { glXSwapBuffers(d,glxWin); th->coreRendering(font, false); //Call glFlush to offload work on the GPU glFlush(); } profile->accountTime(chronometer.checkpoint()); th->renderNeeded=false; } } catch(LightsparkException& e) { LOG(LOG_ERROR,_("Exception in RenderThread ") << e.what()); sys->setError(e.cause); } glDisable(GL_TEXTURE_2D); th->commonGLDeinit(); glXMakeCurrent(d,None,NULL); glXDestroyContext(d,th->mContext); XCloseDisplay(d); return NULL; }
void NetStream::execute() { //checkPolicyFile only applies to per-pixel access, loading and playing is always allowed. //So there is no need to disallow playing if policy files disallow it. //We do need to check if per-pixel access is allowed. SecurityManager::EVALUATIONRESULT evaluationResult = sys->securityManager->evaluatePoliciesURL(url, true); if(evaluationResult == SecurityManager::NA_CROSSDOMAIN_POLICY) rawAccessAllowed = true; if(downloader->hasFailed()) { this->incRef(); sys->currentVm->addEvent(_MR(this),_MR(Class<Event>::getInstanceS("ioError"))); sys->downloadManager->destroy(downloader); return; } //The downloader hasn't failed yet at this point istream s(downloader); s.exceptions ( istream::eofbit | istream::failbit | istream::badbit ); ThreadProfile* profile=sys->allocateProfiler(RGB(0,0,200)); profile->setTag("NetStream"); bool waitForFlush=true; StreamDecoder* streamDecoder=NULL; //We need to catch possible EOF and other error condition in the non reliable stream try { Chronometer chronometer; streamDecoder=new FFMpegStreamDecoder(s); if(!streamDecoder->isValid()) threadAbort(); bool done=false; while(!done) { //Check if threadAbort has been called, if so, stop this loop if(closed) done = true; bool decodingSuccess=streamDecoder->decodeNextFrame(); if(decodingSuccess==false) done = true; if(videoDecoder==NULL && streamDecoder->videoDecoder) { videoDecoder=streamDecoder->videoDecoder; this->incRef(); getVm()->addEvent(_MR(this), _MR(Class<NetStatusEvent>::getInstanceS("status", "NetStream.Play.Start"))); this->incRef(); getVm()->addEvent(_MR(this), _MR(Class<NetStatusEvent>::getInstanceS("status", "NetStream.Buffer.Full"))); } if(audioDecoder==NULL && streamDecoder->audioDecoder) audioDecoder=streamDecoder->audioDecoder; if(audioStream==NULL && audioDecoder && audioDecoder->isValid() && sys->audioManager->pluginLoaded()) audioStream=sys->audioManager->createStreamPlugin(audioDecoder); if(audioStream && audioStream->paused() && !paused) { //The audio stream is paused but should not! //As we have new data fill the stream audioStream->fill(); } if(!tickStarted && isReady()) { multiname onMetaDataName; onMetaDataName.name_type=multiname::NAME_STRING; onMetaDataName.name_s="onMetaData"; onMetaDataName.ns.push_back(nsNameAndKind("",NAMESPACE)); ASObject* callback = client->getVariableByMultiname(onMetaDataName); if(callback && callback->getObjectType() == T_FUNCTION) { ASObject* callbackArgs[1]; ASObject* metadata = Class<ASObject>::getInstanceS(); double d; uint32_t i; if(streamDecoder->getMetadataDouble("width",d)) metadata->setVariableByQName("width", "",abstract_d(d),DYNAMIC_TRAIT); else metadata->setVariableByQName("width", "", abstract_d(getVideoWidth()),DYNAMIC_TRAIT); if(streamDecoder->getMetadataDouble("height",d)) metadata->setVariableByQName("height", "",abstract_d(d),DYNAMIC_TRAIT); else metadata->setVariableByQName("height", "", abstract_d(getVideoHeight()),DYNAMIC_TRAIT); if(streamDecoder->getMetadataDouble("framerate",d)) metadata->setVariableByQName("framerate", "",abstract_d(d),DYNAMIC_TRAIT); if(streamDecoder->getMetadataDouble("duration",d)) metadata->setVariableByQName("duration", "",abstract_d(d),DYNAMIC_TRAIT); if(streamDecoder->getMetadataInteger("canseekontime",i)) metadata->setVariableByQName("canSeekToEnd", "",abstract_b(i == 1),DYNAMIC_TRAIT); if(streamDecoder->getMetadataDouble("audiodatarate",d)) metadata->setVariableByQName("audiodatarate", "",abstract_d(d),DYNAMIC_TRAIT); if(streamDecoder->getMetadataDouble("videodatarate",d)) metadata->setVariableByQName("videodatarate", "",abstract_d(d),DYNAMIC_TRAIT); //TODO: missing: audiocodecid (Number), cuePoints (Object[]), //videocodecid (Number), custommetadata's client->incRef(); metadata->incRef(); callbackArgs[0] = metadata; callback->incRef(); _R<FunctionEvent> event(new FunctionEvent(_MR(static_cast<IFunction*>(callback)), _MR(client), callbackArgs, 1)); getVm()->addEvent(NullRef,event); } tickStarted=true; if(frameRate==0) { assert(videoDecoder->frameRate); frameRate=videoDecoder->frameRate; } sys->addTick(1000/frameRate,this); //Also ask for a render rate equal to the video one (capped at 24) float localRenderRate=dmin(frameRate,24); sys->setRenderRate(localRenderRate); } profile->accountTime(chronometer.checkpoint()); if(aborting) throw JobTerminationException(); } } catch(LightsparkException& e) { LOG(LOG_ERROR, "Exception in NetStream " << e.cause); threadAbort(); waitForFlush=false; } catch(JobTerminationException& e) { waitForFlush=false; } catch(exception& e) { LOG(LOG_ERROR, _("Exception in reading: ")<<e.what()); } if(waitForFlush) { //Put the decoders in the flushing state and wait for the complete consumption of contents if(audioDecoder) audioDecoder->setFlushing(); if(videoDecoder) videoDecoder->setFlushing(); if(audioDecoder) audioDecoder->waitFlushed(); if(videoDecoder) videoDecoder->waitFlushed(); this->incRef(); getVm()->addEvent(_MR(this), _MR(Class<NetStatusEvent>::getInstanceS("status", "NetStream.Play.Stop"))); this->incRef(); getVm()->addEvent(_MR(this), _MR(Class<NetStatusEvent>::getInstanceS("status", "NetStream.Buffer.Flush"))); } //Before deleting stops ticking, removeJobs also spin waits for termination sys->removeJob(this); tickStarted=false; sem_wait(&mutex); //Change the state to invalid to avoid locking videoDecoder=NULL; audioDecoder=NULL; //Clean up everything for a possible re-run sys->downloadManager->destroy(downloader); //This transition is critical, so the mutex is needed downloader=NULL; if(audioStream) sys->audioManager->freeStreamPlugin(audioStream); audioStream=NULL; sem_post(&mutex); delete streamDecoder; }
void* RenderThread::worker(RenderThread* th) { sys=th->m_sys; rt=th; const EngineData* e=th->engineData; SemaphoreLighter lighter(th->initialized); //Get information about changes in the available space g_signal_connect(e->container,"size-allocate",G_CALLBACK(SizeAllocateCallback),th); th->windowWidth=e->width; th->windowHeight=e->height; Display* d=XOpenDisplay(NULL); #ifndef ENABLE_GLES2 int a,b; Bool glx_present=glXQueryVersion(d,&a,&b); if(!glx_present) { LOG(LOG_ERROR,_("glX not present")); return NULL; } int attrib[10]={GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_DOUBLEBUFFER, True, None}; GLXFBConfig* fb=glXChooseFBConfig(d, 0, attrib, &a); if(!fb) { attrib[6]=None; LOG(LOG_ERROR,_("Falling back to no double buffering")); fb=glXChooseFBConfig(d, 0, attrib, &a); } if(!fb) { LOG(LOG_ERROR,_("Could not find any GLX configuration")); ::abort(); } int i; for(i=0;i<a;i++) { int id; glXGetFBConfigAttrib(d,fb[i],GLX_VISUAL_ID,&id); if(id==(int)e->visual) break; } if(i==a) { //No suitable id found LOG(LOG_ERROR,_("No suitable graphics configuration available")); return NULL; } th->mFBConfig=fb[i]; cout << "Chosen config " << hex << fb[i] << dec << endl; XFree(fb); th->mContext = glXCreateNewContext(d,th->mFBConfig,GLX_RGBA_TYPE ,NULL,1); GLXWindow glxWin=e->window; glXMakeCurrent(d, glxWin,th->mContext); if(!glXIsDirect(d,th->mContext)) cout << "Indirect!!" << endl; #else int a; eglBindAPI(EGL_OPENGL_ES_API); EGLDisplay ed = EGL_NO_DISPLAY; ed = eglGetDisplay(d); if (ed == EGL_NO_DISPLAY) { LOG(LOG_ERROR, _("EGL not present")); return NULL; } EGLint major, minor; if (eglInitialize(ed, &major, &minor) == EGL_FALSE) { LOG(LOG_ERROR, _("EGL initialization failed")); return NULL; } LOG(LOG_NO_INFO, _("EGL version: ") << eglQueryString(ed, EGL_VERSION)); EGLint config_attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; if (!eglChooseConfig(ed, config_attribs, 0, 0, &a)) { LOG(LOG_ERROR,_("Could not get number of EGL configurations")); } else { LOG(LOG_NO_INFO, "Number of EGL configurations: " << a); } EGLConfig *conf = new EGLConfig[a]; if (!eglChooseConfig(ed, config_attribs, conf, a, &a)) { LOG(LOG_ERROR,_("Could not find any EGL configuration")); ::abort(); } int i; for(i=0;i<a;i++) { EGLint id; eglGetConfigAttrib(ed, conf[i], EGL_NATIVE_VISUAL_ID, &id); LOG(LOG_ERROR, id <<" -> "<<e->visual); if(id==(int)e->visual) break; } if(i==a) { //No suitable id found LOG(LOG_ERROR,_("No suitable graphics configuration available")); return NULL; } th->mEGLConfig=conf[i]; cout << "Chosen config " << hex << conf[i] << dec << endl; th->mEGLContext = eglCreateContext(ed, th->mEGLConfig, EGL_NO_CONTEXT, context_attribs); if (th->mEGLContext == EGL_NO_CONTEXT) { LOG(LOG_ERROR,_("Could not create EGL context")); return NULL; } EGLSurface win = eglCreateWindowSurface(ed, th->mEGLConfig, e->window, NULL); if (win == EGL_NO_SURFACE) { LOG(LOG_ERROR,_("Could not create EGL surface")); return NULL; } eglMakeCurrent(ed, win, win, th->mEGLContext); #endif th->commonGLInit(th->windowWidth, th->windowHeight); th->commonGLResize(); lighter.light(); ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0)); profile->setTag("Render"); glEnable(GL_TEXTURE_2D); try { Chronometer chronometer; while(1) { sem_wait(&th->event); if(th->m_sys->isShuttingDown()) break; chronometer.checkpoint(); if(th->resizeNeeded) { th->windowWidth=th->newWidth; th->windowHeight=th->newHeight; th->newWidth=0; th->newHeight=0; th->resizeNeeded=false; LOG(LOG_NO_INFO,_("Window resized to ") << th->windowWidth << 'x' << th->windowHeight); th->commonGLResize(); th->m_sys->resizeCompleted(); profile->accountTime(chronometer.checkpoint()); continue; } if(th->newTextureNeeded) th->handleNewTexture(); if(th->prevUploadJob) th->finalizeUpload(); if(th->uploadNeeded) { th->handleUpload(); profile->accountTime(chronometer.checkpoint()); continue; } if(th->m_sys->isOnError()) { th->renderErrorPage(th, th->m_sys->standalone); #ifndef ENABLE_GLES2 glXSwapBuffers(d,glxWin); #else eglSwapBuffers(ed, win); #endif } else { #ifndef ENABLE_GLES2 glXSwapBuffers(d,glxWin); #else eglSwapBuffers(ed, win); #endif th->coreRendering(); //Call glFlush to offload work on the GPU glFlush(); } profile->accountTime(chronometer.checkpoint()); th->renderNeeded=false; } } catch(LightsparkException& e) { LOG(LOG_ERROR,_("Exception in RenderThread ") << e.what()); sys->setError(e.cause); } glDisable(GL_TEXTURE_2D); th->commonGLDeinit(); #ifndef ENABLE_GLES2 glXMakeCurrent(d,None,NULL); glXDestroyContext(d,th->mContext); #else eglMakeCurrent(ed, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(ed, th->mEGLContext); #endif XCloseDisplay(d); return NULL; }
void on_push() { //get_Window().mouse_grab(true); get_Window().mouse_hide(true); //get_Game().joy_mouse.enabled = false; m_chrono.start(); }
void RenderThread::worker() { setTLSSys(m_sys); /* set TLS variable for getRenderThread() */ g_static_private_set(&renderThread, this, NULL); ThreadProfile* profile=m_sys->allocateProfiler(RGB(200,0,0)); profile->setTag("Render"); try { init(); ThreadProfile* profile=m_sys->allocateProfiler(RGB(200,0,0)); profile->setTag("Render"); glEnable(GL_TEXTURE_2D); Chronometer chronometer; while(1) { event.wait(); if(m_sys->isShuttingDown()) break; chronometer.checkpoint(); if(resizeNeeded) { windowWidth=newWidth; windowHeight=newHeight; newWidth=0; newHeight=0; resizeNeeded=false; LOG(LOG_INFO,_("Window resized to ") << windowWidth << 'x' << windowHeight); commonGLResize(); m_sys->resizeCompleted(); profile->accountTime(chronometer.checkpoint()); continue; } if(newTextureNeeded) handleNewTexture(); if(prevUploadJob) finalizeUpload(); if(uploadNeeded) { handleUpload(); profile->accountTime(chronometer.checkpoint()); continue; } if(m_sys->isOnError()) { renderErrorPage(this, m_sys->standalone); } #if defined(_WIN32) SwapBuffers(mDC); #elif !defined(ENABLE_GLES2) glXSwapBuffers(mDisplay, engineData->window); #else eglSwapBuffers(mEGLDisplay, mEGLSurface); #endif if(!m_sys->isOnError()) { coreRendering(); //Call glFlush to offload work on the GPU glFlush(); } profile->accountTime(chronometer.checkpoint()); renderNeeded=false; } deinit(); } catch(LightsparkException& e) { LOG(LOG_ERROR,_("Exception in RenderThread ") << e.what()); m_sys->setError(e.cause); } /* cleanup */ //Keep addUploadJob from enqueueing status=TERMINATED; //Fence existing jobs Locker l(mutexUploadJobs); if(prevUploadJob) prevUploadJob->uploadFence(); for(auto i=uploadJobs.begin(); i != uploadJobs.end(); ++i) (*i)->uploadFence(); }
int main(int argc, char *argv[]) { Chronometer total; total.start(); try { Util::check(argv[1] == NULL, "You must specify an output directory."); TaskPlotter plotter(argv[1], new RangeLoop("Generation", 0, 50, 5)); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_IMPLEMENTATION), IT_SSE2); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_FUNCTION), FT_IDENTITY); plotter.parameters.putNumber(Dummy::WEIGHS_RANGE, 5); plotter.parameters.putNumber(Population::MUTATION_RANGE, 2); unsigned populationSize = 8; plotter.parameters.putNumber(Population::SIZE, populationSize); plotter.parameters.putNumber(Population::NUM_SELECTION, populationSize / 2); plotter.parameters.putNumber(Population::NUM_CROSSOVER, populationSize / 2); // plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_BUFFER), BT_BIT); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_RESET_ALG), RA_DISABLED); JoinEnumLoop linesLoop(ET_CROSS_ALG); linesLoop.addEnumLoop(CA_UNIFORM, new RangeLoop(Population::UNIFORM_CROSS_PROB, 0.2, 0.5, 0.2)); linesLoop.addEnumLoop(CA_MULTIPOINT, new RangeLoop(Population::MULTIPOINT_NUM, 1, 7, 5)); linesLoop.addEnumLoop(CA_PROPORTIONAL, NULL); EnumLoop averageLoop(ET_BUFFER, 3, BT_FLOAT, BT_BIT, BT_SIGN); averageLoop.addInnerLoop(new EnumLoop(ET_CROSS_LEVEL)); JoinEnumLoop* selectionLoop = new JoinEnumLoop(ET_SELECTION_ALGORITHM); selectionLoop->addEnumLoop(SA_ROULETTE_WHEEL, NULL); selectionLoop->addEnumLoop(SA_RANKING, NULL); selectionLoop->addEnumLoop(SA_TOURNAMENT, new RangeLoop(Population::TOURNAMENT_SIZE, 3, 5, 3)); selectionLoop->addEnumLoop(SA_TRUNCATION, NULL); averageLoop.addInnerLoop(selectionLoop); JoinEnumLoop* mutationLoop = new JoinEnumLoop(ET_MUTATION_ALG); // mutationLoop->addEnumLoop(MA_DISABLED, NULL); mutationLoop->addEnumLoop(MA_PER_INDIVIDUAL, new RangeLoop(Population::MUTATION_NUM, 2, 3, 2)); mutationLoop->addEnumLoop(MA_PROBABILISTIC, new RangeLoop(Population::MUTATION_PROB, 0.05, 0.30, 0.35)); averageLoop.addInnerLoop(mutationLoop); plotter.parameters.putNumber(Dummy::SIZE, 2); plotter.parameters.putNumber(Dummy::NUM_TESTS, 0); EnumLoop filesLoop(ET_TEST_TASKS, 3, TT_BIN_OR, TT_BIN_AND, TT_BIN_XOR); plotter.plotTaskFilesAveraged("CrossoverAlg", &linesLoop, &filesLoop, &averageLoop); plotter.parameters.putNumber(Dummy::SIZE, 6); plotter.parameters.putNumber(Dummy::NUM_TESTS, 2); plotter.parameters.putNumber(Enumerations::enumTypeToString(ET_TEST_TASKS), TT_REVERSI); // plotter.plotTaskAveraged("CrossoverAlg_REVERSI", &linesLoop, &averageLoop); printf("Exit success.\n"); } catch (std::string error) { cout << "Error: " << error << endl; // } catch (...) { // printf("An error was thrown.\n", 1); } MemoryManagement::printTotalAllocated(); MemoryManagement::printTotalPointers(); MemoryManagement::printListOfPointers(); total.stop(); printf("Total time spent: %f \n", total.getSeconds()); return EXIT_SUCCESS; }
void on_pop() { //get_Window().mouse_grab(false); get_Window().mouse_hide(false); //get_Game().joy_mouse.enabled = true; m_chrono.stop(); }
int main(int argc, char *argv[]) { Chronometer total; total.start(); try { Test test; test.parameters.putNumber(Dummy::WEIGHS_RANGE, 20); test.parameters.putNumber(Enumerations::enumTypeToString(ET_FUNCTION), FT_IDENTITY); RangeLoop* sizeLoop = new RangeLoop(Dummy::SIZE, 100, 101, 100); Loop* loop = sizeLoop; RangeLoop* outputSizeLoop = new RangeLoop(Dummy::OUTPUT_SIZE, 1, 4, 2); loop->addInnerLoop(outputSizeLoop); EnumLoop* bufferTypeLoop = new EnumLoop(Enumerations::enumTypeToString(ET_BUFFER), ET_BUFFER); loop->addInnerLoop(bufferTypeLoop); // loop->addInnerLoop(new EnumLoop(ET_IMPLEMENTATION, 2, IT_C, IT_SSE2)); sizeLoop->addInnerLoop(new EnumLoop(ET_IMPLEMENTATION)); loop->print(); // test.testMemoryLosses(testLoops, ¶metersMap, "test loops", &loop); test.testMemoryLosses(testBuffer, "Buffer", loop); // exclude BYTE bufferTypeLoop->exclude(ET_BUFFER, 1, BT_BYTE); test.testMemoryLosses(testConnection, "Connection", loop); RangeLoop* numInputsLoop = new RangeLoop(Dummy::NUM_INPUTS, 1, 3, 1); loop->addInnerLoop(numInputsLoop); test.testMemoryLosses(testLayer, "Layer", loop); RangeLoop* numLayersLoop = new RangeLoop(Dummy::NUM_LAYERS, 1, 3, 1); loop->addInnerLoop(numLayersLoop); test.testMemoryLosses(testNeuralNet, "NeuralNet", loop); test.testMemoryLosses(testIndividual, "Individual", loop); sizeLoop->resetRange(1, 3, 1); outputSizeLoop->resetRange(1, 1, 1); numInputsLoop->resetRange(1, 1, 1); numLayersLoop->resetRange(1, 1, 1); test.testMemoryLosses(testPopulation, "Population", loop); delete(loop); MemoryManagement::printListOfPointers(); printf("Exit success.\n"); } catch (string& error) { cout << "Error: " << error << endl; } catch (...) { printf("An error was thrown.\n"); } MemoryManagement::printTotalAllocated(); MemoryManagement::printTotalPointers(); total.stop(); printf("Total time spent: %f \n", total.getSeconds()); return EXIT_SUCCESS; }
int main() { double t1, t2; const int dim = 2000; Chronometer chrono; t1 = chrono.click(); Vector x(dim); Matrix A(dim); t2 = chrono.click(); std::cout << "Time to create matrix: " << t2 - t1 << " sec.\n"; t1 = chrono.click(); matrixAssembly(A); t2 = chrono.click(); std::cout << "Time to compute coefficients of the matrix: " << t2 - t1 << " sec.\n"; t1 = chrono.click(); assemblyRhs(A, x); t2 = chrono.click(); std::cout << "Time to compute coefficients of the right hand side: " << t2 - t1 << " sec.\n"; t1 = chrono.click(); factorize(A); t2 = chrono.click(); std::cout << "Time to factorize the matrix: " << t2 - t1 << " sec.\n"; t1 = chrono.click(); forward(A, x); backward(A, x); t2 = chrono.click(); std::cout << "Time to solve the linear system: " << t2 - t1 << " sec.\n"; verifySolution(x); return EXIT_SUCCESS; }
void NetStream::execute() { //mutex access to downloader istream s(downloader); s.exceptions ( istream::eofbit | istream::failbit | istream::badbit ); ThreadProfile* profile=sys->allocateProfiler(RGB(0,0,200)); profile->setTag("NetStream"); //We need to catch possible EOF and other error condition in the non reliable stream uint32_t decodedTime=0; uint32_t videoFrameCount=0; try { Chronometer chronometer; STREAM_TYPE t=classifyStream(s); if(t==FLV_STREAM) { FLV_HEADER h(s); if(!h.isValid()) threadAbort(); unsigned int prevSize=0; bool done=false; do { UI32 PreviousTagSize; s >> PreviousTagSize; PreviousTagSize.bswap(); assert_and_throw(PreviousTagSize==prevSize); //Check tag type and read it UI8 TagType; s >> TagType; switch(TagType) { case 8: { AudioDataTag tag(s); prevSize=tag.getTotalLen(); #ifdef ENABLE_SOUND if(audioDecoder) { assert_and_throw(audioCodec==tag.SoundFormat); uint32_t decodedBytes=audioDecoder->decodeData(tag.packetData,tag.packetLen,decodedTime); if(soundStreamId==0 && audioDecoder->isValid()) soundStreamId=sys->soundManager->createStream(audioDecoder); //Adjust timing decodedTime+=decodedBytes/audioDecoder->getBytesPerMSec(); } else { audioCodec=tag.SoundFormat; switch(tag.SoundFormat) { case AAC: assert_and_throw(tag.isHeader()) #ifdef ENABLE_LIBAVCODEC audioDecoder=new FFMpegAudioDecoder(tag.SoundFormat, tag.packetData, tag.packetLen); #else audioDecoder=new NullAudioDecoder(); #endif break; default: throw RunTimeException("Unsupported SoundFormat"); } if(audioDecoder->isValid()) soundStreamId=sys->soundManager->createStream(audioDecoder); } #endif break; } case 9: { VideoDataTag tag(s); prevSize=tag.getTotalLen(); //Reset the current time, the video flow driver the stream decodedTime=videoFrameCount*1000/frameRate; videoFrameCount++; assert_and_throw(tag.codecId==7); if(tag.isHeader()) { //The tag is the header, initialize decoding assert_and_throw(videoDecoder==NULL); //The decoder can be set only once #ifdef ENABLE_LIBAVCODEC videoDecoder=new FFMpegVideoDecoder(tag.packetData,tag.packetLen); #else videoDecoder=new NullVideoDecoder(); #endif tag.releaseBuffer(); Event* status=Class<NetStatusEvent>::getInstanceS("status", "NetStream.Play.Start"); getVm()->addEvent(this, status); status->decRef(); status=Class<NetStatusEvent>::getInstanceS("status", "NetStream.Buffer.Full"); getVm()->addEvent(this, status); status->decRef(); } else videoDecoder->decodeData(tag.packetData,tag.packetLen, decodedTime); break; } case 18: { ScriptDataTag tag(s); prevSize=tag.getTotalLen(); //The frameRate of the container overrides the stream if(tag.frameRate) frameRate=tag.frameRate; break; } default: LOG(LOG_ERROR,"Unexpected tag type " << (int)TagType << " in FLV"); threadAbort(); } if(!tickStarted && isReady()) { tickStarted=true; if(frameRate==0) { assert(videoDecoder->frameRate); frameRate=videoDecoder->frameRate; } sys->addTick(1000/frameRate,this); } profile->accountTime(chronometer.checkpoint()); if(aborting) throw JobTerminationException(); } while(!done); } else threadAbort(); }