-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
101 lines (88 loc) · 2.01 KB
/
types.go
File metadata and controls
101 lines (88 loc) · 2.01 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import "github.com/go-gl/mathgl/mgl32"
/*
* Chunks: 16x16x16 blocks
* Pillars: arrays of chunks, summing up to 1024 blocks in height
* Accesing a chunk is really easy, we just need to get the X,Z pos of the pillar, and div the Y pos by 16 to get the chunk index.
*/
type Pillar struct {
chunks [64]*Chunk // 64 chunks per pillar
pos PillarPos
}
/*
* To access a chunk, you would find the pillarPosition and access the chunk by its pillar index
*/
type ChunkPosition struct {
pillarPos PillarPos
index uint8
}
func (c ChunkPosition) getWorldY() int32 {
return int32(c.index*CHUNK_SIZE) - 32
}
func getWorldYFromIndex(cI uint8) int32 {
return int32(cI*CHUNK_SIZE) - 32
}
func (c ChunkPosition) getWorldX() int32 {
return c.pillarPos.x * CHUNK_SIZE_i32
}
func (c ChunkPosition) getWorldZ() int32 {
return c.pillarPos.z * CHUNK_SIZE_i32
}
func (p PillarPos) getWorldX() int32 {
return p.x * CHUNK_SIZE_i32
}
func (p PillarPos) getWorldZ() int32 {
return p.z * CHUNK_SIZE_i32
}
type Chunk struct {
blocksData [CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE]*Block
lightSources []blockPosition
vao uint32
trisCount int32
}
type Block struct {
blockType uint16 // dirt, wood, stone, etc.
blockLight uint8 // light level of the block
sunLight uint8 // sunlight level of the block
}
func (block Block) isSolid() bool {
return BlockProperties[block.blockType].IsSolid
}
func (block Block) isTransparent() bool {
return BlockProperties[block.blockType].IsTransparent
}
func (block Block) lightLevel() uint8 {
return max(block.blockLight, block.sunLight)
}
type blockPosition struct {
x uint8
y uint8
z uint8
}
type Vec3Int8 struct {
x int8
y int8
z int8
}
type PillarPos struct {
x int32
z int32
}
type aabb struct {
Min, Max mgl32.Vec3
}
type text struct {
Texture uint32
Position mgl32.Vec2
Update bool
FontSize float64
Content interface{}
}
type collider struct {
Time float32
Normal []int
}
type ChunkBlockPositions struct {
chunkPos ChunkPosition
blockPos blockPosition
}