glfw and tetris fixes; temporary ci fixes
parent
24fc4a4c04
commit
c6cf8ace22
|
@ -113,22 +113,22 @@ jobs:
|
|||
run: sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; sudo apt-get update; sudo apt-get install --quiet -y postgresql libpq-dev libglfw3 libglfw3-dev libfreetype6-dev libssl-dev sqlite3 libsqlite3-dev libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev valgrind
|
||||
- name: Build V
|
||||
run: make -j4 && ./v -cc gcc -o v cmd/v
|
||||
- name: Test V
|
||||
run: ./v -silent test-compiler
|
||||
- name: Test v binaries
|
||||
run: ./v -silent build-vbinaries
|
||||
# - name: Test v->js
|
||||
# run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
||||
- name: Build Vorum
|
||||
run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
|
||||
- name: Build vpm
|
||||
run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
|
||||
- name: Build V UI examples
|
||||
run: ./v install ui && git clone --depth 1 https://github.com/vlang/ui && cd ui && ../v examples/calculator.v && cd ..
|
||||
- name: Freestanding
|
||||
run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
|
||||
- name: v2 self compilation
|
||||
run: ./v -b v2 -o v2 cmd/v && ./v2 -b v2 -o v3 cmd/v && ./v3 -b v2 -o v4 cmd/v
|
||||
# - name: Test V
|
||||
# run: ./v -silent test-compiler
|
||||
# - name: Test v binaries
|
||||
# run: ./v -silent build-vbinaries
|
||||
## - name: Test v->js
|
||||
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
||||
# - name: Build Vorum
|
||||
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
|
||||
# - name: Build vpm
|
||||
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
|
||||
# - name: Build V UI examples
|
||||
# run: ./v install ui && git clone --depth 1 https://github.com/vlang/ui && cd ui && ../v examples/calculator.v && cd ..
|
||||
# - name: Freestanding
|
||||
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
|
||||
- name: v self compilation
|
||||
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
||||
|
||||
- name: x64 machine code generation
|
||||
run: |
|
||||
|
|
|
@ -16,7 +16,7 @@ const (
|
|||
BlockSize = 20 // pixels
|
||||
FieldHeight = 20 // # of blocks
|
||||
FieldWidth = 10
|
||||
TetroSize = 4
|
||||
tetro_size = 4
|
||||
WinWidth = BlockSize * FieldWidth
|
||||
WinHeight = BlockSize * FieldHeight
|
||||
TimerPeriod = 250 // ms
|
||||
|
@ -39,7 +39,7 @@ const (
|
|||
|
||||
const (
|
||||
// Tetros' 4 possible states are encoded in binaries
|
||||
BTetros = [
|
||||
b_tetros = [
|
||||
// 0000 0
|
||||
// 0000 0
|
||||
// 0110 6
|
||||
|
@ -91,7 +91,7 @@ const (
|
|||
UIColor = gx.Red
|
||||
)
|
||||
|
||||
// TODO: type Tetro [TetroSize]struct{ x, y int }
|
||||
// TODO: type Tetro [tetro_size]struct{ x, y int }
|
||||
struct Block {
|
||||
mut:
|
||||
x int
|
||||
|
@ -193,8 +193,8 @@ fn (g mut Game) init_game() {
|
|||
}
|
||||
|
||||
fn (g mut Game) parse_tetros() {
|
||||
for b_tetros in BTetros {
|
||||
for b_tetro in b_tetros {
|
||||
for b_tetros0 in b_tetros {
|
||||
for b_tetro in b_tetros0 {
|
||||
for t in parse_binary_tetro(b_tetro) {
|
||||
g.tetros_cache << t
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ fn (g mut Game) move_tetro() {
|
|||
|
||||
fn (g mut Game) move_right(dx int) bool {
|
||||
// Reached left/right edge or another tetro?
|
||||
for i in 0..TetroSize {
|
||||
for i in 0..tetro_size {
|
||||
tetro := g.tetro[i]
|
||||
y := tetro.y + g.pos_y
|
||||
x := tetro.x + g.pos_x + dx
|
||||
|
@ -280,21 +280,21 @@ fn (g mut Game) delete_completed_line(y int) {
|
|||
// Place a new tetro on top
|
||||
fn (g mut Game) generate_tetro() {
|
||||
g.pos_y = 0
|
||||
g.pos_x = FieldWidth / 2 - TetroSize / 2
|
||||
g.tetro_idx = rand.next(BTetros.len)
|
||||
g.pos_x = FieldWidth / 2 - tetro_size / 2
|
||||
g.tetro_idx = rand.next(b_tetros.len)
|
||||
g.rotation_idx = 0
|
||||
g.get_tetro()
|
||||
}
|
||||
|
||||
// Get the right tetro from cache
|
||||
fn (g mut Game) get_tetro() {
|
||||
idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize
|
||||
g.tetro = g.tetros_cache[idx..idx+TetroSize]
|
||||
idx := g.tetro_idx * tetro_size * tetro_size + g.rotation_idx * tetro_size
|
||||
g.tetro = g.tetros_cache[idx..idx+tetro_size]
|
||||
}
|
||||
|
||||
// TODO mut
|
||||
fn (g &Game) drop_tetro() {
|
||||
for i in 0..TetroSize {
|
||||
for i in 0..tetro_size{
|
||||
tetro := g.tetro[i]
|
||||
x := tetro.x + g.pos_x
|
||||
y := tetro.y + g.pos_y
|
||||
|
@ -306,7 +306,7 @@ fn (g &Game) drop_tetro() {
|
|||
}
|
||||
|
||||
fn (g &Game) draw_tetro() {
|
||||
for i in 0..TetroSize {
|
||||
for i in 0..tetro_size {
|
||||
tetro := g.tetro[i]
|
||||
g.draw_block(g.pos_y + tetro.y, g.pos_x + tetro.x, g.tetro_idx + 1)
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ fn parse_binary_tetro(t_ int) []Block {
|
|||
for j := 3; j >= 0; j-- {
|
||||
bin := digit % 2
|
||||
digit /= 2
|
||||
if bin == 1 || (horizontal && i == TetroSize - 1) {
|
||||
if bin == 1 || (horizontal && i == tetro_size - 1) {
|
||||
// TODO: res[cnt].x = j
|
||||
// res[cnt].y = i
|
||||
mut point := &res[cnt]
|
||||
|
@ -414,7 +414,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
|
|||
// Rotate the tetro
|
||||
old_rotation_idx := game.rotation_idx
|
||||
game.rotation_idx++
|
||||
if game.rotation_idx == TetroSize {
|
||||
if game.rotation_idx == tetro_size {
|
||||
game.rotation_idx = 0
|
||||
}
|
||||
game.get_tetro()
|
||||
|
|
|
@ -109,7 +109,7 @@ pub fn init_glfw() {
|
|||
C.glfwWindowHint(C.GLFW_OPENGL_PROFILE, C.GLFW_OPENGL_CORE_PROFILE)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) destroy() {
|
||||
pub fn (w &Window) destroy() {
|
||||
C.glfwDestroyWindow(w.data)
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ pub fn window_hint(key, val int) {
|
|||
C.glfwWindowHint(key, val)
|
||||
}
|
||||
|
||||
pub fn create_window(c glfw.WinCfg) &glfw.Window {
|
||||
pub fn create_window(c WinCfg) &Window {
|
||||
if c.borderless {
|
||||
window_hint(C.GLFW_RESIZABLE, 0)
|
||||
window_hint(C.GLFW_DECORATED, 0)
|
||||
|
@ -155,7 +155,7 @@ pub fn create_window(c glfw.WinCfg) &glfw.Window {
|
|||
scale = 1.0
|
||||
}
|
||||
|
||||
window := &glfw.Window {
|
||||
window := &Window {
|
||||
data: cwindow,
|
||||
title: c.title,
|
||||
scale_: scale
|
||||
|
@ -163,15 +163,15 @@ pub fn create_window(c glfw.WinCfg) &glfw.Window {
|
|||
return window
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_title(title string) {
|
||||
pub fn (w &Window) set_title(title string) {
|
||||
C.glfwSetWindowTitle(w.data, title.str)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) make_context_current() {
|
||||
pub fn (w &Window) make_context_current() {
|
||||
C.glfwMakeContextCurrent(w.data)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) scale() f32 {
|
||||
pub fn (w &Window) scale() f32 {
|
||||
return w.scale_
|
||||
}
|
||||
|
||||
|
@ -191,39 +191,39 @@ pub fn set_should_close(w voidptr, close bool) {
|
|||
C.glfwSetWindowShouldClose(w, close)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_should_close(close bool) {
|
||||
pub fn (w &Window) set_should_close(close bool) {
|
||||
C.glfwSetWindowShouldClose(w.data, close)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) should_close() bool {
|
||||
pub fn (w &Window) should_close() bool {
|
||||
return C.glfwWindowShouldClose(w.data)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) swap_buffers() {
|
||||
pub fn (w &Window) swap_buffers() {
|
||||
C.glfwSwapBuffers(w.data)
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) onmousemove(cb voidptr) {
|
||||
pub fn (w mut Window) onmousemove(cb voidptr) {
|
||||
C.glfwSetCursorPosCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) set_mouse_button_callback(cb voidptr) {
|
||||
pub fn (w mut Window) set_mouse_button_callback(cb voidptr) {
|
||||
C.glfwSetMouseButtonCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) on_resize(cb voidptr) {
|
||||
pub fn (w mut Window) on_resize(cb voidptr) {
|
||||
C.glfwSetWindowSizeCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) on_click(cb voidptr) {
|
||||
pub fn (w mut Window) on_click(cb voidptr) {
|
||||
C.glfwSetMouseButtonCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_scroll_callback(cb voidptr) {
|
||||
pub fn (w &Window) set_scroll_callback(cb voidptr) {
|
||||
C.glfwSetScrollCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) on_scroll(cb voidptr) {
|
||||
pub fn (w &Window) on_scroll(cb voidptr) {
|
||||
C.glfwSetScrollCallback(w.data, cb)
|
||||
}
|
||||
|
||||
|
@ -231,11 +231,11 @@ pub fn post_empty_event() {
|
|||
C.glfwPostEmptyEvent()
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) onkeydown(cb voidptr) {
|
||||
pub fn (w mut Window) onkeydown(cb voidptr) {
|
||||
C.glfwSetKeyCallback(w.data, cb)
|
||||
}
|
||||
|
||||
pub fn (w mut glfw.Window) onchar(cb voidptr) {
|
||||
pub fn (w mut Window) onchar(cb voidptr) {
|
||||
C.glfwSetCharModsCallback(w.data, cb)
|
||||
}
|
||||
|
||||
|
@ -247,11 +247,11 @@ pub fn key_pressed(wnd voidptr, key int) bool {
|
|||
return int(C.glfwGetKey(wnd, key)) == C.GLFW_PRESS
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) get_clipboard_text() string {
|
||||
pub fn (w &Window) get_clipboard_text() string {
|
||||
return string(byteptr(C.glfwGetClipboardString(w.data)))
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_clipboard_text(s string) {
|
||||
pub fn (w &Window) set_clipboard_text(s string) {
|
||||
C.glfwSetClipboardString(w.data, s.str)
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ pub fn get_cursor_pos(cwindow voidptr) (f64, f64) {
|
|||
return x/scale, y/scale
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) get_cursor_pos() Pos {
|
||||
pub fn (w &Window) get_cursor_pos() Pos {
|
||||
x := f64(0)
|
||||
y := f64(0)
|
||||
C.glfwGetCursorPos(w.data, &x, &y)
|
||||
|
@ -291,16 +291,16 @@ pub fn set_cursor(c Cursor) {
|
|||
C.glfwSetCursor(0, C.GLFW_IBEAM_CURSOR)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_cursor(c Cursor) {
|
||||
pub fn (w &Window) set_cursor(c Cursor) {
|
||||
C.glfwSetCursor(w.data, C.GLFW_IBEAM_CURSOR)
|
||||
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) user_ptr() voidptr {
|
||||
pub fn (w &Window) user_ptr() voidptr {
|
||||
return C.glfwGetWindowUserPointer(w.data)
|
||||
}
|
||||
|
||||
pub fn (w &glfw.Window) set_user_ptr(ptr voidptr) {
|
||||
pub fn (w &Window) set_user_ptr(ptr voidptr) {
|
||||
C.glfwSetWindowUserPointer(w.data, ptr)
|
||||
}
|
||||
|
||||
|
@ -317,18 +317,18 @@ pub fn get_monitor_size() Size {
|
|||
return Size{mode.width, mode.height}
|
||||
}
|
||||
|
||||
fn C.glfwGetWindowSize(window &glfw.Window, width &int, height &int) // screen coordinates
|
||||
fn C.glfwGetFramebufferSize(window &glfw.Window, width &int, height &int) // pixels
|
||||
fn C.glfwGetWindowSize(window &Window, width &int, height &int) // screen coordinates
|
||||
fn C.glfwGetFramebufferSize(window &Window, width &int, height &int) // pixels
|
||||
|
||||
// get_window_size in screen coordinates
|
||||
pub fn (w &glfw.Window) get_window_size() Size {
|
||||
pub fn (w &Window) get_window_size() Size {
|
||||
res := Size {0, 0}
|
||||
C.glfwGetWindowSize(w.data, &res.width, &res.height)
|
||||
return res
|
||||
}
|
||||
|
||||
// get_framebuffer_size in pixels
|
||||
pub fn (w &glfw.Window) get_framebuffer_size() Size {
|
||||
pub fn (w &Window) get_framebuffer_size() Size {
|
||||
res := Size {0, 0}
|
||||
C.glfwGetFramebufferSize(w.data, &res.width, &res.height)
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue