From: Michael Georgoulopoulos Date: Tue, 4 Oct 2016 23:40:34 +0000 (+0300) Subject: Removed division in displacement inner loop X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=4eabd99a0c9a1de4c1e6bccdeec2d4b9a66e227a Removed division in displacement inner loop Stole Optimus' FPS counter as an extern --- diff --git a/src/grise.c b/src/grise.c index 543b51e..1a1cebf 100644 --- a/src/grise.c +++ b/src/grise.c @@ -26,6 +26,8 @@ static RLEBitmap *rleEncode(RLEBitmap *b, unsigned char *pixels, unsigned int w, static void updatePropeller(float t); +extern void drawFps(unsigned short *vram); + #define BG_FILENAME "data/grise.png" #define GROBJ_01_FILENAME "data/grobj_01.png" @@ -97,7 +99,6 @@ struct screen *grise_screen(void) return &scr; } - static int init(void) { unsigned char *tmpBitmap; @@ -167,6 +168,9 @@ static void draw(void) int i = 0; short *dispScanline; int d; + int accum = 0; + int md, sc; + int scrolledIndex; lastFrameDuration = (time_msec - lastFrameTime) / 1000.0f; lastFrameTime = time_msec; @@ -203,8 +207,19 @@ static void draw(void) src = dst + BB_SIZE; /* The pixels to be displaced are 1 scanline below */ dispScanline = displacementMap; for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) { + + md = scrollModTable[scanline]; + sc = scrollTableRounded[scanline]; + accum = 0; + for (i = 0; i < fb_width; i++) { - d = dispScanline[(i + scrollTableRounded[scanline]) % scrollModTable[scanline]]; + /* Try to immitate modulo without the division */ + if (i == md) accum += md; + scrolledIndex = i - accum + sc; + if (scrolledIndex >= md) scrolledIndex -= md; + + /* Displace */ + d = dispScanline[scrolledIndex]; *dst++ = src[i + d]; } src += backgroundW; @@ -224,6 +239,8 @@ static void draw(void) dst += fb_width; } + drawFps(vmem_back); + swap_buffers(0); }