Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmacro system
- "Creates a system to be executed in an environment and pushes it into the global system registry."
- [name & fields]
- ;; @TODO: track and use pred to maintain a filtered list of entities updated on batched component addition/removal for each system.
- (let [kname# (keyword name)
- system# (apply hash-map fields)
- system# (with-meta system# {:name kname#})
- ctor# (:ctor system#)
- args# (:arglist (meta (var ctor#)))
- factory# `(fn ~args# (if ~ctor# (apply ~ctor# (cons ~system# ~args#)) ~system#))]
- (swap! systems assoc kname# factory#)
- (if (kname# @components)
- `(do (println "*WARN* System" ~kname# "already exists. Overwriting...") (def ~name ~factory#))
- `(def ~name ~factory#))))
Advertisement
Add Comment
Please, Sign In to add comment