void Game::Initialize() { /*Font* font = new Font("Fonts/arial.ttf",Font::PLAIN,16); SDL_Color color; color.r = 255; color.g = 255; color.b = 255; color.a = 255; SDL_Color bgcolor; bgcolor.r = 0; bgcolor.g = 0; bgcolor.b = 0; bgcolor.a = 0; SDL_Surface* surface = TTF_RenderGlyph_Shaded(font->getTTF(), 'H', color, bgcolor); Console::WriteLine((String)"H: " + surface->w + ", " + surface->h); SDL_FreeSurface(surface); surface = TTF_RenderGlyph_Shaded(font->getTTF(), 'y', color, bgcolor); Console::WriteLine((String)"y: " + surface->w + ", " + surface->h); SDL_FreeSurface(surface); surface = TTF_RenderGlyph_Shaded(font->getTTF(), 'r', color, bgcolor); Console::WriteLine((String)"r: " + surface->w + ", " + surface->h); SDL_FreeSurface(surface); surface = TTF_RenderGlyph_Shaded(font->getTTF(), '.', color, bgcolor); Console::WriteLine((String)".: " + surface->w + ", " + surface->h); SDL_FreeSurface(surface);*/ //Initialize things scaleToWindow(true,900,600); AssetManager::loadImage("Images/icon.png"); setLoadScreen("Images/loading.png"); Global::init(); #ifdef DEBUG showRealFPS(true); #endif if(Preferences::highFPS()) { setFPS(60); setUpdatesPerFrame(1); } else { setFPS(30); setUpdatesPerFrame(2); } //setWindowTitle("Super Smash Bros."); }
void Engine::run() { float currTime = 0; float oldTime; float fix = 1.f / 60.f; //Update Step 60Hz FPS_.start(); while(run_) { oldTime = currTime; currTime = FPS_.getSec(); dt_ = currTime - oldTime; setFPS(dt_); if(dt_ > 0.2f) xLOG[Util::LogType::ERROR]("Engine :: run") << "Unusually high deltaTime: " << dt_ << "\0"; dt_ *= timeScale_; pollEvents(); physicsSystem_->update(fix*timeScale_); camera_->update(); scriptEngine_->update(dt_); stateMachine_->update(dt_); uiManager_->update(dt_); renderSystem_->render(); cleanUp(); } }
void NiAnimation::stopRecording() { is_recording = false; setFPS(DEFAULT_FPS); setNumberOfFrames(current_frame); setFrameTime(frameTime()); }
bool AllegroEngine::Init(int winwidth,int winheight) { map<int,bool> errormap; // if (!al_init()) errormap.insert(pair<int,bool>(E_ALLEGRO,true)); //Did Allegro fail to open? // root = al_create_display(winwidth, winheight); if (!root) errormap.insert(pair<int,bool>(E_DISPLAY,true)); //Did the root display fail to be created? // al_init_font_addon(); // initialize the font addon al_init_ttf_addon();// initialize the ttf (True Type Font) addon font = al_load_ttf_font("malgun.ttf",72,0 ); if (!font) errormap.insert(pair<int,bool>(E_FONT,true)); //Did the font fail to load? // setFPS(errormap, 10); // if (!al_install_mouse()) errormap.insert(pair<int,bool>(E_MOUSE,true)); //No mouse? if (!al_install_keyboard()) errormap.insert(pair<int,bool>(E_KEYBOARD,true)); //No mouse? // event_queue = al_create_event_queue(); if (!event_queue) errormap.insert(pair<int,bool>(E_EVENTQUEUE,true)); //Did the event queue not appear? // al_register_event_source(event_queue, al_get_display_event_source(root)); //register display as event source al_register_event_source(event_queue, al_get_timer_event_source(timer_fps)); //register timer as event source al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_mouse_event_source()); // bool errors = EngineInit(errormap); return errors || errormap.size()==0?true:false; }
//TODO: Optimize this .. void Sprite::init(TiXmlElement * pElement) { if(pElement->ValueStr() != "sprite") return; TiXmlAttribute * pAtt = pElement->FirstAttribute(); setFPS( pAtt->IntValue() ); TiXmlElement * pChild = pElement->FirstChildElement(); while(pChild != NULL) { if(pChild->ValueStr() != "surface") continue; std::string fileName = pChild->GetText(); SDL_SurfacePtr pSurface = load_image(fileName); float zoom = 1.0f; float rot = 0.0f; float alpha = 1.0; TiXmlAttribute * pAttrib = pChild->FirstAttribute(); if(pAttrib != NULL) { SDL_Rect rect = {-1,-1,-1,-1}; while(pAttrib != NULL) { //std::cout << pAttrib->Name() << std::endl; if(pAttrib->Name() == std::string("x")) rect.x = pAttrib->IntValue(); else if(pAttrib->Name() == std::string("y")) rect.y = pAttrib->IntValue(); else if(pAttrib->Name() == std::string("w")) rect.w = pAttrib->IntValue(); else if(pAttrib->Name() == std::string("h")) rect.h = pAttrib->IntValue(); else if(pAttrib->Name() == std::string("rot")) rot = pAttrib->DoubleValue(); else if(pAttrib->Name() == std::string("zoom")) zoom = pAttrib->DoubleValue(); else if(pAttrib->Name() == std::string("alpha")) alpha = pAttrib->DoubleValue(); pAttrib = pAttrib->Next(); } if( rect.x != -1 && rect.y != -1 && rect.w != -1 && rect.h != -1) pSurface = getSurface( pSurface.get(), rect ); if( zoom != 1.0 || rot != 0.0f ) pSurface = rotozoomSurface( pSurface.get(), rot, zoom, 1); //1 is for smoothing if( alpha != 1.0 ) { int a = 255*alpha; SDL_SetAlpha( pSurface.get(), SDL_SRCALPHA|SDL_RLEACCEL, a); } } m_Sprites.push_back( new SDL_SurfacePtr(pSurface) ); pChild = pChild->NextSiblingElement(); } }
RobotWindow::RobotWindow(double x, double y, double z) : WindowControl(), platform(x, y, z), robot(5, platform), textLives(), textGameOver(), textFps(), borderland(8, 200), platformColor() { // registra os parêmtros da criação da classe platWidth = x; platHeight = y; platDeep = z; // cria e configura objetos para desenhar os textos textGameOver.setFontStyle(GLUT_BITMAP_TIMES_ROMAN_24); textGameOver.setText("GAME OVER"); textGameOver.setPosition(-0.25, 0.1, -1); textGameOver.setColor(vermelho); textLives.setText("Vidas: %d", robot.getLives()); textLives.setPosition(-0.95, 0.9, -1); textLives.setColor(verde); textFps.setText("FPS: %d", getFps()); textFps.setPosition(-0.95, -0.95, -1); // agenda um evento para garantir ao menos um // glutPostRedisplay() por segundo newEvent(EVENT_POST_REDISPLAY, 1000); setFPS(120); // executa a configuração do ambiente openGL setTitle("SCARA - OpenGL"); configure(); // configura a posicição inicial da câmera robot.configureLookAt(lookAt); // agenda o evento de animação de iniciação do programa cameraRadius = 400; setCameraPosition(180, 90); newEvent(EVENT_RESET, interval); // inicia desenhando o limite espacial do jogo drawCage = true; // define as cores do robô platformColor.setColor(cinzaEscuro); robot.base.setColor(cinzaMaisEscuro); robot.armBase.setColor(amarelo); robot.arm.setColor(cinzaMaisEscuro); robot.clawBase.setColor(amarelo); robot.claw.hand.setColor(vermelho); // configurações iniciais de controles do jogo mouseX = mouseY = 0; mouseButton = 0; mouseState = GLUT_UP; eventFlying = 0; }
//! Configure number of frames per second. //! @param[in] fps frames per second. void setFPS(unsigned fps) { switch (fps) { case 15: setFPS(FPS_15); break; case 7: setFPS(FPS_7); break; case 3: setFPS(FPS_3); break; default: throw std::runtime_error("invalid FPS value"); } }
void Game::initialize() { getWindow()->setSize(Vector2u(SMASHBROS_WINDOWWIDTH, SMASHBROS_WINDOWHEIGHT)); getWindow()->getView()->setSize(SMASHBROS_WINDOWWIDTH, SMASHBROS_WINDOWHEIGHT); getWindow()->getView()->setLetterboxed(true); setFPS(60); menuLoad = new MenuLoad(*getWindow(), "assets/menu"); moduleLoad = new ModuleLoad(*getWindow(), "assets/characters", "assets/stages"); smashData = new SmashData(getWindow(), menuLoad, moduleLoad); }
//OFX FENSTER ofxFenster::ofxFenster(){ singleton = this; width = 800; height = 400; nextWinUpdate = 0; nextWinDraw = 0; setFPS(60); hasGlut = false; mainContextSkip = 0; };
KinectRecorder::KinectRecorder() :is_playing(false) ,is_loaded(false) ,next_frame_millis(0) ,index(0) ,fps(0) ,num_frames(0) { setFPS(10); }
void Game::initialize() { setFPS(30); getWindow()->getView()->setSize(426, 240); getWindow()->getView()->setLetterboxed(true); getWindow()->getView()->setMaintainResolution(true); Vector2d viewSize = getWindow()->getView()->getSize(); cameraCenter.x = viewSize.x/2; cameraCenter.y = viewSize.y/2; getWindow()->setSize(Vector2u(800, 600)); }
void FPSCounter::update(int dt) { _pImpl->curFPS++; _pImpl->time += dt; if (_pImpl->time >= 1000) { _pImpl->fps = _pImpl->curFPS; _pImpl->curFPS = 0; _pImpl->time = 0; emit setFPS(_pImpl->fps); } }
void INKFrame::init(int iFps) { setFPS(iFps); //intialize SDL if(-1 == SDL_Init(SDL_INIT_VIDEO)) { throw std::runtime_error("Unable to initialize SDL"); } SDL_WM_SetCaption(_strTitle.c_str(), 0); //open the window if(!SDL_SetVideoMode(_iW, _iH, _iBbp, SDL_OPENGL | SDL_GL_DOUBLEBUFFER )) { throw std::runtime_error("Unable to open a window"); } SDL_EnableUNICODE(SDL_ENABLE); }
bool STexture::openVideo(QString s, double fps, bool loop, int start, int stop) { clearCallBacks(); setPlaying(false); setFPS(fps); setLooping(loop); videoFileName = s; bool ok=false; for (physicalFirstFrame=0; physicalFirstFrame < (unsigned)max(20,max(start,stop)); physicalFirstFrame++) { QString fn = frameFilename(physicalFirstFrame); QFileInfo info(fn); if (info.isFile() && info.isReadable()) { ok=true; break; } } if (!ok) { videoFileName.clear(); return false; } unsigned in = physicalFirstFrame; unsigned out = 100000; while (out-in > 1) { int mid = in + ((out-in)/2); QString fn = frameFilename(mid); QFileInfo info(fn); if (info.isFile() && info.isReadable()) in = mid; else out = mid; } physicalLastFrame=in; position=firstFrame=physicalFirstFrame; lastFrame=physicalLastFrame; if (start>=0) setFirstFrame(start); if (stop>=0) setLastFrame(stop); return true; }
bool CTimer::Start() { //Timer stats setFPS(_wantedFPS); SetIterDuration(1000); //Sleep _IterBeginTick = SDL_GetTicks(); _NextIterTick = _IterBeginTick + _IterDuration; _NextIterBeginTime = _IterBeginTick + ((_CurrentIterUpdates + 1) * _IterDuration / _UpdatesPerIter); //Delta time _SDLTicks = _IterBeginTick; _LastIterBeginTick = _SDLTicks; //Time _beginTick = SDL_GetTicks(); return true; }
ParticleHandler(MultiParticleHandler * _owner):owner(_owner){ params = new ofParameterGroup(); params->setName("partGroup"); setFPS(30); nn = make_shared<MyNN>(); physics = new PhysicsHandler(this); forceHandler = new ForceHandler(this); init(); CPARAM(lineStyle,0,0,10); // lineStyle.addListener(this,&ParticleHandler::changedLineStyle); CPARAM(originType,0,0,10); CPARAM(kNN,6,-1,20); kNN.addListener(this ,&ParticleHandler::changedLineStyle); params->add(*forceHandler->forcesParams); params->add(*physics->params); originType.addListener(this ,&ParticleHandler::changeOrigin); };
// ------------------------------------------------------ init void ofxBox2d::init() { // settings bHasContactListener = false; bCheckBounds = false; bEnableGrabbing = true; bWorldCreated = false; scale = OFX_BOX2D_SCALE; doSleep = true; // gravity gravity.set(0, 5.0f); setFPS(60.0); velocityIterations = 40; positionIterations = 20; // mouse grabbing mouseJoint = NULL; mouseBody = NULL; // ground/bounds ground = NULL; // debug drawer debugRender.setScale(scale); debugRender.SetFlags(1); //worldAABB.lowerBound.Set(-100.0f, -100.0f); //worldAABB.upperBound.Set(100.0f, 100.0f); world = new b2World(b2Vec2(gravity.x, gravity.y), doSleep); world->SetDebugDraw(&debugRender); ofLog(OF_LOG_NOTICE, "- Box2D Created -\n"); bWorldCreated = true; world->SetContactListener(this); }
ofxGameEng& ofxGameEng::loadXml(string filePath = "config.xml"){ ofxXmlSettings XML; //cout << "Reading game engine configuration file " << filePath; if (XML.loadFile(filePath)){ //cout << " [ OK ]" << endl; init(); if ( XML.tagExists("world:gravity")) setGravity(XML.getValue("world:gravity:x",0), XML.getValue("world:gravity:y",10) ); setFPS(XML.getValue("world:fps",30)); bool bGrabbing = XML.getValue("world:grabbing",0); if (bGrabbing) registerGrabbing(); if ( XML.tagExists("world:ground:x")) groundX = XML.getValue("world:ground:x",0); if ( XML.tagExists("world:ground:y")) groundY = XML.getValue("world:ground:y",10); if( boundingObj != NULL ){ createGround(ofPoint( (groundX!=-1)?groundX:0, (groundY!=-1)?groundY:0), ofPoint((groundX!=-1)?groundX:boundingObj->getScaledWidth(), (groundY!=-1)?groundY:boundingObj->getScaledHeight())); createBounds(0, 0, boundingObj->getScaledWidth(),boundingObj->getScaledHeight()); } // TODO: // This need some love } else cout << " [ FAIL ]" << endl; return * this; }
// ------------------------------------------------------ init void ofxBox2d::init() { //settings bHasContactListener = false; bCheckBounds = false; bEnableGrabbing = true; bWorldCreated = false; scale = OFX_BOX2D_SCALE; doSleep = true; //gravity gravity.set(0, 5.0f); setFPS(60.0); //mouse grabbing mouseJoint = NULL; ground = NULL; //debug drawer debugRender.setScale(scale); debugRender.SetFlags(1); worldAABB.lowerBound.Set(-100.0f, -100.0f); worldAABB.upperBound.Set(100.0f, 100.0f); world = new b2World(worldAABB, b2Vec2(gravity.x, gravity.y), doSleep); world->SetDebugDraw(&debugRender); float bw = ofGetWidth()/scale; ofLog(OF_LOG_NOTICE, "- Box2D Created -\n"); ofAddListener(ofEvents.mousePressed, this, &ofxBox2d::mousePressed); ofAddListener(ofEvents.mouseDragged, this, &ofxBox2d::mouseDragged); ofAddListener(ofEvents.mouseReleased, this, &ofxBox2d::mouseReleased); bWorldCreated = true; }
FPSTimer():isSkip_(false),lastDrawTime_(0),frameCount_(1),timeForRealFPS_(0),realFPS_(0),drawCount_(0){ setFPS(60); }
void qavimator::onFpsSpinValueChanged(int newValue) { setFPS(newValue); }
void setIRFPS(int fps) { setFPS(getIRGenerator(), fps); }
void setImageFPS(int fps) { setFPS(getImageGenerator(), fps); }
void Connection::socketData() { int toRead; int bytesRead=0; int thisRead=0; int version; int subversion; int header_size=0; int answer_size=0; char* ans; QString answer; if (bytes < 0) { //fprintf(stderr,"QtRadio: FATAL: INVALID byte counter: %d\n", bytes); //tcpSocket->close(); return; } toRead=tcpSocket->bytesAvailable(); if (toRead <= 0) { return; } while(bytesRead<toRead) { //fprintf (stderr, "%d of %d [%d]\n", bytesRead, toRead, state); switch(state) { case READ_HEADER_TYPE: thisRead=tcpSocket->read(&hdr[bytes],3 - bytes); if (thisRead < 0) { fprintf(stderr,"QtRadio: FATAL: READ_AUDIO_HEADER: error in read: %d\n", thisRead); tcpSocket->close(); return; } bytes+=thisRead; if (bytes == 3){ switch(hdr[0]) { case AUDIO_BUFFER: state=READ_AUDIO_HEADER; break; case SPECTRUM_BUFFER: version=hdr[1]; subversion=hdr[2]; switch(version) { case 2: switch(subversion) { case 0: header_size=HEADER_SIZE_2_0; break; case 1: header_size=HEADER_SIZE_2_1; break; default: fprintf(stderr,"QtRadio: Invalid subversion. Expected %d.%d got %d.%d\n",HEADER_VERSION,HEADER_SUBVERSION,version,subversion); break; } break; default: fprintf(stderr,"QtRadio: Invalid version. Expected %d.%d got %d.%d\n",HEADER_VERSION,HEADER_SUBVERSION,version,subversion); break; } state=READ_HEADER; break; case BANDSCOPE_BUFFER: break; case RTP_REPLY_BUFFER: state=READ_RTP_REPLY; break; case 52: //ANSWER_BUFFER // answer size is in hdr pos 1 & 2 max 99 state = READ_ANSWER; bytes = 0; answer_size = atoi(hdr) - 400 ; // 1st digt is buffer type 4 ans = (char*)malloc(answer_size +1); break; } } break; case READ_AUDIO_HEADER: //fprintf (stderr, "READ_AUDIO_HEADER: hdr size: %d bytes: %d\n", AUDIO_HEADER_SIZE, bytes); thisRead=tcpSocket->read(&hdr[bytes],AUDIO_HEADER_SIZE - bytes); if (thisRead < 0) { fprintf(stderr,"QtRadio: FATAL: READ_AUDIO_HEADER: error in read: %d\n", thisRead); tcpSocket->close(); return; } bytes+=thisRead; if (bytes == AUDIO_HEADER_SIZE){ // g0orx binary header //length = atoi(&hdr[AUDIO_LENGTH_POSITION]); length=((hdr[3]&0xFF)<<8)+(hdr[4]&0xFF); buffer = (char*)malloc(length); bytes = 0; state = READ_BUFFER; } break; case READ_HEADER: //fprintf (stderr, "READ_HEADER: hdr size: %d bytes: %d\n", header_size, bytes); thisRead=tcpSocket->read(&hdr[bytes],header_size - bytes); if (thisRead < 0) { fprintf(stderr,"QtRadio: FATAL: READ_HEADER: error in read: %d\n", thisRead); tcpSocket->close(); return; } bytes+=thisRead; if(bytes==header_size) { // g0orx binary header length=((hdr[3]&0xFF)<<8)+(hdr[4]&0xFF); if ((length < 0) || (length > 4096)){ state = READ_HEADER_TYPE; } else { buffer=(char*)malloc(length); bytes=0; state=READ_BUFFER; } } break; case READ_BUFFER: //fprintf (stderr, "READ_BUFFER: length: %d bytes: %d\n", length, bytes); thisRead=tcpSocket->read(&buffer[bytes],length-bytes); if (thisRead < 0) { fprintf(stderr,"QtRadio: FATAL: READ_BUFFER: error in read: %d\n", thisRead); tcpSocket->close(); return; } bytes+=thisRead; //qDebug() << "READ_BUFFER: read " << bytes << " of " << length; if(bytes==length) { version=hdr[1]; subversion=hdr[2]; queue.enqueue(new Buffer(hdr,buffer)); QTimer::singleShot(0,this,SLOT(processBuffer())); hdr=(char*)malloc(HEADER_SIZE_2_1); bytes=0; state=READ_HEADER_TYPE; } break; case READ_RTP_REPLY: thisRead=tcpSocket->read(&hdr[bytes],7-bytes); // length and port bytes+=thisRead; if(bytes==7) { /* int port; port=((hdr[5]&0xFF)<<8) + (hdr[6]&0xFF); // configure this ends rtp so we can send to remote qDebug() << "Connection emit remoteRTP "<<host<<":"<<port; emit remoteRTP((char*)host.toUtf8().constData(),port); */ bytes=0; state=READ_HEADER_TYPE; } break; case READ_ANSWER: //qDebug() << "Connection READ ANSWER"; thisRead=tcpSocket->read(&ans[bytes],answer_size - bytes); if (thisRead < 0) { fprintf(stderr,"QtRadio: FATAL: READ_BUFFER: error in read: %d\n", thisRead); tcpSocket->close(); return; } bytes+=thisRead; if(bytes==answer_size) { //fprintf(stderr,"ans length = %lu\n",strlen(ans)); ans[answer_size] = '\0'; answer = ans; QRegExp rx; if(answer.contains("q-version")){ //"20120107;-rxtx-rtp"; YYYYMMDD; text desc rx.setPattern(":(\\d+);-(\\S+)"); rx.indexIn(answer); #if QT_VERSION >= 0x050000 emit setdspversion(rx.cap(1).toLong(),rx.cap(2).toUtf8()); #else emit setdspversion(rx.cap(1).toLong(),rx.cap(2).toAscii()); #endif serverver = rx.cap(1).toLong(); if (serverver < 20120201){ // tx login start emit setCanTX(true); //server to old to tell } sendCommand("q-master"); }else if(answer.contains("q-server")){ rx.setPattern("q-server:(\\S+)"); rx.indexIn(answer); QString servername = rx.cap(1); emit setservername(servername); rx.setPattern("([YNP])$"); // Y no checking, N no TX, P depend who and where we are rx.indexIn(answer); QString hasTX = rx.cap(1); if (hasTX.compare("N") == 0){ emit setCanTX(false); }else if(hasTX.compare("P") == 0){ emit setCanTX(false); emit setChkTX(true); }else{ // must be yes //qDebug() <<"Yes Master"; if (amSlave){ emit setCanTX(false); emit setChkTX(false); }else{ emit setCanTX(true); emit setChkTX(false); } } }else if(answer.contains("q-master")){ //qDebug() << "q-master:" << answer; if (answer.contains("slave")){ amSlave = true; emit printStatusBar(" ...Slave Mode. "); }else{ amSlave = false; emit printStatusBar(" ...Master Mode. "); } }else if(answer.contains("q-rtpport")){ rx.setPattern("rtpport:(\\d+);"); rx.indexIn(answer); QString p = rx.cap(1); emit setRemoteRTPPort(host,p.toInt()); }else if(answer.contains("q-cantx:")){ rx.setPattern("([YN])$"); rx.indexIn(answer); QString TXNow= rx.cap(1); if (TXNow.compare("Y") == 0){ emit setCanTX(true); }else{ emit setCanTX(false); } }else if(answer.contains("q-loffset:")){ rx.setPattern("q-loffset:(\\d+)\\."); rx.indexIn(answer); double loffset= rx.cap(1).toDouble(); emit resetbandedges(loffset); }else if(answer.contains("q-info")){ rx.setPattern("info:s;(\\d+);f;(\\d+);m;(\\d+);z;(\\d+);l;(\\d+|-\\d+);r;(\\d+|-\\d+)"); rx.indexIn(answer); QString f = rx.cap(2); QString m = rx.cap(3); QString z = rx.cap(4); QString l = rx.cap(5); QString r = rx.cap(6); long long newf = f.toLongLong(); int newmode = m.toInt(); int zoom = z.toInt(); int left = l.toInt(); int right = r.toInt(); emit slaveSetFreq(newf); emit slaveSetFilter(left, right); emit slaveSetZoom(zoom); if(newmode != lastMode){ emit slaveSetMode(newmode); } lastFreq = newf; lastMode = newmode; } else if (answer.contains("q-protocol3")){ rx.setPattern("([YN])$"); rx.indexIn(answer); QString protocol3= rx.cap(1); if (protocol3.compare("Y") == 0){ emit setProtocol3(true); emit setFPS(); } } else if (answer[0] == '*') { qDebug() << "--------------->" << answer; emit hardware (QString(answer)); } //answer.prepend(" Question/Answer "); //emit printStatusBar(answer); qDebug() << "ANSWER bytes "<< bytes <<" answer "<< ans; free(ans); bytes=0; state=READ_HEADER_TYPE; } break; default: fprintf (stderr, "FATAL: WRONG STATUS !!!!!\n"); } bytesRead+=thisRead; } }
void ofxFenster::setFPS(int fps){ setFPS(fps, fps); };
void setDepthFPS(int fps) { setFPS(getDepthGenerator(), fps); }
void TupProject::fromXml(const QString &xml) { QDomDocument document; if (!document.setContent(xml)) return; QDomElement root = document.documentElement(); QDomNode n = root.firstChild(); int i = 0; while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "project") { setProjectName(e.attribute("name", projectName())); QDomNode n1 = e.firstChild(); e = n1.toElement(); if (e.tagName() == "meta") { QDomNode n1 = e.firstChild(); while (!n1.isNull()) { QDomElement e1 = n1.toElement(); if (e1.tagName() == "author") { if (e1.firstChild().isText()) setAuthor(e1.text()); } else if (e1.tagName() == "bgcolor") { if (e1.text().isEmpty()) setBgColor(QColor("#ffffff")); else setBgColor(QColor(e1.text())); } else if (e1.tagName() == "description") { if (e1.firstChild().isText()) setDescription(e1.text()); } else if (e1.tagName() == "dimension") { if (e1.firstChild().isText()) { QStringList list = e1.text().split(","); int x = list.at(0).toInt(); int y = list.at(1).toInt(); QSize size(x,y); setDimension(size); } } else if (e1.tagName() == "fps") { if (e1.firstChild().isText()) setFPS(e1.text().toInt()); } n1 = n1.nextSibling(); } } } } n = n.nextSibling(); i++; } }
static void VS_CC mvflowfpsCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { MVFlowFPSData d; MVFlowFPSData *data; int err; d.num = vsapi->propGetInt(in, "num", 0, &err); if (err) d.num = 25; d.den = vsapi->propGetInt(in, "den", 0, &err); if (err) d.den = 1; d.maskmode = int64ToIntS(vsapi->propGetInt(in, "mask", 0, &err)); if (err) d.maskmode = 2; d.ml = vsapi->propGetFloat(in, "ml", 0, &err); if (err) d.ml = 100.0; d.blend = !!vsapi->propGetInt(in, "blend", 0, &err); if (err) d.blend = 1; d.thscd1 = int64ToIntS(vsapi->propGetInt(in, "thscd1", 0, &err)); if (err) d.thscd1 = MV_DEFAULT_SCD1; d.thscd2 = int64ToIntS(vsapi->propGetInt(in, "thscd2", 0, &err)); if (err) d.thscd2 = MV_DEFAULT_SCD2; d.isse = !!vsapi->propGetInt(in, "isse", 0, &err); if (err) d.isse = 1; if (d.maskmode < 0 || d.maskmode > 2) { vsapi->setError(out, "FlowFPS: mask must be 0, 1, or 2."); return; } if (d.ml <= 0.0) { vsapi->setError(out, "FlowFPS: ml must be greater than 0."); return; } d.super = vsapi->propGetNode(in, "super", 0, NULL); char errorMsg[1024]; const VSFrameRef *evil = vsapi->getFrame(0, d.super, errorMsg, 1024); if (!evil) { vsapi->setError(out, std::string("FlowFPS: failed to retrieve first frame from super clip. Error message: ").append(errorMsg).c_str()); vsapi->freeNode(d.super); return; } const VSMap *props = vsapi->getFramePropsRO(evil); int evil_err[2]; int nHeightS = int64ToIntS(vsapi->propGetInt(props, "Super_height", 0, &evil_err[0])); d.nSuperHPad = int64ToIntS(vsapi->propGetInt(props, "Super_hpad", 0, &evil_err[1])); vsapi->freeFrame(evil); for (int i = 0; i < 2; i++) if (evil_err[i]) { vsapi->setError(out, "FlowFPS: required properties not found in first frame of super clip. Maybe clip didn't come from mv.Super? Was the first frame trimmed away?"); vsapi->freeNode(d.super); return; } d.mvbw = vsapi->propGetNode(in, "mvbw", 0, NULL); d.mvfw = vsapi->propGetNode(in, "mvfw", 0, NULL); // XXX F**k all this trying. try { d.mvClipB = new MVClipDicks(d.mvbw, d.thscd1, d.thscd2, vsapi); } catch (MVException &e) { vsapi->setError(out, std::string("FlowFPS: ").append(e.what()).c_str()); vsapi->freeNode(d.super); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.mvfw); return; } try { d.mvClipF = new MVClipDicks(d.mvfw, d.thscd1, d.thscd2, vsapi); } catch (MVException &e) { vsapi->setError(out, std::string("FlowFPS: ").append(e.what()).c_str()); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); delete d.mvClipB; return; } // XXX Alternatively, use both clips' delta as offsets in GetFrame. if (d.mvClipF->GetDeltaFrame() != d.mvClipB->GetDeltaFrame()) { vsapi->setError(out, "FlowFPS: mvbw and mvfw must be generated with the same delta."); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); delete d.mvClipB; delete d.mvClipF; return; } // Make sure the motion vector clips are correct. if (!d.mvClipB->IsBackward() || d.mvClipF->IsBackward()) { if (!d.mvClipB->IsBackward()) vsapi->setError(out, "FlowFPS: mvbw must be generated with isb=True."); else vsapi->setError(out, "FlowFPS: mvfw must be generated with isb=False."); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); delete d.mvClipB; delete d.mvClipF; return; } try { d.bleh = new MVFilter(d.mvfw, "FlowFPS", vsapi); } catch (MVException &e) { vsapi->setError(out, std::string("FlowFPS: ").append(e.what()).c_str()); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); delete d.mvClipB; delete d.mvClipF; return; } try { // So it checks the similarity of mvfw and mvfw? ????? // Copied straight from 2.5.11.3... d.bleh->CheckSimilarity(d.mvClipF, "mvfw"); d.bleh->CheckSimilarity(d.mvClipB, "mvbw"); } catch (MVException &e) { vsapi->setError(out, std::string("FlowFPS: ").append(e.what()).c_str()); delete d.bleh; delete d.mvClipB; delete d.mvClipF; vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); return; } if (d.bleh->nPel == 1) d.finest = vsapi->cloneNodeRef(d.super); // v2.0.9.1 else { VSPlugin *mvtoolsPlugin = vsapi->getPluginById("com.nodame.mvtools", core); VSPlugin *stdPlugin = vsapi->getPluginById("com.vapoursynth.std", core); VSMap *args = vsapi->createMap(); vsapi->propSetNode(args, "super", d.super, paReplace); vsapi->propSetInt(args, "isse", d.isse, paReplace); VSMap *ret = vsapi->invoke(mvtoolsPlugin, "Finest", args); if (vsapi->getError(ret)) { vsapi->setError(out, std::string("FlowFPS: ").append(vsapi->getError(ret)).c_str()); delete d.bleh; delete d.mvClipB; delete d.mvClipF; vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeMap(args); vsapi->freeMap(ret); return; } d.finest = vsapi->propGetNode(ret, "clip", 0, NULL); vsapi->freeMap(ret); vsapi->clearMap(args); vsapi->propSetNode(args, "clip", d.finest, paReplace); vsapi->freeNode(d.finest); ret = vsapi->invoke(stdPlugin, "Cache", args); vsapi->freeMap(args); if (vsapi->getError(ret)) { // prefix the error messages vsapi->setError(out, std::string("FlowFPS: ").append(vsapi->getError(ret)).c_str()); delete d.bleh; delete d.mvClipB; delete d.mvClipF; vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeMap(ret); return; } d.finest = vsapi->propGetNode(ret, "clip", 0, NULL); vsapi->freeMap(ret); } d.node = vsapi->propGetNode(in, "clip", 0, 0); d.vi = *vsapi->getVideoInfo(d.node); if (d.vi.fpsNum == 0 || d.vi.fpsDen == 0) { vsapi->setError(out, "FlowFPS: The input clip must have a frame rate. Invoke AssumeFPS if necessary."); vsapi->freeNode(d.finest); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.node); delete d.bleh; delete d.mvClipB; delete d.mvClipF; return; } int64_t numeratorOld = d.vi.fpsNum; int64_t denominatorOld = d.vi.fpsDen; int64_t numerator, denominator; if (d.num != 0 && d.den != 0) { numerator = d.num; denominator = d.den; } else { numerator = numeratorOld * 2; // double fps by default denominator = denominatorOld; } // safe for big numbers since v2.1 d.fa = denominator * numeratorOld; d.fb = numerator * denominatorOld; int64_t fgcd = gcd(d.fa, d.fb); // general common divisor d.fa /= fgcd; d.fb /= fgcd; setFPS(&d.vi, numerator, denominator); if (d.vi.numFrames) d.vi.numFrames = (int)(1 + (d.vi.numFrames - 1) * d.fb / d.fa); if (d.bleh->nWidth != d.vi.width || d.bleh->nHeight != d.vi.height) { vsapi->setError(out, "FlowFPS: inconsistent source and vector frame size."); vsapi->freeNode(d.finest); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.node); delete d.bleh; delete d.mvClipB; delete d.mvClipF; return; } const VSVideoInfo *supervi = vsapi->getVideoInfo(d.super); int nSuperWidth = supervi->width; if (d.bleh->nHeight != nHeightS || d.bleh->nWidth != nSuperWidth - d.nSuperHPad * 2) { vsapi->setError(out, "FlowFPS: wrong source or super clip frame size."); vsapi->freeNode(d.finest); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.node); delete d.bleh; delete d.mvClipB; delete d.mvClipF; return; } if (!((d.bleh->nWidth + d.bleh->nHPadding*2) == supervi->width && (d.bleh->nHeight + d.bleh->nVPadding*2) <= supervi->height)) { vsapi->setError(out, "FlowFPS: inconsistent clips frame size! Incomprehensible error messages are the best, right?"); vsapi->freeNode(d.finest); vsapi->freeNode(d.super); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.node); delete d.bleh; delete d.mvClipB; delete d.mvClipF; return; } if (!isConstantFormat(&d.vi) || d.vi.format->bitsPerSample > 16 || d.vi.format->sampleType != stInteger || d.vi.format->subSamplingW > 1 || d.vi.format->subSamplingH > 1 || (d.vi.format->colorFamily != cmYUV && d.vi.format->colorFamily != cmGray)) { vsapi->setError(out, "FlowFPS: input clip must be GRAY, 420, 422, 440, or 444, up to 16 bits, with constant dimensions."); vsapi->freeNode(d.super); vsapi->freeNode(d.finest); vsapi->freeNode(d.mvfw); vsapi->freeNode(d.mvbw); vsapi->freeNode(d.node); delete d.bleh; delete d.mvClipB; delete d.mvClipF; return; } if (d.vi.format->bitsPerSample > 8) d.isse = 0; d.nBlkXP = (d.bleh->nBlkX * (d.bleh->nBlkSizeX - d.bleh->nOverlapX) + d.bleh->nOverlapX < d.bleh->nWidth) ? d.bleh->nBlkX + 1 : d.bleh->nBlkX; d.nBlkYP = (d.bleh->nBlkY * (d.bleh->nBlkSizeY - d.bleh->nOverlapY) + d.bleh->nOverlapY < d.bleh->nHeight) ? d.bleh->nBlkY + 1 : d.bleh->nBlkY; d.nWidthP = d.nBlkXP * (d.bleh->nBlkSizeX - d.bleh->nOverlapX) + d.bleh->nOverlapX; d.nHeightP = d.nBlkYP * (d.bleh->nBlkSizeY - d.bleh->nOverlapY) + d.bleh->nOverlapY; d.nWidthPUV = d.nWidthP / d.bleh->xRatioUV; d.nHeightPUV = d.nHeightP / d.bleh->yRatioUV; d.nHeightUV = d.bleh->nHeight / d.bleh->yRatioUV; d.nWidthUV = d.bleh->nWidth / d.bleh->xRatioUV; d.nHPaddingUV = d.bleh->nHPadding / d.bleh->xRatioUV; d.nVPaddingUV = d.bleh->nVPadding / d.bleh->yRatioUV; d.VPitchY = (d.nWidthP + 15) & (~15); d.VPitchUV = (d.nWidthPUV + 15) & (~15); d.VXFullYB = new uint8_t [d.nHeightP * d.VPitchY]; d.VYFullYB = new uint8_t [d.nHeightP * d.VPitchY]; d.VXFullYF = new uint8_t [d.nHeightP * d.VPitchY]; d.VYFullYF = new uint8_t [d.nHeightP * d.VPitchY]; d.VXSmallYB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallYB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VXSmallYF = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallYF = new uint8_t [d.nBlkXP * d.nBlkYP]; if (d.maskmode == 2) { d.VXFullYBB = new uint8_t [d.nHeightP * d.VPitchY]; d.VYFullYBB = new uint8_t [d.nHeightP * d.VPitchY]; d.VXFullYFF = new uint8_t [d.nHeightP * d.VPitchY]; d.VYFullYFF = new uint8_t [d.nHeightP * d.VPitchY]; d.VXSmallYBB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallYBB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VXSmallYFF = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallYFF = new uint8_t [d.nBlkXP * d.nBlkYP]; } d.MaskSmallB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.MaskFullYB = new uint8_t [d.nHeightP * d.VPitchY]; d.MaskSmallF = new uint8_t [d.nBlkXP * d.nBlkYP]; d.MaskFullYF = new uint8_t [d.nHeightP * d.VPitchY]; d.upsizer = new SimpleResize(d.nWidthP, d.nHeightP, d.nBlkXP, d.nBlkYP); if (d.vi.format->colorFamily != cmGray) { d.VXFullUVB = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VYFullUVB = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VXFullUVF = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VYFullUVF = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VXSmallUVB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallUVB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VXSmallUVF = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallUVF = new uint8_t [d.nBlkXP * d.nBlkYP]; if (d.maskmode == 2) { d.VXFullUVBB = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VYFullUVBB = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VXFullUVFF = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VYFullUVFF = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.VXSmallUVBB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallUVBB = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VXSmallUVFF = new uint8_t [d.nBlkXP * d.nBlkYP]; d.VYSmallUVFF = new uint8_t [d.nBlkXP * d.nBlkYP]; } d.MaskFullUVB = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.MaskFullUVF = new uint8_t [d.nHeightPUV * d.VPitchUV]; d.upsizerUV = new SimpleResize(d.nWidthPUV, d.nHeightPUV, d.nBlkXP, d.nBlkYP); } d.LUTVB = new int[256]; d.LUTVF = new int[256]; d.nleftLast = -1000; d.nrightLast = -1000; data = (MVFlowFPSData *)malloc(sizeof(d)); *data = d; // Can't use fmParallel because of nleftLast/nrightLast. vsapi->createFilter(in, out, "FlowFPS", mvflowfpsInit, mvflowfpsGetFrame, mvflowfpsFree, fmParallelRequests, 0, data, core); // AssumeFPS sets the _DurationNum and _DurationDen properties. VSNodeRef *node = vsapi->propGetNode(out, "clip", 0, NULL); VSMap *args = vsapi->createMap(); vsapi->propSetNode(args, "clip", node, paReplace); vsapi->freeNode(node); vsapi->propSetInt(args, "fpsnum", d.vi.fpsNum, paReplace); vsapi->propSetInt(args, "fpsden", d.vi.fpsDen, paReplace); VSPlugin *stdPlugin = vsapi->getPluginById("com.vapoursynth.std", core); VSMap *ret = vsapi->invoke(stdPlugin, "AssumeFPS", args); const char *error = vsapi->getError(ret); if (error) { vsapi->setError(out, std::string("FlowFPS: Failed to invoke AssumeFPS. Error message: ").append(error).c_str()); vsapi->freeMap(args); vsapi->freeMap(ret); return; } node = vsapi->propGetNode(ret, "clip", 0, NULL); vsapi->freeMap(ret); vsapi->clearMap(args); vsapi->propSetNode(args, "clip", node, paReplace); vsapi->freeNode(node); ret = vsapi->invoke(stdPlugin, "Cache", args); vsapi->freeMap(args); error = vsapi->getError(ret); if (error) { vsapi->setError(out, std::string("FlowFPS: Failed to invoke Cache. Error message: ").append(error).c_str()); vsapi->freeMap(ret); return; } node = vsapi->propGetNode(ret, "clip", 0, NULL); vsapi->freeMap(ret); vsapi->propSetNode(out, "clip", node, paReplace); vsapi->freeNode(node); }
Window::Window() { setPosition(); setFPS(); }