annotate krapula.c @ 17:758a39d3f750

Various "engine" cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 29 Sep 2012 13:27:38 +0300
parents 833dad075e3b
children ccc5cdce91e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmargs.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmvecmat.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmres.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include "dmimage.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "jss.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "jssmod.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "jssmix.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "jssplr.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <math.h>
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #define DM_COLORS (256)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 typedef struct
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 int x, y;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 } DMCoords;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 typedef struct
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 int x, y;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 char *filename;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 SDL_Surface *img;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 } DMCredits;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 typedef struct
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 int currFrame, endTime, startTime, totalFrameTime;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 BOOL pauseFlag, exitFlag;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 SDL_Surface *screen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 SDL_Event event;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 } DMEngineData;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 typedef struct
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 int currFrame, endTime, startTime;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 } DMFrameData;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 int optScrWidth = 640, optScrHeight = 480;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 int optBenchmarkLen = 20;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 DMOptArg optList[] = {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 { 0, '?', "help", "Show this help", OPT_NONE },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 { 2, 'v', "verbose", "Be more verbose", OPT_NONE },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 { 3, 'f', "fs", "Fullscreen", OPT_NONE },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 // { 5, 's', "size", "Screen resolution -s 640x480", OPT_ARGREQ },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 };
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 const int optListN = sizeof(optList) / sizeof(optList[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 void argShowHelp()
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 dmPrintBanner(stdout, dmProgName, "[options]");
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 dmArgsPrintHelp(stdout, optList, optListN);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 switch (optN) {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 case 0:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 argShowHelp();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 exit(0);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 case 2:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 dmVerbosity++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 case 3:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 optVFlags |= SDL_FULLSCREEN;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 case 5:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 int w, h;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 if (sscanf(optArg, "%dx%d", &w, &h) == 2)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 if (w < 320 || h < 200 || w > 1024 || h > 768)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 dmError("Invalid width or height: %d x %d\n", w, h);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 return FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 optScrWidth = w;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 optScrHeight = h;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 dmError("Invalid size argument '%s'.\n", optArg);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 return FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 default:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 dmError("Unknown option '%s'.\n", currArg);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 return FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 return TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 void dmMakePalette(SDL_Surface *scr)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 SDL_Color pal[DM_COLORS];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 int n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 for (n = 0; n < 256; n++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 pal[n].r = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 pal[n].g = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 pal[n].b = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 SDL_SetColors(scr, pal, 0, DM_COLORS);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 BOOL dmInitializeVideo(SDL_Surface **screen)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 32, optVFlags); // | SDL_RESIZABLE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 if (*screen == NULL)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 return FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 SDL_ShowCursor(SDL_DISABLE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 return TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 void dmRandom(SDL_Surface *screen, int q)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 Uint8 *pix = screen->pixels;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 int xc, yc;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 for (yc = 0; yc < screen->h; yc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 Uint8 *dp = pix;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 for (xc = 0; xc < screen->w; xc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 *dp++ = yc + (xc ^ q) + (yc & q);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 pix += screen->pitch;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 void dmPerlin(SDL_Surface *screen, float f)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 Uint8 *pix = screen->pixels;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 int xc, yc;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 for (yc = 0; yc < screen->h; yc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 Uint8 *dp = pix;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 for (xc = 0; xc < screen->w; xc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 *dp++ = 128 + dmPerlinNoise2D(xc, yc, 0.01, 0.1, 3) / 34.0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 pix += screen->pitch;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 #define QWIDTH 256
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 #define QHEIGHT 160
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 typedef Uint8 DMBlockMap[QHEIGHT][QWIDTH];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 static DMFloat dmClip(DMFloat a)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a));
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 void dmMakeBumpMap(DMBlockMap map, DMFloat q, DMFloat m)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 int x, y;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 for (y = 0; y < QHEIGHT; y++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 for (x = 0; x < QWIDTH; x++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 DMFloat f = 0.40f + dmPerlinNoise2D(x, y, 1.1f, q, 2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 map[y][x] = (int) (dmClip(f) * m);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 void dmShadowTraceHeightMap(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 int i, j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 for (j = 0; j < QHEIGHT; j++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 for (i = 0; i < QWIDTH; i++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 DMVector vr, vl, va;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 DMFloat vrayLen, vfactor;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 int vlen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 BOOL wasHit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 /* Perform shadow occlusion via simplistic raytracing */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 vr.x = i;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 vr.y = j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 vr.z = light->z; // - 10.0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 // vr.z = pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 /* Calculate light vector vector */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 dm_vector_sub_r(&vl, &vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 vrayLen = dm_vector_length(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 dm_vector_copy(&va, &vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 dm_vector_normalize(&va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 dm_vector_scale(&va, 0.6f);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 dm_vector_copy(&vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 vlen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 wasHit = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 do
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 float h;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 /* If ray is inside the heightmap, get value */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 if (vr.x >= 0 && vr.y >= 0 && vr.x < QWIDTH && vr.y < QHEIGHT)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 h = pheightMap[(int) vr.y][(int) vr.x];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 /* Check for hits */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 if (h > vr.z)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 wasHit = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 /* Move forwards */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 dm_vector_add(&vr, &va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 vlen++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 while (!wasHit && vlen <= vrayLen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 /* Check if the ray hit something, e.g. is this point occluded? */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 if (wasHit && vlen < vrayLen)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 vfactor = vlen * 0.01;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 vfactor = vlen * 0.02;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 #endif
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 /* Calculate light's intensity based on the angle it "hits"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 *
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 * 1) Calculate the vectors that form the imaginary "plane"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 * 2) Cross-product -> normal vector of the plane
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 * 2) Normalize the normal vector
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 * 3) Calculate light vector's hit angle by dot product
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 DMVector v1, v2;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 DMFloat c;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 v1.x = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 v1.y = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 v1.z = (DMFloat) (pheightMap[j][i] - pheightMap[j][i + 1]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 v2.x = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 v2.y = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 v2.z = (DMFloat) (pheightMap[j][i] - pheightMap[j + 1][i]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 dm_vector_cross(&vr, &v1, &v2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 dm_vector_normalize(&vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 dm_vector_normalize(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 c = dm_vector_dot(&vl, &vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 vrayLen = 255 - (vrayLen * 0.1) * vrayLen + (c * 128.0f) + (vfactor * vfactor * 1255);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 #else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 vrayLen = 255 - vrayLen * vrayLen * (vfactor * vfactor);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 if (vrayLen < 0) vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 vrayLen += pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 #endif
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 /* Clip result */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 if (vrayLen < 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 else if (vrayLen > 255.0f)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 vrayLen = 255.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 lightMap[j][i] = vrayLen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 void dmShadowTraceHeightMap2(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 int i, j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 light->z = 150;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 for (j = 0; j < QHEIGHT; j++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 for (i = 0; i < QWIDTH; i++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 DMVector vr, vl, va;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 DMFloat vrayLen, vfactor;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 int vlen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 BOOL wasHit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 /* Perform shadow occlusion via simplistic raytracing */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 vr.x = i;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 vr.y = j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 vr.z = 200; //light->z; // - 10.0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 /* Calculate light vector vector */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 dm_vector_sub_r(&vl, &vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 vrayLen = dm_vector_length(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 dm_vector_copy(&va, &vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 dm_vector_normalize(&va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 dm_vector_copy(&vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 vlen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 wasHit = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 do
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 float h;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 /* If ray is inside the heightmap, get value */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 if (vr.x >= 0 && vr.y >= 0 && vr.x < QWIDTH && vr.y < QHEIGHT)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 h = pheightMap[(int) vr.y][(int) vr.x];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 /* Check for hits */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 if (h > vr.z)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 wasHit = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 /* Move forwards */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 dm_vector_add(&vr, &va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 vlen++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 while (!wasHit && vlen <= vrayLen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 /* Check if the ray hit something, e.g. is this point occluded? */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 if (wasHit && vlen < vrayLen)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 vfactor = vlen * 0.05;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 vfactor = vlen * 0.001;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 #endif
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 #if 0
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 /* Calculate light's intensity based on the angle it "hits"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 *
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 * 1) Calculate the vectors that form the imaginary "plane"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 * 2) Cross-product -> normal vector of the plane
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 * 2) Normalize the normal vector
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 * 3) Calculate light vector's hit angle by dot product
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 DMVector v1, v2;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 DMFloat c;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 v1.x = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 v1.y = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 v1.z = (DMFloat) (pheightMap[j][i] - pheightMap[j][i + 1]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 v2.x = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 v2.y = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 v2.z = (DMFloat) (pheightMap[j][i] - pheightMap[j + 1][i]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 dm_vector_cross(&vr, &v1, &v2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 dm_vector_normalize(&vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 dm_vector_normalize(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 c = dm_vector_dot(&vl, &vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 vrayLen = 255 - (vrayLen * 0.1) * vrayLen + (c * 128.0f) + (vfactor * vfactor * 1255);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 #else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 vrayLen = 255 - vrayLen * vrayLen * (vfactor * vfactor);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 if (vrayLen < 0) vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 vrayLen -= pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 #endif
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 /* Clip result */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 if (vrayLen < 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 else if (vrayLen > 255.0f)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 vrayLen = 255.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 lightMap[j][i] = vrayLen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
417 void engineAudioCallback(void *userdata, Uint8 *stream, int len)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 JSSMixer *d = (JSSMixer *) userdata;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 if (d != NULL)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 jvmRenderAudio(d, stream, len / jvmGetSampleSize(d));
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 #define DEBUG 0
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 #define CREDITS_SPEED 1000
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 #define CREDITS_RAND 4
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 #define NOSFE_MIN 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 #define NOSFE_MAX 269
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 static const DMCoords randomCoords[] =
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 { -300, -430 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 { 700, -550 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 { -200, 600 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 { 700, 600 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 };
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 const int nrandomCoords = sizeof(randomCoords) / sizeof(randomCoords[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 static DMCredits credits[] =
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 { 91, 223, "g4014.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 { 151, 250, "g4026.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 { 217, 227, "g4020.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 { 173, 268, "g4032.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 { 115, 359, "g4038.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 { 437, 130, "g4062.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 { 457, 102, "g4068.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 { 450, 210, "g4056.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 { 420, 320, "g4044.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 { 486, 381, "g4050.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 };
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 const int ncredits = sizeof(credits) / sizeof(credits[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
464
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
465
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 DMEngineData engine;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 DMFrameData frame;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 int engineGetTick()
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 return (frame.startTime - engine.startTime) + DEBUG * 1000;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 float engineGetTimeDT()
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 return (float) engineGetTick() / 1000.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 int engineGetTimeDTi()
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 return (float) engineGetTick() / 1000;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 int engineGetTime(int t)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 return engineGetTick() - (1000 * t);;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 int engineGetDT(int t)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 return engineGetTime(t) / 1000;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 int dmScaledBlitSurface32to32TransparentX(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
501 int engineResImageLoad(DMResource *res)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
502 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
503 SDL_Surface *img = dmLoadImage(res);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
504 if (res != NULL)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
505 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
506 res->rdata = img;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
507 return DMERR_OK;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
508 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
509 else
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
510 return dmferror(res);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
511 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
512
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
513 void engineResImageFree(DMResource *res)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
514 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
515 SDL_FreeSurface((SDL_Surface *)res->rdata);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
516 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
517
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
518 int engineResModuleLoad(DMResource *res)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
519 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
520 return jssLoadXM(res, (JSSModule **) &(res->rdata));
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
521 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
522
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
523 void engineResModuleFree(DMResource *res)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
524 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
525 jssFreeModule((JSSModule *) res->rdata);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
526 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
527
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
528
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
529 static DMResourceDataOps engineResImage =
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
530 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
531 engineResImageLoad,
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
532 engineResImageFree
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
533 };
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
534
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
535 static DMResourceDataOps engineResModule =
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
536 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
537 engineResModuleLoad,
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
538 engineResModuleFree
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
539 };
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
540
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
541
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
542 int engineClassifier(DMResource *res)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
543 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
544 DMResourceDataOps *rops = NULL;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
545 char *fext;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
546
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
547 if (res == NULL)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
548 return DMERR_NULLPTR;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
549
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
550 if ((fext = strrchr(res->filename, '.')) != NULL)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
551 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
552 if (strcasecmp(fext, ".png") == 0 || strcasecmp(fext, ".jpg") == 0)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
553 rops = &engineResImage;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
554 else
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
555 if (strcasecmp(fext, ".xm") == 0 || strcasecmp(fext, ".jmod") == 0)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
556 rops = &engineResModule;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
557 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
558
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
559 res->rops = rops;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
560
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
561 return DMERR_OK;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
562 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
563
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
564
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
565 void *engineGetResource(const char *name)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
566 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
567 DMResource *res = dmres_find(name);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
568 if (res != NULL && res->rdata != NULL)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
569 return res->rdata;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
570 else
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
571 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
572 dmError("Could not find resource '%s'.\n", name);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
573 return NULL;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
574 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
575 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
576
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
577
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
578 #define engineGetResImage(name) (SDL_Surface *) engineGetResource(name)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
579 #define engineGetResModule(name) (JSSModule *) engineGetResource(name)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
580
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
582 int engineLoadResources()
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 {
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
584 int err, loaded, total;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
585
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
586 err = dmres_preload(TRUE, &loaded, &total);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
588 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
589 {
9
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
590 // Show a nice progress bar while loading
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
591 if (total > 0 && (loaded % 2) == 0)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
592 {
9
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
593 int dx = 60,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
594 dh = 20,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
595 dw = engine.screen->w - (2 * dx),
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
596 dy = (engine.screen->h - dh) / 2;
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
597
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
598 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
599 return DMERR_INIT_FAIL;
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
600
9
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
601 // Draw the progress bar
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
602 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
9
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
603 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255));
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
604 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0));
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
605
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
606 if (total > 0)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
607 {
9
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
608 dmFillRect(engine.screen,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
609 dx+3, dy+3,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
610 dx + 3 + ((dw - 3) * loaded) / total,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
611 dy + dh - 3,
ca2daec08204 Improve loading progress bar.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
612 dmMapRGB(engine.screen, 200,200,200));
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
613 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
614
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
615 // Flip screen
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
616 if (SDL_MUSTLOCK(engine.screen) != 0)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
617 SDL_UnlockSurface(engine.screen);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
618
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
619 SDL_Flip(engine.screen);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
620 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
621 }
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
622
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
623 return err;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
624 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
625
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
626
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
627
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
628 int main(int argc, char *argv[])
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
629 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
630 BOOL initSDL = FALSE;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
631 JSSModule *mod = NULL;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
632 JSSMixer *dev = NULL;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
633 JSSPlayer *plr = NULL;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
634 int err, i;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
635 SDL_AudioSpec afmt;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
636
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
637 memset(&afmt, 0, sizeof(afmt));
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
638 memset(&frame, 0, sizeof(frame));
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
639 memset(&engine, 0, sizeof(engine));
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
640
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
641 dmInitProg("krapula", "Lauantai Aamun Krapula", "0.2", "(c) 2012 Anciat Prodz & TNSP", "PENIS.");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
642 if (!dmArgsProcess(argc, argv, optList, optListN,
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
643 argHandleOpt, NULL, FALSE))
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
644 exit(1);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
645
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
646 dmPrint(0, "%s\n", dmProgDesc);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
647 dmPrint(0, "%s\n", dmProgAuthor);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
648 dmPrint(0, "TNSP PIERUPASKA engine 2012 'passeli professional' loading.\n");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
649
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
650 // Initialize resource subsystem
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
651 dmPrint(1, "Initializing resources subsystem.\n");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
652 if ((err = dmres_init("orvellys.dat", NULL, DRF_USE_PACK | DRF_PRELOAD_RES, engineClassifier)) != DMERR_OK)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
653 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
654 dmError("Could not initialize resource manager: %d, %s.\n", err, dmErrorStr(err));
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
655 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
656 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
657
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
658
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
659 // Initialize SDL components
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
660 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
661 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
662 dmError("Could not initialize SDL: %s\n", SDL_GetError());
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
663 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
664 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
665 initSDL = TRUE;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
666
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
667
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
668 // Initialize JSS
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
669 jssInit();
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
670
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
671 afmt.freq = 44100;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
672 afmt.format = AUDIO_S16SYS;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
673 afmt.channels = 2;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
674 afmt.samples = 16*1024;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
675
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
676 dmPrint(1, "Initializing miniJSS mixer with: %d, %d, %d\n",
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
677 JSS_AUDIO_S16, afmt.channels, afmt.freq);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
678
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
679 if ((dev = jvmInit(JSS_AUDIO_S16, afmt.channels, afmt.freq, JMIX_AUTO)) == NULL)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
680 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
681 dmError("jvmInit() returned NULL, voi perkele.\n");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
682 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
683 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
684
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
685 if ((plr = jmpInit(dev)) == NULL)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
686 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
687 dmError("jmpInit() returned NULL\n");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
688 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
689 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
690
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
691 // Initialize SDL audio
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
692 dmPrint(1, "Trying to init SDL audio with: %d, %d, %d\n",
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
693 afmt.format, afmt.channels, afmt.freq);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
694
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
695 afmt.callback = engineAudioCallback;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
696 afmt.userdata = (void *) dev;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
697
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
698 if (SDL_OpenAudio(&afmt, NULL) < 0)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
699 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
700 dmError("Couldn't open audio: %s\n", SDL_GetError());
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
701 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
702 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
703
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
704 // Initialize SDL video
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
705 dmPrint(1, "Initializing SDL video %d x %d x %dbpp - %08x flags\n",
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
706 optScrWidth, optScrHeight, 32, optVFlags);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
707
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
708 engine.screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 32, optVFlags);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
709 if (engine.screen == NULL)
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
710 {
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
711 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
712 goto error_exit;
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
713 }
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
714
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
715 SDL_ShowCursor(SDL_DISABLE);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
716 SDL_WM_SetCaption(dmProgDesc, dmProgName);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
717
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
718
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
719 // Load resources
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
720 err = engineLoadResources();
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
721 if (err != DMERR_OK)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
722 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
723 dmError("Error loading resources, %d: %s.\n",
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
724 err, dmErrorStr(err));
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
725 goto error_exit;
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
726 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
727
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
728 // Initialize effect stuff
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 dmPerlinInit();
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
730 SDL_Surface *nosfe[NOSFE_MAX - NOSFE_MIN + 1];
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
731 for (i = 0; i < NOSFE_MAX; i++)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
732 {
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
733 char fname[64];
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
734 snprintf(fname, sizeof(fname), "%08d.jpg", NOSFE_MIN + i);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
735 nosfe[i] = engineGetResImage(fname);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
736 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
737
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
738 for (i = 0; i < ncredits; i++)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
739 credits[i].img = engineGetResImage(credits[i].filename);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 SDL_Surface *bmap = SDL_CreateRGBSurface(SDL_SWSURFACE, QWIDTH, QHEIGHT, 8, 0, 0, 0, 0);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
743
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
744 // Initialize music player
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
745 jvmSetCallback(dev, jmpExec, plr);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
746 jmpSetModule(plr, engineGetResModule("krapula.xm"));
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
747 jmpPlayOrder(plr, 0);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
748 jvmSetGlobalVol(dev, 55);
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
749 SDL_PauseAudio(0);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 engine.startTime = SDL_GetTicks();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 while (!engine.exitFlag)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 while (SDL_PollEvent(&engine.event))
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 switch (engine.event.type)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759 case SDL_KEYDOWN:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 switch (engine.event.key.keysym.sym)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 case SDLK_ESCAPE:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 engine.exitFlag = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766 case SDLK_SPACE:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 engine.pauseFlag = !engine.pauseFlag;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 default:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 case SDL_VIDEOEXPOSE:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 case SDL_QUIT:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 engine.exitFlag = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784 // Draw frame
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 frame.startTime = SDL_GetTicks();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 dmError("Can't lock surface.\n");
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 goto error_exit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 float t = engineGetTimeDT();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 if (t < 5)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
797 SDL_Surface *anciat;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 int dt = engineGetTime(0);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 static DMLerpContext lerpX, lerpY, lerpD;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 static DMScaledBlitFunc nblit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 DMVector light;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 static BOOL nollattu = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803 if (!nollattu)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
805 anciat = engineGetResImage("anciat.png");
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 nblit = dmGetScaledBlitFunc(bmap->format, engine.screen->format, DMD_NONE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 dmMakePalette(bmap);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 dmLerpInit(&lerpX, 0, QWIDTH, 5000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 dmLerpInit(&lerpY, QHEIGHT * 0.25, QHEIGHT * 0.75, 5000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 dmLerpInit(&lerpD, 0.04, 0.08, 5000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 nollattu = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 light.x = dmLerpSCurve(&lerpX, dt);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 light.y = dmLerp1(&lerpY, dt);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 light.z = 128;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 dmShadowTraceHeightMap2(bmap->pixels, anciat->pixels, &light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 nblit(bmap, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 if (t < 10)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
824 SDL_Surface *logobg, *logolayer1, *logolayer2;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825 int dt = engineGetTime(5);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 static DMScaledBlitFunc nblit, kblit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827 static DMLerpContext lerpD;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 static BOOL nollattu = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 if (!nollattu)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
832 logobg = engineGetResImage("logobg.png");
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
833 logolayer1 = engineGetResImage("logolayer1.png");
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
834 logolayer2 = engineGetResImage("logolayer2.png");
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
835
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 nblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_NONE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 dmLerpInit(&lerpD, 0.01, 500, 10000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 nollattu = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 float q = dmLerpSCurve(&lerpD, dt);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 float t = sin((float) dt / 150.0f);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 int x = t * 25.0f + q, y = t * 35.0f + q*2.0f,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 w = t * 70.0f + q, h = t * 40.0f + q*2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
846
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847 float t2 = sin((float) dt / 150.0f + 0.2f);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848 int x2 = t2 * 25.0f + q, y2 = t * 35.0f + q*2.0f,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 w2 = t2 * 70.0f + q, h2 = t * 40.0f + q*2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851 kblit(logobg, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 nblit(logolayer1, -x, -y, engine.screen->w+w, engine.screen->h+h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 nblit(logolayer2, -x2, -y2, engine.screen->w+w2, engine.screen->h+h2, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 if (t < 20)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
858 SDL_Surface *gay, *logobg;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 int dt = engineGetTime(10);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 static DMLerpContext lerpX, lerpY, lerpD;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 static DMScaledBlitFunc nblit, kblit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 static BOOL nollattu = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863 DMVector light;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 DMBlockMap heightMap;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866 if (!nollattu)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
868 gay = engineGetResImage("gay.png");
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
869 logobg = engineGetResImage("logobg.png");
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 nblit = dmGetScaledBlitFunc(bmap->format, engine.screen->format, DMD_NONE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872 dmMakePalette(bmap);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
873 dmLerpInit(&lerpX, QWIDTH, 0, 10000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 dmLerpInit(&lerpY, QHEIGHT * 0.25, QHEIGHT * 0.75, 10000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
875 dmLerpInit(&lerpD, 0.04, 0.08, 10000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 nollattu = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
878
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
879 light.x = dmLerpSCurve(&lerpX, dt);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880 light.y = QHEIGHT * 0.5 + sin(dmLerp1(&lerpY, dt)) * 0.5;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
881 light.z = 128;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
883 dmMakeBumpMap(heightMap, dmLerpSCurve(&lerpD, dt), 254);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
884
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
885 dmShadowTraceHeightMap(bmap->pixels, heightMap, &light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
887 nblit(bmap, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
888
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
889 if ((dt / 100) % 10 < 5)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
890 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
891 kblit(gay, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
892 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
893 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
894 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 if (t < 45)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
896 {
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
897 static SDL_Surface *ruutu;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
898 static int currState, currCredit, creditStartTime;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
899 static DMLerpContext lerpX, lerpY, lerpZ;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900 static DMScaledBlitFunc nblit, kblit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901 static BOOL stateChange, nollattu = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 int currFrame = engineGetTime(20) * 15 / 1000;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
903 if (!nollattu)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
904 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
905 ruutu = engineGetResImage("ruutu.png");
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
906 dmClearSurface(ruutu, dmMapRGBA(ruutu, 0,0,0,0));
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907 nblit = dmGetScaledBlitFunc(nosfe[0]->format, engine.screen->format, DMD_NONE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
908 kblit = dmGetScaledBlitFunc(credits[0].img->format, engine.screen->format, DMD_TRANSPARENT);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
909 currCredit = -1;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
910 currState = -1;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
911 stateChange = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 nollattu = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
913 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
914
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
915 float gt = 1.0f + sin(engineGetTime(0) / 250.0f);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
916 int g1 = gt * 25.0f, g2 = gt * 50.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
918 nblit(nosfe[currFrame % NOSFE_MAX], -g1, -g1, engine.screen->w+g2, engine.screen->h+g2, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920 if (t >= 30)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
921 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 int qtime = engineGetTime(30);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 int creditTime = (engineGetTime(0) - creditStartTime);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
924 float zscale;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
925 if ( ( (qtime / (CREDITS_SPEED + 500)) % 2) == 0 && currState == -1)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
926 stateChange = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 if (stateChange && currCredit < ncredits)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930 // fprintf(stderr, "[%6d] stateChange: st=%d, credit=%d\n", creditTime, currState, currCredit);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 stateChange = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 switch (currState)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 case 0:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
935 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936 int qt = (qtime / 100) % nrandomCoords;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 creditStartTime = engineGetTime(0);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
938 creditTime = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
939 dmLerpInit(&lerpX, randomCoords[qt].x, credits[currCredit].x - 50, CREDITS_SPEED);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
940 dmLerpInit(&lerpY, randomCoords[qt].y, credits[currCredit].y - 50, CREDITS_SPEED);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
941 dmLerpInit(&lerpZ, 5.0f, 0.0f, CREDITS_SPEED);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
942 currState = 1;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
943 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
945
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
946 case 2:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
947 if (creditTime >= CREDITS_SPEED)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 creditTime = CREDITS_SPEED - 1;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 zscale = dmLerpSCurve(&lerpZ, creditTime);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
951 dmScaledBlitSurface32to32TransparentX(
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952 credits[currCredit].img,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953 dmLerpSCurve(&lerpX, creditTime) - (zscale * credits[currCredit].img->w),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
954 dmLerpSCurve(&lerpY, creditTime) - (zscale * credits[currCredit].img->h),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 credits[currCredit].img->w * (1.0f + zscale),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956 credits[currCredit].img->h * (1.0f + zscale),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 ruutu);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
959 currState = -1;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
960 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
961
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
962 default:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
963 currCredit++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
964 currState = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
965 stateChange = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
966 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
967 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
968
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969 // fprintf(stderr, "[%6d] changed: st=%d, credit=%d, chg=%d\n", creditTime, currState, currCredit, stateChange);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
971
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
972
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
973 if (currCredit > 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
974 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
975 kblit(ruutu, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
977
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
978 if (currState == 1)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
980 if (creditTime >= CREDITS_SPEED)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
981 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
982 creditTime = CREDITS_SPEED;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983 stateChange = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 currState = 2;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
987 zscale = dmLerpSCurve(&lerpZ, creditTime);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988 kblit(credits[currCredit].img,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 dmLerpSCurve(&lerpX, creditTime) - (zscale * credits[currCredit].img->w),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990 dmLerpSCurve(&lerpY, creditTime) - (zscale * credits[currCredit].img->h),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 credits[currCredit].img->w * (1.0f + zscale),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 credits[currCredit].img->h * (1.0f + zscale),
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993 engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
995 }
14
b2b506e1f42a Add nice headache white fade synced to beat.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
996
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
999 if (t < 60)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
1001 SDL_Surface *logobg, *greets;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002 int dt = engineGetTime(45);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1003 static DMScaledBlitFunc nblit, kblit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004 static DMLerpContext lerpD;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1005 static BOOL nollattu = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1007 if (!nollattu)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 {
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
1009 logobg = engineGetResImage("logobg.png");
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
1010 greets = engineGetResImage("greetings.png");
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1011 nblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1012 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_NONE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1013 dmLerpInit(&lerpD, 0.01, 500, 10000);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1014 nollattu = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1015 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1017 float q = dmLerpSCurve(&lerpD, dt);
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1018 float t = sin((float) dt / 150.0f),
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1019 j = (1.0 + t) * 15;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1020 int x = t * 25.0f + q, y = t * 35.0f + q,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021 w = t * 70.0f + q*2.0f, h = t * 40.0f + q*2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1022
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1023 kblit(logobg, -j, -j, engine.screen->w+j*2.0f, engine.screen->h+j*2.0f, engine.screen);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1024 nblit(greets, -x, -y, engine.screen->w+w, engine.screen->h+h, engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1025 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1026 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 engine.exitFlag = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1029 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1030 static SDL_Surface *feidi;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1031 static int fadeStartTime;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1032 static BOOL fadeActive, nollattu = FALSE;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1033 static DMLerpContext fadeLerp;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1034 BOOL hit;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1035 int ch;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1036
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1037 if (!nollattu)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1038 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1039 feidi = engineGetResImage("feidi.png");
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1040 dmLerpInit(&fadeLerp, 255, 0, 250);
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1041 nollattu = TRUE;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1042 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1043
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1044 JSS_LOCK(plr);
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1045 for (hit = FALSE, ch = 0; ch < 6; ch++)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1046 if (plr->iCExtInstrumentN[ch] == 0)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1047 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1048 hit = TRUE;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1049 break;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1050 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1051 JSS_UNLOCK(plr);
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1052
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1053 if (hit && !fadeActive)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1054 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1055 fadeActive = TRUE;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1056 fadeStartTime = engineGetTime(0);
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1057 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1058 if (fadeActive)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1059 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1060 int fadeTime = engineGetTime(0) - fadeStartTime;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1061 if (fadeTime < 250)
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1062 {
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1063 dmScaledBlitSurface32to32TransparentGA(feidi,
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1064 0, 0, engine.screen->w, engine.screen->h, engine.screen,
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1065 dmLerpSCurve(&fadeLerp, fadeTime));
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1066 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1067 else
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1068 fadeActive = FALSE;
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1069 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1070 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
1071
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1072 // Flip screen
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 if (SDL_MUSTLOCK(engine.screen) != 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 SDL_UnlockSurface(engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 SDL_Flip(engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077 SDL_Delay(20);
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
1078
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
1079 // Get frame time, etc
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1080 frame.endTime = SDL_GetTicks();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1081 engine.currFrame++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1082 engine.totalFrameTime += frame.endTime - frame.startTime;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1083 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1084
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1085 // Print benchmark results
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1086 engine.endTime = SDL_GetTicks();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1087 dmMsg(0, "%d frames in %d ms, fps = %1.3f\n",
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1088 engine.currFrame, engine.endTime - engine.startTime,
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1089 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1090
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1091
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1092 error_exit:
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1093 dmMsg(0, "Shutting down.\n");
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094 SDL_ShowCursor(SDL_ENABLE);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1095 SDL_PauseAudio(1);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1096
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1097 if (engine.screen)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1098 SDL_FreeSurface(engine.screen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1099
7
2ff53bcfe366 Try to make sure that the audio shutdown does not hang.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1100 SDL_LockAudio();
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1101 jmpClose(plr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1102 jvmClose(dev);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1103 jssFreeModule(mod);
16
833dad075e3b Close JSS.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
1104 jssClose();
7
2ff53bcfe366 Try to make sure that the audio shutdown does not hang.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1105 SDL_UnlockAudio();
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1106
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1107 dmres_close();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1108
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109 if (initSDL)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1110 SDL_Quit();
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1111
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1112 dmPrint(0, "SDL on muuten melko paska kirjasto.\n");
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1113
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1114 return 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115 }