timers
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package shoal
|
||||||
|
|
||||||
|
@(private)
|
||||||
|
signal_buffer_b: [dynamic]string
|
||||||
|
@(private)
|
||||||
|
signal_buffer_a: [dynamic]string
|
||||||
|
|
||||||
|
write :: proc(name: string) {
|
||||||
|
append(&signal_buffer_b, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
read :: proc(name: string) -> bool {
|
||||||
|
for s in signal_buffer_a {
|
||||||
|
if s == name {return true}
|
||||||
|
}
|
||||||
|
for s in signal_buffer_b {
|
||||||
|
if s == name {return true}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
signal_system :: proc() {
|
||||||
|
signal_buffer_a = signal_buffer_b
|
||||||
|
clear(&signal_buffer_b)
|
||||||
|
}
|
||||||
+2
-2
@@ -3,9 +3,9 @@ package shoal
|
|||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
DefaultPlugin :: proc(app: ^App) {
|
DefaultPlugin :: proc(app: ^App) {
|
||||||
app.systems = make(map[int][dynamic]proc())
|
|
||||||
|
|
||||||
add_system(app, DRAW, draw_sprite)
|
add_system(app, DRAW, draw_sprite)
|
||||||
|
add_system(app, UPDATE, signal_system)
|
||||||
|
add_system(app, UPDATE, run_timers)
|
||||||
|
|
||||||
display := spawn_entity(app)
|
display := spawn_entity(app)
|
||||||
add_component(
|
add_component(
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package shoal
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
Timer :: struct {
|
||||||
|
lifetime: f32,
|
||||||
|
signal: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
@(private)
|
||||||
|
timers: [dynamic]Timer
|
||||||
|
|
||||||
|
start_timer :: proc(time: f32, signal: string = "") -> int {
|
||||||
|
new_timer: Timer
|
||||||
|
new_timer.lifetime = time
|
||||||
|
append(&timers, new_timer)
|
||||||
|
return len(timers)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_timer :: proc(index: int) -> Timer {
|
||||||
|
if index <= len(timers) - 1 {
|
||||||
|
return timers[index]
|
||||||
|
}
|
||||||
|
return Timer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_timers :: proc() {
|
||||||
|
for &t, i in timers {
|
||||||
|
t.lifetime -= rl.GetFrameTime()
|
||||||
|
if t.lifetime <= 0 {
|
||||||
|
unordered_remove(&timers, i)
|
||||||
|
if t.signal != "" {
|
||||||
|
write(t.signal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user