LPXLFOPER EXCEL_EXPORT xlEchoArgList( LPXLFOPER argsa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper argsb( (argsa)); CellMatrix argsc( argsb.AsCellMatrix("argsc")); ArgumentList args( ArgumentList(argsc,"args")); HiResTimer t; CellMatrix result( EchoArgList( args) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlstats( LPXLFOPER dataa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper datab( (dataa)); MyArray data( datab.AsArray("data")); HiResTimer t; MyArray result( stats( data) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlSystemTime( LPXLFOPER ticksPerSeconda) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper ticksPerSecondb( (ticksPerSeconda)); CellMatrix ticksPerSecond( ticksPerSecondb.AsCellMatrix("ticksPerSecond")); HiResTimer t; double result( SystemTime( ticksPerSecond) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
HiResTimer* InitTimer(int clock_number) { HiResTimer* timer; timer = HiResTimer::getHiResTimer(clock_number); //for keeping time timer->init(); timer->start(); return (timer); }
LPXLFOPER EXCEL_EXPORT xlEchoCells( LPXLFOPER Echoeea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper Echoeeb( (Echoeea)); CellMatrix Echoee( Echoeeb.AsCellMatrix("Echoee")); HiResTimer t; CellMatrix result( EchoCells( Echoee) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlMCVanillaChoiceEulerStepping( LPXLFOPER parametersMatrixa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper parametersMatrixb( (parametersMatrixa)); CellMatrix parametersMatrix( parametersMatrixb.AsCellMatrix("parametersMatrix")); HiResTimer t; CellMatrix result( MCVanillaChoiceEulerStepping( parametersMatrix) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlMCVanillaChoice3( LPXLFOPER parametersMatrixa, double seeda) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper parametersMatrixb( (parametersMatrixa)); CellMatrix parametersMatrix( parametersMatrixb.AsCellMatrix("parametersMatrix")); unsigned long seed( static_cast<unsigned long>(seeda)); HiResTimer t; CellMatrix result( MCVanillaChoice3( parametersMatrix, seed) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
void VideoInput::updateFrame() { static HiResTimer timer; // Start the timer for fps calculations if(frameCount == 1) timer.start(); static double trackerResolution = frame.size().height; frameCount++; // Every 20 frames, calculate the fps and reset timer if(frameCount % 20 == 0) { timer.stop(); frameRate = (double) 20 / (timer.getElapsedTime()/1000.0); timer.start(); } if (!(captureFromVideo && frameCount == 1)) { // If capturing from video and video size is not equal to desired resolution, carry on with resizing if (captureFromVideo && videoResolution != trackerResolution) { cv::Mat temp_image; _capture.read(temp_image); cv::Mat roi = temp_image; if (videoResolution == 720 && trackerResolution == 480) { roi = temp_image(cv::Rect(160, 0, 960, 720)); } else if (videoResolution == 1080 && trackerResolution == 480) { roi = temp_image(cv::Rect(240, 0, 1440, 1080)); } resize(roi, frame, frame.size(), 0, 0, CV_INTER_CUBIC); } else { _capture.read(frame); } } if(frame.empty()) { throw Utils::QuitNow(); } if (!captureFromVideo) { flip(frame, frame, 1); } copyToDebugFrame(); cvtColor(frame, frameGrey, CV_BGR2GRAY); }
LPXLFOPER EXCEL_EXPORT xlmxlw_EchoDate( double date) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); HiResTimer t; double result( mxlw_EchoDate( date) ); CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t.elapsed(); resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
void gameLoop() { wParams.mFullscreen = false; wParams.mHeight = screenHeight; wParams.mWidth = screenWidth; wParams.mTitle = "Laboration 2"; wParams.mPosX = 0; wParams.mPosY = 0; if (common.init(wParams)) { common.registerTextureResource("explosion", "image/explosion.png"); EventManager em; common.setEventProcessor(&em); Graphics *g = common.getGraphics(); g->setViewport(0, 0, screenWidth, screenHeight); Renderer2D *renderer = g->createRenderer2D(); float rot = 0.0f; HiResTimer timer; timer.restart(); //Set program scale. AnimationSystem animationSystem(common); const float TIME_STEP = 1.0 / 50.0f; float accumulator = 0.0f; while (gRunning) { common.getInputState(&inputState); if (inputState.isDown(Button::BUTTON_ESCAPE)) { gRunning = 0; } common.frame(); timer.tick(); g->clear(Color::Black, true); accumulator += timer.getDeltaSeconds(); while (accumulator >= TIME_STEP) { accumulator -= TIME_STEP; animationSystem.UpdateEmitter(TIME_STEP); } renderer->begin(Renderer2D::SPRITE_SORT_DEFERRED, Renderer2D::SPRITE_BLEND_ALPHA); animationSystem.RenderEmitter(renderer); rot += timer.getDeltaSeconds() * 0.1f; renderer->end(); g->present(); } animationSystem.FreeMem(); } }
void GameController::gameLoop() { wParams.mFullscreen = false; wParams.mHeight = screenHeight; wParams.mWidth = screenWidth; wParams.mTitle = "Project"; wParams.mPosX = 0; wParams.mPosY = 0; if (common.init(wParams)) { //Load all textures common.registerSoundResource("soundExplosion", "sound/explosion.ogg"); common.registerSoundResource("soundShoot", "sound/fire.ogg"); common.registerTextureResource("shoot", "image/spark.png"); common.registerTextureResource("plane", "image/plane.png"); common.registerTextureResource("explosion", "image/explosion.png"); common.registerTextureResource("asteroid1", "image/asteroid1.png"); common.registerTextureResource("asteroid2", "image/asteroid2.png"); common.registerTextureResource("asteroid3", "image/asteroid3.png"); common.registerTextureResource("asteroid4", "image/asteroid4.png"); common.registerTextureResource("asteroid5", "image/asteroid5.png"); common.registerTextureResource("asteroid6", "image/asteroid6.png"); common.registerTextureResource("background_menu", "image/space_background_menu.png"); common.registerTextureResource("background_after_game", "image/space_background_after_game.png"); common.registerTextureResource("health_package", "image/health_package.png"); common.registerFontResource("sans16", 16, "fonts/ARIAL.ttf"); common.registerFontResource("sans20", 20, "fonts/OpenSans-Regular.ttf"); common.registerFontResource("lobsterBold", 30, "fonts/LobsterTWo-Bold.otf"); EventManager em; common.setEventProcessor(&em); Graphics *g = common.getGraphics(); g->setViewport(0, 0, screenWidth, screenHeight); HiResTimer timer; timer.restart(); SetAsteroidType(currentLvl); Model::MenuModel menuModel; View::MenuView menuView(&common, &menuModel); menuModel.AddView(&menuView); int height, width; common.getGraphics()->getContextSize(&width, &height); menuModel.Init(Vec2(width, height)); Model::ManagerModel *managerModel = DBG_NEW Model::ManagerModel; View::ManagerView *managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); currentState = GAMESTATE_INMENU; while (gRunning) { timer.tick(); // Process OS events. common.frame(); if (timerEsc <= 0) { timerEsc = 0; } else { timerEsc -= timer.getDeltaSeconds(); } InputState input; common.getInputState(&input); if (input.isDown(Button::BUTTON_ESCAPE)) { if (timerEsc <= 0) { if (currentState == GAMESTATE_INGAME) { currentState = GAMESTATE_INMENU; } else { currentState = GAMESTATE_INGAME; } timerEsc = coolDownEsc; } } if (managerModel->WonRound() || managerModel->LostRound()) { if (timerResultScreen <= 0) { timerResultScreen = 0; } else { timerResultScreen -= timer.getDeltaSeconds(); } if (managerModel->LostRound()) { menuModel.ShowLostRound(); currentState = GAMESTATE_AFTER_GAME; timerDelayScreenForExplosion = timeElapsedForExplosion; } else { if (currentLvl >= 2) { menuModel.ShowWonGame(); currentState = GAMESTATE_AFTER_GAME; } else { menuModel.ShowWonRound(); currentState = GAMESTATE_AFTER_GAME; } } if (timerResultScreen == 0) { timerResultScreen = timeElapseResultScreen; if (currentLvl >= 2) { currentState = GAMESTATE_INMENU; } else { currentState = GAMESTATE_INGAME; //Start new game. } if (managerModel->WonRound()) { ++currentLvl; SetAsteroidType(currentLvl); } delete managerModel; delete managerView; managerModel = NULL; managerView = NULL; managerModel = DBG_NEW Model::ManagerModel; managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); } } if (currentState == GAMESTATE_INMENU) { //ShowCursor(TRUE); menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); if (menuModel.IsPaused() && isGameStarted) { currentState = GAMESTATE_INGAME; } else if (menuModel.IsNewGame()) { currentState = GAMESTATE_INGAME; currentLvl = 0; SetAsteroidType(currentLvl); delete managerModel; delete managerView; managerModel = NULL; managerView = NULL; managerModel = DBG_NEW Model::ManagerModel; managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); } g->clear(Color::Black, true); menuView.OnRenderMenu(); } else if (currentState == GAMESTATE_INGAME) { isGameStarted = true; //ShowCursor(FALSE); managerModel->OnUpdate(timer.getDeltaSeconds()); managerView->OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); managerView->OnRender(); } else if (currentState == GAMESTATE_AFTER_GAME) { timerDelayScreenForExplosion -= timer.getDeltaSeconds(); if (timerDelayScreenForExplosion <= 0) { menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); menuView.OnRenderAfterGame(); } else if (timerResultScreen > 0) { menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); menuView.OnRenderAfterGame(); } else { managerModel->OnUpdate(timer.getDeltaSeconds()); managerView->OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); managerView->OnRender(); } } g->present(); } } }
void GameController::gameLoop() { //set program scale. View::Camera camera; camera.scale = Vec2(1.f, 1.f); screenHeight *= camera.scale.y; screenWidth *= camera.scale.x; Vec2 boarder = Vec2((screenWidth / 2) - (boarderMargin * camera.scale.x), (screenHeight / 2) - (boarderMargin * camera.scale.y)); Vec2 origin = Vec2(screenWidth / 2, screenHeight / 2); wParams.mFullscreen = false; wParams.mHeight = screenHeight; wParams.mWidth = screenWidth; wParams.mTitle = "Laboration 3"; wParams.mPosX = 0; wParams.mPosY = 0; if (common.init(wParams)) { //Load all textures common.registerTextureResource("smoke", "image/particlesmoke.tga"); common.registerTextureResource("spark", "image/spark.png"); common.registerTextureResource("explosion", "image/explosion.png"); common.registerTextureResource("ball", "image/ball.png"); common.registerSoundResource("shoot", "sound/fire.wav"); EventManager em; common.setEventProcessor(&em); Graphics *g = common.getGraphics(); g->setViewport(0, 0, screenWidth, screenHeight); Renderer2D *renderer = g->createRenderer2D(); float rot = 0.0f; HiResTimer timer; timer.restart(); const float TIME_STEP = 1.0 / 60.0f; float accumulator = 0.0f; float accumulatorKeyPress = 0.0f; float oldAccumulatorKeyPress = 0.0f; while (gRunning) { common.getInputState(&inputState); if (inputState.isDown(Button::BUTTON_ESCAPE)) { gRunning = 0; } common.frame(); timer.tick(); g->clear(Color::White, true); accumulator += timer.getDeltaSeconds(); //setting timer for key pressing. accumulatorKeyPress += timer.getDeltaSeconds(); //Identify key press. if (accumulatorKeyPress - oldAccumulatorKeyPress > .5f) { if (inputState.isDown(Button::BUTTON_MOUSELEFT)) { oldAccumulatorKeyPress = accumulatorKeyPress; splitter.push_back(new View::SplitterSystem(common, camera.scale, Vec2(screenWidth, screenHeight), Vec2(inputState.mMouseX, inputState.mMouseY))); smoke.push_back(new View::SmokeSystem(common, camera.scale, Vec2(screenWidth, screenHeight), Vec2(inputState.mMouseX, inputState.mMouseY))); common.getAudio(); } } while (accumulator >= TIME_STEP) { accumulator -= TIME_STEP; for (int i = 0; i != splitter.size(); ++i) { splitter[i]->UpdateEmitter(TIME_STEP); smoke[i]->UpdateEmitter(TIME_STEP); } } renderer->begin(Renderer2D::SPRITE_SORT_DEFERRED, Renderer2D::SPRITE_BLEND_ALPHA); for (int i = 0; i != splitter.size(); ++i) { splitter[i]->RenderEmitter(renderer); smoke[i]->RenderEmitter(renderer); } rot += timer.getDeltaSeconds() * 0.1f; renderer->end(); g->present(); } } }