Compare commits

..
1 Commits
Author SHA1 Message Date
harper 7fd3c96d01 Delete .DS_Store 2026-10-09 17:36:50 -07:00
4 changed files with 2 additions and 15 deletions
-1
View File
@@ -1 +0,0 @@
.DS_Store
+1 -4
View File
@@ -13,18 +13,15 @@ App :: struct {
entities: [dynamic]Entity, 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()) { add_system :: proc(app: ^App, schedule: int, system: proc()) {
append(&app.systems[schedule], system) 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)) { add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) {
append(&app.plugins, plugin) append(&app.plugins, plugin)
} }
// run the app run :: proc(app: ^App, entity_limit: int = 1000) {
run :: proc(app: ^App) {
for p in app.plugins { for p in app.plugins {
p(app) p(app)
} }
-9
View File
@@ -8,7 +8,6 @@ Storage :: struct($T: typeid) {
data: map[Entity]T, data: map[Entity]T,
} }
// adds a new entity id to app and returns it
spawn_entity :: proc(app: ^App) -> Entity { spawn_entity :: proc(app: ^App) -> Entity {
entity_num := len(&app.entities) entity_num := len(&app.entities)
entity: Entity = Entity(entity_num) entity: Entity = Entity(entity_num)
@@ -16,30 +15,23 @@ spawn_entity :: proc(app: ^App) -> Entity {
return entity return entity
} }
// create a new component of type and add to Storage
add_component :: proc { add_component :: proc {
add_fresh_component, add_fresh_component,
add_component_with_data, add_component_with_data,
} }
// initializes new component of type and add to Storage
add_fresh_component :: proc(entity: Entity, storage: ^Storage($T)) { add_fresh_component :: proc(entity: Entity, storage: ^Storage($T)) {
storage.data[entity] = 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) { add_component_with_data :: proc(entity: Entity, storage: ^Storage($T), component: T) {
storage.data[entity] = component storage.data[entity] = component
} }
// get components saved in Storage
// returns storage.data
slice :: proc(storage: ^Storage($T)) -> map[Entity]T { slice :: proc(storage: ^Storage($T)) -> map[Entity]T {
return storage.data return storage.data
} }
// get component saved in Storage
// returns Entity and component of type
single :: proc(storage: ^Storage($T)) -> (Entity, ^T) { single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
for i, &v in slice(storage) { for i, &v in slice(storage) {
return i, &v return i, &v
@@ -47,7 +39,6 @@ single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
return Entity{}, new(T) return Entity{}, new(T)
} }
// get component of type from entity
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T { get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
if c, exists := &storage.data[entity]; exists { if c, exists := &storage.data[entity]; exists {
return c return c
+1 -1
View File
@@ -13,7 +13,7 @@ DefaultPlugin :: proc(app: ^App) {
) )
} }
@(private)
draw_sprite :: proc() { draw_sprite :: proc() {
for i, &v in slice(&Sprite) { for i, &v in slice(&Sprite) {
sprite_transform := get_component(i, &Transform) sprite_transform := get_component(i, &Transform)