make RenderTheme only return render instruction

- i.e. dont pass render callback

remove unused matchWay function
This commit is contained in:
Hannes Janetzek 2013-03-18 05:10:24 +01:00
parent 0b7edab572
commit a6063997db
4 changed files with 45 additions and 78 deletions

View File

@ -62,16 +62,16 @@ public interface IMapDatabaseCallback {
void renderWay(byte layer, Tag[] tags, float[] wayNodes, short[] wayLength, void renderWay(byte layer, Tag[] tags, float[] wayNodes, short[] wayLength,
boolean closed, int prio); boolean closed, int prio);
/** // /**
* TBD: check if way will be rendered before decoding // * TBD: check if way will be rendered before decoding - MUST be called before renderWay!
* // *
* @param tags // * @param tags
* ... // * ...
* @param closed // * @param closed
* ... // * ...
* @return true if the way will be rendered (i.e. found match in // * @return true if the way will be rendered (i.e. found match in
* RenderTheme) // * RenderTheme)
*/ // */
boolean checkWay(Tag[] tags, boolean closed); // boolean matchWay(Tag[] tags, boolean closed);
} }

View File

@ -59,7 +59,7 @@ import android.util.Log;
*/ */
public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
private static String TAG = TileGenerator.class.getName(); private static final String TAG = TileGenerator.class.getName();
private static final double STROKE_INCREASE = Math.sqrt(2.2); private static final double STROKE_INCREASE = Math.sqrt(2.2);
private static final byte LAYERS = 11; private static final byte LAYERS = 11;
@ -67,6 +67,14 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
public static final byte STROKE_MIN_ZOOM_LEVEL = 12; public static final byte STROKE_MIN_ZOOM_LEVEL = 12;
public static final byte STROKE_MAX_ZOOM_LEVEL = 17; public static final byte STROKE_MAX_ZOOM_LEVEL = 17;
private static final Tag[] debugTagBox = { new Tag("debug", "box") };
private static final Tag[] debugTagWay = { new Tag("debug", "way") };
private static final Tag[] debugTagArea = { new Tag("debug", "area") };
private final float[] debugBoxCoords = { 0, 0, 0, Tile.TILE_SIZE,
Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE, 0, 0, 0 };
private final short[] debugBoxIndex = { 10 };
private static RenderTheme renderTheme; private static RenderTheme renderTheme;
private static int renderLevels; private static int renderLevels;
private static DebugSettings debug; private static DebugSettings debug;
@ -93,18 +101,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
private float mStrokeScale = 1.0f; private float mStrokeScale = 1.0f;
private RenderInstruction[] mRenderInstructions = null; private float mLatScaleFactor;
//private final MapView mMapView;
private final Tag[] debugTagBox = { new Tag("debug", "box") };
private final Tag[] debugTagWay = { new Tag("debug", "way") };
private final Tag[] debugTagArea = { new Tag("debug", "area") };
private final float[] debugBoxCoords = { 0, 0, 0, Tile.TILE_SIZE,
Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE, 0, 0, 0 };
private final short[] debugBoxIndex = { 10 };
private float mProjectionScaleFactor;
private float mPoiX, mPoiY; private float mPoiX, mPoiY;
private int mPriority; private int mPriority;
@ -130,11 +127,8 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
} }
/** /**
* @param mapView
* the MapView
*/ */
public TileGenerator(MapView mapView) { public TileGenerator() {
// mMapView = mapView;
mClipper = new LineClipper(0, 0, Tile.TILE_SIZE, Tile.TILE_SIZE, true); mClipper = new LineClipper(0, 0, Tile.TILE_SIZE, Tile.TILE_SIZE, true);
} }
@ -161,7 +155,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
setScaleStrokeWidth(tile.zoomLevel); setScaleStrokeWidth(tile.zoomLevel);
// account for area changes with latitude // account for area changes with latitude
mProjectionScaleFactor = 0.5f + 0.5f * ( mLatScaleFactor = 0.5f + 0.5f * (
(float) Math.sin(Math.abs(MercatorProjection (float) Math.sin(Math.abs(MercatorProjection
.pixelYToLatitude(tile.pixelY, tile.zoomLevel)) * (Math.PI / 180))); .pixelYToLatitude(tile.pixelY, tile.zoomLevel)) * (Math.PI / 180)));
@ -299,23 +293,27 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mTagHouseNr = null; mTagHouseNr = null;
mCurLineLayer = null; mCurLineLayer = null;
mPriority = prio;
mClosed = closed;
// replace tags that should not be cached in Rendertheme (e.g. name) // replace tags that should not be cached in Rendertheme (e.g. name)
if (!filterTags(tags)) if (!filterTags(tags))
return; return;
mPriority = prio;
mClosed = closed;
mDrawingLayer = getValidLayer(layer) * renderLevels; mDrawingLayer = getValidLayer(layer) * renderLevels;
mCoords = coords; mCoords = coords;
mIndices = indices; mIndices = indices;
mRenderInstructions = TileGenerator.renderTheme.matchWay(this, tags, RenderInstruction[] ri = TileGenerator.renderTheme.matchWay(this, tags,
(byte) (mTile.zoomLevel + 0), closed, true); (byte) (mTile.zoomLevel + 0), closed, false);
if (mRenderInstructions == null && mDebugDrawUnmatched) if (ri != null) {
for (int i = 0, n = ri.length; i < n; i++)
ri[i].renderWay(this, tags);
} else {
if (mDebugDrawUnmatched)
debugUnmatched(closed, tags); debugUnmatched(closed, tags);
}
mCurLineLayer = null; mCurLineLayer = null;
} }
@ -336,15 +334,6 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
public void renderWaterBackground() { public void renderWaterBackground() {
} }
@Override
public boolean checkWay(Tag[] tags, boolean closed) {
mRenderInstructions = TileGenerator.renderTheme.matchWay(this, tags,
(byte) (mTile.zoomLevel + 0), closed, false);
return mRenderInstructions != null;
}
// ----------------- RenderThemeCallback ----------------- // ----------------- RenderThemeCallback -----------------
@Override @Override
public void renderWay(Line line, int level) { public void renderWay(Line line, int level) {
@ -371,7 +360,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
float w = line.width; float w = line.width;
if (!line.fixed) { if (!line.fixed) {
w *= mStrokeScale; w *= mStrokeScale;
w *= mProjectionScaleFactor; w *= mLatScaleFactor;
} }
lineLayer.width = w; lineLayer.width = w;
} }
@ -396,7 +385,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
float w = line.width; float w = line.width;
if (!line.fixed) { if (!line.fixed) {
w *= mStrokeScale; w *= mStrokeScale;
w *= mProjectionScaleFactor; w *= mLatScaleFactor;
} }
lineLayer.width = w; lineLayer.width = w;
} }

View File

@ -151,14 +151,7 @@ public class RenderTheme {
return mMapBackground; return mMapBackground;
} }
private static void render(IRenderCallback renderCallback,
RenderInstruction[] renderInstructions, Tag[] tags) {
for (int i = 0, n = renderInstructions.length; i < n; i++)
renderInstructions[i].renderNode(renderCallback, tags);
}
/** /**
* @param renderCallback
* ... * ...
* @param tags * @param tags
* ... * ...
@ -166,8 +159,7 @@ public class RenderTheme {
* ... * ...
* @return ... * @return ...
*/ */
public RenderInstruction[] matchNode(IRenderCallback renderCallback, public RenderInstruction[] matchNode(Tag[] tags, byte zoomLevel) {
Tag[] tags, byte zoomLevel) {
// list of renderinsctruction items in cache // list of renderinsctruction items in cache
RenderInstructionItem ris = null; RenderInstructionItem ris = null;
@ -206,7 +198,7 @@ public class RenderTheme {
List<RenderInstruction> matches = mNodeInstructionList; List<RenderInstruction> matches = mNodeInstructionList;
matches.clear(); matches.clear();
for (int i = 0, n = mRulesList.size(); i < n; ++i) for (int i = 0, n = mRulesList.size(); i < n; ++i)
mRulesList.get(i).matchNode(renderCallback, tags, zoomLevel, matches); mRulesList.get(i).matchNode(tags, zoomLevel, matches);
int size = matches.size(); int size = matches.size();
@ -262,9 +254,6 @@ public class RenderTheme {
} }
} }
if (ri.list != null)
render(renderCallback, ri.list, tags);
mPrevNodeItem = ri; mPrevNodeItem = ri;
return ri.list; return ri.list;
@ -277,21 +266,15 @@ public class RenderTheme {
/** /**
* Matches a way with the given parameters against this RenderTheme. * Matches a way with the given parameters against this RenderTheme.
* *
* @param renderCallback
* the callback implementation which will be executed on each
* match.
* @param tags * @param tags
* the tags of the way. * the tags of the way.
* @param zoomLevel * @param zoomLevel
* the zoom level at which the way should be matched. * the zoom level at which the way should be matched.
* @param closed * @param closed
* way is Closed * way is Closed
* @param render
* ...
* @return currently processed render instructions * @return currently processed render instructions
*/ */
public RenderInstruction[] matchWay(IRenderCallback renderCallback, public RenderInstruction[] matchWay(Tag[] tags, byte zoomLevel, boolean closed) {
Tag[] tags, byte zoomLevel, boolean closed, boolean render) {
// list of renderinsctruction items in cache // list of renderinsctruction items in cache
RenderInstructionItem ris = null; RenderInstructionItem ris = null;
@ -354,7 +337,7 @@ public class RenderTheme {
matches.clear(); matches.clear();
for (int i = 0, n = mRulesList.size(); i < n; ++i) for (int i = 0, n = mRulesList.size(); i < n; ++i)
mRulesList.get(i).matchWay(renderCallback, tags, zoomLevel, c, matches); mRulesList.get(i).matchWay(tags, zoomLevel, c, matches);
int size = matches.size(); int size = matches.size();
// check if same instructions are used in another level // check if same instructions are used in another level
@ -421,11 +404,6 @@ public class RenderTheme {
mPrevWayItem = ri; mPrevWayItem = ri;
} }
if (render && ri.list != null) {
for (int i = 0, n = ri.list.length; i < n; i++)
ri.list[i].renderWay(renderCallback, tags);
}
return ri.list; return ri.list;
} }

View File

@ -196,7 +196,7 @@ abstract class Rule {
abstract boolean matchesWay(Tag[] tags); abstract boolean matchesWay(Tag[] tags);
void matchNode(IRenderCallback renderCallback, Tag[] tags, byte zoomLevel, void matchNode(Tag[] tags, byte zoomLevel,
List<RenderInstruction> matchingList) { List<RenderInstruction> matchingList) {
if ((mElement != Element.WAY) if ((mElement != Element.WAY)
&& mZoomMin <= zoomLevel && mZoomMin <= zoomLevel
@ -207,12 +207,12 @@ abstract class Rule {
matchingList.add(mRenderInstructionArray[i]); matchingList.add(mRenderInstructionArray[i]);
for (int i = 0, n = mSubRuleArray.length; i < n; i++) for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].matchNode(renderCallback, tags, zoomLevel, matchingList); mSubRuleArray[i].matchNode(tags, zoomLevel, matchingList);
} }
} }
void matchWay(IRenderCallback renderCallback, Tag[] tags, byte zoomLevel, void matchWay(Tag[] tags, byte zoomLevel,
int closed, List<RenderInstruction> matchingList) { int closed, List<RenderInstruction> matchingList) {
if ((mElement != Element.NODE) if ((mElement != Element.NODE)
@ -227,7 +227,7 @@ abstract class Rule {
// check subrules // check subrules
for (int i = 0, n = mSubRuleArray.length; i < n; i++) for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].matchWay(renderCallback, tags, zoomLevel, closed, mSubRuleArray[i].matchWay(tags, zoomLevel, closed,
matchingList); matchingList);
} }