Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def world
- "The world as it is this frame"
- (atom {}))
- (def old-world
- "The world as it was last frame"
- (atom {}))
- (def world-fns
- "Vector of fns to run against the world before updates."
- (atom []))
- (defn update-entity
- "Return new entity running all logic for given entity"
- [entity world]
- (reduce
- (fn [entity* logic]
- (logic entity* world))
- entity
- (or (entity :logic) [])))
- (defn update-world
- "Return new world after running all logic on all entities"
- [world]
- (reduce
- (fn [world* [id entity]]
- (assoc world* id (update-entity entity world)))
- {}
- world))
- (defcomponent World []
- (Update [this]
- (doseq [f @world-fns]
- (f @world))
- (reset! old-world @world)
- (swap! world update-world)))
- (defn present!
- "Run all presentation logic for a given entity, new entity, and game object"
- [entity old-entity go]
- (doseq [f (or (entity :presentation) [])]
- (f entity old-entity go)))
- (defcomponent Entity [id]
- (Update [this]
- (let [entity (@world id)
- old-entity (@old-world id)]
- (present! entity old-entity this))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement