 
 ; -------------------------------------------------------------------
 
-(def curr-world (atom {})) ; { :world => world-actx
+(def prog-world (atom {})) ; { :world => world-actx
                            ;   :net-listen-ch => ch
                            ;   :net-connect-ch => ch }
 

; --------------------------------------------

(defn kv-server [name & ports]
  (let [world (:world @curr-world)
        done (atom false)]
    (act server-init world
         (doseq [port ports]
           (when-let [listen-result-ch (achan server-init)]
             (aput server-init (:net-listen-ch @curr-world) [name port listen-result-ch])
             (when-let [[accept-ch close-accept-ch] (atake server-init listen-result-ch)]
               (cbfg.world.net/server-accept-loop world accept-ch close-accept-ch)
               (swap! curr-world #(update-in % [:servers name] conj port)))))
         (reset! done true))
    (wait-done done)))

(defn kv-client [client-addr server-addr server-port]
  (let [world (:world @curr-world)
        done (atom false)]
    (act client-init world
         (let [res-ch (achan client-init)
               req-ch (cbfg.world.net/client-loop world (:net-connect-ch @curr-world)
                                                  server-addr server-port
                                                  client-addr res-ch)]
           (swap! curr-world #(assoc-in % [:clients client-addr]
                                        {:client-addr client-addr
                                         :server-addr server-addr
                                         :server-port server-port

                                 event-ch step-ch render-ch)
        (cbfg.vis/process-render el-prefix world render-ch nil)
        (make-net world
                  (:net-listen-ch @prog-world)
                  (:net-connect-ch @prog-world))
        (let [prog (get-el-value "prog")
              prog-js (str "with (cbfg.world.t1) {" prog "}")
              prog-res (try (js/eval prog-js) (catch js/Object ex ex))]
          (println :prog-res prog-res)
          (println :prog-world @prog-world)
          (<! prog-ch)
          (close! event-ch)
          (close! render-ch)
