-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.v
74 lines (59 loc) · 1.93 KB
/
game.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module main
import time
import mathf
import graphics
import misc
import glfw
import terrain
fn init_fn(game_ptr voidptr) {
mut game := &Game(game_ptr)
mut progress := misc.create_progress()
eprintln('1')
mesh := graphics.load_mesh('assets/objects/cube.obj', mut progress) or { panic(err) }
eprintln('2')
object := graphics.create_object(mesh,
position: mathf.vec3<f32>(0, 0, 5)
rotation: mathf.vec3<f32>(0, 0, 0)
scale: mathf.vec3<f32>(1, 1, 1)
)
game.world.add_object(object)
/*
mut plane := graphics.create_plane(quad_length: 1, height: 20, width: 20, y_mult: 0.01)
seed := time.now().unix
heightmap := terrain.create_random_heightmap(int(seed), 20, 20, 1, 1, terrain.perlin_map_gen)
plane.update_by_heightmap(heightmap) or { panic(err) }
game.world.add_object(plane, mathf.vec3<f32>(0, 0, 5), mathf.vec3<f32>(0, 0,
0), mathf.vec3<f32>(1, 1, 1))*/
}
fn mouse_fn(game_ptr voidptr) {
mut game := &Game(game_ptr)
game.camera.look(game.mouse.off_y, game.mouse.off_x)
}
fn loop_fn(delta time.Duration, game_ptr voidptr) ? {
mut game := &Game(game_ptr)
delta_seconds := f32(delta.seconds())
// Key handling
if game.keyboard.is_pressed(.key_w) {
game.camera.move(mathf.vec3<f32>(0, 0, 1), delta_seconds)
}
if game.keyboard.is_pressed(.key_s) {
game.camera.move(mathf.vec3<f32>(0, 0, -1), delta_seconds)
}
if game.keyboard.is_pressed(.key_d) {
game.camera.move(mathf.vec3<f32>(1, 0, 0), delta_seconds)
}
if game.keyboard.is_pressed(.key_a) {
game.camera.move(mathf.vec3<f32>(-1, 0, 0), delta_seconds)
}
if game.keyboard.is_pressed(.key_escape) {
glfw.show_mouse(game.window)
}
game.rotation += delta_seconds * 0.25
for i, obj in game.world.objects {
/*
game.world.meshes[i].ubo.update_ubo(game.fov, f32(game.width) / f32(game.height),
game.near_plane, game.far_plane, game.camera.look_at(), mesh.position, mesh.rotation,
mesh.scale)
game.world.uniform_buffers[i].map_buffer<mathf.UBO>(&mesh.ubo) ?*/
}
}