#ifdef WIN32
#define WINDOWS_VERSION
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma warning(disable : 4244)
#endif
#if !defined(BUILTIN_PLUGINS)
#define THIS_IS_THE_PLUGIN
#endif
#include <stdlib.h>
#include <stdio.h>
//#include <string.h>
//#include <math.h>
//#include <stdint.h>
#if defined(PSP_VERSION)
#include <pspsdk.h>
#include <pspmath.h>
#include <pspdisplay.h>
#define sin(x) vfpu_sinf(x)
#endif
#include "plugin/agsplugin.h"
#if defined(BUILTIN_PLUGINS)
namespace agswave {
#endif
#if defined(__GNUC__)
inline unsigned long _blender_alpha16_bgr(unsigned long y) __attribute__((always_inline));
inline void calc_x_n(unsigned long bla) __attribute__((always_inline));
#endif
const unsigned int Magic = 0xBABE0000;
const unsigned int Version = 1;
const unsigned int SaveMagic = Magic + Version;
const float PI = 3.14159265f;
int screen_width = 640;
int screen_height = 360;
int screen_color_depth = 32;
IAGSEngine* engine;
// Imported script functions
int dY=0;
int tDy=0;
int direction=0;
void CastWave(int delayMax, int PixelsWide)
{
tDy++;
if (tDy >delayMax)
{
tDy=0;
if (direction==0) dY++;
if (direction==1) dY--;
if ( (dY>PixelsWide && direction==0) || (dY<-PixelsWide && direction==1) )
{
if (direction==0){dY=PixelsWide;direction=1;}
else {dY=-PixelsWide;direction=0;}
}
}
}
void DrawEffect(int sprite_a,int sprite_b,int id)
{
int x, y;
BITMAP* src_a = engine->GetSpriteGraphic(sprite_a);
BITMAP* src_b = engine->GetSpriteGraphic(sprite_b);
unsigned int** pixel_a = (unsigned int**)engine->GetRawBitmapSurface(src_a);
unsigned int** pixel_b = (unsigned int**)engine->GetRawBitmapSurface(src_b);
for (y = 0; y < screen_height; y++)
{
if (id==0) CastWave(2,1);
if (id==1) CastWave(15,1);
for (x = 0; x < screen_width; x++)
{
unsigned int colorfromB = pixel_b[y][x];
int getX=x;
int getY=y;
if (id==0)
{
getX=x-(rand() % 2)-2;
getY=y+dY;
}
if (id==1)
{
getX=x;
getY=y+dY;
}
if (getX < 0) getX=0;
if (getX > screen_width-1) getX = screen_width-1;
if (getY > screen_height-1) getY = screen_height-1;
if (getY < 0) getY = 0;
pixel_a[getY][getX]=colorfromB; //
}
}
engine->ReleaseBitmapSurface(src_a);
engine->ReleaseBitmapSurface(src_b);
}
void RestoreGame(FILE* file)
{
unsigned int Position = ftell(file);
unsigned int DataSize;
unsigned int SaveVersion = 0;
fread(&SaveVersion, 4, 1, file);
if (SaveVersion == SaveMagic)
{
fread(&DataSize, 4, 1, file);
// Current version
//fread(&g_DarknessLightLevel, 4, 1, file);
}
else if ((SaveVersion & 0xFFFF0000) == Magic)
{
// Unsupported version, skip it
DataSize = 0;
fread(&DataSize, 4, 1, file);
fseek(file, Position + DataSize - 8, SEEK_SET);
}
else
{
// Unknown data, loading might fail but we cannot help it
fseek(file, Position, SEEK_SET);
}
}
void SaveGame(FILE* file)
{
unsigned int StartPosition = ftell(file);
fwrite(&SaveMagic, 4, 1, file);
fwrite(&StartPosition, 4, 1, file); // Update later with the correct size
//fwrite(&g_DarknessLightLevel, 4, 1, file);
unsigned int EndPosition = ftell(file);
unsigned int SaveSize = EndPosition - StartPosition;
fseek(file, StartPosition + 4, SEEK_SET);
fwrite(&SaveSize, 4, 1, file);
fseek(file, EndPosition, SEEK_SET);
}
// ********************************************
// ************ AGS Interface ***************
// ********************************************
void DrawScreenEffect(int sprite,int sprite_prev,int ide)
{
DrawEffect(sprite,sprite_prev,ide);
}
void AGS_EngineStartup(IAGSEngine *lpEngine)
{
engine = lpEngine;
if (engine->version < 13)
engine->AbortGame("Engine interface is too old, need newer version of AGS.");
engine->RegisterScriptFunction("DrawScreenEffect", (void*)&DrawScreenEffect);
engine->RequestEventHook(AGSE_PREGUIDRAW);
engine->RequestEventHook(AGSE_PRESCREENDRAW);
#if defined(PSP_VERSION) || defined(ANDROID_VERSION) || defined(IOS_VERSION)
engine->RequestEventHook(AGSE_SAVEGAME);
engine->RequestEventHook(AGSE_RESTOREGAME);
#endif
}
void AGS_EngineShutdown()
{
}
int AGS_EngineOnEvent(int event, int data)
{
if (event == AGSE_PREGUIDRAW)
{
// WindEffect(g_Fx,g_Fy,g_Trans,g_RW,g_RH);
/*
BITMAP* screen = engine->GetVirtualScreen();
BITMAP* ParticleGraph = engine->GetSpriteGraphic(4322);
//engine->BlitBitmap (100, 100, ParticleGraph, 0);
engine->BlitSpriteTranslucent(100, 100, ParticleGraph,50);
engine->ReleaseBitmapSurface(screen);
//engine->MarkRegionDirty(0,0,screen_width,screen_height);
engine->SetVirtualScreen(screen);*/
}
#if defined(PSP_VERSION) || defined(ANDROID_VERSION) || defined(IOS_VERSION)
else if (event == AGSE_RESTOREGAME)
{
RestoreGame((FILE*)data);
}
else if (event == AGSE_SAVEGAME)
{
SaveGame((FILE*)data);
}
#endif
else if (event == AGSE_PRESCREENDRAW)
{
// Get screen size once here.
//engine->GetScreenDimensions(&screen_width, &screen_height, &screen_color_depth);
engine->UnrequestEventHook(AGSE_SAVEGAME);
engine->UnrequestEventHook(AGSE_RESTOREGAME);
}
return 0;
}
int AGS_EngineDebugHook(const char *scriptName, int lineNum, int reserved)
{
return 0;
}
void AGS_EngineInitGfx(const char *driverID, void *data)
{
}
#if defined(WINDOWS_VERSION) && !defined(BUILTIN_PLUGINS)
// ********************************************
// *********** Editor Interface *************
// ********************************************
//AGSFlashlight
const char* scriptHeader =
"import void DrawScreenEffect(int sprite,int sprite_prev,int ide);\r\n";
IAGSEditor* editor;
LPCSTR AGS_GetPluginName(void)
{
// Return the plugin description
return "AGSWave";
}
int AGS_EditorStartup(IAGSEditor* lpEditor)
{
// User has checked the plugin to use it in their game
// If it's an earlier version than what we need, abort.
if (lpEditor->version < 1)
return -1;
editor = lpEditor;
editor->RegisterScriptHeader(scriptHeader);
// Return 0 to indicate success
return 0;
}
void AGS_EditorShutdown()
{
// User has un-checked the plugin from their game
editor->UnregisterScriptHeader(scriptHeader);
}
void AGS_EditorProperties(HWND parent)
{
// User has chosen to view the Properties of the plugin
// We could load up an options dialog or something here instead
MessageBoxA(parent, "AGSWave", "About", MB_OK | MB_ICONINFORMATION);
}
int AGS_EditorSaveGame(char* buffer, int bufsize)
{
// We don't want to save any persistent data
return 0;
}
void AGS_EditorLoadGame(char* buffer, int bufsize)
{
// Nothing to load for this plugin
}
#endif
#if defined(BUILTIN_PLUGINS)
} // namespace agswave
#endif