annotate krapula.c @ 26:077d08c442f7

Update to match latest engine changes.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Oct 2012 10:15:06 +0300
parents 98dcf1847e75
children 8af550785710
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
1 #include "dmsimple.h"
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmvecmat.h"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include <math.h>
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
5
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
6 DMOptArg optList[] =
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 { 0, '?', "help", "Show this help", OPT_NONE },
22
af6fad875a28 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
9 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
af6fad875a28 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
10 { 2, 'f', "fs", "Fullscreen", OPT_NONE },
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
11 #ifdef DM_DEBUG
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
12 { 3, 'd', "debug", "Debug mode", OPT_NONE },
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
13 #endif
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 };
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 const int optListN = sizeof(optList) / sizeof(optList[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 void argShowHelp()
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 dmPrintBanner(stdout, dmProgName, "[options]");
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 dmArgsPrintHelp(stdout, optList, optListN);
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 {
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
29 (void) optArg;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
30
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
31 switch (optN)
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
32 {
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
33 case 0:
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
34 argShowHelp();
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
35 exit(0);
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
36 break;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
38 case 1:
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
39 dmVerbosity++;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
40 break;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
41
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
42 case 2:
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
43 engine.optVFlags |= SDL_FULLSCREEN;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
44 break;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
46 #ifdef DM_DEBUG
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
47 case 3:
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
48 engine.optDebug = TRUE;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
49 break;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
50 #endif
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
51
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
52 default:
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
53 dmError("Unknown option '%s'.\n", currArg);
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
54 return FALSE;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 return TRUE;
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
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
61 #define DM_COLORS (256)
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
62
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 void dmMakePalette(SDL_Surface *scr)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 SDL_Color pal[DM_COLORS];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 int n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 for (n = 0; n < 256; n++)
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 pal[n].r = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 pal[n].g = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 pal[n].b = n;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 SDL_SetColors(scr, pal, 0, DM_COLORS);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
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 void dmRandom(SDL_Surface *screen, int q)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 Uint8 *pix = screen->pixels;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 int xc, yc;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 for (yc = 0; yc < screen->h; yc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 Uint8 *dp = pix;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 for (xc = 0; xc < screen->w; xc++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 *dp++ = yc + (xc ^ q) + (yc & q);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 pix += screen->pitch;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 #define QWIDTH 256
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 #define QHEIGHT 160
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 typedef Uint8 DMBlockMap[QHEIGHT][QWIDTH];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
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 static DMFloat dmClip(DMFloat a)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a));
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
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 void dmMakeBumpMap(DMBlockMap map, DMFloat q, DMFloat m)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 int x, y;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 for (y = 0; y < QHEIGHT; y++)
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
112 {
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 for (x = 0; x < QWIDTH; x++)
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 DMFloat f = 0.40f + dmPerlinNoise2D(x, y, 1.1f, q, 2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 map[y][x] = (int) (dmClip(f) * m);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
118 }
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
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 void dmShadowTraceHeightMap(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light)
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 int i, j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 for (j = 0; j < QHEIGHT; j++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 for (i = 0; i < QWIDTH; i++)
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 DMVector vr, vl, va;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 DMFloat vrayLen, vfactor;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 int vlen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 BOOL wasHit;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 /* Perform shadow occlusion via simplistic raytracing */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 vr.x = i;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 vr.y = j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 vr.z = light->z; // - 10.0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 // vr.z = pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 /* Calculate light vector vector */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 dm_vector_sub_r(&vl, &vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 vrayLen = dm_vector_length(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 dm_vector_copy(&va, &vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 dm_vector_normalize(&va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 dm_vector_scale(&va, 0.6f);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 dm_vector_copy(&vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 vlen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 wasHit = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 do
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 float h;
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 /* If ray is inside the heightmap, get value */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 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
158 h = pheightMap[(int) vr.y][(int) vr.x];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 break;
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 /* Check for hits */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 if (h > vr.z)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 wasHit = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 /* Move forwards */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 dm_vector_add(&vr, &va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 vlen++;
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 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 while (!wasHit && vlen <= vrayLen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 /* Check if the ray hit something, e.g. is this point occluded? */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 if (wasHit && vlen < vrayLen)
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 vfactor = vlen * 0.01;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 vfactor = vlen * 0.02;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 #endif
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 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 /* Calculate light's intensity based on the angle it "hits"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 *
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 * 1) Calculate the vectors that form the imaginary "plane"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 * 2) Cross-product -> normal vector of the plane
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 * 2) Normalize the normal vector
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 * 3) Calculate light vector's hit angle by dot product
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 DMVector v1, v2;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 DMFloat c;
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 v1.x = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 v1.y = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 v1.z = (DMFloat) (pheightMap[j][i] - pheightMap[j][i + 1]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 v2.x = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 v2.y = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 v2.z = (DMFloat) (pheightMap[j][i] - pheightMap[j + 1][i]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 dm_vector_cross(&vr, &v1, &v2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 dm_vector_normalize(&vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 dm_vector_normalize(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 c = dm_vector_dot(&vl, &vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 vrayLen = 255 - (vrayLen * 0.1) * vrayLen + (c * 128.0f) + (vfactor * vfactor * 1255);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 #else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 vrayLen = 255 - vrayLen * vrayLen * (vfactor * vfactor);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 if (vrayLen < 0) vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 vrayLen += pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 #endif
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 /* Clip result */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 if (vrayLen < 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 else if (vrayLen > 255.0f)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 vrayLen = 255.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 lightMap[j][i] = vrayLen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 void dmShadowTraceHeightMap2(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light)
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 int i, j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 light->z = 150;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 for (j = 0; j < QHEIGHT; j++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 for (i = 0; i < QWIDTH; i++)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 DMVector vr, vl, va;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 DMFloat vrayLen, vfactor;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 int vlen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 BOOL wasHit;
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 /* Perform shadow occlusion via simplistic raytracing */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 vr.x = i;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 vr.y = j;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 vr.z = 200; //light->z; // - 10.0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 /* Calculate light vector vector */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 dm_vector_sub_r(&vl, &vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 vrayLen = dm_vector_length(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 #if 1
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 dm_vector_copy(&va, &vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 dm_vector_normalize(&va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 dm_vector_copy(&vr, light);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 vlen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 wasHit = FALSE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 do
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 float h;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 /* If ray is inside the heightmap, get value */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 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
263 h = pheightMap[(int) vr.y][(int) vr.x];
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 break;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 /* Check for hits */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 if (h > vr.z)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 wasHit = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 else
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 /* Move forwards */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 dm_vector_add(&vr, &va);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 vlen++;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
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 while (!wasHit && vlen <= vrayLen);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 /* Check if the ray hit something, e.g. is this point occluded? */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 if (wasHit && vlen < vrayLen)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 vfactor = vlen * 0.05;
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 else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 vfactor = vlen * 0.001;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 #endif
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 #if 0
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 {
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 /* Calculate light's intensity based on the angle it "hits"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 *
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 * 1) Calculate the vectors that form the imaginary "plane"
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 * 2) Cross-product -> normal vector of the plane
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 * 2) Normalize the normal vector
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 * 3) Calculate light vector's hit angle by dot product
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 DMVector v1, v2;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 DMFloat c;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 v1.x = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 v1.y = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 v1.z = (DMFloat) (pheightMap[j][i] - pheightMap[j][i + 1]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 v2.x = 0.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 v2.y = 2.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 v2.z = (DMFloat) (pheightMap[j][i] - pheightMap[j + 1][i]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 dm_vector_cross(&vr, &v1, &v2);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 dm_vector_normalize(&vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 dm_vector_normalize(&vl);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 c = dm_vector_dot(&vl, &vr);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 vrayLen = 255 - (vrayLen * 0.1) * vrayLen + (c * 128.0f) + (vfactor * vfactor * 1255);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 #else
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 vrayLen = 255 - vrayLen * vrayLen * (vfactor * vfactor);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 if (vrayLen < 0) vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 vrayLen -= pheightMap[j][i];
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 #endif
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 /* Clip result */
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 if (vrayLen < 0)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 vrayLen = 0;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 else if (vrayLen > 255.0f)
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 vrayLen = 255.0f;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 lightMap[j][i] = vrayLen;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 }
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 #define CREDITS_SPEED 1000
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 #define CREDITS_RAND 4
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
335 typedef struct
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
336 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
337 int x, y;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
338 } DMCoords;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
339
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
340
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
341 typedef struct
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
342 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
343 int x, y;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
344 char *filename;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
345 SDL_Surface *img;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
346 } DMCredits;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
347
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
348
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 static const DMCoords randomCoords[] =
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 { -300, -430 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 { 700, -550 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 { -200, 600 },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 { 700, 600 }
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 const int nrandomCoords = sizeof(randomCoords) / sizeof(randomCoords[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 static DMCredits credits[] =
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 { 91, 223, "g4014.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 { 151, 250, "g4026.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 { 217, 227, "g4020.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 { 173, 268, "g4032.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 { 115, 359, "g4038.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 { 437, 130, "g4062.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 { 457, 102, "g4068.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 { 450, 210, "g4056.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 { 420, 320, "g4044.png", NULL },
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 { 486, 381, "g4050.png", NULL },
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
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 const int ncredits = sizeof(credits) / sizeof(credits[0]);
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
379 #define NOSFE_MIN 1
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
380 #define NOSFE_MAX 269
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
382 SDL_Surface *bmap;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
383 SDL_Surface *nosfe[NOSFE_MAX - NOSFE_MIN + 1];
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
384
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
385
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
386 int demoPreInit(int argc, char *argv[])
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
387 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
388 dmInitProg("krapula", "Lauantai Aamun Krapula", "0.2", "(c) 2012 Anciat Prodz & TNSP", "PENIS.");
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
389
26
077d08c442f7 Update to match latest engine changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
390 engine.optPackFilename = "orvellys.dat";
077d08c442f7 Update to match latest engine changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
391 engine.optDataPath = NULL;
077d08c442f7 Update to match latest engine changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
392 engine.optResFlags = DRF_USE_PACK | DRF_PRELOAD_RES;
077d08c442f7 Update to match latest engine changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
393
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
394 engine.optScrWidth = 640;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
395 engine.optScrHeight = 480;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
396 engine.optBitDepth = 32;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
397 engine.optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
398 #ifdef DM_DEBUG
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
399 engine.demoDuration = 150;
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
400 #endif
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
402 if (!dmArgsProcess(argc, argv, optList, optListN,
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
403 argHandleOpt, NULL, FALSE))
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
404 return DMERR_INIT_FAIL;
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
405
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
406 dmPrint(0, "%s\n", dmProgDesc);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
407 dmPrint(0, "%s\n", dmProgAuthor);
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
408 dmPrint(0, "TNSP PIERUPASKA engine 2012 'passeli professional' loading.\n");
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
409
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
410 return DMERR_OK;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
411 }
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
412
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
413
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
414 int demoInit()
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
415 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
416 int i;
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
417
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
418 // Initialize effect stuff
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 dmPerlinInit();
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
420
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
421 for (i = 0; i < NOSFE_MAX; i++)
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
422 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
423 char fname[32];
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
424 snprintf(fname, sizeof(fname), "%08d.jpg", NOSFE_MIN + i);
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
425 engineGetResImage(nosfe[i], fname);
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
426 }
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
427
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
428 for (i = 0; i < ncredits; i++)
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
429 engineGetResImage(credits[i].img, credits[i].filename);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
431 bmap = SDL_CreateRGBSurface(SDL_SWSURFACE, QWIDTH, QHEIGHT, 8, 0, 0, 0, 0);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
17
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
433
758a39d3f750 Various "engine" cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
434 // Initialize music player
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
435 JSSModule *mod = NULL;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
436 engineGetResModule(mod, "krapula.xm");
24
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
437
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
438 if ((i = jssConvertModuleForPlaying(mod)) != DMERR_OK)
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
439 {
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
440 dmError("Could not convert module for playing, %d: %s\n",
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
441 i, dmErrorStr(i));
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
442 return DMERR_INIT_FAIL;
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
443 }
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
444
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
445 jvmSetCallback(engine.dev, jmpExec, engine.plr);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
446 jmpSetModule(engine.plr, mod);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
447 jmpPlayOrder(engine.plr, 0);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
448 jvmSetGlobalVol(engine.dev, 55);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
450 return DMERR_OK;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
451 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
452
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
25
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
454 void demoShutdown()
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
455 {
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
456 SDL_FreeSurface(bmap);
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
457 }
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
458
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
459
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
460 void demoQuit()
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
461 {
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
462 dmPrint(0, "Krapulassa on kivaa.\n");
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
463 }
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
464
98dcf1847e75 Cleanups, add the debug mode enabling option.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
465
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
466 int demoMainTick()
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
467 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
468 float t = engineGetTimeDT();
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
470 if (t < 5)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
472 int dt = engineGetTime(0);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
473 static SDL_Surface *anciat;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
474 static DMLerpContext lerpX, lerpY, lerpD;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
475 static DMScaledBlitFunc nblit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
476 DMVector light;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
477 static BOOL nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
478 if (!nollattu)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
480 engineGetResImage(anciat, "anciat.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
481 nblit = dmGetScaledBlitFunc(bmap->format, engine.screen->format, DMD_NONE);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
482 dmMakePalette(bmap);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
483 dmLerpInit(&lerpX, 0, QWIDTH, 5000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
484 dmLerpInit(&lerpY, QHEIGHT * 0.25, QHEIGHT * 0.75, 5000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
485 dmLerpInit(&lerpD, 0.04, 0.08, 5000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
486 nollattu = TRUE;
2
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
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
489 light.x = dmLerpSCurve(&lerpX, dt);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
490 light.y = dmLerp1(&lerpY, dt);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
491 light.z = 128;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
493 dmShadowTraceHeightMap2(bmap->pixels, anciat->pixels, &light);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
494 nblit(bmap, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
495 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
496 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
497 if (t < 10)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
498 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
499 int dt = engineGetTime(5);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
500 static SDL_Surface *logobg, *logolayer1, *logolayer2;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
501 static DMScaledBlitFunc nblit, kblit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
502 static DMLerpContext lerpD;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
503 static BOOL nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
504
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
505 if (!nollattu)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
507 engineGetResImage(logobg, "logobg.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
508 engineGetResImage(logolayer1, "logolayer1.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
509 engineGetResImage(logolayer2, "logolayer2.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
510
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
511 nblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
512 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_NONE);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
513 dmLerpInit(&lerpD, 0.01, 500, 10000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
514 nollattu = TRUE;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
517 float q = dmLerpSCurve(&lerpD, dt);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
518 float t = sin((float) dt / 150.0f);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
519 int x = t * 25.0f + q, y = t * 35.0f + q*2.0f,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
520 w = t * 70.0f + q, h = t * 40.0f + q*2.0f;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
522 float t2 = sin((float) dt / 150.0f + 0.2f);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
523 int x2 = t2 * 25.0f + q, y2 = t * 35.0f + q*2.0f,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
524 w2 = t2 * 70.0f + q, h2 = t * 40.0f + q*2.0f;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
526 kblit(logobg, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
527 nblit(logolayer1, -x, -y, engine.screen->w+w, engine.screen->h+h, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
528 nblit(logolayer2, -x2, -y2, engine.screen->w+w2, engine.screen->h+h2, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
529 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
530 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
531 if (t < 20)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
532 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
533 int dt = engineGetTime(10);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
534 static SDL_Surface *gay, *logobg;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
535 static DMLerpContext lerpX, lerpY, lerpD;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
536 static DMScaledBlitFunc nblit, kblit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
537 static BOOL nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
538 DMVector light;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
539 DMBlockMap heightMap;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
541 if (!nollattu)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
542 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
543 engineGetResImage(gay, "gay.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
544 engineGetResImage(logobg, "logobg.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
545 nblit = dmGetScaledBlitFunc(bmap->format, engine.screen->format, DMD_NONE);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
546 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
547 dmMakePalette(bmap);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
548 dmLerpInit(&lerpX, QWIDTH, 0, 10000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
549 dmLerpInit(&lerpY, QHEIGHT * 0.25, QHEIGHT * 0.75, 10000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
550 dmLerpInit(&lerpD, 0.04, 0.08, 10000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
551 nollattu = TRUE;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
554 light.x = dmLerpSCurve(&lerpX, dt);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
555 light.y = QHEIGHT * 0.5 + sin(dmLerp1(&lerpY, dt)) * 0.5;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
556 light.z = 128;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
557
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
558 dmMakeBumpMap(heightMap, dmLerpSCurve(&lerpD, dt), 254);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
560 dmShadowTraceHeightMap(bmap->pixels, heightMap, &light);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
562 nblit(bmap, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
564 if ((dt / 100) % 10 < 5)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
565 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
566 kblit(gay, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 }
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
568 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
569 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
570 if (t < 45)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
571 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
572 static SDL_Surface *ruutu;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
573 static int currState, currCredit, creditStartTime;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
574 static DMLerpContext lerpX, lerpY, lerpZ;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
575 static DMScaledBlitFunc nblit, kblit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
576 static BOOL stateChange, nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
577 int currFrame = engineGetTime(20) * 15 / 1000;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
578 if (!nollattu)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
580 engineGetResImage(ruutu, "ruutu.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
581 dmClearSurface(ruutu, dmMapRGBA(ruutu, 0,0,0,0));
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
582 nblit = dmGetScaledBlitFunc(nosfe[0]->format, engine.screen->format, DMD_NONE);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
583 kblit = dmGetScaledBlitFunc(credits[0].img->format, engine.screen->format, DMD_TRANSPARENT);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
584 currCredit = -1;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
585 currState = -1;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
586 stateChange = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
587 nollattu = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
588 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
589
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
590 float gt = 1.0f + sin(engineGetTime(0) / 250.0f);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
591 int g1 = gt * 25.0f, g2 = gt * 50.0f;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
592
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
593 nblit(nosfe[currFrame % NOSFE_MAX], -g1, -g1, engine.screen->w+g2, engine.screen->h+g2, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
594
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
595 if (t >= 30)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
596 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
597 int qtime = engineGetTime(30);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
598 int creditTime = (engineGetTime(0) - creditStartTime);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
599 float zscale;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
600 if ( ( (qtime / (CREDITS_SPEED + 500)) % 2) == 0 && currState == -1)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 stateChange = TRUE;
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
603 if (stateChange && currCredit < ncredits)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
605 stateChange = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
606 switch (currState)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
608 case 0:
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
609 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
610 int qt = (qtime / 100) % nrandomCoords;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
611 creditStartTime = engineGetTime(0);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
612 creditTime = 0;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
613 dmLerpInit(&lerpX, randomCoords[qt].x, credits[currCredit].x - 50, CREDITS_SPEED);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
614 dmLerpInit(&lerpY, randomCoords[qt].y, credits[currCredit].y - 50, CREDITS_SPEED);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
615 dmLerpInit(&lerpZ, 5.0f, 0.0f, CREDITS_SPEED);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
616 currState = 1;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
617 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
618 break;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
620 case 2:
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
621 if (creditTime >= CREDITS_SPEED)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
622 creditTime = CREDITS_SPEED - 1;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
624 zscale = dmLerpSCurve(&lerpZ, creditTime);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
625 dmScaledBlitSurface32to32TransparentX(
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
626 credits[currCredit].img,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
627 dmLerpSCurve(&lerpX, creditTime) - (zscale * credits[currCredit].img->w),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
628 dmLerpSCurve(&lerpY, creditTime) - (zscale * credits[currCredit].img->h),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
629 credits[currCredit].img->w * (1.0f + zscale),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
630 credits[currCredit].img->h * (1.0f + zscale),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
631 ruutu);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
633 currState = -1;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
634 break;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
635
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
636 default:
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
637 currCredit++;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
638 currState = 0;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 stateChange = TRUE;
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
640 break;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 }
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 }
14
b2b506e1f42a Add nice headache white fade synced to beat.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
643
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
645 if (currCredit > 0)
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
647 kblit(ruutu, 0, 0, engine.screen->w, engine.screen->h, engine.screen);
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
648 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
649
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
650 if (currState == 1)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
651 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
652 if (creditTime >= CREDITS_SPEED)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
653 {
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
654 creditTime = CREDITS_SPEED;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
655 stateChange = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
656 currState = 2;
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
657 }
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
658
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
659 zscale = dmLerpSCurve(&lerpZ, creditTime);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
660 kblit(credits[currCredit].img,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
661 dmLerpSCurve(&lerpX, creditTime) - (zscale * credits[currCredit].img->w),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
662 dmLerpSCurve(&lerpY, creditTime) - (zscale * credits[currCredit].img->h),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
663 credits[currCredit].img->w * (1.0f + zscale),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
664 credits[currCredit].img->h * (1.0f + zscale),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
665 engine.screen);
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
666 }
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
667 }
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
668
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
669 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
670 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
671 if (t < 60)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
672 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
673 int dt = engineGetTime(45);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
674 static SDL_Surface *logobg, *greets;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
675 static DMScaledBlitFunc nblit, kblit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
676 static DMLerpContext lerpD;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
677 static BOOL nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
678
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
679 if (!nollattu)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
680 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
681 engineGetResImage(logobg, "logobg.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
682 engineGetResImage(greets, "greetings.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
683 nblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_TRANSPARENT);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
684 kblit = dmGetScaledBlitFunc(logobg->format, engine.screen->format, DMD_NONE);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
685 dmLerpInit(&lerpD, 0.01, 500, 10000);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
686 nollattu = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
687 }
15
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
688
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
689 float q = dmLerpSCurve(&lerpD, dt);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
690 float t = sin((float) dt / 150.0f),
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
691 j = (1.0 + t) * 15;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
692 int x = t * 25.0f + q, y = t * 35.0f + q,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
693 w = t * 70.0f + q*2.0f, h = t * 40.0f + q*2.0f;
8
b3d6670c4324 Use new resource management system.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
694
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
695 kblit(logobg, -j, -j, engine.screen->w+j*2.0f, engine.screen->h+j*2.0f, engine.screen);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
696 nblit(greets, -x, -y, engine.screen->w+w, engine.screen->h+h, engine.screen);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 }
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
698 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
699 engine.exitFlag = TRUE;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
702 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
703 static SDL_Surface *feidi;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
704 static int fadeStartTime;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
705 static BOOL fadeActive, nollattu = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
706 static DMLerpContext fadeLerp;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
707 BOOL hit;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
708 int ch;
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
710 if (!nollattu)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
711 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
712 engineGetResImage(feidi, "feidi.png");
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
713 dmLerpInit(&fadeLerp, 255, 0, 250);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
714 nollattu = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
715 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
716
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
717 JSS_LOCK(engine.plr);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
718 for (hit = FALSE, ch = 0; ch < 6; ch++)
24
01f3af410abb Update to match changes in the dmlib API and JSS engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
719 if (engine.plr->channels[ch].iCExtInstrumentN == 0)
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
720 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
721 hit = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
722 break;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
723 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
724 JSS_UNLOCK(engine.plr);
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
726 if (hit && !fadeActive)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
727 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
728 fadeActive = TRUE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
729 fadeStartTime = engineGetTime(0);
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
730 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
731 if (fadeActive)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
732 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
733 int fadeTime = engineGetTime(0) - fadeStartTime;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
734 if (fadeTime < 250)
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
735 {
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
736 dmScaledBlitSurface32to32TransparentGA(feidi,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
737 0, 0, engine.screen->w, engine.screen->h, engine.screen,
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
738 dmLerpSCurve(&fadeLerp, fadeTime));
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
739 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
740 else
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
741 fadeActive = FALSE;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
742 }
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
743 }
2
9578b979556a Import main code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744
21
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
745 return DMERR_OK;
ea93b1d5c894 Use the dmsimple demo engine "framework".
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
746 }