Hey that looks cool! So its a 2D gui being rendered over a 3D scene. I feel so inaduquate, my level editor is plane old 2D!
I was just thinking of a new method for sorting the components making it quiker to find.
Instead of finding which area on a grid the component was in, i found which horizontal line it was on.
For each line i know the index of the components on it.
This method uses less memory than the grid because the grid needs to be fairly fine, and is a fixed size. Where as the each line can be spaced further apart, and uses only as much as needed.
Tell me what you think. You can see its not optimized, im still working on the idea.
[this code has been tested and edited, and now works]
Also how do i get my formating to stay?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
public static void sortComponents () { if(!isDepthSorted) depthSort (); int y=0; int maxLines = height/yPad; compRegions = new int[maxLines+1][0]; int[] compLine = new int[200]; int compOnLine = 0; lineLoop: for(int i=0; i<=maxLines; i++) { compLoop: for(int j=0; j<componentCount; j++) { GComponent comp = components[j]; for(int k=0; k<width; k++) { if(comp.contains (k,y) || comp.contains (k,y-(yPad/2)) || comp.contains (k,y+(yPad/2)) ) { compLine[compOnLine++] = j; continue compLoop; } } } compRegions[i] = new int[compOnLine]; for(int k=0; k<compOnLine; k++) { compRegions[i][k] = compLine[k]; } y += yPad; compOnLine = 0; }
}
private static GComponent findComponent (int x,int y) { if(lastContainer!=null && lastContainer.contains (x,y)) { int[] kids = lastContainer.getChildren (); for(int i=kids.length-1; i>=0; i--) { if(components[kids[i]].contains (x,y))return components[kids[i]]; } } int[] comps = compRegions[(y/yPad)]; if(comps.length<1)return null; for(int i=comps.length-1; i>=0; i--) { GComponent comp = components[comps[i]]; if(x >= comp.getX () && x<comp.getX ()+comp.getWidth ()) { return comp; } } return null; }
|