Example #1
0
int main(int argc, char** argv)
{
    QString fPath = QString(argv[0]);
    appName = fPath.mid( fPath.findRev("/") +1 );
    appPath = fPath.left( fPath.findRev("/") );

    DBG_OUT("App Name : %s", appName.ascii() );
    DBG_OUT("App Path : %s", appPath.ascii() );

    checkDirectories();
    APPDB_Open();

	ZApplication* app = new ZApplication(argc, argv);

    FullPath_7z = APP_FULLPATH_7Z;

    if ( !detectLanguageFile(appPath) )
    {
        detectLanguageFile( APP_SYSFILES_PATH );
    }

    if ( !LoadCustomizationFile(appPath) )
    {
        LoadCustomizationFile( APP_SYSFILES_PATH );
    }

    srand( (int)getpid() );

    if (argc>1)
    {
        if ( checkParameters(argc,argv) )
        {
            delete app;
            return 0;
        }
    }

    // LoadAllRegisteredApp();

    DBG_OUT("Register Load DONE");

	zBaseGUI *gui = new zBaseGUI(NULL);
//    DBG_OUT("GUI Done (gui = %Xl , app = %Xl )", (uint)gui, (uint)app);
	app->setMainWidget(gui);
//	DBG_OUT("Set Main");
        gui->show();

	int ret=app->exec();
//int ret=0;
	delete gui;
	delete app;

    APPDB_Close();
	return ret;
}
int main( int argc, char **argv )
{
        ZApplication* a = new ZApplication( argc, argv );
        testWidget = new TestWidget(NULL, NULL);
        testWidget->setGeometry(0,0,240,320);
	a->setMainWidget(testWidget);
	testWidget->show();
	int ret = a->exec();
        delete testWidget;
	delete a;
	return ret;
}
RRESULT OnRender(void *pParam)
{
	__BP(101, "main::OnRender");
	if( !RIsActive() && RIsFullScreen() )
	{
		__EP(101);
		return R_NOTREADY;
	}

	g_App.OnDraw();


#ifdef _SMOOTHLOOP
	Sleep(10);
#endif

#ifndef _PUBLISH

	if(g_pDefFont) {
		static char __buffer[256];

		float fMs = 1000.f/g_fFPS;
		float fScore = 100-(fMs-(1000.f/60.f))*2;

		sprintf(__buffer, "GAME_STATE: %d  FPS : %3.3f %.3f점 (%.3f ms)", ZGetGameInterface()->GetState(),g_fFPS,fScore,fMs);
		g_pDefFont->m_Font.DrawText( CCGetWorkspaceWidth()-400,0,__buffer );
//		OutputDebugString(__buffer);
	}

#endif

	__EP(101);

	return R_OK;
}
RRESULT OnDestroy(void *pParam)
{
	cclog("Destroy gunz\n");

	g_App.OnDestroy();

	SAFE_DELETE(g_pDefFont); 

	g_Core.Finalize();

	cclog("interface finalize.\n");

	SAFE_DELETE(g_pInput);
	g_DInput.Destroy();

	cclog("game input destroy.\n");

//	RGetShaderMgr()->Release();

	ZGetConfiguration()->Destroy();

	cclog("game gonfiguration destroy.\n");

	delete g_pDC;

	struct _finddata_t c_file;
	intptr_t hFile;
	char szFileName[256];
#define FONT_DIR	"Font/"
#define FONT_EXT	"ttf"
	if( (hFile = _findfirst(FONT_DIR"*."FONT_EXT, &c_file )) != -1L ){
		do{
			strcpy(szFileName, FONT_DIR);
			strcat(szFileName, c_file.name);
			RemoveFontResource(szFileName);
		}while( _findnext( hFile, &c_file ) == 0 );
		_findclose(hFile);
	}

	CCFontManager::Destroy();
	CCBitmapManager::Destroy();
	CCBitmapManager::DestroyAniBitmap();

	cclog("Bitmap manager destroy Animation bitmap.\n");


//	ZBasicInfoItem::Release(); 
//	ZGetStencilLight()->Destroy();
//	LightSource::Release();
	RBspObject::DestroyShadeMap();
	RDestroyLenzFlare();
	RAnimationFileMgr::GetInstance()->Destroy();
	ZStringResManager::ResetInstance();
	cclog("destroy gunz finish.\n");

	return R_OK;
}
RRESULT OnRestore(void *pParam)
{
	for(int i=0; i<CCBitmapManager::GetCount(); i++){
		CCBitmapR2* pBitmap = (CCBitmapR2*)CCBitmapManager::Get(i);
		pBitmap->OnLostDevice();
	}

	g_App.OnRestore();

	return R_OK;
}
RRESULT OnUpdate(void* pParam)
{
	__BP(100, "main::OnUpdate");

	g_pInput->Update();
	g_App.OnUpdate();

	const DWORD dwCurrUpdateTime = timeGetTime();
	__EP(100);

	return R_OK;
} 
RRESULT OnCreate(void *pParam)
{
	/*
	//	Walk through in debug to trace all routes
	*/
	g_App.PreCheckArguments();

	sprintf( cstrReleaseDate, "Version : %s", ZGetSVNRevision().c_str()); //Possibly
	cclog(cstrReleaseDate); cclog("\n");

	g_DInput.Create(g_hWnd, FALSE, FALSE);
	g_pInput = new ZInput(&g_DInput);
	RSetGammaRamp(Z_VIDEO_GAMMA_VALUE);
	RSetRenderFlags(RRENDER_CLEAR_BACKBUFFER);

	ZGetInitialLoading()->Initialize(  1, 0, 0, RGetScreenWidth(), RGetScreenHeight(), 0, 0, 1024, 768 );

	cclog("InitialLoading success.\n");

	struct _finddata_t c_file;
	intptr_t hFile;
	char szFileName[256];
	#define FONT_DIR	"Font/"
	#define FONT_EXT	"ttf"
	if( (hFile = _findfirst(FONT_DIR"*."FONT_EXT, &c_file )) != -1L ){
		do{
			strcpy(szFileName, FONT_DIR);
			strcat(szFileName, c_file.name);
			AddFontResource(szFileName);
		}while( _findnext( hFile, &c_file ) == 0 );
		_findclose(hFile);
	}

	g_pDefFont = new CCFontR2;

	if( !g_pDefFont->Create("Default", Z_LOCALE_DEFAULT_FONT, DEFAULT_FONT_HEIGHT, 1.0f) )	{
		cclog("Fail to Create default font : CCFontR2 / main.cpp.. onCreate\n" );
		g_pDefFont->Destroy();
		SAFE_DELETE( g_pDefFont );
		g_pDefFont	= NULL;
	}
	g_pDC = new CCDrawContextR2(RGetDevice());

	if( ZGetInitialLoading()->IsUseEnable() )
	{
		ZGetInitialLoading()->AddBitmap( 0, "Interface/Default/LOADING/loading_adult.jpg" );
		ZGetInitialLoading()->AddBitmapBar( "Interface/Default/LOADING/loading.bmp" );
		ZGetInitialLoading()->SetText( g_pDefFont, 5, 5, cstrReleaseDate );
		ZGetInitialLoading()->AddBitmapGrade( "Interface/Default/LOADING/loading_grade_fifteen.jpg" );
		ZGetInitialLoading()->SetPercentage( 0.0f );
		ZGetInitialLoading()->Draw( MODE_FADEIN, 0 , true );
	}


	g_Core.Initialize(800, 600, g_pDC, g_pDefFont);
	Core::GetInstance()->SetHWND(RealSpace2::g_hWnd);

	cclog("interface Initialize success\n");

	ZLoadingProgress appLoading("application");
	if(!g_App.OnCreate(&appLoading))
	{
		ZGetInitialLoading()->Release();
		return R_ERROR_LOADING;
	}

	ZGetSoundEngine()->SetEffectVolume(Z_AUDIO_EFFECT_VOLUME);
	ZGetSoundEngine()->SetMusicVolume(Z_AUDIO_BGM_VOLUME);
	ZGetSoundEngine()->SetEffectMute(Z_AUDIO_EFFECT_MUTE);
	ZGetSoundEngine()->SetMusicMute(Z_AUDIO_BGM_MUTE);

	g_Core.SetWorkspaceSize(g_ModeParams.nWidth, g_ModeParams.nHeight);
	g_Core.GetMainFrame()->SetSize(g_ModeParams.nWidth, g_ModeParams.nHeight);
	ZGetOptionInterface()->Resize(g_ModeParams.nWidth, g_ModeParams.nHeight);

	// Default Key
	for(int i=0; i<ZACTION_COUNT; i++){
		ZACTIONKEYDESCRIPTION& keyDesc = ZGetConfiguration()->GetKeyboard()->ActionKeys[i];
		g_pInput->RegisterActionKey(i, keyDesc.nVirtualKey);
		if(keyDesc.nVirtualKeyAlt!=-1)
			g_pInput->RegisterActionKey(i, keyDesc.nVirtualKeyAlt);
	}

	g_App.SetInitialState();

//	ParseParameter(g_szCmdLine);

//	ZGetFlashBangEffect()->SetDrawCopyScreen(true);

	static const char *szDone = "Done.";
	ZGetInitialLoading()->SetLoadingStr(szDone);
	if( ZGetInitialLoading()->IsUseEnable() )
	{
#ifndef _FASTDEBUG
		ZGetInitialLoading()->SetPercentage( 100.f );
		ZGetInitialLoading()->Draw( MODE_FADEOUT, 0 ,true  );
#endif
		ZGetInitialLoading()->Release();
	}

	cclog("main : OnCreate() done\n");

	SetFocus(g_hWnd);

	return R_OK;
}
// STEP1
int WINAPI WinMain(HINSTANCE this_inst, HINSTANCE prev_inst, LPSTR cmdline, int cmdshow)
{
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	InitLog(CCLOGSTYLE_DEBUGSTRING|CCLOGSTYLE_FILE);
	g_dwMainThreadID= GetCurrentThreadId();
	

	char szModuleFileName[_MAX_DIR] = {0,};
	GetModuleFileName(NULL, szModuleFileName, _MAX_DIR);
	PathRemoveFileSpec(szModuleFileName);
	SetCurrentDirectory(szModuleFileName);
	cclog("-------------------------------------------------------------\n");
	cclog("Current working directory: %s\n", szModuleFileName);
	cclog("-------------------------------------------------------------\n");
	srand( (unsigned)time( NULL ));
	cclog("GUNZ " STRFILEVER " launched. build ("__DATE__" "__TIME__") \n");
	char szDateRun[128]="";
	char szTimeRun[128]="";
	_strdate( szDateRun );
	_strtime( szTimeRun );
	cclog("Log time (%s %s)\n", szDateRun, szTimeRun);
	CCSysInfoLog();

	g_App.InitFileSystem();
	ZGetConfiguration()->Load();

	ZStringResManager::MakeInstance();
	if( !ZApplication::GetInstance()->InitLocale() )
	{
		CCLog("Locale Init error !!!\n");
		return false;
	}

	DWORD ver_major = 0;
	DWORD ver_minor = 0;
	TCHAR ver_letter = ' ';



	if(CheckFont()==false) {
		CCLog("CheckFont() failed.\n");
		return 0;
	}

	RSetFunction(RF_CREATE	,	OnCreate);
	RSetFunction(RF_RENDER	,	OnRender);
	RSetFunction(RF_UPDATE	,	OnUpdate);
	RSetFunction(RF_DESTROY ,	OnDestroy);
	RSetFunction(RF_INVALIDATE,	OnInvalidate);
	RSetFunction(RF_RESTORE,	OnRestore);
	RSetFunction(RF_ACTIVATE,	OnActivate);
	RSetFunction(RF_DEACTIVATE,	OnDeActivate);
	RSetFunction(RF_ERROR,		OnError);

	SetModeParams();

//	STEP2	
	cclog("Entering RMain()\n");
	const int nRMainReturn = RMain(APPLICATION_NAME,this_inst,prev_inst,cmdline,cmdshow,&g_ModeParams,WndProc,IDI_ICON1);
	if( 0 != nRMainReturn )
		return nRMainReturn;


	if( 0 != RInitD3D(&g_ModeParams) )
	{
		MessageBox(g_hWnd, "fail to initialize DirectX", NULL, MB_OK);
		cclog( "error init RInitD3D\n" );
		return 0;
	}
	cclog("Entering RRun()\n");
	const int nRRunReturn = RRun();
	ShowWindow(g_hWnd, SW_MINIMIZE);

	cclog("========================== DONE ===============================\n");

	ZStringResManager::FreeInstance();
	return 0;//nRRunReturn;
	}
RRESULT OnInvalidate(void *pParam)
{
	CCBitmapR2::m_dwStateBlock=NULL;
	g_App.OnInvalidate();
	return R_OK;
}