Пример #1
0
    // Update is called once per frame
    void Update()
    {
        VerletObjectV3 center = (VerletObjectV3)GameObject.Find(CenterBody).GetComponent("VerletObjectV3");

        CenterBodyOffset = center.position;
        minicounter++;
        masterDaysCounter = masterTimeCounter / 86400;
        //Debug.Log("On frame : "+minicounter+", "+counter+" loops have completed.");
        runThreads();
    }
Пример #2
0
    IEnumerator finished(VerletV3ControlThread myJob)
    {
        yield return(StartCoroutine(myJob.WaitFor()));

        //Debug.Log("finished "+myJob.ThreadName+"	it was: "+myJob.p);
        for (int i = 0; i < myJob.names.Length; i++)
        {
            VerletObjectV3 thisObject = ((VerletObjectV3)massObject[i].GetComponent("VerletObjectV3"));
            thisObject.newPos(myJob.positions[i]);
            thisObject.previousPosition = myJob.previousPositions[i];
        }
        masterTimeCounter  = myJob.masterTimeCounter;
        lastFrameCompleted = myJob.frameCompleted;
        multiThreadFlag   += 1;
        runThreads();
    }
Пример #3
0
    private bool flag = false;                  //If the parse process failed

    // Use this for initialization
    void Start()
    {
        XmlDocument dataFile = new XmlDocument();                                                                       //The file of data about the bodies

        dataFile.Load(@"Assets/Big-Birtha/PlanetaryData/filename.xml");
        XmlDocument orbitFile = new XmlDocument();                                                                      //The file of the orbit data for each body

        orbitFile.Load(@"Assets/Big-Birtha/PlanetaryData/orbitData.xml");
        foreach (XmlNode node in dataFile.DocumentElement.ChildNodes)                           //For every body
        {
            bodyName = node.Attributes["name"].Value;                                           //Name the body
            foreach (XmlNode subnode in node.ChildNodes)                                        //For all accociated data
            {
                if (subnode.Name == "mass")                                                     //Get the mass
                //mass = float.Parse(subnode.InnerText);
                {
                    bool successfullyParsed = float.TryParse(subnode.InnerText, out mass);
                    if (!successfullyParsed)
                    {
                        flag = true;
                        break;
                    }
                }
                else if (subnode.Name == "radius")                                                                      //Get the radius (if available)
                {
                    radius = float.Parse(subnode.InnerText);
                }
                else if (subnode.Name == "rotation")
                {
                    rotation = float.Parse(subnode.InnerText);
                }
            }
            DateTime currenttime  = DateTime.Now;                                                                       //The current date/time
            string   currentMonth = "";
            switch (currenttime.Month)                                                                                  //Getting the month correct
            {
            case 1:
                currentMonth = "Jan";
                break;

            case 2:
                currentMonth = "Feb";
                break;

            case 3:
                currentMonth = "Mar";
                break;

            case 4:
                currentMonth = "Apr";
                break;

            case 5:
                currentMonth = "May";
                break;

            case 6:
                currentMonth = "Jun";
                break;

            case 7:
                currentMonth = "Jul";
                break;

            case 8:
                currentMonth = "Aug";
                break;

            case 9:
                currentMonth = "Sep";
                break;

            case 10:
                currentMonth = "Oct";
                break;

            case 11:
                currentMonth = "Nov";
                break;

            case 12:
                currentMonth = "Dec";
                break;
            }
            string targetDateTime = currenttime.Year.ToString() + "-" + currentMonth + "-";
            if (currenttime.Day < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Day.ToString() + " ";
            if (currenttime.Hour < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Hour + ":00:00.0000";

            foreach (XmlNode orbitNode in orbitFile.DocumentElement.ChildNodes)                 //For every planet
            {
                if (orbitNode.Attributes["name"].Value == bodyName)
                {
                    foreach (XmlNode orbitsubnode in orbitNode.ChildNodes)                              //For every orbit datapoint
                    {
                        if (orbitsubnode.Attributes["timeStamp"].Value == targetDateTime)
                        {
                            x  = float.Parse(orbitsubnode["X"].InnerText);                                      //(above) if the timestamp is the reqested one
                            y  = float.Parse(orbitsubnode["Y"].InnerText);                                      //		Get the data
                            z  = float.Parse(orbitsubnode["Z"].InnerText);
                            vx = float.Parse(orbitsubnode["VX"].InnerText);
                            vy = float.Parse(orbitsubnode["VY"].InnerText);
                            vz = float.Parse(orbitsubnode["VZ"].InnerText);
                        }
                    }
                }
            }
            if (!flag)                                                                          //Flag prevents bad input
            //defaultBody.name = bodyName;										//This code sets the default body values to the given data and instantiates it
            {
                VerletObjectV3 df = VerletObjectV3.Constructor();
                df.gameObject.name = bodyName;
                df.mass            = mass;
                df.inputPosition   = new Vector3(x, y, z);
                df.inputVelocity   = new Vector3(vx, vy, vz);
                df.radius          = radius;
                df.rotation        = rotation;
                //GameObject body = Instantiate(defaultBody);
                //body.name = bodyName;
                rotation = 0;
                radius   = 1737;
            }
            else
            {
                flag = false;
            }
        }
    }
Пример #4
0
    void runThreads()
    {
        if (multiThreadFlag == multithreadedJobs.Length && timeStep != 0)                       //If the threads have completed
        {
            if (timeStep != 0 && timeStep == previousTimeStep)
            {
                Debug.Log(lastFrameCompleted + "	"+ stepTimeStep + "	" + timeStep + "	"+ stepTimeStep / timeStep + "	"+ (int)Mathf.CeilToInt(stepTimeStep / timeStep));
                //Debug.Log(lastFrameCompleted + "	" + multiple + "	" + stepTimeStep + "	" + (multiple - Mathf.Log(Mathf.Pow(multiple, 1/6))));
                if (lastFrameCompleted && multiple >= 1.05)
                {
                    stepTimeStep  = stepTimeStep / multiple;
                    stepsPerFrame = Mathd.CeilToInt(timeStep / stepTimeStep);
                }
                if (!lastFrameCompleted && multiple >= 1.05)
                {
                    stepTimeStep  = stepTimeStep * multiple;
                    stepsPerFrame = Mathd.CeilToInt(timeStep / stepTimeStep);
                    multiple      = multiple - Mathf.Log(Mathf.Pow(multiple, 1 / 6));
                }
                if ((lastFrameCompleted && multiple < 1.05) || (Mathf.Abs(stepTimeStep) < 0.05))
                {
                    Debug.Log("Ping");
                    multiple = 1;
                }
                if (!lastFrameCompleted && multiple < 1.05)
                {
                    multiple = 5;
                }
            }
            else if (previousTimeStep != timeStep)
            {
                multiple     = 10;
                stepTimeStep = 10;
            }
            multiThreadFlag = 0;
            massObject      = GameObject.FindGameObjectsWithTag("massObject");                  //Gathers all of the massObjects for calculation
            float[]    masses            = new float[massObject.Length];                        //Gathers all of the masses in order
            Vector3d[] positions         = new Vector3d[massObject.Length];                     //Gathers all of the vectors of the objects in order
            string[]   names             = new string[massObject.Length];
            Vector3d[] previousPositions = new Vector3d[massObject.Length];
            for (int i = 0; i < massObject.Length; i++)                                                         //For every object, get data for mass and position
            {
                VerletObjectV3 obj = (VerletObjectV3)massObject[i].GetComponent("VerletObjectV3");
                masses[i]            = obj.mass;
                positions[i]         = obj.position;
                names[i]             = obj.name;
                previousPositions[i] = obj.previousPosition;                //Assign previous position
            }
            simulationControlThread                   = new VerletV3ControlThread();
            simulationControlThread.masses            = masses;
            simulationControlThread.massObjectNames   = names;
            simulationControlThread.masterTimeCounter = masterTimeCounter;
            simulationControlThread.positions         = positions;
            simulationControlThread.timestep          = stepTimeStep;
            simulationControlThread.steps             = stepsPerFrame;
            simulationControlThread.names             = names;
            simulationControlThread.previousPositions = previousPositions;
            simulationControlThread.previousTimeStep  = stepTimeStepP;

            simulationControlThread.Start();                                                            //Start thread
            StartCoroutine("finished", simulationControlThread);                                        //Start end coroutine

            previousTimeStep = timeStep;
            stepTimeStepP    = stepTimeStep;
        }
    }