-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.wl
91 lines (75 loc) · 1.96 KB
/
entity.wl
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
import "libwl/vec.wl"
import "libwl/gl.wl"
import "libwl/collision.wl"
import "drawDevice.wl"
class Entity {
vec4 position
float rotation
static Entity first
Entity next
weak Entity prev
static void setFirst(Entity e) first = e
static Entity getFirst() return first
bool isDead() return false
static void add(Entity e) {
if(!first) {
first = e
} else {
first.prev = e
e.next = first
first = e
}
}
static void removeAll() {
// ideally the refcounters would handle deleting all these
first.next = null
first = null
}
float nummies() return 0.01f
float yummyNummies() return 0.0f
bool areYouCookie() return false
void update(float dt) {
}
GLMesh getMesh() return null
GLTexture getTexture() return null
float getScale() return 1.0f
Box3 getHitbox() {
vec4 d = vec4(1, 1, 1, 0)
return Box3(.position, d)
}
void draw(mat4 view) {
GLDrawDevice dev = GLDrawDevice.getInstance()
float scale = .getScale()
mat4 mat = mat4()
vec4 axis = vec4(0, 1, 0, 0)
mat = mat.rotate(.rotation, axis)
mat = mat.scale(scale, scale, scale)
mat = mat.translate(.position)
mat = view.mul(mat)
dev.runMeshProgram(.getMesh(), .getTexture(), mat)
if(dev.drawHitbox) dev.drawBoundingBox(.getHitbox(), view)
}
}
void updateEntities(float dt) {
Entity e = Entity.first
while(e) {
e.update(dt)
if(e.isDead()) {
Entity del = e
if(e.prev) e.prev.next = e.next
if(e.next) e.next.prev = e.prev
if(e == Entity.first) Entity.first = e.next
e = e.next
delete del
continue
}
e = e.next
}
}
void drawEntities(mat4 view) {
Entity e = Entity.first
while(e) {
e.draw(view)
e = e.next
}
}