From: Michael Kargas Date: Sun, 18 Sep 2016 21:26:29 +0000 (+0100) Subject: My first commit in this project, just a lame plasma test effect and my tinyfps with... X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=a8d502c1e163a95f25b2f5aec1478d2cb61027c2 My first commit in this project, just a lame plasma test effect and my tinyfps with a minimal font from another project to monitor fps while the effect running --- diff --git a/dosdemo.vcxproj b/dosdemo.vcxproj index a1791c3..b1bb483 100644 --- a/dosdemo.vcxproj +++ b/dosdemo.vcxproj @@ -89,16 +89,19 @@ + + + diff --git a/dosdemo.vcxproj.filters b/dosdemo.vcxproj.filters index 0af8b7c..fd7403d 100644 --- a/dosdemo.vcxproj.filters +++ b/dosdemo.vcxproj.filters @@ -40,6 +40,12 @@ src + + src + + + src + @@ -51,5 +57,8 @@ src + + src + \ No newline at end of file diff --git a/src/plasma.c b/src/plasma.c new file mode 100644 index 0000000..ac13e6a --- /dev/null +++ b/src/plasma.c @@ -0,0 +1,122 @@ +// Just a test with a run of the mill plasma + +#include +#include + +#include "demo.h" +#include "screen.h" +#include "tinyfps.h" + +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 struct screen scr = { + "plasma", + init, + destroy, + start, + stop, + draw +}; + +unsigned long startingTime; + +#define PSIN_SIZE 4096 +#define PPAL_SIZE 256 + +unsigned char *psin1, *psin2, *psin3; +unsigned short *plasmaPal; + +unsigned short myBuffer[320*240]; + + +struct screen *plasma_screen(void) +{ + return &scr; +} + +static int init(void) +{ + int i; + + initFpsFonts(); + + psin1 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + psin2 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + psin3 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + + for (i = 0; i < PSIN_SIZE; i++) + { + psin1[i] = (unsigned char)(sin((double)i / 45.0) * 63.0 + 63.0); + psin2[i] = (unsigned char)(sin((double)i / 75.0) * 42.0 + 42.0); + psin3[i] = (unsigned char)(sin((double)i / 32.0) * 88.0 + 88.0); + } + + plasmaPal = (unsigned short*)malloc(sizeof(unsigned short) * PPAL_SIZE); + for (i=0; i 127) c = 255 - c; + c >>= 2; + g = 31 - c; + r = c; + b = g; + plasmaPal[i] = (r<<11) | (g<<5) | b; + } + + return 0xCAFE; + //return 0; +} + +static void destroy(void) +{ + free(psin1); + free(psin2); + free(psin3); +} + +static void start(long trans_time) +{ + startingTime = time_msec; +} + +static void stop(long trans_time) +{ +} + +static void draw(void) +{ + int x, y; + unsigned char c; + unsigned char s1, s2; + + float dt = (float)(time_msec - startingTime) / 1000.0f; + int t1 = sin(0.1f * dt) * 132 + 132; + int t2 = sin(0.2f * dt) * 248 + 248; + int t3 = sin(0.5f * dt) * 380 + 380; + + unsigned int *vram32 = (unsigned int*)vmem_back; + unsigned int p0, p1; + for (y = 0; y < fb_height; y++) + { + s1 = psin2[y + t2]; + s2 = psin3[y + t1]; + for (x = 0; x < fb_width; x+=2) + { + c = psin1[x + t1] + s1 + psin3[x + y + t3] + psin1[psin2[x + t2] + s2 + t3]; + p0 = plasmaPal[c]; + c = psin1[x + 1 + t1] + s1 + psin3[x + 1 + y + t3] + psin1[psin2[x + 1 + t2] + s2 + t3]; + p1 = plasmaPal[c]; + + *vram32++ = (p1 << 16) | p0; + } + } + + drawFps((unsigned short*)fb_pixels); + + swap_buffers(0); +} diff --git a/src/screen.c b/src/screen.c index 927903b..c91cb82 100644 --- a/src/screen.c +++ b/src/screen.c @@ -9,8 +9,9 @@ struct screen *tunnel_screen(void); struct screen *fract_screen(void); struct screen *grise_screen(void); struct screen *polytest_screen(void); +struct screen *plasma_screen(void); -#define NUM_SCR 32 +#define NUM_SCR 32 static struct screen *scr[NUM_SCR]; static int num_screens; @@ -33,6 +34,9 @@ int scr_init(void) if(!(scr[idx++] = polytest_screen())) { return -1; } + if (!(scr[idx++] = plasma_screen())) { + return -1; + } num_screens = idx; assert(num_screens <= NUM_SCR); @@ -66,7 +70,7 @@ void scr_shutdown(void) void scr_update(void) { - if(prev) { /* we're in the middle of a transition */ + if(prev) { /* we're in the middle of a transition */ long interval = time_msec - trans_start; if(interval >= trans_dur) { if(next->start) { @@ -111,7 +115,7 @@ int scr_change(struct screen *s, long trans_time) if(s == cur) return 0; if(trans_time) { - trans_dur = trans_time / 2; /* half for each part transition out then in */ + trans_dur = trans_time / 2; /* half for each part transition out then in */ trans_start = time_msec; } else { trans_dur = 0; diff --git a/src/tinyfps.c b/src/tinyfps.c new file mode 100644 index 0000000..4b9d9db --- /dev/null +++ b/src/tinyfps.c @@ -0,0 +1,125 @@ +#include + +#include "tinyfps.h" +#include "demo.h" + +// TinyFPS, just a minimal fraps like font to show FPS during the demo and not just after. +// I'll be using it in my effects for my performance test purposes, just adding it here. +// Maybe it would be nice if initFpsFonts would be called in demo.c once but I avoided touching that code. + +/* +1110 0010 1110 1110 1010 1110 1110 1110 1110 1110 +1010 0010 0010 0010 1010 1000 1000 0010 1010 1010 +1010 0010 1110 0110 1110 1110 1110 0010 1110 1110 +1010 0010 1000 0010 0010 0010 1010 0010 1010 0010 +1110 0010 1110 1110 0010 1110 1110 0010 1110 1110 +*/ + +const unsigned char miniDecimalData[] = { 0xE2, 0xEE, 0xAE, 0xEE, 0xEE, +0xA2, 0x22, 0xA8, 0x82, 0xAA, +0xA2, 0xE6, 0xEE, 0xE2, 0xEE, +0xA2, 0x82, 0x22, 0xA2, 0xA2, +0xE2, 0xEE, 0x2E, 0xE2, 0xEE }; + +unsigned short miniDecimalFonts[FPS_FONT_NUM_PIXELS]; + +unsigned long startingFpsTime = 0; +int fpsFontsInit = 0; +int nFrames = 0; + +void initFpsFonts() +{ + if (fpsFontsInit == 0) + { + unsigned char miniDecimalPixels[FPS_FONT_NUM_PIXELS]; + + int k = 0; + for (int i = 0; i < FPS_FONT_NUM_PIXELS / 8; i++) + { + unsigned char d = miniDecimalData[i]; + for (int j = 0; j < 8; j++) + { + unsigned char c = (d & 0x80) >> 7; + miniDecimalPixels[k++] = c; + d <<= 1; + } + } + + int i = 0; + for (int n = 0; n < FPS_FONTS_NUM; n++) + { + for (int y = 0; y < FPS_FONT_HEIGHT; y++) + { + for (int x = 0; x < FPS_FONT_WIDTH; x++) + { + miniDecimalFonts[i++] = miniDecimalPixels[n * FPS_FONT_WIDTH + x + y * FPS_FONT_WIDTH * FPS_FONTS_NUM] * 0xFFFF; + } + } + } + + fpsFontsInit = 1; + } +} + +void drawFont(unsigned char decimal, int posX, int posY, unsigned char zoom, unsigned short *vram) +{ + int x, y, j, k; + unsigned short c; + + unsigned short *fontData = (unsigned short*)&miniDecimalFonts[decimal * FPS_FONT_WIDTH * FPS_FONT_HEIGHT]; + + vram += posY * fb_width + posX; + + if (zoom < 1) zoom = 1; + if (zoom > 4) zoom = 4; + + for (y = 0; y= 1000) + { + fps = (nFrames * 1000) / dt; + startingFpsTime = time_msec; + nFrames = 0; + } + drawDecimal(fps, 4, 4, 2, vram); +} diff --git a/src/tinyfps.h b/src/tinyfps.h new file mode 100644 index 0000000..6dc74c0 --- /dev/null +++ b/src/tinyfps.h @@ -0,0 +1,12 @@ +#ifndef TINY_FPS_H +#define TINY_FPS_H + +#define FPS_FONT_WIDTH 4 +#define FPS_FONT_HEIGHT 5 +#define FPS_FONTS_NUM 10 +#define FPS_FONT_NUM_PIXELS (FPS_FONTS_NUM * FPS_FONT_WIDTH * FPS_FONT_HEIGHT) + +void initFpsFonts(); +void drawFps(unsigned short *vram); + +#endif