ScreenSaver/src/effects/backup (not used)/raindrops.cpp

145 lines
3.1 KiB
C++

#include "effects.h"
#include <num/num.h>
#include "../utilities/fast_trig.h"
#include <cstring>
#include <gint/rtc.h>
#include <gint/kmalloc.h>
extern bopti_image_t mosaics;
static const int MAX_ARRAY = DWIDTH * MAXHEIGHT;
static const short amplitudes[4] = { -250, -425, -350, -650};
static short *wavemap;
static short *old_wavemap;
static short *p_old;
static short *p_new;
short *address_new, *address_old, *temp;
short height, xdiff;
int8_t *pscreen, *pimage;
void raindrops_init( bopti_image_t *screen )
{
wavemap = (short *) kmalloc( DWIDTH * MAXHEIGHT * sizeof( short ), "extram" );
old_wavemap = (short *) kmalloc( DWIDTH * MAXHEIGHT* sizeof( short ), "extram" );
p_old = old_wavemap;
p_new = wavemap;
image_copy_palette( &mosaics, screen, -1 );
for (int i = 0; i < MAX_ARRAY; ++i)
{
wavemap[i] = 0;
old_wavemap[i] = 0;
}
}
void start_drop()
{
uint32_t v,w;
static const uint16_t b = DWIDTH - 10;
static const uint16_t c = DWIDTH * 10;
static const uint32_t d = (DWIDTH * MAXHEIGHT) - (DWIDTH * 10);
static uint8_t amp_index = 0;
/* borders are invalid so keep trying till valid value*/
do
{
v = rand() % MAX_ARRAY;
w = v % DWIDTH;
}
while (w < 10 || w > b || v < c || v > d);
wavemap[v] = amplitudes[amp_index++];
amp_index &= 4;
}
void raindrops_update( bopti_image_t *screen, [[Maybe_unused]] float dt )
{
uint16_t t;
start_drop();
t = DWIDTH + 1;
address_new = p_new + t;
address_old = p_old + t;
for (int i = 1; i < MAXHEIGHT - 1; ++i)
{
for (int j = 1; j < DWIDTH - 1; ++j)
{
height = 0;
height += *(address_new + DWIDTH);
height += *(address_new - 1);
height += *(address_new + 1);
height += *(address_new - DWIDTH);
height >>= 1;
height -= *address_old;
height -= height >> 5;
*address_old = height;
address_new++;
address_old++;
}
address_new += 2; /* next scanline starting at pos 1 */
address_old += 2;
}
t = screen->stride + 1;
address_old = p_old + t;
pscreen = (int8_t*)screen->data + t;
pimage = (int8_t*)mosaics.data + t;
/* draw waves */
for (int i = 1; i < MAXHEIGHT - 1; ++i)
{
for (int j = 1; j < DWIDTH - 1; ++j)
{
xdiff = *(address_old + 1) - *(address_old);
*pscreen = *(pimage + xdiff);
address_old++;
pscreen++;
pimage++;
}
address_old += 2;
pscreen += 2; /* next scanline starting at pos 1 */
pimage += 2;
}
/* swap wave tables */
temp = p_new;
p_new = p_old;
p_old = temp;
}
void raindrops_render( bopti_image_t *screen )
{
dimage(0,0,screen);
}
void raindrops_deinit( bopti_image_t *screen )
{
free( wavemap );
free( old_wavemap );
}
char raindrops_TextToRender[100] = "Rain Drops on Mosaic Tiles > _\0";
char *raindrops_text( void )
{
return raindrops_TextToRender;
}