annotate tests/efu.c @ 1445:60337b31e427

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 04:44:08 +0300
parents 5be4e2eec84f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmvecmat.h"
7
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
4 #include "dmimage.h"
62
daeb5d4f6bad Do include "dmtext.h" where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
5 #include "dmtext.h"
891
fface5a23b2a Link to -lm and fix to match changes in dmperlin.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
6 #include "dmperlin.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <math.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define DM_COLORS (256)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 char *optFontFile = "font.ttf",
7
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
12 *optBitmapFilename = "tnsp.png";
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 BOOL optBenchmark = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 int optScrWidth = 640, optScrHeight = 480, optFontSize = 20, optScrDepth = 32;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 int optBenchmarkLen = 20;
891
fface5a23b2a Link to -lm and fix to match changes in dmperlin.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
17 DMPerlinContext perlinCtx;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 739
diff changeset
19 static const DMOptArg optList[] =
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 739
diff changeset
20 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 { 0, '?', "help", "Show this help", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 { 2, 'v', "verbose", "Be more verbose", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 { 3, 'f', "full", "Fullscreen", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 { 4, 'h', "hw", "Use SDL hardware surface", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 { 5, 's', "size", "Initial window size/resolution -s 640x480", OPT_ARGREQ },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 { 6, 'd', "depth", "Color depth of mode/window in bits (8/15/16/32)", OPT_ARGREQ },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 { 7, 'b', "bench", "Run in benchmark mode", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 const int optListN = sizeof(optList) / sizeof(optList[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 void argShowHelp()
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 {
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 739
diff changeset
35 dmArgsPrintHelp(stdout, optList, optListN, 0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 switch (optN) {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 case 0:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 argShowHelp();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 case 2:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 dmVerbosity++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 break;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
50
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 case 3:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 optVFlags |= SDL_FULLSCREEN;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 case 6:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 if (optArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 optScrDepth = atoi(optArg);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 case 5:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 int w, h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 if (sscanf(optArg, "%dx%d", &w, &h) == 2)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 if (w < 320 || h < 200 || w > 3200 || h > 3200)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
67 dmErrorMsg("Invalid width or height: %d x %d\n", w, h);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 optScrWidth = w;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 optScrHeight = h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 }
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
73 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
75 dmErrorMsg("Invalid size argument '%s'.\n", optArg);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 case 7:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 optBenchmark = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
86 dmErrorMsg("Unknown option '%s'.\n", currArg);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 }
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
89
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 void DM_MakePalette(SDL_Surface *scr)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 SDL_Color pal[DM_COLORS];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 int n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 for (n = 0; n < 256; n++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 pal[n].r = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 pal[n].g = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 pal[n].b = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 SDL_SetColors(scr, pal, 0, DM_COLORS);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 void DM_PrintRect(FILE *f, SDL_Rect *r)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 fprintf(f, "SDL_Rect <%d, %d : %d, %d>\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 r->x, r->y, r->w, r->h);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 BOOL DM_InitializeVideo(SDL_Surface **screen)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 if (*screen == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
121 dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 #if 0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 SDL_Rect r;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 r.x = -50;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 r.y = 50;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 r.w = 700;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 r.h = 300;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 DM_PrintRect(stderr, &r);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 SDL_SetClipRect(*screen, &r);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 DM_PrintRect(stderr, &r);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 DM_PrintRect(stderr, &((*screen)->clip_rect));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 void DM_Random(SDL_Surface *screen, int q)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 Uint8 *pix = screen->pixels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 int xc, yc;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
144
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 for (yc = 0; yc < screen->h; yc++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 Uint8 *dp = pix;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 for (xc = 0; xc < screen->w; xc++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 *dp++ = yc + (xc ^ q) + (yc & q);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 pix += screen->pitch;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 #define QWIDTH 256
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 #define QHEIGHT 160
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 typedef Uint8 DMBlockMap[QHEIGHT][QWIDTH];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 void dmMakeBumpMap(DMBlockMap map, DMFloat q, DMFloat m)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 int x, y;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 for (y = 0; y < QHEIGHT; y++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 for (x = 0; x < QWIDTH; x++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
891
fface5a23b2a Link to -lm and fix to match changes in dmperlin.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
169 DMFloat f = 0.40f + dmPerlinNoise2D(&perlinCtx, x, y, 1.1f, q, 2);
116
4e82d41f0e6f s/dmClip10/dmClamp10/g
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
170 map[y][x] = (int) (dmClamp10(f) * m);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 void dmShadowTraceHeightMap(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 int i, j;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 light->z = 150;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 for (j = 0; j < QHEIGHT; j++)
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
182 for (i = 0; i < QWIDTH; i++)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
183 {
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
184 DMVector vr, vl, va;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
185 DMFloat vrayLen, vfactor;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
186 int vlen;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
187 BOOL wasHit;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
188
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
189 // Perform shadow occlusion via simplistic raytracing
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
190 vr.x = i;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
191 vr.y = j;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
192 vr.z = 200; //light->z; // - 10.0;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
193
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
194 // Calculate light vector vector
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
195 dm_vector_sub_r(&vl, &vr, light);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
196 vrayLen = dm_vector_length(&vl);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 #if 1
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
199 dm_vector_copy(&va, &vl);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
200 dm_vector_normalize(&va);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
201 dm_vector_copy(&vr, light);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
202
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
203 vlen = 0;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
204 wasHit = FALSE;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
205 do
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
206 {
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
207 float h;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
209 // If ray is inside the heightmap, get value
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
210 if (vr.x >= 0 && vr.y >= 0 && vr.x < QWIDTH && vr.y < QHEIGHT)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
211 h = pheightMap[(int) vr.y][(int) vr.x];
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
212 else
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
213 break;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
214
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
215 // Check for hits
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
216 if (h > vr.z)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
217 wasHit = TRUE;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
218 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 {
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
220 // Move forwards
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
221 dm_vector_add(&vr, &va);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
222 vlen++;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
224 }
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
225 while (!wasHit && vlen <= vrayLen);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
227 // Check if the ray hit something, e.g. is this point occluded?
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
228 if (wasHit && vlen < vrayLen)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
229 {
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
230 vfactor = vlen * 0.05;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
231 }
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
232 else
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
233 vfactor = vlen * 0.001;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 #if 0
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
237 {
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
238 /* Calculate light's intensity based on the angle it "hits"
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
239 *
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
240 * 1) Calculate the vectors that form the imaginary "plane"
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
241 * 2) Cross-product -> normal vector of the plane
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
242 * 2) Normalize the normal vector
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
243 * 3) Calculate light vector's hit angle by dot product
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
244 */
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
245 DMVector v1, v2;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
246 DMFloat c;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
248 v1.x = 2.0f;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
249 v1.y = 0.0f;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
250 v1.z = (DMFloat) (pheightMap[j][i] - pheightMap[j][i + 1]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
252 v2.x = 0.0f;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
253 v2.y = 2.0f;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
254 v2.z = (DMFloat) (pheightMap[j][i] - pheightMap[j + 1][i]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
256 dm_vector_cross(&vr, &v1, &v2);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
257 dm_vector_normalize(&vr);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
258 dm_vector_normalize(&vl);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
259 c = dm_vector_dot(&vl, &vr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
261 vrayLen = 255 - (vrayLen * 0.1) * vrayLen + (c * 128.0f) + (vfactor * vfactor * 1255);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
262 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 #else
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
264 vrayLen = 255 - vrayLen * vrayLen * (vfactor * vfactor);
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
265 if (vrayLen < 0) vrayLen = 0;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
266 vrayLen -= pheightMap[j][i];
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
267
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
270 // Clip result
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
271 if (vrayLen < 0)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
272 vrayLen = 0;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
273 else if (vrayLen > 255.0f)
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
274 vrayLen = 255.0f;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
276 lightMap[j][i] = vrayLen;
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
277 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
1444
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
280 #define Q_KERNEL(x, y, dist, coeff) ( \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
281 in[(y) - (dist)][(x)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
282 in[(y) + (dist)][(x)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
283 in[(y)][(x) - (dist)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
284 in[(y)][(x) + (dist)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
285 in[(y) - (dist)][(x) - (2)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
286 in[(y) - (dist)][(x) + (2)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
287 in[(y) + (dist)][(x) - (2)] * (coeff) + \
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
288 in[(y) + (dist)][(x) + (2)] * (coeff))
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
289
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
290 #define Q_VALUES(coeff) (8 * (coeff))
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
291
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
292 void dmSmoothMap(DMBlockMap out, DMBlockMap in)
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
293 {
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
294 int x, y;
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
295
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
296 for (y = 0; y < QHEIGHT; y++)
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
297 for (x = 0; x < QWIDTH; x++)
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
298 {
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
299 if (y >= 3 && x >= 3 && y < QHEIGHT - 3 && x < QWIDTH - 3)
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
300 out[y][x] = (
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
301 Q_KERNEL(x, y, 3, 1) +
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
302 Q_KERNEL(x, y, 2, 2) +
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
303 Q_KERNEL(x, y, 1, 4) +
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
304 in[y][x] * 16) /
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
305 (16 + Q_VALUES(1) + Q_VALUES(2) + Q_VALUES(4));
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
306 else
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
307 out[y][x] = in[y][x];
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
308 }
5be4e2eec84f Add dmSmoothMap() function to efu test.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
309 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 SDL_Surface *screen = NULL, *bmap = NULL, *logo = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 TTF_Font *font = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 SDL_Color fontcol={255,155,155,0};
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 SDL_Event event;
739
8bf67daf4030 Fix more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
317 int mouseX, mouseY, res;
7
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
318 BOOL initSDL = FALSE, initTTF = FALSE, exitFlag, showMap = FALSE;
739
8bf67daf4030 Fix more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
319 DMResource *file;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
320
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 if (!dmArgsProcess(argc, argv, optList, optListN,
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 739
diff changeset
322 argHandleOpt, NULL, OPTH_BAILOUT))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
327 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 initSDL = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 if (TTF_Init() < 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
335 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError());
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 initTTF = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 font = TTF_OpenFont(optFontFile, optFontSize);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 if (font == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
343 dmErrorMsg("Could not load TTF font '%s' (%d): %s\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 optFontFile, optFontSize, SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348
7
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
349
739
8bf67daf4030 Fix more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
350 if ((res = dmf_create_stdio(optBitmapFilename, "rb", &file)) != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
352 dmErrorMsg("Could not open resource file '%s'.\n", optBitmapFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 }
739
8bf67daf4030 Fix more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
355 logo = dmLoadImage(file);
8bf67daf4030 Fix more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
356 dmf_close(file);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 if (logo == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
359 dmErrorMsg("Could not load image file '%s'.\n", optBitmapFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 }
7
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362
d427763f113a Fix "efu" test, use dmImage instead of SDL_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
363
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 screen = SDL_CreateRGBSurface(SDL_SWSURFACE, optScrWidth, optScrHeight, optScrDepth, 0, 0, 0, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 if (screen == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
369 dmErrorMsg("Could not create screen surface.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 }
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
372
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 dmMsg(0, "Benchmark mode, not opening window.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 if (!DM_InitializeVideo(&screen))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 SDL_WM_SetCaption("Halleluja", "DMT");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
891
fface5a23b2a Link to -lm and fix to match changes in dmperlin.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
383 dmPerlinInit(&perlinCtx, 1234);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 bmap = SDL_CreateRGBSurface(SDL_SWSURFACE, QWIDTH, QHEIGHT, 8, 0, 0, 0, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 DM_MakePalette(bmap);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 DM_Random(bmap, 15);
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
388
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 DMVector light;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 DMBlockMap heightMap;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 light.x = light.y = 128;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 light.z = 128;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 dmMakeBumpMap(heightMap, 0.06, 254);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 int numFrames = 0, startTime = SDL_GetTicks(), endTime = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 exitFlag = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 dmMsg(0, "Starting benchmark, running for %d seconds.\n", optBenchmarkLen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 while (!exitFlag)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 if (!optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 while (SDL_PollEvent(&event))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 switch (event.type)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 case SDL_KEYDOWN:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 switch (event.key.keysym.sym)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 case SDLK_ESCAPE: exitFlag = TRUE; break;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
414
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 case SDLK_F1:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 DM_Random(bmap, (SDL_GetTicks() / 10) % 1000);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 case SDLK_F5:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 showMap = !showMap;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 break;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
422
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 break;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
428
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 case SDL_VIDEORESIZE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 optScrWidth = event.resize.w;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 optScrHeight = event.resize.h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 if (!DM_InitializeVideo(&screen))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 break;
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
437
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 case SDL_VIDEOEXPOSE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 case SDL_QUIT:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 SDL_GetMouseState(&mouseX, &mouseY);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 light.x = ((DMFloat) mouseX * QWIDTH) / (DMFloat) optScrWidth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 light.y = ((DMFloat) mouseY * QHEIGHT) / (DMFloat) optScrHeight;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 if (!optBenchmark && SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 891
diff changeset
452 dmErrorMsg("Can't lock surface.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 if (showMap)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 memcpy(bmap->pixels, heightMap, QWIDTH * QHEIGHT);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 dmShadowTraceHeightMap(bmap->pixels, logo->pixels, &light);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 dmScaledBlitSurfaceAny(bmap, 0, 0, screen->w, screen->h, screen, DMD_NONE);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 if (!optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 {
1445
60337b31e427 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1444
diff changeset
467 dmDrawTTFText(screen, font, fontcol, 0, 0, "%3.1f FPS",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 (float) (numFrames * 1000.0f) / (float) (endTime - startTime));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 if (SDL_MUSTLOCK(screen) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 SDL_UnlockSurface(screen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 SDL_Flip(screen);
120
a4830b62ff5d Increase delay here a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
474 SDL_Delay(20);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 endTime = SDL_GetTicks();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 numFrames++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 if (endTime - startTime > optBenchmarkLen * 1000)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 exitFlag = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 // Print benchmark results
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 dmMsg(0, "%d frames in %d ms, fps = %1.3f\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 numFrames, endTime - startTime,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 (float) (numFrames * 1000.0f) / (float) (endTime - startTime));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 error_exit:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 dmMsg(0, "Shutting down dmlib.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 if (screen)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 SDL_FreeSurface(screen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 if (logo)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 SDL_FreeSurface(logo);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 if (font)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 TTF_CloseFont(font);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 if (initSDL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 SDL_Quit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 if (initTTF)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 TTF_Quit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 }