Compare commits

..
2 Commits
Author SHA1 Message Date
harper 99720dbcd7 fuck DS_Store 2026-10-09 21:26:00 -07:00
harper 508739e9ac add descriptions 2026-10-09 21:20:06 -07:00
4 changed files with 15 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
.DS_Store
+4 -1
View File
@@ -13,15 +13,18 @@ App :: struct {
entities: [dynamic]Entity,
}
// add a new system to the app that will run based on the provided schedule
add_system :: proc(app: ^App, schedule: int, system: proc()) {
append(&app.systems[schedule], system)
}
// add a new plugin to the app. a modular way to add new functionality from beyond the main procedure
add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) {
append(&app.plugins, plugin)
}
run :: proc(app: ^App, entity_limit: int = 1000) {
// run the app
run :: proc(app: ^App) {
for p in app.plugins {
p(app)
}
+9
View File
@@ -8,6 +8,7 @@ Storage :: struct($T: typeid) {
data: map[Entity]T,
}
// adds a new entity id to app and returns it
spawn_entity :: proc(app: ^App) -> Entity {
entity_num := len(&app.entities)
entity: Entity = Entity(entity_num)
@@ -15,23 +16,30 @@ spawn_entity :: proc(app: ^App) -> Entity {
return entity
}
// create a new component of type and add to Storage
add_component :: proc {
add_fresh_component,
add_component_with_data,
}
// initializes new component of type and add to Storage
add_fresh_component :: proc(entity: Entity, storage: ^Storage($T)) {
storage.data[entity] = T{}
}
// creates a copy of component type with data and add to Storage
add_component_with_data :: proc(entity: Entity, storage: ^Storage($T), component: T) {
storage.data[entity] = component
}
// get components saved in Storage
// returns storage.data
slice :: proc(storage: ^Storage($T)) -> map[Entity]T {
return storage.data
}
// get component saved in Storage
// returns Entity and component of type
single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
for i, &v in slice(storage) {
return i, &v
@@ -39,6 +47,7 @@ single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
return Entity{}, new(T)
}
// get component of type from entity
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
if c, exists := &storage.data[entity]; exists {
return c
+1 -1
View File
@@ -13,7 +13,7 @@ DefaultPlugin :: proc(app: ^App) {
)
}
@(private)
draw_sprite :: proc() {
for i, &v in slice(&Sprite) {
sprite_transform := get_component(i, &Transform)