add ui draw, add debug ui

This commit is contained in:
fnicon 2026-03-22 01:49:56 +09:00
parent 6f1b083076
commit 11bfd4404e
5 changed files with 116 additions and 73 deletions

View File

@ -33,14 +33,14 @@ function wrapper:load(_args)
data = {
velocity = {0.0, 0.0},
max_speed = 10.0,
accel = 2.0,
brake = 1.0,
grip = 1.0,
steer = 1.0,
inertia = {0.0, 0.0},
mass = 1.0,
streamline = 1.0
accel = 0.0,
brake = 0.0,
grip = 0.0,
steer = 0.0,
mass = 0.0,
streamline = 0.0
}
}
})

View File

@ -63,15 +63,6 @@ local function get(e)
e[race.dict.streamline].data
end
local function draw(text, x, y, sx, sy, angle, image, origin)
love.graphics.push()
love.graphics.scale(sx, sy)
-- love.graphics.rotate(angle)
love.graphics.draw(image, x, y, angle, 1, 1, origin[1], origin[2])
love.graphics.print(text, x, y)
love.graphics.pop()
end
function system:load()
component.component("race.pos", function (c, x, y)
c.data = vm.vec2(x, y)
@ -148,18 +139,15 @@ local function get_friction(pos_x, pos_y, floors)
end
local magic_w = {
tire = 1.0,
floor = 1.5,
forward = 1.0,
steer = 1.0,
drag_boost = 1.0,
drag_halt = 1.5,
inertia = 0.001,
centrifugal = 0.001,
drag_movement = 1.0
-- magic_slowdown = 10.0,
-- magic_boost = 10000.0,
-- magic_slow_drift = 10.0
tire = 0.0,
floor = 0.0,
forward = 0.0,
steer = 0.0,
drag_boost = 0.0,
drag_halt = 0.0,
inertia = 0.0,
centrifugal = 0.0,
drag_movement = 0.0
}
local function handle_input(accel, brake, steer)
@ -183,13 +171,58 @@ local function handle_input(accel, brake, steer)
return desire_forward, desire_steer
end
local debug_current = 1
local p_up = love.keyboard.isDown("i")
local p_down = love.keyboard.isDown("k")
local p_left = love.keyboard.isDown("j")
local p_right = love.keyboard.isDown("l")
dict_debugs = {
race.dict.max_speed,
race.dict.velocity,
race.dict.accel,
race.dict.brake,
race.dict.grip,
race.dict.steer,
race.dict.inertia,
race.dict.mass,
race.dict.streamline
}
function system:update(dt)
local i_up = love.keyboard.isDown("i")
local i_down = love.keyboard.isDown("k")
local i_left = love.keyboard.isDown("j")
local i_right = love.keyboard.isDown("l")
if (i_down and not p_down) then
debug_current = debug_current + 1
elseif (i_up and not p_up) then
debug_current = debug_current - 1
end
local dict_debug_current = dict_debugs[1]
if (debug_current > 0 and debug_current <= #dict_debugs) then
dict_debug_current = dict_debugs[debug_current]
end
p_up = i_up
p_down = i_down
p_left = i_left
p_right = i_right
for _, e in ipairs(self.pool) do
if (i_left) then
e[dict_debug_current].data = e[dict_debug_current].data - 1
elseif (i_right) then
e[dict_debug_current].data = e[dict_debug_current].data + 1
end
local max_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
local pos_x, pos_y = e["race.pos"].data[1], e["race.pos"].data[2]
local friction = get_friction(pos_x, pos_y, frictions)
local friction = frictions[1].friction
local drag = drags[1].drag
local desire_forward, desire_steer = handle_input(accel, brake, steer)
@ -206,12 +239,6 @@ function system:update(dt)
magic_w.inertia, magic_w.centrifugal
)
-- if (not up) then
-- force = force - magic_n.magic_slowdown
-- elseif (up and velocity == 0) then
-- force = force + magic_n.magic_boost
-- end
if (mass == 0) then
mass = 1
end
@ -221,54 +248,59 @@ function system:update(dt)
e[race.dict.velocity].data[1] = vm.clamp(e[race.dict.velocity].data[1], -max_speed, max_speed)
e["race.pos"].data = e["race.pos"].data + e[race.dict.velocity].data
-- local new_velocity = racing_phy.accelerate(dt, 1, velocity, max_speed, f_forward*dt/mass, 0)
-- if (not left and not right) then
-- if (not (left) and f_lateral > 0) then
-- f_lateral = f_lateral - (magic_n.magic_slow_drift)
-- if (f_lateral < 0) then
-- f_lateral = 0
-- end
-- elseif (not right and f_lateral < 0) then
-- f_lateral = f_lateral + (magic_n.magic_slow_drift)
-- if (f_lateral > 0) then
-- f_lateral = 0
-- end
-- end
-- end
e[race.dict.inertia].data = force
end
end
-- local new_angle = e["race.angle"].data + f_lateral * dt/mass
-- e["race.angle"].data = new_angle
-- e[race.dict.velocity].data = new_velocity
-- local goal_x, goal_y = racing_phy.drift(dt, pos_x, pos_y, new_velocity, max_speed, new_angle, magic_n.scale_x, magic_n.scale_y)
-- print("force_forward", f_forward, "f_lateral", f_lateral, "velocity", new_velocity, "angle", new_angle, "goal_x", goal_x, "goal_y", goal_y)
-- e["race.pos"].data[1] = goal_x
-- e["race.pos"].data[2] = goal_y
local function draw_debug(x, y, r, g, b, texts)
local font_ix = test.draw_font_start()
test.draw_set_color(r, g, b)
for _, t in ipairs(texts) do
y = y + test.draw_font(font_ix, t, x, y)
end
end
function system:draw()
for _, f in ipairs(frictions) do
-- love.graphics.push()
-- love.graphics.setColor(f.color)
-- love.graphics.rectangle("fill", f.colliders[1], f.colliders[2], f.colliders[3], f.colliders[4])
-- love.graphics.setColor(1, 1, 1)
-- love.graphics.pop()
end
for _, e in ipairs(self.pool) do
local accel, brake, grip, max_speed, steer, velocity = get(e)
local x, y, sx, sy, angle = e["race.pos"].data[1], e["race.pos"].data[2], e["race.scale"].data[1], e["race.scale"].data[2], e["race.angle"].data
local image = e["race.image"].data.image
local origin = e["race.image"].data.origin
--draw(velocity, x, y, sx, sy, angle, image, origin)
local x, y = e["race.pos"].data[1], e["race.pos"].data[2]
local vx = e[race.dict.velocity].data[1]
local vy = e[race.dict.velocity].data[2]
test.set_sphere(x, y, vx, vy)
end
end
function system:ui_draw()
for _, e in ipairs(self.pool) do
local max_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
draw_debug(640, 0, 1.0, 0.0, 1.0, {
string.format("%s max_speed : %s", (debug_current == 1 and ">") or "", max_speed),
string.format("%s velocity : %s", (debug_current == 2 and ">") or "", velocity),
string.format("%s accel : %s", (debug_current == 3 and ">") or "", accel),
string.format("%s brake : %s", (debug_current == 4 and ">") or "", brake),
string.format("%s grip : %s", (debug_current == 5 and ">") or "", grip),
string.format("%s steer : %s", (debug_current == 6 and ">") or "", steer),
string.format("%s inertia : %s", (debug_current == 7 and ">") or "", inertia),
string.format("%s mass : %s", (debug_current == 8 and ">") or "", mass),
string.format("%s streamline : %s", (debug_current == 9 and ">") or "", streamline)
})
draw_debug(640, 300, 1.0, 0.0, 1.0, {
string.format("%s weight tire : %s", (debug_current == 10 and ">") or "", magic_w.tire),
string.format("%s weight floor : %s", (debug_current == 11 and ">") or "", magic_w.floor),
string.format("%s weight forward : %s", (debug_current == 12 and ">") or "", magic_w.forward),
string.format("%s weight steer : %s", (debug_current == 13 and ">") or "", magic_w.steer),
string.format("%s weight drag boost : %s", (debug_current == 14 and ">") or "", magic_w.drag_boost),
string.format("%s weight drag halt : %s", (debug_current == 15 and ">") or "", magic_w.drag_halt),
string.format("%s weight inertia : %s", (debug_current == 16 and ">") or "", magic_w.inertia),
string.format("%s weight centrifugal : %s", (debug_current == 17 and ">") or "", magic_w.centrifugal),
string.format("%s magic drag movement : %s", (debug_current == 18 and ">") or "", magic_w.drag_movement)
})
draw_debug(1000, 0, 1.0, 0.0, 1.0, {
string.format("%s friction : %s", (debug_current == 19 and ">") or "", frictions[1].friction),
string.format("%s drag : %s", (debug_current == 20 and ">") or "", drags[1].drag),
})
end
end
return system

View File

@ -74,6 +74,10 @@ function wrapper:draw()
self.world:emit("draw")
end
function wrapper:ui_draw()
self.world:emit("ui_draw")
end
function wrapper:update(dt)
self.world:emit("update", dt)
end

View File

@ -13,6 +13,9 @@ end
function wrapper:draw()
end
function wrapper:ui_draw()
end
function wrapper:update(dt)
end

View File

@ -187,7 +187,6 @@ local nico_draw = function()
-- enough, and we should discuss this in more detail.
end
local wm = require("world_map")
world = {
@ -218,6 +217,10 @@ function love_draw()
world[current]:draw()
end
local ui_draw = function()
world[current]:ui_draw()
end
function love_keyreleased(key, scancode)
world[current]:keyreleased(key, scancode)
end
@ -281,6 +284,7 @@ function love.run()
end
--nico_draw()
ui_draw()
love.graphics.present()
love.timer.sleep(0.001)