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

TileGroup: only use allocator for ScaleGrid (esp avoid using it for Text)

trethaller пре 5 година
родитељ
комит
dcca82a0ef
2 измењених фајлова са 11 додато и 3 уклоњено
  1. 1 0
      h2d/ScaleGrid.hx
  2. 10 3
      h2d/TileGroup.hx

+ 1 - 0
h2d/ScaleGrid.hx

@@ -19,6 +19,7 @@ class ScaleGrid extends h2d.TileGroup {
 		borderHeight = borderH;
 		width = tile.width;
 		height = tile.height;
+		content.useAllocator = true;
 	}
 
 	function set_tileBorders(b) {

+ 10 - 3
h2d/TileGroup.hx

@@ -10,6 +10,7 @@ class TileLayerContent extends h3d.prim.Primitive {
 	public var yMin : Float;
 	public var xMax : Float;
 	public var yMax : Float;
+	public var useAllocator = false;
 
 	var state : BatchDrawState;
 
@@ -20,7 +21,10 @@ class TileLayerContent extends h3d.prim.Primitive {
 
 	public function clear() {
 		tmp = new hxd.FloatBuffer();
-		if( buffer != null ) hxd.impl.Allocator.get().disposeBuffer(buffer);
+		if( buffer != null ) {
+			if(useAllocator) hxd.impl.Allocator.get().disposeBuffer(buffer);
+			else buffer.dispose();
+		}
 		buffer = null;
 		xMin = hxd.Math.POSITIVE_INFINITY;
 		yMin = hxd.Math.POSITIVE_INFINITY;
@@ -402,13 +406,16 @@ class TileLayerContent extends h3d.prim.Primitive {
 	override public function alloc(engine:h3d.Engine) {
 		if( tmp == null ) clear();
 		if( tmp.length > 0 ) {
-			buffer = hxd.impl.Allocator.get().ofFloats(tmp, 8, RawQuads);
+			buffer = useAllocator
+				? hxd.impl.Allocator.get().ofFloats(tmp, 8, RawQuads)
+				: h3d.Buffer.ofFloats(tmp, 8, [Quads, RawFormat]);
 		}
 	}
 
 	override function dispose() {
 		if( buffer != null ) {
-			hxd.impl.Allocator.get().disposeBuffer(buffer);
+			if(useAllocator) hxd.impl.Allocator.get().disposeBuffer(buffer);
+			else buffer.dispose();
 			buffer = null;
 		}
 		super.dispose();