static void start(long trans_time);
static void stop(long trans_time);
static void draw(void);
+static float smoothstep(float a, float b, float x);
static struct screen scr = {
"console",
static void *saved_fb;
static int fbsize;
-static long trans_start, trans_dur;
+static long trans_start = -1, trans_dur;
+
+#define NBLOCKS 32
+#define MAX_DELAY 0.5
+static float delay[NBLOCKS];
+static int blksz;
struct screen *console_screen(void)
{
static int init(void)
{
+ int i;
fbsize = fb_width * fb_height * fb_depth / 8;
if(!(saved_fb = malloc(fbsize))) {
- perror("failed to allocate memory");
+ perror("failed to allocate console framebuffer");
return -1;
}
memcpy(saved_fb, fb_pixels, fbsize);
+
+ blksz = fb_height / NBLOCKS;
+
+ for(i=0; i<NBLOCKS; i++) {
+ delay[i] = (float)rand() / (float)RAND_MAX * MAX_DELAY;
+ }
+
return 0;
}
unsigned char *dptr = fb_pixels;
unsigned char *sptr = saved_fb;
- if(!trans_start) {
+ if(trans_start < 0) {
return;
}
- printf("console draw\n");
elapsed = time_msec - trans_start;
- offs = fb_width * elapsed / trans_dur;
- rem = fb_width - offs;
for(i=0; i<fb_height; i++) {
+ int bidx = i / blksz;
+ float t = (float)elapsed / (float)trans_dur;
+ offs = fb_width * smoothstep(0, 1.0 - delay[bidx], t - delay[bidx]);
+ if(offs < 0) offs = 0;
+ rem = fb_width - offs;
+
if(offs > 0) {
memset(dptr, 0, offs * pixsz);
}
sptr += fb_width * pixsz;
}
}
+
+static float smoothstep(float a, float b, float x)
+{
+ if(x < a) return 0.0;
+ if(x >= b) return 1.0;
+
+ x = (x - a) / (b - a);
+ return x * x * (3.0 - 2.0 * x);
+}
static void stop(long trans_time);
static void draw(void);
-static void (*draw_tunnel_range)(void*, int, int);
+static void (*draw_tunnel_range)(void*, int, int, long);
-static void draw_tunnel_range16(void *pixels, int starty, int num_lines);
-static void draw_tunnel_range32(void *pixels, int starty, int num_lines);
+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 int count_bits(unsigned int x);
static int count_zeros(unsigned int x);
static struct thread_pool *tpool;
+static long trans_start, trans_dur;
+static int trans_dir;
+
struct screen *tunnel_screen(void)
{
static void start(long trans_time)
{
+ trans_start = time_msec;
+ trans_dur = trans_time;
+ trans_dir = 1;
}
static void stop(long trans_time)
{
+ trans_start = time_msec;
+ trans_dur = trans_time;
+ trans_dir = -1;
}
#define NUM_WORK_ITEMS 32
static struct work {
void *pixels;
int starty, num_lines;
+ long tm;
} 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);
+ draw_tunnel_range(w->pixels, w->starty, w->num_lines, w->tm);
}
static void draw(void)
{
int i, num_lines = vysz / NUM_WORK_ITEMS;
+ int draw_lines = num_lines;
+
+ if(trans_dir) {
+ long interval = time_msec - trans_start;
+ int progr = num_lines * interval / trans_dur;
+ if(trans_dir < 0) {
+ draw_lines = num_lines - progr - 1;
+ } else {
+ draw_lines = progr;
+ }
+ if(progr >= num_lines) {
+ trans_dir = 0;
+ }
+ }
+
for(i=0; i<NUM_WORK_ITEMS; i++) {
work[i].pixels = fb_pixels;
work[i].starty = i * num_lines;
- work[i].num_lines = num_lines;
+ work[i].num_lines = draw_lines;
+ work[i].tm = time_msec;
tpool_enqueue(tpool, work + i, work_func, 0);
}
#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)
+static void draw_tunnel_range16(void *pix, int starty, int num_lines, long tm)
{
int i, j;
unsigned int *tmap = tunnel_map + starty * vxsz;
unsigned char *fog = tunnel_fog + starty * vxsz;
- long toffs = time_msec / 4;
+ long toffs = tm / 4;
unsigned int *pixels = (unsigned int*)pix + starty * (xsz >> 1);
for(i=0; i<num_lines; i++) {
}
}
-static void draw_tunnel_range32(void *pix, int starty, int num_lines)
+static void draw_tunnel_range32(void *pix, int starty, int num_lines, long tm)
{
int i, j;
unsigned int *tmap = tunnel_map + starty * vxsz;
unsigned char *fog = tunnel_fog + starty * vxsz;
- long toffs = time_msec / 4;
+ long toffs = tm / 4;
unsigned int *pixels = (unsigned int*)pix + starty * xsz * VSCALE;
for(i=0; i<num_lines; i++) {