Progressing

This commit is contained in:
Norbi Peti 2018-11-28 21:48:05 +01:00
parent 7ed8cfd8d0
commit 1c77835855
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 29 additions and 24 deletions

View file

@ -1,5 +1,6 @@
package sznp.virtualcomputer;
@SuppressWarnings("unused")
public interface PXCLib {
/**
* Testing only
@ -14,13 +15,14 @@ public interface PXCLib {
* @param address Bitmap address from VirtualBox
* @param w Width of the screen
* @param h Height of the screen
* @param mc Total count of maps used for the screen
* @param mcx Width of the screen in maps
* @param mcy Height of the screen in maps
*/
void setSource(long address, int w, int h, int mcx, int mcy);
/**
* Updates map and returns it's content
* @return Full map data [mapc][data]
* Updates map and returns it's content, where affected
* @return Partial map data [mapc][data]
*/
byte[][] updateAndGetMap(int x, int y, int width, int height); //TODO: Only update parts that actually updated and return them per-map (flagDirty)
}

View file

@ -25,14 +25,12 @@ typedef struct { //BGRA
int alpha : 8;
} NativeColor; //Used for the screen data
char matchColor(NativeColor* p);
char matchColor(NativeColor nc);
void* image=NULL;
void* maps=NULL; //Per map data (1st map, second map etc.)
short width, height, mapcx, mapcy;
char* mapp=NULL; //Pointer inside the map
NativeColor* imgp=NULL; //Pointer inside the image
void setSource(addr address, short w, short h, short mcx, short mcy) {
ct_assert(sizeof(char)==1); //Compile-time assert
@ -40,17 +38,20 @@ void setSource(addr address, short w, short h, short mcx, short mcy) {
image=(void*)address;
maps=malloc(MAPSIZE*MAPSIZE*mcx*mcy); //1 byte per pixel
width=w, height=h, mapcx=mcx, mapcy=mcy;
mapp=maps;
}
//May return 0
void* updateAndGetMap(int x, int y, int w, int h) { //TODO: Support the parameters
if(image==NULL || maps==NULL) return 0;
void* const retp = mapp;
char* mapp = maps;
NativeColor* imgp = image;
for(int k=0; k<mapcx; k++) {
for(int l=0; l<mapcy; l++) {
mapp = maps + MAPSIZE*k + MAPSIZE*mapcx*MAPSIZE*l; //Go to the start of the map
for(short i=0; i<MAPSIZE; i++) { //We need to jump
for(short j=0; j<MAPSIZE; j++) {
*mapp=matchColor(imgp);
imgp++; //Increment by the size of Nativecolor so 4
*mapp=matchColor(*imgp);
imgp++; //Increment by the size of NativeColor so 4
mapp++;
}
imgp+=width-MAPSIZE; //Go back to the first column
@ -60,8 +61,10 @@ void* updateAndGetMap(int x, int y, int w, int h) { //TODO: Support the paramete
(void*)imgp - image > width * height * sizeof(NativeColor)) {
mapp = maps; //Start over
imgp = image; //Start over
} //TODO: This is only one map, do it for all of them
return retp;
}
}
}
return maps; //TODO: Return changed only
}
const Color colors[] = {
@ -133,9 +136,9 @@ double getDistance(Color c1, Color c2) {
}
//Code from Bukkit's MapPalette class
char matchColor(NativeColor* const p) {
if (p->alpha < 128) return 0;
Color color={.red=p->red, .green=p->green, .blue=p->blue};
char matchColor(NativeColor nc) {
if (nc.alpha < 128) return 0;
Color color={.red=nc.red, .green=nc.green, .blue=nc.blue};
char index = 0;
double best = -1;