reverse strip logic
saves a single cycle per bullet, but...
This commit is contained in:
@ -61,11 +61,11 @@ end
|
|||||||
|
|
||||||
-- call f on everything on list
|
-- call f on everything on list
|
||||||
-- and return a new list of
|
-- and return a new list of
|
||||||
-- items for which f was false.
|
-- items for which f was true.
|
||||||
function stripped(list, f)
|
function filtered(list, f)
|
||||||
local ret, n = {}, 0
|
local ret, n = {}, 0
|
||||||
for v in all(list) do
|
for v in all(list) do
|
||||||
if not f(v) then
|
if f(v) then
|
||||||
n += 1
|
n += 1
|
||||||
ret[n] = v
|
ret[n] = v
|
||||||
end
|
end
|
||||||
@ -75,25 +75,25 @@ end
|
|||||||
|
|
||||||
-- call :move on everything on
|
-- call :move on everything on
|
||||||
-- src and dump everything
|
-- src and dump everything
|
||||||
-- for which it returned false
|
-- for which it returned true
|
||||||
-- onto dest.
|
-- onto dest.
|
||||||
function appendmove(dest, src)
|
function appendmove(dest, src)
|
||||||
local n = #dest
|
local n = #dest
|
||||||
for v in all(src) do
|
for v in all(src) do
|
||||||
if not v:move() then
|
if v:move() then
|
||||||
n += 1
|
n += 1
|
||||||
dest[n] = v
|
dest[n] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- like stripped, but calls
|
-- like filtered, but calls
|
||||||
-- :move on stuff in the list
|
-- :move on stuff in the list
|
||||||
-- instead of taking a func arg.
|
-- instead of taking a func arg.
|
||||||
function stripmoved(list)
|
function filtermoved(list)
|
||||||
local ret, n = {}, 0
|
local ret, n = {}, 0
|
||||||
for v in all(list) do
|
for v in all(list) do
|
||||||
if not v:move() then
|
if v:move() then
|
||||||
n += 1
|
n += 1
|
||||||
ret[n] = v
|
ret[n] = v
|
||||||
end
|
end
|
||||||
@ -196,11 +196,11 @@ function updategame()
|
|||||||
current_wave = flotilla.new()
|
current_wave = flotilla.new()
|
||||||
current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4))
|
current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4))
|
||||||
end
|
end
|
||||||
events = stripmoved(events)
|
events = filtermoved(events)
|
||||||
appendmove(events, new_events)
|
appendmove(events, new_events)
|
||||||
new_events = {}
|
new_events = {}
|
||||||
intangibles_bg = stripmoved(intangibles_bg)
|
intangibles_bg = filtermoved(intangibles_bg)
|
||||||
eships = stripmoved(eships)
|
eships = filtermoved(eships)
|
||||||
|
|
||||||
-- eship collider will be used
|
-- eship collider will be used
|
||||||
-- both for pship and pbullets.
|
-- both for pship and pbullets.
|
||||||
@ -213,25 +213,26 @@ function updategame()
|
|||||||
ps:hitship(es)
|
ps:hitship(es)
|
||||||
es:hitship(ps)
|
es:hitship(ps)
|
||||||
end
|
end
|
||||||
ebullets = stripped(ebullets, function(eb)
|
ebullets = filtered(ebullets, function(eb)
|
||||||
if (eb:move()) return true
|
if (not eb:move()) return
|
||||||
if (not collides(pbox, hurtbox(eb))) return
|
if (not collides(pbox, hurtbox(eb))) return true
|
||||||
ps:hitbullet(eb)
|
ps:hitbullet(eb)
|
||||||
return eb:hitship(ps)
|
return not eb:hitship(ps)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
ebullets=stripmoved(ebullets)
|
ebullets=filtermoved(ebullets)
|
||||||
end
|
end
|
||||||
|
|
||||||
pbullets = stripped(pbullets, function(pb)
|
pbullets = filtered(pbullets, function(pb)
|
||||||
if (pb:move()) return true
|
if (not pb:move()) return
|
||||||
for es in eship_collider:iterate_collisions(hurtbox(pb)) do
|
for es in eship_collider:iterate_collisions(hurtbox(pb)) do
|
||||||
es:hitbullet(pb)
|
es:hitbullet(pb)
|
||||||
if (pb:hitship(es)) return true
|
if (pb:hitship(es)) return
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
intangibles_fg = stripmoved(intangibles_fg)
|
intangibles_fg = filtermoved(intangibles_fg)
|
||||||
|
|
||||||
if waves_complete == 32767 and #eships == 0 and #ebullets == 0 and #events == 0 then
|
if waves_complete == 32767 and #eships == 0 and #ebullets == 0 and #events == 0 then
|
||||||
game_state = win
|
game_state = win
|
||||||
@ -535,7 +536,7 @@ function ship_m:constrain(p, dp, pmin, pmax, want)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ship_m:move()
|
function ship_m:move()
|
||||||
if (self.dead) return true;
|
if (self.dead) return;
|
||||||
self:refresh_shield()
|
self:refresh_shield()
|
||||||
local dx, dy, shoot_spec1, shoot_spec2 = self:act()
|
local dx, dy, shoot_spec1, shoot_spec2 = self:act()
|
||||||
local sg, xm, ym = self.special_guns, self.xmomentum, self.ymomentum
|
local sg, xm, ym = self.special_guns, self.xmomentum, self.ymomentum
|
||||||
@ -555,7 +556,7 @@ function ship_m:move()
|
|||||||
self.xmomentum = xm
|
self.xmomentum = xm
|
||||||
self.ymomentum = ym
|
self.ymomentum = ym
|
||||||
|
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function ship_m:draw()
|
function ship_m:draw()
|
||||||
@ -774,7 +775,7 @@ end
|
|||||||
function bullet_base:move()
|
function bullet_base:move()
|
||||||
local x,y = self.x + self.dx, self.y+self.dy
|
local x,y = self.x + self.dx, self.y+self.dy
|
||||||
self.x,self.y=x,y
|
self.x,self.y=x,y
|
||||||
return (y>128) or (y < -(self.height<<3)) or (x > 128) or (x < -(self.width<<3))
|
return (y<=128) and (y >= -(self.height<<3)) and (x <= 128) and (x >= -(self.width<<3))
|
||||||
end
|
end
|
||||||
|
|
||||||
function bullet_base:draw()
|
function bullet_base:draw()
|
||||||
@ -1573,13 +1574,13 @@ blip_fx = mknew{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function blip_fx:move()
|
function blip_fx:move()
|
||||||
if (self.cancel) return true
|
if (self.cancel) return
|
||||||
self.frames -= 1
|
self.frames -= 1
|
||||||
if self.frames < 0 then
|
if self.frames < 0 then
|
||||||
self.obj.fx_pal = nil
|
self.obj.fx_pal = nil
|
||||||
return true
|
return
|
||||||
end
|
end
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function blip_fx:abort()
|
function blip_fx:abort()
|
||||||
@ -1624,11 +1625,12 @@ spark_particle=mknew{}
|
|||||||
|
|
||||||
function spark_particle:move()
|
function spark_particle:move()
|
||||||
if (rnd(4) < 1) self.sidx += 1
|
if (rnd(4) < 1) self.sidx += 1
|
||||||
if (self.sidx > #self.sprs) return true
|
if (self.sidx > #self.sprs) return
|
||||||
self.x += self.dx
|
self.x += self.dx
|
||||||
self.y += self.dy
|
self.y += self.dy
|
||||||
self.dx -= mid(0.05,-0.05, self.dx)
|
self.dx -= mid(0.05,-0.05, self.dx)
|
||||||
self.dy -= mid(0.05,-0.05, self.dy)
|
self.dy -= mid(0.05,-0.05, self.dy)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
function spark_particle:draw()
|
function spark_particle:draw()
|
||||||
pset(self.x,self.y,self.sprs[self.sidx])
|
pset(self.x,self.y,self.sprs[self.sidx])
|
||||||
|
Reference in New Issue
Block a user