change how systems are stored
This commit is contained in:
+8
-17
@@ -3,27 +3,18 @@ package shoal
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
STARTUP := 0
|
STARTUP :: 0
|
||||||
UPDATE := 1
|
UPDATE :: 1
|
||||||
DRAW := 2
|
DRAW :: 2
|
||||||
|
|
||||||
App :: struct {
|
App :: struct {
|
||||||
startup_systems: [dynamic]proc(),
|
systems: map[int][dynamic]proc(),
|
||||||
update_systems: [dynamic]proc(),
|
|
||||||
draw_systems: [dynamic]proc(),
|
|
||||||
plugins: [dynamic]proc(app: ^App),
|
plugins: [dynamic]proc(app: ^App),
|
||||||
entities: [dynamic]Entity,
|
entities: [dynamic]Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
add_system :: proc(app: ^App, schedule: int, system: proc()) {
|
add_system :: proc(app: ^App, schedule: int, system: proc()) {
|
||||||
switch schedule {
|
append(&app.systems[schedule], system)
|
||||||
case STARTUP:
|
|
||||||
append(&app.startup_systems, system)
|
|
||||||
case UPDATE:
|
|
||||||
append(&app.update_systems, system)
|
|
||||||
case DRAW:
|
|
||||||
append(&app.draw_systems, system)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) {
|
add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) {
|
||||||
@@ -34,7 +25,7 @@ run :: proc(app: ^App, entity_limit: int = 1000) {
|
|||||||
for p in app.plugins {
|
for p in app.plugins {
|
||||||
p(app)
|
p(app)
|
||||||
}
|
}
|
||||||
for i in app.startup_systems {i()}
|
for i in app.systems[STARTUP] {i()}
|
||||||
|
|
||||||
_, window := single(&Window)
|
_, window := single(&Window)
|
||||||
rl.InitWindow(window.width, window.height, strings.clone_to_cstring(window.title))
|
rl.InitWindow(window.width, window.height, strings.clone_to_cstring(window.title))
|
||||||
@@ -43,9 +34,9 @@ run :: proc(app: ^App, entity_limit: int = 1000) {
|
|||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
rl.ClearBackground(window.background)
|
rl.ClearBackground(window.background)
|
||||||
for i in app.update_systems {i()}
|
for i in app.systems[UPDATE] {i()}
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
for i in app.draw_systems {i()}
|
for i in app.systems[DRAW] {i()}
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user