lowkey im high rn
This commit is contained in:
+8
-1
@@ -2,6 +2,13 @@ package shoal
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
WindowComponent :: struct {
|
||||
width: i32,
|
||||
height: i32,
|
||||
title: string,
|
||||
}
|
||||
Window: Storage(WindowComponent)
|
||||
|
||||
SpriteComponent :: struct {
|
||||
texture: rl.Texture2D,
|
||||
}
|
||||
@@ -9,6 +16,6 @@ Sprite: Storage(SpriteComponent)
|
||||
|
||||
TransformComponent :: struct {
|
||||
translation: rl.Vector2,
|
||||
rotation: int,
|
||||
rotation: f32,
|
||||
}
|
||||
Transform: Storage(TransformComponent)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package shoal
|
||||
|
||||
import "core:strings"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
STARTUP := 0
|
||||
@@ -30,15 +31,18 @@ add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) {
|
||||
}
|
||||
|
||||
run :: proc(app: ^App, entity_limit: int = 1000) {
|
||||
rl.InitWindow(800, 600, "shoal window")
|
||||
defer rl.CloseWindow()
|
||||
|
||||
for p in app.plugins {
|
||||
p(app)
|
||||
}
|
||||
|
||||
for i in app.startup_systems {i()}
|
||||
|
||||
_, window := single(&Window)
|
||||
rl.InitWindow(window.width, window.height, strings.clone_to_cstring(window.title))
|
||||
defer rl.CloseWindow()
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
for !rl.WindowShouldClose() {
|
||||
rl.ClearBackground(rl.WHITE)
|
||||
for i in app.update_systems {i()}
|
||||
rl.BeginDrawing()
|
||||
for i in app.draw_systems {i()}
|
||||
|
||||
+17
-1
@@ -15,14 +15,30 @@ spawn_entity :: proc(app: ^App) -> Entity {
|
||||
return entity
|
||||
}
|
||||
|
||||
add_component :: proc(entity: Entity, storage: ^Storage($T)) {
|
||||
add_component :: proc {
|
||||
add_fresh_component,
|
||||
add_component_with_data,
|
||||
}
|
||||
|
||||
add_fresh_component :: proc(entity: Entity, storage: ^Storage($T)) {
|
||||
storage.data[entity] = T{}
|
||||
}
|
||||
|
||||
add_component_with_data :: proc(entity: Entity, storage: ^Storage($T), component: T) {
|
||||
storage.data[entity] = component
|
||||
}
|
||||
|
||||
slice :: proc(storage: ^Storage($T)) -> map[Entity]T {
|
||||
return storage.data
|
||||
}
|
||||
|
||||
single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
|
||||
for i, &v in slice(storage) {
|
||||
return i, &v
|
||||
}
|
||||
return Entity{}, new(T)
|
||||
}
|
||||
|
||||
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
|
||||
if c, exists := &storage.data[entity]; exists {
|
||||
return c
|
||||
|
||||
+10
-2
@@ -4,11 +4,19 @@ import rl "vendor:raylib"
|
||||
|
||||
DefaultPlugin :: proc(app: ^App) {
|
||||
add_system(app, DRAW, draw_sprite)
|
||||
|
||||
display := spawn_entity(app)
|
||||
add_component(
|
||||
display,
|
||||
&Window,
|
||||
WindowComponent{width = 800, height = 600, title = "shoal window"},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
draw_sprite :: proc() {
|
||||
for i, &v in sprites.data {
|
||||
sprite_transform := transforms.data[i]
|
||||
for i, &v in slice(&Sprite) {
|
||||
sprite_transform := get_component(i, &Transform)
|
||||
rl.DrawTexture(
|
||||
v.texture,
|
||||
i32(sprite_transform.translation.x),
|
||||
|
||||
Reference in New Issue
Block a user