examples: fix the mandelbrot set example on Windows (#13251)
parent
fba9587323
commit
22c21e62a1
|
@ -21,8 +21,8 @@ struct AppState {
|
||||||
mut:
|
mut:
|
||||||
gg &gg.Context = 0
|
gg &gg.Context = 0
|
||||||
iidx int
|
iidx int
|
||||||
pixels [pheight][pwidth]u32
|
pixels []u32 = []u32{len: pwidth * pheight}
|
||||||
npixels [pheight][pwidth]u32 // all drawing happens here, results are copied with vmemcpy to pixels at the end
|
npixels []u32 = []u32{len: pwidth * pheight} // all drawing happens here, results are copied at the end
|
||||||
view ViewRect = ViewRect{-2.7610033817025625, 1.1788897130338223, -1.824584023871934, 2.1153096311072788}
|
view ViewRect = ViewRect{-2.7610033817025625, 1.1788897130338223, -1.824584023871934, 2.1153096311072788}
|
||||||
ntasks int = runtime.nr_jobs()
|
ntasks int = runtime.nr_jobs()
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ fn (mut state AppState) update() {
|
||||||
threads << go state.recalc_lines(cview, start, start + sheight)
|
threads << go state.recalc_lines(cview, start, start + sheight)
|
||||||
}
|
}
|
||||||
threads.wait()
|
threads.wait()
|
||||||
unsafe { vmemcpy(&state.pixels[0], &state.npixels[0], int(sizeof(state.pixels))) }
|
state.pixels = state.npixels
|
||||||
println('$state.ntasks threads; $sw.elapsed().milliseconds() ms / frame')
|
println('$state.ntasks threads; $sw.elapsed().milliseconds() ms / frame')
|
||||||
oview = cview
|
oview = cview
|
||||||
}
|
}
|
||||||
|
@ -65,14 +65,14 @@ fn (mut state AppState) recalc_lines(cview ViewRect, ymin f64, ymax f64) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.npixels[int(y_pixel)][int(x_pixel)] = u32(colors[iter % 8].abgr8())
|
state.npixels[int(y_pixel) * pwidth + int(x_pixel)] = u32(colors[iter % 8].abgr8())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut state AppState) draw() {
|
fn (mut state AppState) draw() {
|
||||||
mut istream_image := state.gg.get_cached_image_by_idx(state.iidx)
|
mut istream_image := state.gg.get_cached_image_by_idx(state.iidx)
|
||||||
istream_image.update_pixel_data(&state.pixels)
|
istream_image.update_pixel_data(&state.pixels[0])
|
||||||
size := gg.window_size()
|
size := gg.window_size()
|
||||||
state.gg.draw_image(0, 0, size.width, size.height, istream_image)
|
state.gg.draw_image(0, 0, size.width, size.height, istream_image)
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ fn graphics_keydown(code gg.KeyCode, mod gg.Modifier, mut state AppState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[console]
|
||||||
fn main() {
|
fn main() {
|
||||||
mut state := &AppState{}
|
mut state := &AppState{}
|
||||||
state.gg = gg.new_context(
|
state.gg = gg.new_context(
|
||||||
|
|
Loading…
Reference in New Issue