GP32 Basic Dynamic Plasma (too slow)


synkro

0xdeadbeef
Joined
Aug 26, 2003
Messages
823
Location
Germany
Website
Visit site
How can I speed up things?

/*
* Plasma grafic test
*
*
*
*
*/


#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"

#define PI 3.141592654

GPDRAWSURFACE gpDraw[2];
int nflip;

void GpMain(void *arg)
{
int i, j;
unsigned char keydata;
int pos_x, pos_y, color;
int cosinus[256];
unsigned char p1,p2,p3,p4,t1,t2,t3,t4;

for(i = 0 ; i < 2 ; i++)
{
GpLcdSurfaceGet(&gpDraw, i);
}

GpSurfaceSet(&gpDraw[0]);

for (i=0;i<256;i++)
cosinus=30*(cos(i*PI/64));

nflip = 1;

pos_x = 1;
pos_y = 1;
p1 = 0;
p2 = 0;
p3 = 0;
p4 = 0;

while(1)
{
t1 = p1;
t2 = p2;

for (i = 0; i < 240; i++)
{
t3 = p3;
t4 = p4;
for (j = 0; j < 320; j++)
{
color = cosinus[t1]+cosinus[t2]+cosinus[t3]+cosinus[t4];
GpPointSet(&gpDraw[nflip], j, i, color);
t3+=1;
t4+=3;
}
t1+=2;
t2+=1;

}

p1+=1;
p2-=2;
p3+=3;
p4-=4;

// Flip Grafic Buffer
GpSurfaceFlip(&gpDraw[nflip++]);
nflip &= 0x01;
}
}
 
Well, GpPointSet would have to be your main culprit here.

If you turn around the loops so it does vertical lines rather than horizontal ones, you can just treat the LCD buffer as a memory area and fill it up. Simple, and it does seem to be quite a bit faster.
Code:
int i,j;
	unsigned short *p;
	unsigned char keydata;
	int pos_x, pos_y;
	int cosinus[256];
	unsigned char p1,p2,p3,p4,t1,t2,t3,t4, color;
	unsigned char *pScreen;

	for(i = 0; i < 2; i++)
	{
  GpLcdSurfaceGet(&gpDraw[i], i);
	}

	GpSurfaceSet(&gpDraw[0]);

	for (i=0;i<256;i++)
  cosinus[i]=30*(cos(i*PI/64));

	nflip = 1;

	pos_x = 1;
	pos_y = 1;
	p1 = 0;
	p2 = 0;
	p3 = 0;
	p4 = 0;

	while(1)
	{
  t1 = p1;
  t2 = p2;

  pScreen = gpDraw[nflip].ptbuffer;

  for (i = 0; i < 320; i++)
  {
  	t3 = p3;
  	t4 = p4;

  	for ( j=0; j<240; j++ )
  	{
    color = cosinus[t1]+cosinus[t2]+cosinus[t3]+cosinus[t4];
    *pScreen++ = color;
    t3+=1;
    t4+=3;
  	}
  	t1+=2;
  	t2+=1;
  }

  p1+=1;
  p2-=2;
  p3+=3;
  p4-=4;

  // Flip Grafic Buffer
  GpSurfaceFlip(&gpDraw[nflip++]);
  nflip &= 0x01;
	}
I changed color to an unsigned char, because that's what it's used as anyway.
 
this should speed it up to!!!


int i,j;
unsigned short *p;
unsigned char keydata;
int pos_x, pos_y;
int cosinus[256];
unsigned char p1,p2,p3,p4,t1,t2,t3,t4, color;
unsigned char *pScreen;
int tc1;
for(i = 0; i < 2; i++)
{
GpLcdSurfaceGet(&gpDraw, i);
}

GpSurfaceSet(&gpDraw[0]);

for (i=0;i<256;i++)
cosinus=30*(cos(i*PI/64));

nflip = 1;

pos_x = 1;
pos_y = 1;
p1 = 0;
p2 = 0;
p3 = 0;
p4 = 0;

while(1)
{
t1 = p1;
t2 = p2;

pScreen = gpDraw[nflip].ptbuffer;

for (i = 0; i < 320; i++)
{
t3 = p3;
t4 = p4;
tc1=cosinus[t1]+cosinus[t2];
for ( j=240>>3; j; j-- )
{
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
*pScreen++ = tc1+cosinus[t3]+cosinus[t4]; t3+=1; t4+=3;
}
t1+=2;
t2+=1;
}

p1+=1;
p2-=2;
p3+=3;
p4-=4;

// Flip Grafic Buffer
GpSurfaceFlip(&gpDraw[nflip++]);
nflip &= 0x01;
}
 
Back
Top