1 /*
2  *  Copyright (C) 2000-2013  The Exult Team
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef GUMP_UTILS_H
20 #define GUMP_UTILS_H
21 
22 #include <unistd.h>
23 
24 #include "SDL_timer.h"
25 #include "SDL_events.h"
26 
27 /*
28  *  Delay between animations.
29  */
30 
31 #define DELAY_TOTAL_MS 10
32 #define DELAY_SINGLE_MS 1
33 
Delay()34 inline void Delay(
35 ) {
36 	Uint32 expiration = DELAY_TOTAL_MS + SDL_GetTicks();
37 	for (;;) {
38 		SDL_PumpEvents();
39 		if ((SDL_PeepEvents(nullptr, 0, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) != 0) ||
40 		    (static_cast<Sint32>(SDL_GetTicks()) >= static_cast<Sint32>(expiration))) return;
41 
42 		SDL_Delay(DELAY_SINGLE_MS);
43 	}
44 }
45 
46 #endif
47