initialization is very slightly faster this way, I think
This commit is contained in:
		| @@ -350,14 +350,12 @@ prof(function(b1,b2) | ||||
| 	  and b1[3]>=b2[1] | ||||
| 	  and b1[4]>=b2[2] | ||||
| end,function(b1, b2) | ||||
|  local b1x1, b1y1, b1x2, b1y2 = unpack(b1) | ||||
|  local b2x1, b2y1, b2x2, b2y2 = unpack(b2) | ||||
| 	return  | ||||
| 	  b1x1<=b2x2 | ||||
| 	  and b1y1<=b2y2 | ||||
| 	  and b1x2>=b2x1 | ||||
| 	  and b2y2>=b2y1 | ||||
| end,{ locals={{1,1,1,1},{1,1,1,1}} }) | ||||
| 	  b1.x1<=b2.x2 | ||||
| 	  and b1.y1<=b2.y2 | ||||
| 	  and b1.x2>=b2.x1 | ||||
| 	  and b1.y2>=b2.y1 | ||||
| end,{ locals={{1,1,1,1,x1=1,x2=1,y1=1,y2=1},{1,1,1,1,x1=1,x2=1,y1=1,y2=1}} }) | ||||
|  | ||||
| -- "locals" (optional) are | ||||
| -- passed in as args. see the | ||||
|   | ||||
| @@ -568,7 +568,7 @@ end | ||||
| function hurtbox(ship) | ||||
|  local h = ship.hurt | ||||
|  local x1,y1 = ship.x + h.x_off, ship.y+h.y_off | ||||
|  return {x1, y1, x1+h.width, y1+h.height} | ||||
|  return {x1=x1, y1=y1, x2=x1+h.width, y2=y1+h.height} | ||||
| end | ||||
|  | ||||
| function ship_m:maybe_shoot(gun) | ||||
| @@ -1354,12 +1354,11 @@ end | ||||
|  | ||||
| -- box: x1, y1, x2, y2 | ||||
| function collides(b1, b2) | ||||
|  -- x1, y1, x2, y2 | ||||
| 	return  | ||||
| 	  b1[1]<=b2[3] | ||||
| 	  and b1[2]<=b2[4] | ||||
| 	  and b1[3]>=b2[1] | ||||
| 	  and b1[4]>=b2[2] | ||||
| 	  b1.x1<=b2.x2 | ||||
| 	  and b1.y1<=b2.y2 | ||||
| 	  and b1.x2>=b2.x1 | ||||
| 	  and b1.y2>=b2.y1 | ||||
| end | ||||
|  | ||||
| collider = mknew{ | ||||
| @@ -1380,8 +1379,8 @@ collider = mknew{ | ||||
| } | ||||
|  | ||||
| function collider_indexes(box) | ||||
|  local ret, ylo, yhi = {}, box[2]\8, box[4]\8 | ||||
|  for x = box[1]\8, box[3]\8 do | ||||
|  local ret, ylo, yhi = {}, box.y1\8, box.y2\8 | ||||
|  for x = box.x1\8, box.x2\8 do | ||||
|   for y = ylo, yhi do | ||||
|    add(ret, x+(y<<8)) | ||||
|   end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user