projects
/
fbgfx
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3a148d9
)
better tunnel
author
John Tsiombikas
<nuclear@mutantstargoat.com>
Mon, 22 Aug 2016 04:31:31 +0000
(07:31 +0300)
committer
John Tsiombikas
<nuclear@mutantstargoat.com>
Mon, 22 Aug 2016 04:31:31 +0000
(07:31 +0300)
src/tunnel.c
patch
|
blob
|
history
diff --git
a/src/tunnel.c
b/src/tunnel.c
index
8dec902
..
c331f2d
100644
(file)
--- a/
src/tunnel.c
+++ b/
src/tunnel.c
@@
-7,23
+7,22
@@
#include "demo.h"
#include "screen.h"
#include "demo.h"
#include "screen.h"
+#define VSCALE 1.5
+
#define TEX_FNAME "data/grid.png"
#define TEX_USCALE 4
#define TEX_VSCALE 2
#define TEX_FNAME "data/grid.png"
#define TEX_USCALE 4
#define TEX_VSCALE 2
-#define USCALE 2
-#define VSCALE 1
-
static int init(void);
static void destroy(void);
static void start(long trans_time);
static void stop(long trans_time);
static void draw(void);
static int init(void);
static void destroy(void);
static void start(long trans_time);
static void stop(long trans_time);
static void draw(void);
-static void (*draw_tunnel_range)(void*, int, int, long);
+static void (*draw_tunnel_range)(void*, int, int, int, int, long);
-static void draw_tunnel_range16(void *pixels, int starty, int num_lines, long tm);
-static void draw_tunnel_range32(void *pixels, int starty, int num_lines, long tm);
+static void draw_tunnel_range16(void *pixels, int xoffs, int yoffs, int starty, int num_lines, long tm);
+static void draw_tunnel_range32(void *pixels, int xoffs, int yoffs, int starty, int num_lines, long tm);
static int count_bits(unsigned int x);
static int count_zeros(unsigned int x);
static int count_bits(unsigned int x);
static int count_zeros(unsigned int x);
@@
-37,6
+36,7
@@
static struct screen scr = {
};
static int xsz, ysz, vxsz, vysz;
};
static int xsz, ysz, vxsz, vysz;
+static int pan_width, pan_height;
static unsigned int *tunnel_map;
static unsigned char *tunnel_fog;
static unsigned int *tunnel_map;
static unsigned char *tunnel_fog;
@@
-76,10
+76,13
@@
static int init(void)
return -1;
}
return -1;
}
- xsz = fb_width;
+ xsz = fb_width / 2;
ysz = fb_height;
ysz = fb_height;
- vxsz = xsz / USCALE;
- vysz = ysz / VSCALE;
+ vxsz = xsz * VSCALE;
+ vysz = ysz * VSCALE;
+
+ pan_width = vxsz - xsz;
+ pan_height = vysz - ysz;
if(!(tunnel_map = malloc(vxsz * vysz * sizeof *tunnel_map))) {
fprintf(stderr, "failed to allocate tunnel map\n");
if(!(tunnel_map = malloc(vxsz * vysz * sizeof *tunnel_map))) {
fprintf(stderr, "failed to allocate tunnel map\n");
@@
-104,7
+107,7
@@
static int init(void)
int tx = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff;
int ty = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff;
int tx = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff;
int ty = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff;
- int f = (int)(d * 95.0);
+ int f = (int)(d * 128.0);
*tmap++ = (tx << 16) | ty;
*fog++ = f > 255 ? 255 : f;
*tmap++ = (tx << 16) | ty;
*fog++ = f > 255 ? 255 : f;
@@
-167,18
+170,21
@@
static struct work {
void *pixels;
int starty, num_lines;
long tm;
void *pixels;
int starty, num_lines;
long tm;
+ int xoffs, yoffs;
} work[NUM_WORK_ITEMS];
static void work_func(void *cls)
{
struct work *w = (struct work*)cls;
} work[NUM_WORK_ITEMS];
static void work_func(void *cls)
{
struct work *w = (struct work*)cls;
- draw_tunnel_range(w->pixels, w->starty, w->num_lines, w->tm);
+ draw_tunnel_range(w->pixels, w->xoffs, w->yoffs, w->starty, w->num_lines, w->tm);
}
static void draw(void)
{
}
static void draw(void)
{
- int i, num_lines = vysz / NUM_WORK_ITEMS;
+ int i, num_lines = ysz / NUM_WORK_ITEMS;
int draw_lines = num_lines;
int draw_lines = num_lines;
+ float t;
+ int xoffs, yoffs;
if(trans_dir) {
long interval = time_msec - trans_start;
if(trans_dir) {
long interval = time_msec - trans_start;
@@
-193,11
+199,17
@@
static void draw(void)
}
}
}
}
+ t = time_msec / 10000.0;
+ xoffs = (int)(cos(t * 3.0) * pan_width / 2) + pan_width / 2;
+ yoffs = (int)(sin(t * 4.0) * pan_height / 2) + pan_height / 2;
+
for(i=0; i<NUM_WORK_ITEMS; i++) {
work[i].pixels = fb_pixels;
work[i].starty = i * num_lines;
work[i].num_lines = draw_lines;
work[i].tm = time_msec;
for(i=0; i<NUM_WORK_ITEMS; i++) {
work[i].pixels = fb_pixels;
work[i].starty = i * num_lines;
work[i].num_lines = draw_lines;
work[i].tm = time_msec;
+ work[i].xoffs = xoffs;
+ work[i].yoffs = yoffs;
tpool_enqueue(tpool, work + i, work_func, 0);
}
tpool_enqueue(tpool, work + i, work_func, 0);
}
@@
-231,47
+243,51
@@
static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpa
#define PACK_RGB32(r, g, b) \
((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
#define PACK_RGB32(r, g, b) \
((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
-static void draw_tunnel_range16(void *pix, int starty, int num_lines, long tm)
+static void draw_tunnel_range16(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm)
{
int i, j;
{
int i, j;
- unsigned int *tmap = tunnel_map + starty * vxsz;
- unsigned char *fog = tunnel_fog + starty * vxsz;
+ unsigned int *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
+ unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs;
long toffs = tm / 4;
long toffs = tm / 4;
- unsigned int *pixels = (unsigned int*)pix + starty * (xsz >> 1);
+ unsigned int *pixels = (unsigned int*)pix + starty * (fb_width >> 1);
for(i=0; i<num_lines; i++) {
for(i=0; i<num_lines; i++) {
- for(j=0; j<vxsz; j++) {
+ for(j=0; j<xsz; j++) {
unsigned int col;
int r, g, b;
unsigned int col;
int r, g, b;
- tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
+ tunnel_color(&r, &g, &b, toffs, tmap[j], fog[j]);
col = PACK_RGB16(r, g, b);
*pixels++ = col;
}
col = PACK_RGB16(r, g, b);
*pixels++ = col;
}
+ tmap += vxsz;
+ fog += vxsz;
}
}
}
}
-static void draw_tunnel_range32(void *pix, int starty, int num_lines, long tm)
+static void draw_tunnel_range32(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm)
{
int i, j;
{
int i, j;
- unsigned int *tmap = tunnel_map + starty * vxsz;
- unsigned char *fog = tunnel_fog + starty * vxsz;
+ unsigned int *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs;
+ unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs;
long toffs = tm / 4;
long toffs = tm / 4;
- unsigned int *pixels = (unsigned int*)pix + starty * xsz * VSCALE;
+ unsigned int *pixels = (unsigned int*)pix + starty * fb_width;
for(i=0; i<num_lines; i++) {
for(i=0; i<num_lines; i++) {
- for(j=0; j<vxsz; j++) {
+ for(j=0; j<xsz; j++) {
unsigned int col;
int r, g, b;
unsigned int col;
int r, g, b;
- tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
+ tunnel_color(&r, &g, &b, toffs, tmap[j], fog[j]);
col = PACK_RGB32(r, g, b);
*pixels++ = col;
*pixels++ = col;
}
col = PACK_RGB32(r, g, b);
*pixels++ = col;
*pixels++ = col;
}
+ tmap += vxsz;
+ fog += vxsz;
}
}
}
}