Преглед изворни кода

optimize for 1x1 tile ScaleGrid (constant color)

Nicolas Cannasse пре 4 месеци
родитељ
комит
47c2911b24
1 измењених фајлова са 18 додато и 0 уклоњено
  1. 18 0
      h2d/ScaleGrid.hx

+ 18 - 0
h2d/ScaleGrid.hx

@@ -201,6 +201,10 @@ class ScaleGrid extends h2d.TileGroup {
 	}
 	}
 
 
 	function updateContent() {
 	function updateContent() {
+
+		if( tile != null && tile.width == 1 && tile.height == 1 )
+			return;
+
 		var bt = borderTop, bb = borderBottom, bl = borderLeft, br = borderRight;
 		var bt = borderTop, bb = borderBottom, bl = borderLeft, br = borderRight;
 		var unscaledBl : Float = bl * borderScale,
 		var unscaledBl : Float = bl * borderScale,
 			unscaledBr : Float = br * borderScale,
 			unscaledBr : Float = br * borderScale,
@@ -353,6 +357,20 @@ class ScaleGrid extends h2d.TileGroup {
 		}
 		}
 	}
 	}
 
 
+	override function draw(ctx:RenderContext) {
+		if( tile != null && tile.width == 1 && tile.height == 1 ) @:privateAccess {
+			var ow = tile.width;
+			var oh = tile.height;
+			tile.width = width;
+			tile.height = height;
+			emitTile(ctx,tile);
+			tile.width = ow;
+			tile.height = oh;
+			return;
+		}
+		super.draw(ctx);
+	}
+
 	override function sync( ctx : RenderContext ) {
 	override function sync( ctx : RenderContext ) {
 		checkUpdate();
 		checkUpdate();
 		super.sync(ctx);
 		super.sync(ctx);