mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
remove os/time references from live programs, fix warnings
This commit is contained in:
parent
8082a5e7f4
commit
32b0225079
@ -1,6 +1,5 @@
|
|||||||
module main
|
module main
|
||||||
|
|
||||||
import time
|
|
||||||
import gg
|
import gg
|
||||||
import glfw
|
import glfw
|
||||||
import gx
|
import gx
|
||||||
@ -50,9 +49,7 @@ fn main() {
|
|||||||
gg.post_empty_event() // needed so the animation does not stop
|
gg.post_empty_event() // needed so the animation does not stop
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
a.update()
|
a.update()
|
||||||
print_automaton(a)
|
print_automaton(a)
|
||||||
|
|
||||||
graphics.render()
|
graphics.render()
|
||||||
time.sleep_ms(1) // TODO: remove this when live reload depence on the time module is fixed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ fn main() {
|
|||||||
dy: 2
|
dy: 2
|
||||||
height: height
|
height: height
|
||||||
width: width
|
width: width
|
||||||
|
main_wnd: 0
|
||||||
|
draw_fn: 0
|
||||||
}
|
}
|
||||||
window := glfw.create_window(glfw.WinCfg {
|
window := glfw.create_window(glfw.WinCfg {
|
||||||
width: width
|
width: width
|
||||||
@ -49,6 +51,7 @@ fn main() {
|
|||||||
height: height
|
height: height
|
||||||
font_size: 20
|
font_size: 20
|
||||||
use_ortho: true
|
use_ortho: true
|
||||||
|
window_user_ptr: 0
|
||||||
})
|
})
|
||||||
println('Starting the game loop...')
|
println('Starting the game loop...')
|
||||||
go game.run()
|
go game.run()
|
||||||
@ -63,26 +66,39 @@ fn main() {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
width = 50
|
width = 50
|
||||||
|
red = gx.rgb(255,0,0)
|
||||||
|
green = gx.rgb(0,255,0)
|
||||||
|
blue = gx.rgb(0,0,255)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Try uncommenting or changing the lines inside the live functions.
|
||||||
|
// Guess what will happen:
|
||||||
[live]
|
[live]
|
||||||
fn (game &Game) draw() {
|
fn (game &Game) draw() {
|
||||||
game.gg.draw_rect(game.x, game.y, width, width, gx.rgb(255, 0, 0))
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
[live]
|
||||||
|
fn (game mut Game) update_model() {
|
||||||
|
// game.x = 0 game.y = 0 game.dx = 1 game.dy = 1
|
||||||
|
// game.dx = 3 game.dy = 3
|
||||||
|
speed := 2
|
||||||
|
game.x += speed * game.dx
|
||||||
|
game.y += speed * game.dy
|
||||||
|
if game.y >= game.height - width || game.y <= 0 {
|
||||||
|
game.dy = - game.dy
|
||||||
|
}
|
||||||
|
if game.x >= game.width - width || game.x <= 0 {
|
||||||
|
game.dx = - game.dx
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (game mut Game) run() {
|
fn (game mut Game) run() {
|
||||||
for {
|
for {
|
||||||
game.x += game.dx
|
game.update_model()
|
||||||
game.y += game.dy
|
glfw.post_empty_event() // Refresh
|
||||||
if game.y >= game.height - width || game.y <= 0 {
|
|
||||||
game.dy = - game.dy
|
|
||||||
}
|
|
||||||
if game.x >= game.width - width || game.x <= 0 {
|
|
||||||
game.dx = - game.dx
|
|
||||||
}
|
|
||||||
// Refresh
|
|
||||||
time.sleep_ms(17)
|
time.sleep_ms(17)
|
||||||
glfw.post_empty_event()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,12 @@ import gx
|
|||||||
import gg
|
import gg
|
||||||
import time
|
import time
|
||||||
import glfw
|
import glfw
|
||||||
// import math
|
import math
|
||||||
import os
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Size = 700
|
Size = 700
|
||||||
Scale = 50.0
|
Scale = 50.0
|
||||||
|
pi = math.pi
|
||||||
)
|
)
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
@ -17,7 +17,6 @@ struct Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
os.clear()
|
|
||||||
glfw.init_glfw()
|
glfw.init_glfw()
|
||||||
ctx:= &Context{
|
ctx:= &Context{
|
||||||
gg: gg.new_context(gg.Cfg {
|
gg: gg.new_context(gg.Cfg {
|
||||||
@ -40,23 +39,31 @@ fn main() {
|
|||||||
|
|
||||||
[live]
|
[live]
|
||||||
fn (ctx &Context) draw() {
|
fn (ctx &Context) draw() {
|
||||||
ctx.gg.draw_line(0, Size / 2, Size, Size / 2) // x axis
|
|
||||||
ctx.gg.draw_line(Size / 2, 0, Size / 2, Size) // y axis
|
|
||||||
center := f64(Size / 2)
|
center := f64(Size / 2)
|
||||||
|
ctx.gg.draw_line(0, center, Size, center) // x axis
|
||||||
|
ctx.gg.draw_line(center, 0, center, Size) // y axis
|
||||||
|
atime := f64( time.ticks() / 10 )
|
||||||
|
stime := math.sin( 2.0 * pi * f64( time.ticks() % 6000 ) / 6000 )
|
||||||
mut y := 0.0
|
mut y := 0.0
|
||||||
for x := -10.0; x <= 10.0; x += 0.002 {
|
y = 1.0
|
||||||
y = x * x - 1
|
for x := -10.0; x <= 10.0; x += 0.02 {
|
||||||
//y = (x + 3) * (x + 3) - 1
|
//y = x*x + 2
|
||||||
//y = math.sqrt(30.0 - x * x)
|
y = x*x + stime*stime
|
||||||
ctx.gg.draw_rect(center + x * Scale, center - y * Scale, 1, 1, gx.Black)
|
//y = stime
|
||||||
//ctx.gg.draw_rect(center + x * Scale, center + y * Scale, 1, 1, gx.Black)
|
//y = stime * x
|
||||||
|
y = stime*1.0*math.sin(x + stime+atime/50) * x
|
||||||
|
//y = (stime * x) * x + stime
|
||||||
|
//y = (x + 3) * (x + 3) / stime + stime*2.5
|
||||||
|
//y = math.sqrt(30.0 - x * x) * stime
|
||||||
|
//y -= (stime-0.5) + stime
|
||||||
|
ctx.gg.draw_rect(center + x * Scale, center - y * Scale, 1, 1, gx.Blue)
|
||||||
|
ctx.gg.draw_rect(center + x * Scale, center + y * Scale, 1, 1, gx.Red)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update() {
|
fn update() {
|
||||||
for {
|
for {
|
||||||
gg.post_empty_event()
|
gg.post_empty_event()
|
||||||
time.sleep_ms(300)
|
time.sleep_ms(16) // 60 fps
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// v -live message.v
|
// v -live message.v
|
||||||
module main
|
module main
|
||||||
|
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
[live]
|
[live]
|
||||||
@ -11,7 +10,6 @@ fn print_message() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
os.clear()
|
|
||||||
for {
|
for {
|
||||||
print_message()
|
print_message()
|
||||||
time.sleep_ms(500)
|
time.sleep_ms(500)
|
||||||
|
@ -277,7 +277,7 @@ fn todo_remove_me(cfg Cfg, scale int) {
|
|||||||
}
|
}
|
||||||
width := cfg.width * scale
|
width := cfg.width * scale
|
||||||
height := cfg.height * scale
|
height := cfg.height * scale
|
||||||
font_size := cfg.font_size * scale
|
//font_size := cfg.font_size * scale
|
||||||
gl.enable(C.GL_BLEND)
|
gl.enable(C.GL_BLEND)
|
||||||
//# glBlendFunc(C.GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
//# glBlendFunc(C.GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
shader := gl.new_shader('text')
|
shader := gl.new_shader('text')
|
||||||
|
@ -272,8 +272,8 @@ pub fn identity3() []f32 {
|
|||||||
|
|
||||||
// https://github.com/toji/gl-matrix/blob/1549cf21dfa14a2bc845993485343d519cf064fe/src/gl-matrix/mat4.js
|
// https://github.com/toji/gl-matrix/blob/1549cf21dfa14a2bc845993485343d519cf064fe/src/gl-matrix/mat4.js
|
||||||
fn ortho_js(left, right, bottom, top f32) &f32 {
|
fn ortho_js(left, right, bottom, top f32) &f32 {
|
||||||
mynear := 1
|
// mynear := 1
|
||||||
myfar := 1
|
// myfar := 1
|
||||||
lr := 1.0 / (left - right)
|
lr := 1.0 / (left - right)
|
||||||
bt := 1.0 / (bottom - top)
|
bt := 1.0 / (bottom - top)
|
||||||
nf := 1.0 / 1.0// (mynear -myfar)
|
nf := 1.0 / 1.0// (mynear -myfar)
|
||||||
|
Loading…
Reference in New Issue
Block a user