/*	Displays a text string in the center of the screen and waits for a Y or N
	keypress.
*/
int SCR_ModalMessage (char *text, float timeout) //johnfitz -- timeout
{
	double time1, time2; //johnfitz -- timeout

	if (cls.state == ca_dedicated)
		return true;

	scr_notifystring = text;

	// draw a fresh screen
	bDrawDialog = true;
	Video_Frame();
	bDrawDialog = false;

	S_ClearBuffer ();		// so dma doesn't loop current sound

	time1 = System_DoubleTime () + timeout; //johnfitz -- timeout
	time2 = 0.0f; //johnfitz -- timeout

	do
	{
		key_count = -1;		// wait for a key down and up

		Input_Frame();

		if (timeout)
			time2 = System_DoubleTime (); //johnfitz -- zero timeout means wait forever.
	} while(	key_lastpress != 'y'		&&
				key_lastpress != 'n'		&&
				key_lastpress != K_ESCAPE	&&
				time2 <= time1);

//	SCR_UpdateScreen (); //johnfitz -- commented out

	//johnfitz -- timeout
	if (time2 > time1)
		return false;
	//johnfitz

	return key_lastpress == 'y';
}
Esempio n. 2
0
int Draw_LoopIteration() {
	SDL_Event event;

// Process Events
#ifdef EMSCRIPTEN
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			Input_SetKey(InputKey_Exit, 1);
		}
		if (event.type == SDL_KEYDOWN) {
			if (event.key.keysym.sym == SDLK_ESCAPE) {
				Input_SetKey(InputKey_Exit, 1);
			}
		}
		if (event.type == SDL_MOUSEMOTION) {
			Input_SetPointerPosition(event.motion.x / (float)_width,
									 event.motion.y / (float)_height);
		}
		if (event.type == SDL_MOUSEBUTTONDOWN) {
			Input_SetPointerPosition(event.button.x / (float)_width,
									 event.button.y / (float)_height);
			Input_SetPointerDown(1);
		}
		if (event.type == SDL_FINGERMOTION) {
			Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
		}
		if (event.type == SDL_FINGERDOWN) {
			Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
			Input_SetPointerDown(1);
		}
		if (event.type == SDL_TOUCHBUTTONDOWN) {
			Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
			Input_SetPointerDown(1);
		}
		if (event.type == SDL_MOUSEBUTTONUP) {
			Input_SetPointerPosition(event.button.x / (float)_width,
									 event.button.y / (float)_height);
			Input_SetPointerDown(0);
		}
		if (event.type == SDL_FINGERUP) {
			Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
			Input_SetPointerDown(0);
		}
		if (event.type == SDL_TOUCHBUTTONUP) {
			Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
			Input_SetPointerDown(0);
		}
	}
#else
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			Input_SetKey(InputKey_Exit, 1);
			if (!_draw_exitoverrided) {
				_draw_looping = 0;
			}
		}
		if (event.type == SDL_KEYDOWN) {
			if (event.key.keysym.sym == SDLK_ESCAPE) {
				Input_SetKey(InputKey_Exit, 1);
				if (!_draw_exitoverrided) {
					_draw_looping = 0;
				}
			}
		}
		if (event.type == SDL_MOUSEMOTION) {
			Input_SetPointerPosition(event.motion.x / (float)_width,
									 event.motion.y / (float)_height);
		}
		if (event.type == SDL_MOUSEBUTTONDOWN) {
			Input_SetPointerPosition(event.button.x / (float)_width,
									 event.button.y / (float)_height);
			Input_SetPointerDown(1);
		}
		if (event.type == SDL_MOUSEBUTTONUP) {
			Input_SetPointerPosition(event.button.x / (float)_width,
									 event.button.y / (float)_height);
			Input_SetPointerDown(0);
		}
	}
#endif

#ifndef EMSCRIPTEN
	// Process keys for Draw
	Uint8 *keys;
	keys = (Uint8 *)SDL_GetKeyState(NULL);
	if (keys[SDLK_F12]) {
		// Screenshot key
		char strFile[255];
		int idx = -1;
		do {
			idx++;
			snprintf(strFile, 255, "shot-%04d.png", idx);
		} while (access(strFile, F_OK) != -1);
		Draw_SaveScreenshoot(strFile);
	}
#endif

	// Process
	if (_proc_func) {
		if (_accTime > 100000) {
			_accTime = 100000;
		}
		while (_accTime >= proc_t_frame && _draw_looping) {
			Input_Frame();
			_proc_func(_data);
			_accTime -= proc_t_frame;
			Input_PostFrame();
		}
	}

	// Sound Frame
	Audio_Frame();

	// Draw
	SDL_GL_SwapBuffers();
	if (_draw_func) {
		_draw_func(_data, (float)_accTime / (float)proc_t_frame);
		Draw_Flush();
	}

	return _draw_looping;
}