#include #include #define MAPSIZE 128 #if MAPSIZE>255 #error MAPSIZE must be a short value #endif //--------------------------------------------------------------------- // http://www.pixelbeat.org/programming/gcc/static_assert.html #define ct_assert(e) {enum { ct_assert_value = 1/(!!(e)) };} //--------------------------------------------------------------------- typedef long long int addr; typedef struct { //RGB unsigned int red : 8; unsigned int green : 8; unsigned int blue : 8; } Color; //Used for Bukkit's initializers (for simplicity) typedef struct { //BGRA unsigned int blue : 8; unsigned int green : 8; unsigned int red : 8; unsigned int alpha : 8; } NativeColor; //Used for the screen data char matchColor(NativeColor nc); void* image=NULL; void* maps=NULL; //Per map data (1st map, second map etc.) short width, height, mapcx, mapcy; void setSource(addr address, short w, short h, short mcx, short mcy) { ct_assert(sizeof(char)==1); //Compile-time assert ct_assert(sizeof(Color)==4); //Compile-time assert image=(void*)address; maps=malloc(MAPSIZE*MAPSIZE*mcx*mcy); //1 byte per pixel width=w, height=h, mapcx=mcx, mapcy=mcy; printf("PXC: w=%d h=%d mcx=%d mcy=%d\n", w, h, mcx, mcy); } NativeColor* getNativeColor(int x, int y) { if(x<0||x>width||y<0||y>height) return NULL; return ((NativeColor*)image)+x+y*width; } char* getMapColor(int x, int y) { if(x<0||x>width||y<0||y>height) return NULL; int mc=x/MAPSIZE+y/MAPSIZE*mapcx; return maps+mc*MAPSIZE*MAPSIZE; //TODO: Use } //May return 0 void* updateAndGetMap(int x, int y, int w, int h, int** out_changed) { //TODO: Support the parameters if(image==NULL || maps==NULL) return 0; for(int l=y; l