Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit 2f422f3

Browse files
authored
glwindow changes + depwarns (#194)
* accompany new changes from GLWindow * Fix deprecations * include new glwindow
1 parent d7f584d commit 2f422f3

29 files changed

+182
-190
lines changed

REQUIRE

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ julia 0.6
33
StaticArrays 0.6.0
44
GeometryTypes 0.4.1
55

6-
GLWindow 0.6 # 0.6 for fullscreen
6+
GLWindow 0.7 # 0.7 for reactive_run_till_now
77
GLAbstraction 0.5
88
ModernGL 0.1.0
99

examples/ExampleRunner.jl

+7-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function flatten_paths(path::String, paths = String[])
4343
paths
4444
end
4545

46-
type RunnerConfig
46+
mutable struct RunnerConfig
4747
resolution
4848
make_docs
4949
files
@@ -368,7 +368,7 @@ end
368368
to_toggle(v0, b) = !v0
369369

370370

371-
import GLWindow: poll_reactive, poll_glfw, sleep_pessimistic
371+
import GLWindow: reactive_run_till_now, poll_glfw, sleep_pessimistic
372372

373373

374374
function inner_test(path, config, window, break_loop, runthrough, increase)
@@ -377,21 +377,18 @@ function inner_test(path, config, window, break_loop, runthrough, increase)
377377
display_msg(test_module, config)
378378
timings = Float64[]
379379
frames = 0;
380-
@eval poll_glfw()
381-
@eval poll_reactive()
382-
@eval poll_reactive()
383-
yield()
380+
poll_glfw()
381+
reactive_run_till_now()
384382
while !break_loop[] && isopen(config.rootscreen)
385-
tic()
383+
t = time()
386384
poll_glfw()
387385
if Base.n_avail(Reactive._messages) > 0
388-
poll_reactive()
389-
poll_reactive() # two times for secondary signals
386+
reactive_run_till_now() # two times for secondary signals
390387
render_frame(config.rootscreen)
391388
swapbuffers(config.rootscreen)
392389
end
393390
frames += 1
394-
t = toq()
391+
t = time() - t
395392
if length(timings) < 1000 && frames > 2
396393
push!(timings, t)
397394
end
@@ -453,7 +450,6 @@ function make_tests(config)
453450
end
454451

455452
failed = fill(false, length(config.files))
456-
Reactive.stop() # stop Reactive! We be pollin' ourselves!
457453
io = nothing
458454
while i <= length(config.files) && isopen(config.rootscreen)
459455
path = config.files[i]

examples/interactive/mario_game.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You can move mario around with the arrow keys
99
"""
1010
const record_interactive = true
1111

12-
type Mario{T}
12+
mutable struct Mario{T}
1313
x ::T
1414
y ::T
1515
vx ::T

examples/introduction/video_recording.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ for i=1:10 # record 10 frames
3232
# if you call @async renderloop(window) you can replace this part with yield
3333
GLWindow.render_frame(window)
3434
GLWindow.swapbuffers(window)
35-
GLWindow.poll_reactive()
35+
GLWindow.reactive_run_till_now()
3636

3737
# add the frame from the current window
3838
GLVisualize.add_frame!(io, window, buffer)

examples/parallel/simulation3d.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ function p_empty!()
4444
end
4545

4646

47-
function solve_particles!{N, T}(
47+
function solve_particles!(
4848
positions::AbstractVector{Point{N, T}}, s, dt::T = T(0.01)
49-
)
49+
) where {N, T}
5050
P = Point{N, T}
5151
# since Points are immutable, and we don't have comprehensions yet, there is
5252
# a map(index _> ..., ::Point) which we can use
@@ -70,7 +70,7 @@ end
7070
Generic implementation of initialising `N` dimensional points on an `N` dimensional
7171
Sphere.
7272
"""
73-
function startpositions{T}(N, radius::T, n)
73+
function startpositions(N, radius::T, n) where T
7474
sphere = HyperSphere(Point{N, T}(0), T(radius))
7575
n = N == 3 ? floor(Int, sqrt(n)) : n # n must be n^2 for 3D Sphere
7676
decompose(Point{N, T}, sphere, n)

examples/sprites/distancefield.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dfield = map(timesignal) do t
3131
Float32[xy_data(x,y,tpi) + 0.5f0 for x=1:n2, y=1:n2]
3232
end
3333
Base.rand(m::MersenneTwister, ::Type{N0f8}) = N0f8(rand(m, UInt8))
34-
Base.rand{T <: Colorant}(m::MersenneTwister, ::Type{T}) = T(ntuple(x->rand(m, eltype(T)), Val{length(T)})...)
34+
Base.rand(m::MersenneTwister, ::Type{T}) where {T <: Colorant} = T(ntuple(x->rand(m, eltype(T)), Val{length(T)})...)
3535

3636
distfield = visualize((DISTANCEFIELD, positions),
3737
stroke_width=4f0,

src/GLVisualize.jl

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ import GLAbstraction: N0f8
2424
export N0f8 # reexport for examples/tests
2525
using Base.Iterators: filter
2626
import Base: merge, convert, show
27-
if VERSION >= v"0.6.0-dev.1015"
28-
using Base.Iterators: Repeated, repeated
29-
else
30-
using Base.Repeated
31-
end
27+
using Base.Iterators: Repeated, repeated
3228

3329
import AxisArrays, ImageAxes, Images
3430
const HasAxesArray{T, N} = Union{AxisArrays.AxisArray{T, N}, Images.ImageMetadata.ImageMetaAxis{T, N}}

src/StructsOfArrays.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ module StructsOfArrays
22

33
export StructOfArrays, ScalarRepeat
44

5-
immutable StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N}
5+
struct StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N}
66
arrays::U
77
end
88

99

10-
type ScalarRepeat{T}
10+
mutable struct ScalarRepeat{T}
1111
scalar::T
1212
end
1313
Base.ndims(::ScalarRepeat) = 1
1414
Base.getindex(s::ScalarRepeat, i...) = s.scalar
1515
#should setindex! really be allowed? It will set the index for the whole row...
16-
Base.setindex!{T}(s::ScalarRepeat{T}, value, i...) = (s.scalar = T(value))
16+
Base.setindex!(s::ScalarRepeat{T}, value, i...) where {T} = (s.scalar = T(value))
1717
Base.eltype{T}(::ScalarRepeat{T}) = T
1818

1919
Base.start(::ScalarRepeat) = 1
@@ -85,7 +85,7 @@ Base.convert{T,S,N}(::Type{StructOfArrays{T}}, A::AbstractArray{S,N}) =
8585
Base.convert{T,N}(::Type{StructOfArrays}, A::AbstractArray{T,N}) =
8686
convert(StructOfArrays{T,N}, A)
8787

88-
function Base.size{T, N, U}(A::StructOfArrays{T, N, U})
88+
function Base.size(A::StructOfArrays{T, N, U}) where {T, N, U}
8989
for elem in A.arrays
9090
if isa(elem, AbstractArray)
9191
return size(elem)
@@ -104,7 +104,7 @@ end
104104
)
105105
end
106106

107-
function _getindex{T}(x::T, i)
107+
function _getindex(x::T, i) where T
108108
is_tuple_struct(T) ? x[i] : getfield(x, i)
109109
end
110110
@generated function Base.setindex!{T}(A::StructOfArrays{T}, x, i::Integer...)

src/boundingbox.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
AbsoluteRectangle{N,T}(mini::Vec{N,T}, maxi::Vec{N,T}) = HyperRectangle{N,T}(mini, maxi-mini)
1+
AbsoluteRectangle(mini::Vec{N,T}, maxi::Vec{N,T}) where {N,T} = HyperRectangle{N,T}(mini, maxi-mini)
22

3-
(::Type{AABB})(a) = AABB{Float32}(a)
4-
function (B::Type{AABB{T}}){T}(a::Pyramid)
3+
AABB(a) = AABB{Float32}(a)
4+
function (B::Type{AABB{T}})(a::Pyramid) where T
55
w,h = a.width/T(2), a.length
66
m = Vec{3,T}(a.middle)
77
B(m-Vec{3,T}(w,w,0), m+Vec{3,T}(w, w, h))
88
end
9-
(B::Type{AABB{T}}){T}(a::Cube) = B(origin(a), widths(a))
10-
(B::Type{AABB{T}}){T}(a::AbstractMesh) = B(vertices(a))
11-
(B::Type{AABB{T}}){T}(a::NativeMesh) = B(gpu_data(a.data[:vertices]))
9+
(B::Type{AABB{T}})(a::Cube) where {T} = B(origin(a), widths(a))
10+
(B::Type{AABB{T}})(a::AbstractMesh) where {T} = B(vertices(a))
11+
(B::Type{AABB{T}})(a::NativeMesh) where {T} = B(gpu_data(a.data[:vertices]))
1212

1313

14-
function (B::Type{AABB{T}}){T}(
14+
function (B::Type{AABB{T}})(
1515
positions, scale, rotation,
1616
primitive::AABB{T}
17-
)
17+
) where T
1818

1919
ti = TransformationIterator(positions, scale, rotation)
2020
B(ti, primitive)
2121
end
22-
function (B::Type{AABB{T}}){T}(instances::Instances)
22+
function (B::Type{AABB{T}})(instances::Instances) where T
2323
ti = TransformationIterator(instances)
2424
B(ti, B(instances.primitive))
2525
end
@@ -38,9 +38,9 @@ function transform(translation, scale, rotation, points)
3838
AABB{Float32}(_min, _max-_min)
3939
end
4040

41-
function (B::Type{AABB{T}}){T}(
41+
function (B::Type{AABB{T}})(
4242
ti::TransformationIterator, primitive::AABB{T}
43-
)
43+
) where T
4444
state = start(ti)
4545
if done(ti, state)
4646
return primitive

src/camera.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function cubeside_const_lift(_, id, mousehover)
1212
Vec3f0(1)
1313
end
1414
import Base: +
15-
Base.clamp{T}(x::T) = clamp(x, T(0),T(1))
16-
+{T}(a::RGBA{T}, b::Number) = RGBA{T}(clamp(comp1(a)+b), clamp(comp2(a)+b), clamp(comp3(a)+b), clamp(alpha(a)+b))
15+
Base.clamp(x::T) where {T} = clamp(x, T(0),T(1))
16+
+(a::RGBA{T}, b::Number) where {T} = RGBA{T}(clamp(comp1(a)+b), clamp(comp2(a)+b), clamp(comp3(a)+b), clamp(alpha(a)+b))
1717

1818
function cubeside_color(id, mousehover, startcolors, colortex)
1919
index = mousehover[2]
@@ -39,7 +39,7 @@ function colored_cube()
3939
cube_steering = merge(map(GLNormalMesh, quads))
4040
end
4141

42-
Base.middle{T}(r::SimpleRectangle{T}) = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))
42+
Base.middle(r::SimpleRectangle{T}) where {T} = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))
4343

4444

4545
function get_rotation(m)

src/documentation.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
pretty_print(x::Signal) = string(value(x))
33
pretty_print(x::Vector) = string("[", first(x), "...", last(x), "]")
4-
pretty_print{T}(x::Matrix{T}) = string("Matrix{", T, "}")
4+
pretty_print(x::Matrix{T}) where {T} = string("Matrix{", T, "}")
55
pretty_print(x::DataType) = string(x.name.name)
66
pretty_print(x) = string(x)
77

88
print_type(x::Function) = string(x.env.name)
99
print_type(x::Symbol) = string(":", x)
10-
function print_type{T<:Tuple}(x::Type{T})
10+
function print_type(x::Type{T}) where T<:Tuple
1111
"($(join(map(print_type, x.parameters), ", ")))"
1212
end
1313
function print_type(x::TypeVar)
@@ -84,7 +84,7 @@ end
8484
_tuple(x) = (x,)
8585
_tuple(x::Core.SimpleVector) = tuple(x...)
8686
_tuple(x::Tuple) = x
87-
_tuple{T<:Tuple}(x::Type{T}) = tuple(x.parameters...)
87+
_tuple(x::Type{T}) where {T<:Tuple} = tuple(x.parameters...)
8888

8989
function all_docs(io = STDOUT)
9090
method_table = methods(GLVisualize._default)

src/gui/buttons.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function toggle(ispressed::Signal{Bool}, screen, default=true; signal=Signal(def
3737
signal
3838
end
3939

40-
function toggle{T<:Union{Int, Tuple, RenderObject}}(id1::Union{Signal{T}, T}, screen, default=true; signal=Signal(default))
40+
function toggle(id1::Union{Signal{T}, T}, screen, default=true; signal=Signal(default)) where T<:Union{Int, Tuple, RenderObject}
4141
m2id = mouse2id(screen)
4242
is_clicked = droprepeats(map(screen.inputs[:mouse_buttons_pressed]) do mbp
4343
if GLAbstraction.singlepressed(mbp, GLFW.MOUSE_BUTTON_LEFT)
@@ -141,10 +141,10 @@ function slider(
141141
end
142142

143143

144-
function widget{T <: Range}(
144+
function widget(
145145
r::Signal{T}, screen::Screen;
146146
args...
147-
)
147+
) where T <: Range
148148
slider(value(r), screen; args...)
149149
end
150150
function playbutton(screen; icon_size = 10mm)

src/gui/color_chooser.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
_clamp(x) = Point2f0(clamp(x[1], 0, 1), clamp(x[2], 0, 1))
2-
function widget{T<:RGBA}(
2+
function widget(
33
color::Signal{T}, window;
44
area=(30, 30),
55
kw_args...
6-
)
6+
) where T<:RGBA
77
@materialize mouse_buttons_pressed, mouseposition = window.inputs
88
color_button = visualize(
99
(ROUNDED_RECTANGLE, zeros(Point2f0, 1));

src/gui/line_edit.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ function edit_line(
5858
end
5959

6060

61-
function widget{T}(
61+
function widget(
6262
line::Vector{Point{2,T}}, window;
6363
direction_restriction = Vec2f0(1),
6464
clampto = (-Inf, Inf),
6565
kw_args...
66-
)
66+
) where T
6767
vis, sig = edit_line(
6868
line, direction_restriction, clampto, window;
6969
kw_args...
@@ -98,14 +98,14 @@ function dragg_gpu(v0, dragg)
9898
return id, index, p0
9999
end
100100

101-
immutable ClampFunctor{T}
101+
struct ClampFunctor{T}
102102
a::T
103103
b::T
104104
end
105105

106-
clampU8{T}(x::RGBA{T}) = RGBA{T}(ntuple(i->clamp(getfield(x, i), 0.,1.), Val{4})...)
106+
clampU8(x::RGBA{T}) where {T} = RGBA{T}(ntuple(i->clamp(getfield(x, i), 0.,1.), Val{4})...)
107107
channel_color(channel, value) = RGBA{Float32}(ntuple(i->i==channel ? value : 0.0f0, Val{3})..., 1f0)
108-
function c_setindex{T}(color::RGBA{T}, val, channel)
108+
function c_setindex(color::RGBA{T}, val, channel) where T
109109
v = clamp.(val, 0, 1)
110110
RGBA{T}(
111111
1==channel ? v : comp1(color),
@@ -124,7 +124,7 @@ function edit_color(tex, buff, index_value, channel, maxval)
124124
nothing
125125
end
126126

127-
function widget{T<:Colorant}(colormap::VecTypes{T}, window;
127+
function widget(colormap::VecTypes{T}, window;
128128
area = (300, 30),
129129
slider_colors = (
130130
RGBA{Float32}(0.78125,0.1796875,0.41796875),
@@ -134,7 +134,7 @@ function widget{T<:Colorant}(colormap::VecTypes{T}, window;
134134
),
135135
knob_scale = 9f0,
136136
kw_args...
137-
)
137+
) where T<:Colorant
138138
colors = map(GLAbstraction.gl_promote(T), to_cpu_mem(value(colormap)))
139139
N = length(colors)
140140
color_tex = GLAbstraction.gl_convert(Texture, colormap)

src/gui/numbers.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function slide(startvalue, slide_pos, range::Range)
4646
clamp(val, range)
4747
end
4848

49-
function widget{T <: Union{StaticVector, Real}}(x::T, inputs, numberwidth=5;kw_args...)
49+
function widget(x::T, inputs, numberwidth=5;kw_args...) where T <: Union{StaticVector, Real}
5050
widget(typemin(T):eps(T):typemax(T), inputs, numberwidth; start_value=x, kw_args...)
5151
end
5252

@@ -60,18 +60,18 @@ function range_default{T<:Integer}(::Type{T})
6060
T(-100):T(1):T(100)
6161
end
6262

63-
function calc_val{T<:AbstractFloat}(sval::T, val, range)
63+
function calc_val(sval::T, val, range) where T<:AbstractFloat
6464
clamp(sval+(val*step(range)), first(range), last(range))
6565
end
66-
function calc_val{T<:Integer}(sval::T, val, range)
66+
function calc_val(sval::T, val, range) where T<:Integer
6767
clamp(sval+(round(T, val)*step(range)), first(range), last(range))
6868
end
69-
function widget{T <: StaticVector}(
69+
function widget(
7070
slider_value::Signal{T}, window;
7171
numberwidth = 5, range = range_default(T),
7272
text_scale = 4mm,
7373
kw_args...
74-
)
74+
) where T <: StaticVector
7575
last_x = 0f0
7676
le_sigs = []
7777
gap = text_scale * 2f0 # 2 characters gap
@@ -96,11 +96,11 @@ function widget{T <: StaticVector}(
9696

9797
Context(le_tuple...), map(T, le_sigs...)
9898
end
99-
function widget{T <: Real}(
99+
function widget(
100100
slider_value::Signal{T}, window;
101101
text_scale = 4mm,
102102
numberwidth = 5, range = range_default(T), kw_args...
103-
)
103+
) where T <: Real
104104
@materialize mouse_buttons_pressed, mouseposition = window.inputs
105105
startvalue = value(slider_value)
106106
slider_value_str = map(printforslider, slider_value)

0 commit comments

Comments
 (0)