Răsfoiți Sursa

[hrt] Reduce temporary memory allocations

Clément Espeute 2 luni în urmă
părinte
comite
979af7129d
2 a modificat fișierele cu 3 adăugiri și 2 ștergeri
  1. 1 1
      hrt/prefab/fx/LookAt.hx
  2. 2 1
      hrt/prefab/terrain/Tile.hx

+ 1 - 1
hrt/prefab/fx/LookAt.hx

@@ -79,7 +79,7 @@ class LookAtObject extends h3d.scene.Object {
 
 			var targetOnPlane = h3d.col.Plane.fromNormalPoint(lockAxis.toPoint(), new h3d.col.Point()).project(deltaVec.toPoint()).toVector();
 			targetOnPlane.normalize();
-			var referenceAxis = targetOnPlane.x != 0 ? new h3d.Vector(1, 0, 0) : new h3d.Vector(0, 1, 0);
+			var referenceAxis = inline new h3d.Vector(targetOnPlane.x != 0 ? 1 : 0, targetOnPlane.x != 0 ? 0 : 1, 0);
 			var angle = hxd.Math.acos(referenceAxis.dot(targetOnPlane));
 
 			var cross = referenceAxis.cross(deltaVec);

+ 2 - 1
hrt/prefab/terrain/Tile.hx

@@ -307,6 +307,7 @@ class Tile extends h3d.scene.Mesh {
 			if( surfaceWeights[i] != null ) h3d.pass.Copy.run(surfaceWeights[i], surfaceWeightArray, None, null, i);
 	}
 
+	static var tmpVec4: h3d.Vector4 = new h3d.Vector4();
 	public function getHeight( u : Float, v : Float, ?fast = false ) : Float {
 		var pixels = heightMapPixels;
 		if( pixels == null ) return 0.0;
@@ -332,7 +333,7 @@ class Tile extends h3d.scene.Mesh {
 		else{
 			var x = hxd.Math.floor(u * (pixels.width - 1));
 			var y = hxd.Math.floor(v * (pixels.height - 1));
-			return pixels.getPixelF(x, y).r;
+			return pixels.getPixelF(x, y, tmpVec4).r;
 		}
 	}