Compare commits

..

No commits in common. "d33d7ad6d114a2b42802d449cd5c6349ea065441" and "8fa98e31322bd45dcc6f71b44e27dffaaecf2bc1" have entirely different histories.

View File

@ -81,10 +81,9 @@ function _draw()
print("dx: ".. the_ship.dx, 20, 86, 7) print("dx: ".. the_ship.dx, 20, 86, 7)
meter(80, 86, 128, 90, the_ship.dx/the_ship.maxspd/2) meter(80, 86, 128, 90, the_ship.dx/the_ship.maxspd/2)
print("x: "..the_ship.x, 24, 92, 7) print("x: "..the_ship.x, 24, 92, 7)
print("bx: "..gbx, 20, 98, 7)
print("xmin:"..tostr(constraints.xmin), 12, 108, 7) print("xmin:"..tostr(constraints.xmin), 12, 102, 7)
print("xmax:"..tostr(constraints.xmax), 12, 114, 7) print("xmax:"..tostr(constraints.xmax), 12, 108, 7)
end end
function meter(x0, y0, x1, y1, frac) function meter(x0, y0, x1, y1, frac)
@ -128,11 +127,11 @@ function ship:draw()
spr(1,self.x,self.y) spr(1,self.x,self.y)
end end
--if (self.dx == 0) return if (self.dx == 0) return
local bd, f = brake_dist(self.dx, self.thrust + self.drag) local bd, f = brake_dist(self.dx, self.thrust + self.drag)
gbx = self.x+bd local bdx = self.x+bd-2
spr(3, gbx-2,self.y-2) spr(3, bdx,self.y-2)
print(tostr(f), gbx-2, self.y - 8, 14) print(tostr(f), bdx, self.y - 8, 14)
end end
function calc_velocity(v0, t, vmax, drag) function calc_velocity(v0, t, vmax, drag)
@ -148,8 +147,6 @@ function ship:update()
local t = btn(0) and -1 or btn(1) and 1 or 0 local t = btn(0) and -1 or btn(1) and 1 or 0
t *= self.thrust t *= self.thrust
t = constraints:constrain(self, t) t = constraints:constrain(self, t)
-- t = constraints:constrain(self, t)
-- t = constraints:constrain(self, t)
local s = calc_velocity(self.dx, t, self.maxspd, self.drag) local s = calc_velocity(self.dx, t, self.maxspd, self.drag)
self.x += s self.x += s
@ -173,26 +170,18 @@ function constraints:constrain(s, want)
-- bmx: brake max -- bmx: brake max
local v1, bmx = calc_velocity(s.dx, want, s.maxspd, s.drag), s.thrust + s.drag local v1, bmx = calc_velocity(s.dx, want, s.maxspd, s.drag), s.thrust + s.drag
local bd, bf = brake_dist(v1, bmx) local bd, bf = brake_dist(v1, bmx)
local bx, txm = s.x + bd + v1, self.xmax local bx, txm = s.x + bd, self.xmax
if bx < self.xmin then if bx < self.xmin then
-- predicted brake point left
-- of xmin; apply max reverse
-- thrust, treat xmin as our
-- max target, and handle
-- overbraking by coalescing
-- with past +xmax case
self.color = 9 self.color = 9
want = s.thrust want = s.thrust
txm = self.xmin txm = self.xmin
v1 = calc_velocity(s.dx, want, s.maxspd, s.drag) v1 = calc_velocity(s.dx, want, s.maxspd, s.drag)
bd, bf = brake_dist(v1, bmx) bd, bf = brake_dist(v1, bmx)
bx = bd + s.x + v1 bx = bd + s.x
end end
if (bx <= txm) return want if (bx < txm) return want
self.color = 8 self.color = 8
local overage = bx - txm -- TODO: implement overshot constraint
want -= overage/(bf+1)
if (want < -s.thrust) want = -s.thrust
return want return want
end end