invert eship/pbullet collision
Also mildly trims up linked_list impl.
This commit is contained in:
		| @@ -60,7 +60,7 @@ function mknew(tt) | ||||
| end | ||||
|  | ||||
| -- intrusive singly-linked list. | ||||
| -- cannot be nested! | ||||
| -- cannot be nested or crossed! | ||||
| linked_list = mknew{ | ||||
|  is_linked_list=true, | ||||
|  init = function(x) | ||||
| @@ -93,9 +93,7 @@ end | ||||
|  | ||||
| -- strip calls f(x) for each | ||||
| -- node, removing each node for | ||||
| -- which f(x) returns true. it | ||||
| -- returns the new tail; nil | ||||
| -- if the list is now empty. | ||||
| -- which f(x) returns true. | ||||
| function linked_list:strip(f) | ||||
|  local p, n = self, self.next | ||||
|  while n do | ||||
| @@ -107,7 +105,6 @@ function linked_list:strip(f) | ||||
|   n = n.next | ||||
|  end | ||||
|  self.tail = p | ||||
|  return p | ||||
| end | ||||
|  | ||||
| -- optimized special case - | ||||
| @@ -258,31 +255,35 @@ function updategame() | ||||
|  | ||||
| 	-- many bullets and many enemy ships; | ||||
| 	-- use bucket collider for efficiency | ||||
|  local pbullet_collider = collider.new() | ||||
|  local p, n = pbullets, pbullets.next | ||||
|  | ||||
|  local eship_collider = collider.new() | ||||
|  -- save tokens, lose time: | ||||
|  -- eships:strip(function(s) eship_collider:insert(s) end) | ||||
|  local p, n = eships, eships.next | ||||
|  while n do | ||||
|   n.prev = p | ||||
|   pbullet_collider:insert(n) | ||||
|   eship_collider:insert(n) | ||||
|   p = n | ||||
|   n = p.next | ||||
|  end | ||||
|  | ||||
|  eships:strip( | ||||
|   function(es) | ||||
|    for pb in all(pbullet_collider:get_collisions(es)) do | ||||
|     if pb:hitship(es) then | ||||
|      pbullet_collider:hide(pb) | ||||
|      pb.prev.next = pb.next | ||||
|      if pb.next then | ||||
|       pb.next.prev = pb.prev | ||||
|  -- lose tokens, save time: | ||||
|  -- unroll `strip` to avoid | ||||
|  -- function call overhead | ||||
|  pbullets:strip(function(pb) | ||||
|   for es in all(eship_collider:get_collisions(pb)) do | ||||
|    if es:hitbullet(pb) then | ||||
|     eship_collider:hide(es) | ||||
|     es.prev.next=es.next | ||||
|     if es.next then | ||||
|      es.next.prev = es.prev | ||||
|     else | ||||
|       pbullets.tail = pb.prev | ||||
|      eships.tail = es.prev | ||||
|     end | ||||
|    end | ||||
|     if (es:hitbullet(pb)) return true | ||||
|    if (pb:hitship(es)) return true | ||||
|   end | ||||
|   end | ||||
|  ) | ||||
|  end) | ||||
|   | ||||
|  intangibles_fg:strip(call_move) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user