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