Skip to content

Instantly share code, notes, and snippets.

@nasser
Created July 20, 2014 08:30
Show Gist options
  • Select an option

  • Save nasser/06c3c42be89a40e89dc2 to your computer and use it in GitHub Desktop.

Select an option

Save nasser/06c3c42be89a40e89dc2 to your computer and use it in GitHub Desktop.
Unchecked Math
(ns PathFollowerUnity
(:import
(UnityEngine Transform Debug GUILayout)
(PathFollowerUnity PathFollower)))
(defmacro with-unchecked-math [& xs]
`(binding [*unchecked-math* true]
~@xs))
(defmacro get-component* [obj t]
(with-meta `(.GetComponent ~obj (~'type-args ~t))
{:tag t}))
(with-unchecked-math
(gen-class
:name PathFollowerUnity.PathFollower
:methods [[Update [] void]]
:main false
:extends UnityEngine.MonoBehaviour
:prefix "PathFollower-"
:init init
:state state)
(defn PathFollower-init []
[ []
(into-array System.Object
(vec (repeatedly 1000 #(Vector3. (rand-int 30) (rand-int 18) 0))))])
(defn PathFollower-Update [^UnityEngine.Component self]
(let [^objects ary (.state self)
current-pos (aget ary Time/time)
next-pos (aget ary (inc Time/time))
transform (get-component* self Transform)]
(set! (.localPosition transform)
(Vector3/Lerp
current-pos
next-pos
(rem Time/time 1))))))
public override object invoke (object obj)
{
// runtime call to binding gone, try/finally gone
object obj2 = PathFollowerUnity$fn__28$PathFollower_Update__47__51.__interop_state53 (obj);
object obj3 = ((object[])obj2) [RT.intCast (Time.time)];
object obj4 = ((object[])obj2) [RT.intCast ((double)Time.time + (double))];
object component = ((Component)obj).GetComponent<Transform> (); // same
object result;
// same
((Transform)component).localPosition = (Vector3)(result = Vector3.Lerp ((Vector3)obj3, (Vector3)obj4, (float)Numbers.remainder ((double)Time.time, )));
return result;
}
public override object invoke (object obj)
{
// run time cost associated with the binding form
((IFn)PathFollowerUnity$PathFollower_Update__569.const__0.getRawRoot ()).invoke (((IFn)PathFollowerUnity$PathFollower_Update__569.const__1.getRawRoot ()).invoke (PathFollowerUnity$PathFollower_Update__569.const__2, ));
object result;
try { // why does clojure emit a try/finally?
object obj2 = PathFollowerUnity$PathFollower_Update__569.__interop_state571 (obj);
object obj3 = ((object[])obj2) [RT.intCast (Time.time)];
object obj4 = ((object[])obj2) [RT.intCast ((double)Time.time + (double))];
object component = ((Component)obj).GetComponent<Transform> (); // perfect
object obj5;
// perfect (next line)
((Transform)component).localPosition = (Vector3)(obj5 = Vector3.Lerp ((Vector3)obj3, (Vector3)obj4, (float)Numbers.remainder ((double)Time.time, )));
result = obj5;
}
finally {
// not sure what this is, could be 'undoing' the binding?
((IFn)PathFollowerUnity$PathFollower_Update__569.const__8.getRawRoot ()).invoke ();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment