Inheritance: IDisposable
Example #1
0
 private static NBody CreateInstance()
 {
     if (GameObjectInstance == null)
     {
         GameObjectInstance = new GameObject("NBodyInstance", typeof(NBody));
         UnityEngine.Object.DontDestroyOnLoad(GameObjectInstance);
         s_singleton = GameObjectInstance.GetComponent <NBody>();
     }
     return(s_singleton);
 }
Example #2
0
        public void Awake()
        {
            Debug.Log("NBody Awake()");
            if (s_singleton == null)
            {
                s_singleton = this;
            }
            DontDestroyOnLoad(s_singleton);

            if (ToolbarManager.ToolbarAvailable)
            {
                btnNBodyForce             = ToolbarManager.Instance.add("NBody", "force");
                btnNBodyForce.TexturePath = "NBody/Textures/NBodyOn";
                btnNBodyForce.ToolTip     = "NBody";
                btnNBodyForce.OnClick    += (e) =>
                {
                    forceApplying             = !forceApplying;
                    btnNBodyForce.TexturePath = forceApplying ? "NBody/Textures/NBodyOn" : "NBody/Textures/NBodyOff";
                    OrbitManipulator.s_singleton.SaveConfigs();
                };
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            OtpNode node = new OtpNode("gen");
            OtpMbox mbox = node.createMbox(true);
            OtpErlangObject message = new OtpErlangTuple(new OtpErlangObject[] { mbox.Self, new OtpErlangAtom("new") });

            mbox.send("kernel", "pc@3di0050d", message);
            OtpErlangTuple reply = (OtpErlangTuple)mbox.receive();

            OtpErlangPid self = (OtpErlangPid)reply.elementAt(0);
            OtpErlangAtom ok = (OtpErlangAtom)reply.elementAt(1);
            OtpErlangPid pid = (OtpErlangPid)reply.elementAt(2);

            Console.WriteLine("New: {0}", ok);
            if (ok.ToString() != "ok")
            {
                return;
            }

            mbox.link(pid);

            using (CUDA cuda = new CUDA(0, true))
            {
                float deltaTime = 0.1f;
                int nextTickCount;

                using (NBody nbody = new NBody(cuda, deltaTime, 1.0f, 32))
                {
                    string script = String.Empty;

                    nbody.Initialize();

                    script += String.Format("<128,128,50> translate\n");
                    script += String.Format("/C {{moveto createsphere dup <1,1,1> setsize dup show }} def\n");

                    for (int i = 0; i < nbody.HostOldPos.Length; i++)
                    {
                        Float4 pos = nbody.HostOldPos[i];
                        script += String.Format("<{0},{1},{2}> C /b{3} exch def\n", pos.x, pos.y, pos.z, i);
                    }

                    Load(mbox, pid, script);
                    script = String.Empty;

                    nextTickCount = System.Environment.TickCount;
                    for (ulong frame = 0; frame < 300; frame++)
                    {
                        while (System.Environment.TickCount < nextTickCount);
                        nextTickCount = nextTickCount + (int)(deltaTime * 1000);

                        nbody.Update(0);
                        nbody.Swap();

                        for (int i = 0; i < nbody.HostOldPos.Length; i++)
                        {
                            Float4 pos = nbody.HostOldPos[i];
                            script += String.Format("b{3} <{0},{1},{2}> setposition \n", pos.x, pos.y, pos.z, i);
                        }

                        Load(mbox, pid, script);
                        script = String.Empty;
                    }
                }
            }

            Console.WriteLine("Hit return key to continue");
            Console.ReadLine();

            mbox.send(pid, new OtpErlangTuple(new OtpErlangObject[] { mbox.Self, new OtpErlangAtom("exit") }));
            reply = (OtpErlangTuple)mbox.receive();

            mbox.close();
            node.close();
        }