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,
boolean closed, int prio);
/**
* TBD: check if way will be rendered before decoding
*
* @param tags
* ...
* @param closed
* ...
* @return true if the way will be rendered (i.e. found match in
* RenderTheme)
*/
boolean checkWay(Tag[] tags, boolean closed);
// /**
// * TBD: check if way will be rendered before decoding - MUST be called before renderWay!
// *
// * @param tags
// * ...
// * @param closed
// * ...
// * @return true if the way will be rendered (i.e. found match in
// * RenderTheme)
// */
// boolean matchWay(Tag[] tags, boolean closed);
}

View File

@ -59,7 +59,7 @@ import android.util.Log;
*/
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 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_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 int renderLevels;
private static DebugSettings debug;
@ -93,18 +101,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
private float mStrokeScale = 1.0f;
private RenderInstruction[] mRenderInstructions = null;
//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 mLatScaleFactor;
private float mPoiX, mPoiY;
private int mPriority;
@ -130,11 +127,8 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
}
/**
* @param mapView
* the MapView
*/
public TileGenerator(MapView mapView) {
// mMapView = mapView;
public TileGenerator() {
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);
// account for area changes with latitude
mProjectionScaleFactor = 0.5f + 0.5f * (
mLatScaleFactor = 0.5f + 0.5f * (
(float) Math.sin(Math.abs(MercatorProjection
.pixelYToLatitude(tile.pixelY, tile.zoomLevel)) * (Math.PI / 180)));
@ -299,23 +293,27 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mTagHouseNr = null;
mCurLineLayer = null;
mPriority = prio;
mClosed = closed;
// replace tags that should not be cached in Rendertheme (e.g. name)
if (!filterTags(tags))
return;
mPriority = prio;
mClosed = closed;
mDrawingLayer = getValidLayer(layer) * renderLevels;
mCoords = coords;
mIndices = indices;
mRenderInstructions = TileGenerator.renderTheme.matchWay(this, tags,
(byte) (mTile.zoomLevel + 0), closed, true);
if (mRenderInstructions == null && mDebugDrawUnmatched)
debugUnmatched(closed, tags);
RenderInstruction[] ri = TileGenerator.renderTheme.matchWay(this, tags,
(byte) (mTile.zoomLevel + 0), closed, false);
if (ri != null) {
for (int i = 0, n = ri.length; i < n; i++)
ri[i].renderWay(this, tags);
} else {
if (mDebugDrawUnmatched)
debugUnmatched(closed, tags);
}
mCurLineLayer = null;
}
@ -336,15 +334,6 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
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 -----------------
@Override
public void renderWay(Line line, int level) {
@ -371,7 +360,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
float w = line.width;
if (!line.fixed) {
w *= mStrokeScale;
w *= mProjectionScaleFactor;
w *= mLatScaleFactor;
}
lineLayer.width = w;
}
@ -396,7 +385,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
float w = line.width;
if (!line.fixed) {
w *= mStrokeScale;
w *= mProjectionScaleFactor;
w *= mLatScaleFactor;
}
lineLayer.width = w;
}

View File

@ -151,14 +151,7 @@ public class RenderTheme {
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
* ...
@ -166,8 +159,7 @@ public class RenderTheme {
* ...
* @return ...
*/
public RenderInstruction[] matchNode(IRenderCallback renderCallback,
Tag[] tags, byte zoomLevel) {
public RenderInstruction[] matchNode(Tag[] tags, byte zoomLevel) {
// list of renderinsctruction items in cache
RenderInstructionItem ris = null;
@ -206,7 +198,7 @@ public class RenderTheme {
List<RenderInstruction> matches = mNodeInstructionList;
matches.clear();
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();
@ -262,9 +254,6 @@ public class RenderTheme {
}
}
if (ri.list != null)
render(renderCallback, ri.list, tags);
mPrevNodeItem = ri;
return ri.list;
@ -277,21 +266,15 @@ public class 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
* the tags of the way.
* @param zoomLevel
* the zoom level at which the way should be matched.
* @param closed
* way is Closed
* @param render
* ...
* @return currently processed render instructions
*/
public RenderInstruction[] matchWay(IRenderCallback renderCallback,
Tag[] tags, byte zoomLevel, boolean closed, boolean render) {
public RenderInstruction[] matchWay(Tag[] tags, byte zoomLevel, boolean closed) {
// list of renderinsctruction items in cache
RenderInstructionItem ris = null;
@ -354,7 +337,7 @@ public class RenderTheme {
matches.clear();
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();
// check if same instructions are used in another level
@ -421,11 +404,6 @@ public class RenderTheme {
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;
}

View File

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