示例#1
0
int CCApplication::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    MSG msg;
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nLast;
    LARGE_INTEGER nNow;

    QueryPerformanceFrequency(&nFreq);
    QueryPerformanceCounter(&nLast);

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView();
    pMainWnd->centerWindow();
    ShowWindow(pMainWnd->getHWnd(), SW_SHOW);

    while (1)
    {
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // Get current time tick.
            QueryPerformanceCounter(&nNow);

            // If it's the time to draw next frame, draw it, else sleep a while.
            if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
            {
                nLast.QuadPart = nNow.QuadPart;
                CCDirector::sharedDirector()->mainLoop();
            }
            else
            {
                Sleep(0);
            }
            continue;
        }

        if (WM_QUIT == msg.message)
        {
            // Quit message loop.
            break;
        }

        // Deal with windows message.
        if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}
int CCApplication::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    MSG msg;
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nStart;
    LARGE_INTEGER nEnd;
    LONGLONG deltaQuadPart;
    DOUBLE sleepTime = 0;

    QueryPerformanceFrequency(&nFreq);

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView();
    ShowWindow(pMainWnd->getHWnd(), SW_SHOW);

    while (1)
    {
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            QueryPerformanceCounter(&nStart);
            CCDirector::sharedDirector()->mainLoop();
            QueryPerformanceCounter(&nEnd);

            deltaQuadPart = m_nAnimationInterval.QuadPart - (nEnd.QuadPart - nStart.QuadPart);
            if (deltaQuadPart > 0)
            {
                sleepTime += 1000.0 * deltaQuadPart / nFreq.QuadPart;
                Sleep((int)sleepTime);
                sleepTime -= (int)sleepTime;
            }
            continue;
        }

        if (WM_QUIT == msg.message)
        {
            // Quit message loop.
            break;
        }

        // Deal with windows message.
        if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}
示例#3
0
文件: main.cpp 项目: lovoror/Dorothy
int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR lpCmdLine,
	int nCmdShow)
{
#ifdef _DEBUG
	AllocConsole();
	freopen("CONIN$", "r", stdin);
	freopen("CONOUT$", "w", stdout);
	freopen("CONOUT$", "w", stderr);
#endif
	if (lpCmdLine && lpCmdLine[0])
	{
		string filename = lpCmdLine;
		filename.erase(std::remove(filename.begin(),filename.end(),'\"'),filename.end());
		CCUserDefault::sharedUserDefault()->setStringForKey("ScriptEntry", filename.c_str());
	}

	// create the application instance
	AppDelegate app;
	CCEGLView* eglView = CCEGLView::sharedOpenGLView();
	eglView->setViewName("Dorothy");

	SetClassLong(eglView->getHWnd(), GCL_HICON, (long)LoadIcon(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)));
	int width = CCUserDefault::sharedUserDefault()->getIntegerForKey("Width");
	int height = CCUserDefault::sharedUserDefault()->getIntegerForKey("Height");
	if (width == 0 || height == 0)
	{
		width = 800;
		height = 600;
		CCUserDefault::sharedUserDefault()->setIntegerForKey("Width", width);
		CCUserDefault::sharedUserDefault()->setIntegerForKey("Height", height);
	}

	eglView->setFrameSize(CCSize(width, height));

	int ret = CCApplication::sharedApplication()->run();
#if defined(_DEBUG)
	FreeConsole();
#endif
	return ret;
}
示例#4
0
int UiPlayer::run(void)
{
    const char *QUICK_COCOS2DX_ROOT = getenv("QUICK_COCOS2DX_ROOT");
    SimulatorConfig::sharedDefaults()->setQuickCocos2dxRootPath(QUICK_COCOS2DX_ROOT);

    loadProjectConfig();

    HWND hwndConsole = NULL;
    if (m_project.isShowConsole())
    {
        AllocConsole();
        freopen("CONOUT$", "wt", stdout);
        freopen("CONOUT$", "wt", stderr);

        // disable close console
        hwndConsole = GetConsoleWindow();
        if (hwndConsole != NULL)
        {
            HMENU hMenu = GetSystemMenu(hwndConsole, FALSE);
            if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);

            ShowWindow(hwndConsole, SW_SHOW);
            BringWindowToTop(hwndConsole);
        }
    }

    if (m_project.isWriteDebugLogToFile())
    {
        const string debugLogFilePath = m_project.getDebugLogFilePath();
        m_writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w");
        if (!m_writeDebugLogFile)
        {
            CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str());
        }
    }

    do
    {
        m_exit = TRUE;

        // create the application instance
        m_app = new AppDelegate();
        m_app->setProjectConfig(m_project);

        // set environments
        SetCurrentDirectoryA(m_project.getProjectDir().c_str());
        CCFileUtils::sharedFileUtils()->setSearchRootPath(m_project.getProjectDir().c_str());
        CCFileUtils::sharedFileUtils()->setWritablePath(m_project.getWritableRealPath().c_str());

        // create opengl view
        CCEGLView* eglView = CCEGLView::sharedOpenGLView();
        eglView->setMenuResource(MAKEINTRESOURCE(IDC_LUAHOSTWIN32));
        eglView->setWndProc(WindowProc);
        eglView->setFrameSize(m_project.getFrameSize().width, m_project.getFrameSize().height);
        eglView->setFrameZoomFactor(m_project.getFrameScale());

        // make window actived
        m_hwnd = eglView->getHWnd();
        BringWindowToTop(m_hwnd);
        SetWindowTextA(m_hwnd, "ui-player");

        // restore window position
        const CCPoint windowOffset = m_project.getWindowOffset();
        if (windowOffset.x != 0 || windowOffset.y != 0)
        {
            eglView->moveWindow(windowOffset.x, windowOffset.y);
        }

        // set icon
        HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUAHOSTWIN32));
        SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon);

        if (hwndConsole)
        {
            SendMessage(hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon);
        }

        // update menu
        createViewMenu();
        updateMenu();

        // run game
        CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack();
        const vector<string> arr = m_project.getPackagePathArray();
        for (vector<string>::const_iterator it = arr.begin(); it != arr.end(); ++it)
        {
            stack->addSearchPath(it->c_str());
        }

        m_app->run();

        // cleanup
        CCScriptEngineManager::sharedManager()->removeScriptEngine();
        CCScriptEngineManager::purgeSharedManager();
        CocosDenshion::SimpleAudioEngine::end();

        delete m_app;
        m_app = NULL;
    } while (!m_exit);

    FreeConsole();
    if (m_writeDebugLogFile) fclose(m_writeDebugLogFile);
    return 0;
}
示例#5
0
int LuaHostWin32::run(void)
{
    loadProjectConfig();

    AllocConsole();
    freopen("CONOUT$", "wt", stdout);
    freopen("CONOUT$", "wt", stderr);

    // disable close console
    HWND hwndConsole = GetConsoleWindow();
    if (hwndConsole != NULL)
    {
        HMENU hMenu = GetSystemMenu(hwndConsole, FALSE);
        if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
    }

    do
    {
        m_exit = TRUE;

        if (m_project.isShowConsole())
        {
            ShowWindow(hwndConsole, SW_SHOW);
            BringWindowToTop(hwndConsole);
        }
        else
        {
            ShowWindow(hwndConsole, SW_HIDE);
        }

        // create the application instance
        m_app = new AppDelegate();
        m_app->setStartupScriptFilename(m_project.getScriptFilePath());

        // set environments
        SetCurrentDirectoryA(m_project.getProjectDir().c_str());
        vector<string> searchPaths;
        searchPaths.push_back(m_project.getProjectDir());
        CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);

        // create opengl view
        CCEGLView* eglView = CCEGLView::sharedOpenGLView();    
        eglView->setMenuResource(MAKEINTRESOURCE(IDC_LUAHOSTWIN32));
        eglView->setWndProc(WindowProc);
        eglView->setFrameSize(m_project.getFrameSize().width, m_project.getFrameSize().height);
        eglView->setFrameZoomFactor(m_project.getFrameScale());

        // make window actived
        m_hwnd = eglView->getHWnd();
        BringWindowToTop(m_hwnd);

        // restore window position
        const CCPoint windowOffset = m_project.getWindowOffset();
        if (windowOffset.x >= 0 || windowOffset.y >= 0)
        {
            eglView->moveWindow(windowOffset.x, windowOffset.y);
        }

        // set icon
        HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUAHOSTWIN32));
        SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
        SendMessage(hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon);

        // run game
        CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack();
        const vector<string> arr = m_project.getPackagePathArray();
        for (vector<string>::const_iterator it = arr.begin(); it != arr.end(); ++it)
        {
            stack->addSearchPath(it->c_str());
        }

        m_app->run();

        // cleanup
        CCScriptEngineManager::sharedManager()->removeScriptEngine();
        CCScriptEngineManager::purgeSharedManager();
        CocosDenshion::SimpleAudioEngine::end();

        delete m_app;
        m_app = NULL;
    } while (!m_exit);

    FreeConsole();
    return 0;
}
示例#6
0
//--------------------------------------------------------------------
int CFKCocos2dxAppWrapper::Run()
{
	bool bRet = 0;

	// first ,load project config
	LoadProjectConfig();

	// create consle
	HWND hwndConsole = NULL;
	if (m_tagAppConfig.IsShowConsole())
	{
		AllocConsole();
		freopen("CONOUT$", "wt", stdout);
		freopen("CONOUT$", "wt", stderr);

		// disable close console
		hwndConsole = GetConsoleWindow();
		if (hwndConsole != NULL)
		{
			HMENU hMenu = GetSystemMenu(hwndConsole, FALSE);
			if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);

			ShowWindow(hwndConsole, SW_SHOW);
			BringWindowToTop(hwndConsole);
		}
	}

	// create log file
	if (m_tagAppConfig.IsWriteDebugLogToFile())
	{
		const string debugLogFilePath = m_tagAppConfig.GetDebugLogFilePath();
		m_pWriteDebugLogFile = fopen(debugLogFilePath.c_str(), "w");
		if ( m_pWriteDebugLogFile == NULL )
		{
			FKLOG("Cannot create debug log file %s", debugLogFilePath.c_str());
		}
	}

	// MainLoop
	do
	{
		m_bIsExit = TRUE;

		// create app
		m_pApp = new AppDelegate();
		if( m_pApp == NULL )
		{
			bRet = false;
			break;
		}

		// set some environments
		m_pApp->SetProjectConfig( m_tagAppConfig );
		CCFileUtils::sharedFileUtils()->addSearchPath( m_tagAppConfig.GetProjectDir().c_str() );

		// create openGL view
		CCEGLView* eglView = CCEGLView::sharedOpenGLView();
		eglView->setMenuResource(MAKEINTRESOURCE(IDC_LUAHOSTWIN32));
		eglView->setWndProc (WindowProc );
		eglView->setFrameSize( m_tagAppConfig.GetFrameSize().width, m_tagAppConfig.GetFrameSize().height );
		eglView->setFrameZoomFactor( m_tagAppConfig.GetFrameScale() );

		// set window actived
		m_hWnd = eglView->getHWnd();
		BringWindowToTop(m_hWnd);
		SetWindowTextA(m_hWnd, "FKCocos2dxAppWrapper Project");

		// center window position
		eglView->centerWindow();

		// set icon
		HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUAHOSTWIN32));
		SendMessage( m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
		if (hwndConsole)
		{
			SendMessage(hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon);
		}

		// set menu
		CreateViewMenu();
		UpdateViewMenu();

		// run games 
		m_pApp->run();

		// clean up
		CocosDenshion::SimpleAudioEngine::end();

		delete m_pApp;
		m_pApp = NULL;

	}while( !m_bIsExit );

	// ready exit
	FreeConsole();
	if( m_pWriteDebugLogFile != NULL )
	{
		fclose(m_pWriteDebugLogFile);
	}

	return bRet;
}