Well, I tried various possibilities of speeding things up, but none helped much. I already contemplated the horrifying possibility of implementing my game in C when I finally saw the impact of line [1].
Code: Select all
Circle:eachLine(function(p1, p2)
-- do nothing for current line
if not (p1 == self.cur_point or p2 == self.cur_point) then
screen:print(20, 30, "oki", white) -- [1]
-- check for hit on horizontal line
if hor and not(self.dir[2]==0) and self.y == p1[2] and
is_bound(self.x, p1[1], p2[1]) then -- we hit it
self.dir = {math.sgn(p2[1]-p1[1])*2, 0} -- follow
if not self.cur_point then -- are we free roaming?
self.cur_point = Fibers:resolve(self.x, self.y, p2)
else self.cur_point = p1 end
return
-- check for hit on vertical line
elseif not(self.dir[1]==0) and self.x == p1[1] and
is_bound(self.y, p1[2], p2[2]) then -- we hit it
self.dir = {0, math.sgn(p2[2]-p1[2])*2} -- follow
if not self.cur_point then -- are we free roaming?
self.cur_point = Fibers:resolve(self.x, self.y, p2)
else self.cur_point = p1 end
return
end
end
hor = not hor
end)
What to learn from that? Lua is no way that slow, and make sure that you're doing only what you think you're doing.
While I'm giving advice:
If you use the fast method of developing and are not restarting LuaPlayer between tests do not use require. Use dofile. This was already pointed out by Sprak here but is important enough to mention again (and again, and again). I knew about it and even posted in that thread but still fell into the trap. It can cause very subtle bugs where some files are a new version while others still do the old thing.