Guest User

Untitled

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