Ejemplo n.º 1
0
void doEvents(EventRecord *eventStrucPtr)
{
    WindowRef      windowRef;

    if (eventStrucPtr->what == mouseDown &&
        FindWindow(eventStrucPtr->where,&windowRef) == inMenuBar)
        SelectWindow(SIOUXTextWindow->window);

    SIOUXSettings.standalone = true;
    if (SIOUXHandleOneEvent(eventStrucPtr))
    {
        if (SIOUXQuitting)
            gDone = true;
        SIOUXSettings.standalone = false;
        return;
    }
    SIOUXSettings.standalone = false;

    switch(eventStrucPtr->what)
    {
    case kHighLevelEvent:
        AEProcessAppleEvent(eventStrucPtr);
        break;

    case mouseDown:
        doMouseDown(eventStrucPtr);
        break;

    case keyDown:
    case autoKey:
        break;

    case updateEvt:
        doUpdate(eventStrucPtr);
        break;

    case activateEvt:
        DrawGrowIcon(windowRef);
        break;

    case osEvt:
        doOSEvent(eventStrucPtr);
        break;
    }
}
Ejemplo n.º 2
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;
}