예제 #1
0
int main(int argc, char *argv[])
{
	float td;
	long then, lastFrameTime, frames;
	long expireTextTimer;
	SDL_Event event;
	
	memset(&app, 0, sizeof(App));
	memset(&dev, 0, sizeof(Dev));
	
	handleLoggingArgs(argc, argv);
	
	atexit(cleanup);

	srand(time(NULL));
	
	init18N(argc, argv);
	
	initLookups();

	initSDL();
	
	initGameSystem();
	
	createScreenshotFolder();
	
	if (fileExists(getSaveFilePath(SAVE_FILENAME)))
	{
		loadGame();
	}
	
	handleMissionArgs(argc, argv);
	
	dev.fps = frames = td = 0;
	then = SDL_GetTicks();
	lastFrameTime = SDL_GetTicks() + 1000;
	expireTextTimer = SDL_GetTicks() + (1000 * 10);
	
	while (1)
	{
		td += (SDL_GetTicks() - then);
		
		then = SDL_GetTicks();
		
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_MOUSEMOTION:
					doMouseMotion(&event.motion);
					break;
				
				case SDL_MOUSEWHEEL:
					doMouseWheel(&event.wheel);
					break;
				
				case SDL_MOUSEBUTTONDOWN:
					doMouseDown(&event.button);
					break;

				case SDL_MOUSEBUTTONUP:
					doMouseUp(&event.button);
					break;
				
				case SDL_KEYDOWN:
					doKeyDown(&event.key);
					break;
					
				case SDL_KEYUP:
					doKeyUp(&event.key);
					break;

				case SDL_QUIT:
					exit(0);
					break;
			}
		}
		
		if (app.modalDialog.type != MD_NONE)
		{
			doModalDialog();
		}
		
		while (td >= LOGIC_RATE)
		{
			/* let the delegate decide during logic() */
			app.doTrophyAlerts = 0;
			
			app.delegate.logic();
			
			td -= LOGIC_RATE;
			
			if (app.doTrophyAlerts)
			{
				doTrophyAlerts();
			}
			
			if (app.resetTimeDelta)
			{
				td = 0;
				then = SDL_GetTicks();
				app.resetTimeDelta = 0;
			}
			
			game.stats[STAT_TIME]++;
		}
		
		prepareScene();

		app.delegate.draw();
		
		if (app.doTrophyAlerts)
		{
			drawTrophyAlert();
		}
		
		if (app.modalDialog.type != MD_NONE)
		{
			drawModalDialog();
		}
		
		presentScene();
		
		doDevKeys();
		
		frames++;
		
		if (SDL_GetTicks() > lastFrameTime)
		{
			dev.fps = frames;
			frames = 0;
			lastFrameTime = SDL_GetTicks() + 1000;
			
			if (dev.takeScreenshots)
			{
				saveScreenshot();
			}
		}
		
		if (isControl(CONTROL_SCREENSHOT))
		{
			saveScreenshot();
			
			clearControl(CONTROL_SCREENSHOT);
		}
		
		if (SDL_GetTicks() > expireTextTimer)
		{
			expireTexts(0);
			
			expireTextTimer = SDL_GetTicks() + (1000 * 10);
		}
		
		/* don't save more than once per request, and not in the middle of battle */
		if (app.saveGame && battle.status != MS_IN_PROGRESS)
		{
			saveGame();
			app.saveGame = 0;
		}
		
		/* always zero the mouse motion */
		app.mouse.dx = app.mouse.dy = 0;

		SDL_Delay(1);
	}

	return 0;
}
예제 #2
0
파일: CUIDialog.cpp 프로젝트: deeice/ldview
INT_PTR CUIDialog::dialogProc(
	HWND hDlg,
	UINT message,
	WPARAM wParam,
	LPARAM lParam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)doInitDialog((HWND)wParam);
		break;

	case WM_COMMAND:
		return (INT_PTR)doPrivateCommand(message, wParam, lParam);
	case WM_DESTROY:
		if (doDestroy() == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_VSCROLL:
		if (doVScroll((int)(short)LOWORD(wParam), (int)(short)HIWORD(wParam),
			(HWND)lParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_HSCROLL:
		if (doHScroll((int)(short)LOWORD(wParam), (int)(short)HIWORD(wParam),
			(HWND)lParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_NOTIFY:
		return (INT_PTR)doPrivateNotify(message, wParam, lParam);
	case WM_MOVE:
		if (doMove((int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_SIZE:
		if (doSize(wParam, (int)(short)LOWORD(lParam),
			(int)(short)HIWORD(lParam)) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_ENTERMENULOOP:
		if (doEnterMenuLoop(wParam ? true : false) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_EXITMENULOOP:
		if (doExitMenuLoop(wParam ? true : false) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_INITMENUPOPUP:
		if (doInitMenuPopup((HMENU)wParam, (UINT)LOWORD(lParam),
			(BOOL)HIWORD(lParam)) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_KEYDOWN:
		if (doKeyDown((int)wParam, lParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_KEYUP:
		if (doKeyUp((int)wParam, lParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_CLOSE:
		if (doClose() == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_TIMER:
		if (doTimer(wParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_GETMINMAXINFO:
		if (doGetMinMaxInfo(hDlg, (LPMINMAXINFO)lParam) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_MOUSEWHEEL:
		if (doMouseWheel(LOWORD(wParam), HIWORD(wParam),
			(int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_CONTEXTMENU:
		if (doContextMenu((HWND)wParam, (int)(short)LOWORD(lParam),
			(int)(short)HIWORD(lParam)) == 0)
		{
			return (INT_PTR)TRUE;
		}
		break;
	case WM_DRAWITEM:
		return doPrivateDrawItem(message, wParam, lParam);
	}
	return (INT_PTR)FALSE;
}