TagIncludedValue operator +(TagIncludedValue rhs) const { switch (this->type()) { case TYPE_FIXNUM: switch (rhs.type()) { case TYPE_FIXNUM: { fixint_t l = fix2int(this->u.iv); fixint_t r = fix2int(rhs.u.iv); r = l + r; return from_int(r); } break; case TYPE_FLOAT: { double lv = fix2int(this->u.iv); Object *ro = rhs.u.obj; return from_float(lv + ro->u.fv); } break; default: abort(); } break; case TYPE_FLOAT: { Object *lo = this->u.obj; switch (rhs.type()) { case TYPE_FIXNUM: { /* fl + fi */ fixint_t r = fix2int(rhs.u.iv); double a = lo->u.fv + r; return from_float(a); } break; case TYPE_FLOAT: { Object *ro = rhs.u.obj; /* fl + fl */ return from_float(lo->u.fv + ro->u.fv); } break; default: abort(); // ?? break; } } break; default: abort(); // ?? } abort(); // ?? }
/* raster callback (virtual HBLANK) */ static void raster_callback (int line) { int pos =- 1; RGB color; if (line==1) pos = pos_background[0]; else if (line==32) pos = pos_background[1]; else if (line==48) pos = pos_background[2]; else if (line==64) pos = pos_background[3]; else if (line==112) pos = pos_background[4]; else if (line >= 152) pos = lerp (line, 152,224, pos_background[4], pos_background[5]); if (pos != -1) TLN_SetLayerPosition (LAYER_BACKGROUND, fix2int(pos), 0); /* background color gradients */ if (line < 112) { InterpolateColor (line, 0,112, &sky[0], &sky[1], &color); TLN_SetBGColor (color.r, color.g, color.b); } else if (line >= 144) { InterpolateColor (line, 144,HEIGHT, &sky[2], &sky[3], &color); TLN_SetBGColor (color.r, color.g, color.b); } }
/* entry point */ int main (int argc, char *argv[]) { int c; int pitch, size; BYTE* framebuffer; DWORD t0, t1; /* setup engine */ TLN_Init (WIDTH,HEIGHT, MAX_LAYER, 0, 1); TLN_SetRasterCallback (raster_callback); TLN_SetBGColor (0,128,238); /* load resources*/ LoadLayer (LAYER_FOREGROUND, "Sonic_md_fg1"); LoadLayer (LAYER_BACKGROUND, "Sonic_md_bg1"); /* load sequences */ sp = TLN_LoadSequencePack ("Sonic_md_seq.sqx"); sequence = TLN_FindSequence (sp, "seq_water"); /* assign color sequence to various entries in palette */ palette = TLN_GetTilesetPalette (layers[LAYER_BACKGROUND].tileset); TLN_SetPaletteAnimation (0, palette, sequence, false); /* compute increments for variable background scrolling speeds */ inc_background[0] = float2fix(0.562f); inc_background[1] = float2fix(0.437f); inc_background[2] = float2fix(0.375f); inc_background[3] = float2fix(0.625f); inc_background[4] = float2fix(1.0f); inc_background[5] = float2fix(2.0f); /* framebuffer */ pitch = WIDTH*4; size = pitch*HEIGHT; framebuffer = malloc (size); TLN_SetRenderTarget (framebuffer, pitch); /* main loop */ printf ("Rendering 5 seconds... "); speed = 1.0; t0 = t1 = TLN_GetTicks (); while (t1 - t0 < 5000) { /* timekeeper */ time = frame; /* scroll */ pos_foreground += (int2fix(3)*speed); TLN_SetLayerPosition (LAYER_FOREGROUND, fix2int(pos_foreground), ypos); for (c=0; c<6; c++) pos_background[c] += (inc_background[c] * speed); /* render to window */ TLN_UpdateFrame (time); frame++; t1 = TLN_GetTicks (); } printf ("%d fps\n", frame*1000/(t1 - t0)); /* deinit */ free (framebuffer); FreeLayer (LAYER_FOREGROUND); FreeLayer (LAYER_BACKGROUND); TLN_DeleteSequencePack (sp); TLN_Deinit (); return 0; }