#include <math.h>
#include <assert.h>
#include <imago2.h>
+#ifndef NO_THREADS
#include "tpool.h"
+#endif
#include "demo.h"
#include "screen.h"
draw
};
+struct tunmap {
+ int u, v;
+ unsigned char fog;
+};
+
static int xsz, ysz, vxsz, vysz;
static int pan_width, pan_height;
-static unsigned int *tunnel_map;
-static unsigned char *tunnel_fog;
+static struct tunmap *tunnel_map;
static int tex_xsz, tex_ysz;
static unsigned int *tex_pixels;
static int tex_xshift, tex_yshift;
static unsigned int tex_xmask, tex_ymask;
+#ifndef NO_THREADS
static struct thread_pool *tpool;
+#endif
static long trans_start, trans_dur;
static int trans_dir;
static int init(void)
{
int i, j, n;
- unsigned int *tmap;
- unsigned char *fog;
+ struct tunmap *tmap;
float aspect = (float)fb_width / (float)fb_height;
switch(fb_depth) {
fprintf(stderr, "failed to allocate tunnel map\n");
return -1;
}
- if(!(tunnel_fog = malloc(vxsz * vysz))) {
- fprintf(stderr, "failed to allocate tunnel fog map\n");
- return -1;
- }
tmap = tunnel_map;
- fog = tunnel_fog;
for(i=0; i<vysz; i++) {
float y = 2.0 * (float)i / (float)vysz - 1.0;
float d = sqrt(x * x + y * y);
float tv = d == 0.0 ? 0.0 : 1.0 / d;
- int tx = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff;
- int ty = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff;
-
- int f = (int)(d * 128.0);
+ int fog = (int)(d * 128.0f);
- *tmap++ = (tx << 16) | ty;
- *fog++ = f > 255 ? 255 : f;
+ tmap->u = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff;
+ tmap->v = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff;
+ tmap->fog = fog > 255 ? 255 : fog;
+ tmap++;
}
}
}
tex_yshift = n;
+#ifndef NO_THREADS
if(!(tpool = tpool_create(0))) {
fprintf(stderr, "failed to create thread pool\n");
return -1;
}
+#endif
/* initialize the constant part of all work items */
for(i=0; i<NUM_WORK_ITEMS; i++) {
static void destroy(void)
{
+#ifndef NO_THREADS
tpool_destroy(tpool);
+#endif
free(tunnel_map);
- free(tunnel_fog);
}
static void start(long trans_time)
work[i].xoffs = xoffs;
work[i].yoffs = yoffs;
+#ifdef NO_THREADS
+ work_func(work + i);
+ }
+#else
tpool_enqueue(tpool, work + i, work_func, 0);
}
tpool_wait(tpool);
+#endif
}
-static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpacked, int fog)
+static void tunnel_color(int *rp, int *gp, int *bp, long toffs, struct tunmap *tmap)
{
int r, g, b;
unsigned int col;
- unsigned int tx = (((tpacked >> 16) & 0xffff) << tex_xshift) >> 16;
- unsigned int ty = ((tpacked & 0xffff) << tex_yshift) >> 16;
+ unsigned int tx = (tmap->u << tex_xshift) >> 16;
+ unsigned int ty = (tmap->v << tex_yshift) >> 16;
tx += toffs;
ty += toffs << 1;
g = (col >> 8) & 0xff;
b = (col >> 16) & 0xff;
- *rp = (r * fog) >> 8;
- *gp = (g * fog) >> 8;
- *bp = (b * fog) >> 8;
+ *rp = (r * tmap->fog) >> 8;
+ *gp = (g * tmap->fog) >> 8;
+ *bp = (b * tmap->fog) >> 8;
}
#define PACK_RGB16(r, g, b) \
static void draw_tunnel_range16(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm)
{
int i, j;
- unsigned int *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
- unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs;
+ struct tunmap *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
long toffs = tm / 4;
unsigned int *pixels = (unsigned int*)pix + starty * (fb_width >> 1);
unsigned int col;
int r, g, b;
- tunnel_color(&r, &g, &b, toffs, tmap[j], fog[j]);
+ tunnel_color(&r, &g, &b, toffs, tmap + j);
col = PACK_RGB16(r, g, b);
*pixels++ = (col << 16) | col;
}
tmap += vxsz;
- fog += vxsz;
}
}
static void draw_tunnel_range32(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm)
{
int i, j;
- unsigned int *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
- unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs;
+ struct tunmap *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
long toffs = tm / 4;
unsigned int *pixels = (unsigned int*)pix + starty * fb_width;
unsigned int col;
int r, g, b;
- tunnel_color(&r, &g, &b, toffs, tmap[j], fog[j]);
+ tunnel_color(&r, &g, &b, toffs, tmap + j);
col = PACK_RGB32(r, g, b);
*pixels++ = col;
*pixels++ = col;
}
tmap += vxsz;
- fog += vxsz;
}
}