diff --git a/isotest/app.v b/isotest/app.v index a9e633c..9c02564 100644 --- a/isotest/app.v +++ b/isotest/app.v @@ -67,14 +67,43 @@ fn (mut a App) init(w, h int, title string) { println("app init done") } -fn (mut a App) step() { +fn (mut a App) step() bool { println("app step()") a.dt = f32(20.0) + + mut should_close := false + //for { + //evt := SDL_Event{} + evt := vsdl2.Event{} + for 0 < vsdl2.poll_event(&evt) { + match int(evt.@type) { + C.SDL_QUIT { should_close = true } + + C.SDL_KEYDOWN { + key := evt.key.keysym.sym + if key == C.SDLK_ESCAPE || key == C.SDLK_q { + should_close = true + break + } + } + + else {} + } + + } + //} + + if should_close { + //pp(2) + return false + } //a.render() a.update(a.dt) + + return true } fn (mut a App) flip() { @@ -83,6 +112,14 @@ fn (mut a App) flip() { C.SDL_RenderPresent(a.renderer) } +fn (mut a App) quit() { + println("app quit()") + + //C.SDL_DestroyRenderer(a.renderer) + C.SDL_DestroyWindow(a.window) + C.SDL_Quit() +} + fn (mut a App) update(dt f32) { } diff --git a/isotest/main.v b/isotest/main.v index e5892c6..6e79959 100644 --- a/isotest/main.v +++ b/isotest/main.v @@ -26,8 +26,8 @@ fn main() { tex := d.load_image_tex("res/images/heightmap.png") - for { - app.step() + for app.step() { + //app.step() d.clear() @@ -38,7 +38,9 @@ fn main() { //time.sleep_ms(20) time.sleep_ms(200) //pp(2) - } + } + + app.quit() println("done") }