Skip to content

Commit 8e21e80

Browse files
committed
Simplify visualization infrastructure
1 parent 9f60b42 commit 8e21e80

File tree

4 files changed

+9
-62
lines changed

4 files changed

+9
-62
lines changed

src/TestUtils.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ struct MockStrategy{T<:TrajectoryGame}
1111
player_index::Int
1212
end
1313

14-
function TrajectoryGamesBase.visualize!(canvas, γ::Makie.Observable{<:MockStrategy}; kwargs...)
15-
nothing
16-
end
17-
1814
function (strategy::MockStrategy)(x, t)
1915
zeros(control_dim(strategy.game.dynamics, strategy.player_index))
2016
end

src/TrajectoryGamesExamples.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ using TrajectoryGamesBase:
99
TrajectoryGame,
1010
ZeroSumCostStructure,
1111
num_players,
12-
time_invariant_linear_dynamics,
13-
visualize!
12+
time_invariant_linear_dynamics
1413
using LinearAlgebra: norm, norm_sqr
1514
using BlockArrays: Block, blocks, blocksize
1615
using InfiniteArrays:
@@ -27,11 +26,7 @@ include("TestUtils.jl")
2726

2827
# visualization
2928
include("visualize_simulation.jl")
30-
export animate_sim_steps,
31-
create_environment_axis,#
32-
visualize_players!,
33-
visualize_obstacle_bounds!,
34-
visualize_targets!
29+
export animate_sim_steps, visualize_sim_step, create_environment_axis
3530

3631
# games
3732
include("two_player_meta_tag.jl")

src/dynamics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function TrajectoryGamesBase.control_bounds(dynamics::UnicycleDynamics)
5959
dynamics.control_bounds
6060
end
6161

62-
function (sys::UnicycleDynamics)(state, control, t)
62+
function (sys::UnicycleDynamics)(state, control, t, context = nothing)
6363
px, py, v, θ = state
6464
F, τ = control
6565
dt = sys.dt
@@ -129,7 +129,7 @@ function TrajectoryGamesBase.control_bounds(dynamics::BicycleDynamics)
129129
dynamics.control_bounds
130130
end
131131

132-
function (sys::BicycleDynamics)(state, control, t)
132+
function (sys::BicycleDynamics)(state, control, t, context = nothing)
133133
px, py, v, θ = state
134134
a, ϕ = control
135135
dt = sys.dt

src/visualize_simulation.jl

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function create_environment_axis(
3030
x_limits = x_limits .+ limit_margins
3131
y_limits = y_limits .+ limit_margins
3232

33-
aspect = x_limits[2] / y_limits[2]
33+
aspect = DataAspect()
3434
limits = (x_limits, y_limits)
3535
environment_axis = Makie.Axis(
3636
figure;
@@ -43,54 +43,10 @@ function create_environment_axis(
4343
axis_kwargs...,
4444
)
4545

46-
visualize!(environment_axis, environment; viz_kwargs...)
46+
Makie.plot!(environment_axis, environment; viz_kwargs...)
4747
environment_axis
4848
end
4949

50-
function visualize_players!(
51-
axis,
52-
players;
53-
player_colors = range(colorant"red", colorant"blue", length = blocksize(players[], 1)),
54-
)
55-
for player_i in 1:blocksize(players[], 1)
56-
player_color = player_colors[player_i]
57-
position = Makie.@lift Makie.Point2f($players[Block(player_i)][1:2])
58-
Makie.scatter!(axis, position; color = player_color)
59-
end
60-
end
61-
62-
function visualize_obstacle_bounds!(
63-
axis,
64-
players;
65-
player_colors = range(colorant"red", colorant"blue", length = blocksize(players[], 1)),
66-
obstacle_radius = 1.0,
67-
)
68-
for player_i in 1:blocksize(players[], 1)
69-
player_color = player_colors[player_i]
70-
position = Makie.@lift Makie.Point2f($players[Block(player_i)][1:2])
71-
Makie.scatter!(
72-
axis,
73-
position;
74-
color = (player_color, 0.4),
75-
markersize = 2 * obstacle_radius,
76-
markerspace = :data,
77-
)
78-
end
79-
end
80-
81-
function visualize_targets!(
82-
axis,
83-
targets;
84-
player_colors = range(colorant"red", colorant"blue", length = blocksize(targets[], 1)),
85-
marker = "+",
86-
)
87-
for player_i in 1:blocksize(targets[], 1)
88-
color = player_colors[player_i]
89-
target = Makie.@lift Makie.Point2f($targets[Block(player_i)])
90-
Makie.scatter!(axis, target; color, marker)
91-
end
92-
end
93-
9450
function visualize_sim_step(
9551
game,
9652
step;
@@ -100,7 +56,7 @@ function visualize_sim_step(
10056
ylims = (-5, 5),
10157
aspect = 1,
10258
player_colors = range(colorant"red", colorant"blue", length = num_players(game)),
103-
player_names = ["Pursuer", "Evader"],
59+
player_names = ["P$ii" for ii in 1:num_players(game)],
10460
weight_offset = 0.0,
10561
heading = "",
10662
show_legend = false,
@@ -126,7 +82,7 @@ function visualize_sim_step(
12682
ax_kwargs...,
12783
)
12884

129-
visualize!(ax, game.env)
85+
Makie.plot!(ax, game.env)
13086

13187
plots = []
13288

@@ -135,7 +91,7 @@ function visualize_sim_step(
13591
γ = Makie.@lift $s.strategy.substrategies[ii]
13692
pos = Makie.@lift Makie.Point2f($s.state[Block(ii)][1:2])
13793
scatter = Makie.scatter!(ax, pos; color)
138-
visualize!(ax, γ; weight_offset, color)
94+
Makie.plot!(ax, γ; weight_offset, color)
13995
push!(plots, [scatter])
14096
end
14197

0 commit comments

Comments
 (0)