compiler: fix -live compilation of bounce example with gcc-9 & clang
parent
7a51d4d796
commit
aa9bb6f71a
|
@ -34,7 +34,7 @@ fn main() {
|
||||||
main_wnd: 0
|
main_wnd: 0
|
||||||
draw_fn: 0
|
draw_fn: 0
|
||||||
}
|
}
|
||||||
window := glfw.create_window(glfw.WinCfg {
|
window := glfw.create_window(glfw.WinCfg{
|
||||||
width: width
|
width: width
|
||||||
height: height
|
height: height
|
||||||
borderless: false
|
borderless: false
|
||||||
|
@ -42,11 +42,11 @@ fn main() {
|
||||||
ptr: game
|
ptr: game
|
||||||
always_on_top: true
|
always_on_top: true
|
||||||
})
|
})
|
||||||
//window.onkeydown(key_down)
|
// window.onkeydown(key_down)
|
||||||
game.main_wnd = window
|
game.main_wnd = window
|
||||||
window.make_context_current()
|
window.make_context_current()
|
||||||
gg.init_gg()
|
gg.init_gg()
|
||||||
game.gg = gg.new_context(gg.Cfg {
|
game.gg = gg.new_context(gg.Cfg{
|
||||||
width: width
|
width: width
|
||||||
height: height
|
height: height
|
||||||
font_size: 20
|
font_size: 20
|
||||||
|
@ -69,9 +69,9 @@ fn main() {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
width = 50
|
width = 50
|
||||||
red = gx.rgb(255,0,0)
|
red = gx.rgb(255, 0, 0)
|
||||||
green = gx.rgb(0,255,0)
|
green = gx.rgb(0, 255, 0)
|
||||||
blue = gx.rgb(0,0,255)
|
blue = gx.rgb(0, 0, 255)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Try uncommenting or changing the lines inside the live functions.
|
// Try uncommenting or changing the lines inside the live functions.
|
||||||
|
@ -79,27 +79,28 @@ const (
|
||||||
[live]
|
[live]
|
||||||
fn (game &Game) draw() {
|
fn (game &Game) draw() {
|
||||||
game.gg.draw_rect(game.x, game.y, width, width, blue)
|
game.gg.draw_rect(game.x, game.y, width, width, blue)
|
||||||
// game.gg.draw_rect(game.x, game.y, width, width, gx.rgb(128,10,255))
|
game.gg.draw_rect(550 - game.x + 10, 200 - game.y + 50, width, width, gx.rgb(128, 10, 255))
|
||||||
|
game.gg.draw_rect(game.x - 20, 250 - game.y, width, width, gx.rgb(128, 240, 155))
|
||||||
}
|
}
|
||||||
|
|
||||||
[live]
|
[live]
|
||||||
fn (game mut Game) update_model() {
|
fn (mut game Game) update_model() {
|
||||||
// game.x = 0 game.y = 0 game.dx = 1 game.dy = 1
|
// game.x = 0 game.y = 0 game.dx = 1 game.dy = 1
|
||||||
// game.dx = 3 game.dy = 3
|
// game.dx = 3 game.dy = 3
|
||||||
speed := 2
|
speed := 2
|
||||||
game.x += speed * game.dx
|
game.x += speed * game.dx
|
||||||
game.y += speed * game.dy
|
game.y += speed * game.dy
|
||||||
if game.y >= game.height - width || game.y <= 0 {
|
if game.y >= game.height - width || game.y <= 0 {
|
||||||
game.dy = - game.dy
|
game.dy = -game.dy
|
||||||
}
|
}
|
||||||
if game.x >= game.width - width || game.x <= 0 {
|
if game.x >= game.width - width || game.x <= 0 {
|
||||||
game.dx = - game.dx
|
game.dx = -game.dx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (game mut Game) run() {
|
fn (mut game Game) run() {
|
||||||
for {
|
for {
|
||||||
game.update_model()
|
game.update_model()
|
||||||
glfw.post_empty_event() // Refresh
|
glfw.post_empty_event() // Refresh
|
||||||
time.sleep_ms(17)
|
time.sleep_ms(17)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||||
}
|
}
|
||||||
g.definitions.writeln(');')
|
g.definitions.writeln(');')
|
||||||
g.writeln(') {')
|
g.writeln(') {')
|
||||||
if is_livemain {
|
if is_live_wrap {
|
||||||
// The live function just calls its implementation dual, while ensuring
|
// The live function just calls its implementation dual, while ensuring
|
||||||
// that the call is wrapped by the mutex lock & unlock calls.
|
// that the call is wrapped by the mutex lock & unlock calls.
|
||||||
// Adding the mutex lock/unlock inside the body of the implementation
|
// Adding the mutex lock/unlock inside the body of the implementation
|
||||||
|
|
Loading…
Reference in New Issue