//
//
//	plasma
//
//	programmed by Wataru Ishida
//
//

#include <windows.h>
#include "..\unrealplugin.h"
#include <math.h>

static char* dest;
static int width;
static int height;
static void* hwnd;
static BYTE   wavetable[256],
    pos1,pos2,pos3,pos4;

extern "C" __declspec(dllexport)  void __stdcall  
Open(sUnrealPlugIn * data){
 int i;
 for(i=0;i<256;i++){
   wavetable[i]= (int)(30 * (1 + sin(i*2 * 3.1415 / 256)));
 }
pos1=0;pos2=0;pos3=0;pos4=0;

  dest=(char*)data->screen;	
  width=data->width;
  height=data->height;
for(i=0;i<256;i++){
  data->palette[i].rgbBlue=(int)((sqrt(i)*sqrt(255))*230) >> 8;
  data->palette[i].rgbGreen=(i*230) >> 8;
  data->palette[i].rgbRed=(i*130) >> 8;
  data->palette[i].rgbReserved=i;
}
  data->palette[255].rgbBlue=240;
  data->palette[255].rgbGreen=240;
  data->palette[255].rgbRed=240;
}

extern "C" __declspec(dllexport)  void __stdcall  
Close(){
}

extern "C" __declspec(dllexport)  void __stdcall  
Update(char* filename,int time,void* nothing){
BYTE tp1,tp2,tp3,tp4;
int x,y;
char*p;
    p=dest;
     tp3= pos3;
    tp4= pos4;
	for ( y=0;y<240;y++){
        tp1= pos1;
        tp2= pos2;
        for(x=0;x<320;x++){
          *p++= wavetable[tp1] + wavetable[tp2] +
              wavetable[tp3] + wavetable[tp4];
          tp1++;
          tp2=tp4+1;
        }
        tp3++;
        tp4++;
	}
//end;
    pos1=pos1+3;
    pos2=pos2-4;
    pos3=pos3+5;
    pos4=pos4-10;
}
extern "C" __declspec(dllexport)  void __stdcall  
    Config(sUnrealPlugIn * data){
	hwnd=data->hwndApplication;
	MessageBox(data->hwndApplication,"Have fun!",
		"plasma",MB_ICONINFORMATION+MB_OK
		+MB_APPLMODAL);
}

extern "C" __declspec(dllexport)  char* __stdcall  
    Description(void){
	return "plasma\n"
		"written by 303tek\n"
		"email:info@303tek.com";
}
