PDA

View Full Version : Split Point[] // Basicly like SplitTPAEx



J J
08-03-2012, 09:26 AM
EDIT: Thanks to masterBB I've managed to create a flood fill and it works amazingly well.
Will post code soon.
Rough code: http://paste.villavu.com/show/3157/
Result (in red): http://img404.imageshack.us/img404/2009/floodfillwork.png


Hello,

I'm looking to split a Point[] or delete other Points. I have a Point[] with all points that aren't black in there. I've colored them Cyan to show it.
http://img825.imageshack.us/img825/8650/splitpoint.png

I'm looking to split this array, or better said, delete some points in there. I only want the current room to be drawn (which is the most northern room in this situation.

I've tried some stuff but so far nothing has worked to remove the other points correctly.

Must do something with the x-distance between the pixels but I haven't figured out what the best way is so far. Or a way, actually.

Basicly the same as SplitTPAEx but I'm not sure how that works. I know how to use it, but I have no idea how it gets calculated.

Greetz.

masterBB
08-03-2012, 09:38 AM
If you want to create your own SplitTPA:

https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/tpa.pas#L964

J J
08-03-2012, 09:44 AM
If you want to create your own SplitTPA:

https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/tpa.pas#L964
Oh thanks, I didn't manage to find the documentation on GitHub myself, when I tried to find it... I could make something similar, but there might be some useful functions in Java that I don't know, that could achieve in the same in less lines/time. If anyone knows a way in Java, let me know. For now I'll try to remake this function I guess.

masterBB
08-03-2012, 09:50 AM
Java might have some sort of flood fill that you can use on your position. This way you will always get the island you are standing on.

J J
08-03-2012, 10:20 AM
Java might have some sort of flood fill that you can use on your position. This way you will always get the island you are standing on.
Yeah maybe. I just realised that if I can make it search from the middle of the Minimap MMXY, MMCY I can check for every pixel if there is black to the south. If there is black to the south I can delete all Point that have the same X value and a higher Y value.

And do the same thing for north, east and west.

A problem with this is that the shades of Player/NPC/Item dots are the same kind of black as the outsides, so it could detect one of those as being part of the outside. This could get fixed by checking for three steps north/east/south/west and if they are all black, delete all Points with the same X value and higher Y value (if going south). Or when going north, delete all Points with the same X value and lower Y value.

I think that would work.

Also looked into this: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
Found this floodfill: http://www.netgraphics.sk/floodfill-algorithm-2

I actually looked through many more floodfill aghorithms. Looks like I've got quite a lot work to do :P

masterBB
08-03-2012, 10:23 AM
Yeah maybe. I just realised that if I can make it search from the middle of the Minimap MMXY, MMCY I can check for every pixel if there is black to the south. If there is black to the south I can delete all Point that have the same X value and a higher Y value.

And do the same thing for north, east and west.

A problem with this is that the shades of Player/NPC/Item dots are the same kind of black as the outsides, so it could detect one of those as being part of the outside. This could get fixed by checking for three steps north/east/south/west and if they are all black, delete all Points with the same X value and higher Y value (if going south). Or when going north, delete all Points with the same X value and lower Y value.

I think that would work.

Also looked into this: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
Found this floodfill: http://www.netgraphics.sk/floodfill-algorithm-2

I actually looked through many more floodfill aghorithms. Looks like I've got quite a lot work to do :P

Forget them, don't use Dijkstra. Dijksta is not related to floodfill functions.

I will post some better example in a minute.

edit:


Create a 2D Bool Array with the bounds of the points.
Loop through you point array and set the points to through in the 2D bool array
Start at your position in the bool array, loop through the locations in 4 or 8 directions. Set every point you have been to false. Safe the points in the result array.
done

J J
08-03-2012, 01:47 PM
Thanks for that, :D

What I'm going to try now is to check the difference between each point.

Eg

X = 0 check all Y coords and if the distance between two Y coords is larger than 2, delete all coords with a Y higher than that or something. That way the gap in the middle will get a little bit bigger, but it should also remove the other stuff..

Or I can just check if the x somehow changes a lot then delete it.. should actually use a spiral or something. But I'm just testing out some stuff, we'll see if it works out.

Also looked into flood fill but it is pretty hard to understand right now.

J J
08-04-2012, 09:03 AM
Create a 2D Bool Array with the bounds of the points.
Loop through you point array and set the points to through in the 2D bool array
Start at your position in the bool array, loop through the locations in 4 or 8 directions. Set every point you have been to false. Safe the points in the result array.
done

I now have a 2D boolean array. It represents the black on the minimap, each true represents a black pixel.

Also from another forum:

Instead of building an array of points, build a 2D array of booleans. The width and height of this array will remain contant and is based on the size of the minimap. Make everything false, and put trues at points where it is not black. now you will have a binary map of the minimap, so you can process it such that you can find "bands" of black, that is portions of the screen that fully encompass colored areas, then exclude any points outside of that band.
That's what I did, I'm not sure how I can find the bands/boundaries now.

http://img98.imageshack.us/img98/8577/2dbool.png

For the drawing

g.setColor(Color.GREEN);
if (map.length > 0){
for (int i = 0; i < map.length; i++){
for (int j = 0; j < map[i].length; j++){
if (map[i][j] == true){
g.drawLine(MMX1 + i, MMY1 + j, MMX1 + i, MMY1 + j);
}
}
}
}