PlayerWin *PlayerWin::createWithHwnd(HWND hWnd) { auto instance = new PlayerWin(); instance->_hwnd = hWnd; instance->initServices(); return instance; }
void peano::applications::latticeboltzmann::blocklatticeboltzmann::cca::BlockLatticeBoltzmannBatchJobForRegularGridImplementation::configure(){ std::string configFile = "/home_shared/atanasoa_workspace/PorousMedia.xml"; std::list<tarch::configuration::TopLevelConfiguration*> configurations = tarch::configuration::ConfigurationRegistry::getInstance().readFile( configFile, "peano-configuration" ); if (configurations.empty()) { } std::cout<<"configured"<<std::endl; peano::applications::latticeboltzmann::blocklatticeboltzmann::configurations::BlockLatticeBoltzmannBatchJobConfigurationForRegularGrid* configuration=NULL; int executedRuns = 0; for ( std::list<tarch::configuration::TopLevelConfiguration*>::iterator p = configurations.begin(); (p != configurations.end()) ; p++ ) { (*p)->interpreteConfiguration(); if(dynamic_cast<peano::applications::latticeboltzmann::blocklatticeboltzmann::configurations::BlockLatticeBoltzmannBatchJobConfigurationForRegularGrid*>(*p)!=NULL) configuration=(( peano::applications::latticeboltzmann::blocklatticeboltzmann::configurations::BlockLatticeBoltzmannBatchJobConfigurationForRegularGrid*)(*p)); assertion( configuration->isValid() ); } // configure multicore support #if defined(SharedTBB) tarch::multicore::tbb::Core::getInstance().configure( configuration->getCoreConfiguration().getNumberOfThreads() ); #endif // ----- adapt domain size, domain offset and number of RegularGridVertices for RegularGrid construction ------ // number of blocks (=RegularGridVertices,initialised with the total number of LB cells; // blocks will be computed in next loop!) tarch::la::Vector<DIMENSIONS,int> blocks = configuration->getRegularGridConfiguration().getNumberOfGridPoints(); // domain size (is to be modified for grid construction!) tarch::la::Vector<DIMENSIONS,double> domainSize = configuration->getRegularGridConfiguration().getDomainSize(); // domain offset (is to be modified for grid construction!) tarch::la::Vector<DIMENSIONS,double> domainOffset = configuration->getRegularGridConfiguration().getDomainOffset(); for (int d = 0; d < DIMENSIONS; d++){ // determine how many cells have to be put at the end of the domain and which do not fill a whole block int additionalCellsInLastBlock = blocks(d) % LB_BLOCKSIZE; // number of peano vertices=LB blocks is the number of cells / LB_BLOCKSIZE +1. The +1 comes from the fact, // that the center of the first peano vertex is put at the first corner of the domain. So, we need one more vertex // at the end of the domain. blocks(d) = blocks(d)/LB_BLOCKSIZE + 1; // if we have some cells that do not fill a whole block, we need one more block... if (additionalCellsInLastBlock != 0){ blocks(d) += 1; } // set domain size accordingly domainSize(d) = configuration->getLatticeBoltzmannConfiguration().getDx()*(blocks(d)-1)*LB_BLOCKSIZE; } logDebug("run()", "Total number of blocks (incl. boundary blocks): " << blocks); logDebug("run()", "Domain size for grid construction: " << domainSize << ", respective grid construction offset: " << domainOffset); // ----- adapt domain size, domain offset and number of RegularGridVertices for RegularGrid construction (end) ------ // ----------------- initialise services -------------------------------------------- initServices(*configuration); // hexahedron fitting the domain size. This is used for the regular-grid geometry. However, // THE REAL GEOMETRY is used throughout the LB simulation! peano::geometry::builtin::Hexahedron *hexahedron = new peano::geometry::builtin::Hexahedron(false,domainSize,domainOffset); _repository = peano::applications::latticeboltzmann::blocklatticeboltzmann::repositories::BlockLatticeBoltzmannBatchJobRepositoryFactory::getInstance().createRegularGridStandardImplementation( // use enlarged grid for grid setup *hexahedron, // add another boundary layer of vertices around the domain blocks, // correction for additional boundary layer domainSize, // shift of offset for additional boundary layer domainOffset ); std::cout<<"configured"<<std::endl; configuration->initState(_repository->getRegularGridState()); }
int SimulatorWin::run() { auto player = player::PlayerWin::create(); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); parseCocosProjectConfig(_project); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() == 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); _project.setDebuggerType(kCCRuntimeDebuggerCodeIDE); } } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setDefaultResourceRootPath(_project.getProjectDir()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; if (dpi >= 120 && dpi < 144) { screenScale = 1.25f; } else if (dpi >= 144 && dpi < 192) { screenScale = 1.5f; } else if (dpi >= 192) { screenScale = 2.0f; } CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); std::stringstream title; title << "Cocos Simulator - " << ConfigParser::getInstance()->getInitViewName(); initGLContextAttrs(); auto glview = GLViewImpl::createWithRect(title.str(), frameRect, frameScale); _hwnd = glview->getWin32Window(); DragAcceptFiles(_hwnd, TRUE); //SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); //SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); //FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); director->setAnimationInterval(1.0 / 60.0); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // path for looking Lang file, Studio Default images FileUtils::getInstance()->addSearchPath(getApplicationPath().c_str()); // init player services initServices(); setupUI(); DrawMenuBar(_hwnd); // prepare FileUtils::getInstance()->setPopupNotify(false); _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::windowProc); // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); // startup message loop return app->run(); }
int PlayerWin::run() { FileUtils::getInstance()->setPopupNotify(false); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // set QUICK_V3_ROOT const char *QUICK_V3_ROOT = getenv("QUICK_V3_ROOT"); if (!QUICK_V3_ROOT || strlen(QUICK_V3_ROOT) == 0) { MessageBox("Please run \"setup_win.bat\", set Quick-Cocos2dx-Community root path.", "Quick-Cocos2dx-Community player error"); return 1; } _project.setQuickCocos2dxRootPath(QUICK_V3_ROOT); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() >= 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); } else { _project.resetToWelcome(); } } // set framework path if (!_project.isLoadPrecompiledFramework()) { FileUtils::getInstance()->addSearchPath(_project.getQuickCocos2dxRootPath() + "quick/"); } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // set window icon HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAYER)); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { SendMessage(_hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwndConsole, WM_SETICON, ICON_SMALL, (LPARAM)icon); ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setSearchRootPath(_project.getProjectDir().c_str()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; //if (dpi >= 120 && dpi < 144) //{ // screenScale = 1.25f; //} //else if (dpi >= 144 && dpi < 192) //{ // screenScale = 1.5f; //} //else if (dpi >= 192) //{ // screenScale = 2.0f; //} CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; GLView::setGLContextAttrs(glContextAttrs); //auto glview = GLView::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale, isResize, false, true); auto glview = GLViewImpl::createWithRect("Quick-Cocos2dx-Community", frameRect, frameScale); _hwnd = glview->getWin32Window(); SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // init player services initServices(); loadLuaConfig(); registerKeyboardEvent(); // register event handlers auto eventDispatcher = director->getEventDispatcher(); eventDispatcher->addCustomEventListener("APP.WINDOW_CLOSE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowClose, this)); eventDispatcher->addCustomEventListener("APP.WINDOW_RESIZE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowResize, this)); eventDispatcher->addCustomEventListener("APP.VIEW_SCALE", CC_CALLBACK_1(PlayerWin::onWindowScale, this)); // prepare _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)PlayerWin::windowProc); HWND hwnd = _hwnd; HWND hwndConsole = _hwndConsole; const ProjectConfig &project = _project; director->getScheduler()->schedule([hwnd, hwndConsole, project](float dt) { CC_UNUSED_PARAM(dt); ShowWindow(hwnd, SW_RESTORE); auto glview = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView()); GLFWwindow *window = glview->getWindow(); glfwShowWindow(window); }, this, 0.0f, 0, 0.001f, false, "SHOW_WINDOW_CALLBACK"); if (project.isAppMenu() && GetMenu(hwnd)) { // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); } ShowWindow(_hwnd, SW_MINIMIZE); // startup message loop return app->run(); }
int main(int argc, char *argv[]) { // char filename[]="/test400x240-mpeg4-witch.mp4"; // char filename[]="/test400x240-witch.mp4"; // char filename[]="/test800x400-witch-900kbps.mp4"; // char filename[]="/test800x400-witch-1pass.mp4"; // char filename[]="/test800x400-witch.mp4"; // char filename[]="/test800x480-witch-mpeg4.mp4"; // char filename[]="/test320x176-karanokyoukai.mp4"; char filename[] = "/test.mp4"; MovieState mvS; initServices(); // Register all formats and codecs av_register_all(); av_log_set_level(AV_LOG_INFO); printf("Press start to open the file\n"); waitForStart(); int ret = setup(&mvS, filename); if (ret) { waitForStartAndExit(); return -1; } printf("Press start to decompress\n"); waitForStart(); // Read frames and save first five frames to disk int i = 0; int frameFinished; u64 timeBeginning, timeEnd; u64 timeBefore, timeAfter; u64 timeDecodeTotal = 0, timeScaleTotal = 0, timeDisplayTotal = 0; timeBefore = osGetTime(); timeBeginning = timeBefore; bool stop = false; while (av_read_frame(mvS.pFormatCtx, &mvS.packet) >= 0 && !stop) { // Is this a packet from the video stream? if (mvS.packet.stream_index == mvS.videoStream) { /********************* * Decode video frame *********************/ int err = avcodec_decode_video2(mvS.pCodecCtx, mvS.pFrame, &frameFinished, &mvS.packet); if (err <= 0)printf("decode error\n"); // Did we get a video frame? if (frameFinished) { err = av_frame_get_decode_error_flags(mvS.pFrame); if (err) { char buf[100]; av_strerror(err, buf, 100); } timeAfter = osGetTime(); timeDecodeTotal += timeAfter - timeBefore; /******************************* * Conversion of decoded frame *******************************/ timeBefore = osGetTime(); colorConvert(&mvS); timeAfter = osGetTime(); /*********************** * Display of the frame ***********************/ timeScaleTotal += timeAfter - timeBefore; timeBefore = osGetTime(); if (mvS.renderGpu) { gpuRenderFrame(&mvS); gpuEndFrame(); } else display(mvS.outFrame); timeAfter = osGetTime(); timeDisplayTotal += timeAfter - timeBefore; ++i;//New frame hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) stop = true; // break in order to return to hbmenu if (i % 50 == 0)printf("frame %d\n", i); timeBefore = osGetTime(); } } // Free the packet that was allocated by av_read_frame av_free_packet(&mvS.packet); } timeEnd = timeBefore; tearup(&mvS); printf("Played %d frames in %f s (%f fps)\n", i, (timeEnd - timeBeginning) / 1000.0, i / ((timeEnd - timeBeginning) / 1000.0)); printf("\tdecode:\t%llu\t%f perframe" "\n\tscale:\t%llu\t%f perframe" "\n\tdisplay:\t%llu\t%f perframe\n", timeDecodeTotal, timeDecodeTotal / (double) i, timeScaleTotal, timeScaleTotal / (double) i, timeDisplayTotal, timeDisplayTotal / (double) i); waitForStartAndExit(); return 0; }