6 /* Try to find a window size closest to VGA (640x480) */
7 SDL_DisplayMode
* getWindowSize(SDL_DisplayMode
*desired
) {
10 SDL_DisplayMode desktop
;
11 static SDL_DisplayMode ret
;
13 if (SDL_GetDesktopDisplayMode(display
, &desktop
)) {
14 fprintf(stderr
, "Unable to get desktop display mode: %s\n", SDL_GetError());
18 /* Desktop is weirdly small, use the whole of it... */
19 if (desktop
.w
< desired
->w
|| desktop
.h
< desired
->h
) {
27 /* Enlarge until we can't fit */
28 Uint32 w
= desired
->w
;
29 Uint32 h
= desired
->h
;
36 } while (w
< desktop
.w
&& h
< desktop
.h
);
42 /* Try to find fullscreen mode closest to VGA (640x480) */
43 SDL_DisplayMode
* getFullscreenSize(SDL_DisplayMode
*desired
) {
46 static SDL_DisplayMode best
;
51 int num_modes
= SDL_GetNumDisplayModes(display
);
53 /* Find smallest mode closest to desired */
54 for (i
= 0; i
< num_modes
; i
++) {
57 if (SDL_GetDisplayMode(display
, i
, &mode
)) {
58 fprintf(stderr
, "Unable to get display mode %d: %s\n", i
, SDL_GetError());
62 //printf("Mode %d -- %d x %d\n", i, mode.w, mode.h);
64 /* Correct aspect ration (VGA) */
65 if (mode
.w
% desired
->w
== 0 && mode
.h
% desired
->h
== 0) {
67 /* AND it's smaller, pick it */
68 if (best_mode
== -1 || (mode
.w
< best
.w
&& mode
.h
< best
.h
)) {
77 /* WRONG aspect ratio */
79 /* Still going to pick it, if we don't have anything better */
80 if (best_mode
== -1 || (best_fits
== 0 && (mode
.w
< best
.w
&& mode
.h
< best
.h
)) ) {
94 void generate_name(unit_t
*u
) {
96 static const char first_names
[][80] = {
97 "Gaborn", "Jaz", "Talon", "Fallion",
98 "Myrrima", "Rhianna", "Averan", "Erin",
99 "Jas Laren", "Mendellas", "Roland",
100 "Saffira", "Skalbairn", "Chemoise", "Wuqaz", "Sarka",
101 "Raj", "Feykaald", "Jureem", "Ivarian", "Aelgir",
102 "Waggit", "Conall", "Celinor", "Connall", "Spring",
103 "Anders", "Zandaros", "Binnesman", "Paldane",
104 "Solette", "Poll", "Faharaqin", "Kaul",
105 "Ahten", "Sylvarresta", "Borenson",
108 int i
= rand() % (sizeof(first_names
) / (sizeof(char) * 80));
109 sprintf(u
->name
, "%s", first_names
[i
]);
112 int count_fps(void) {
114 static Uint32 wait
= 0;
115 static Uint32 fps
= 0;
116 static Uint32 fps_counter
= 0;
118 Uint32 tick
= SDL_GetTicks();
119 Uint32 pass
= tick
- wait
;
132 int profile(Uint8 id
, const char *desc
) {
134 static Uint32 wait
[256] = { 0 };
136 Uint32 tick
= SDL_GetTicks();
137 Uint32 pass
= tick
- wait
[id
];
140 printf("Profiler: %s: %d\n", desc
, pass
);