Ejemplo n.º 1
0
        static void Render_file(Panel p, uint partId, string filename, File file, Drive drive, bool short_strings, Vessel v)
        {
            // get experiment info
            ExperimentInfo exp  = Science.Experiment(filename);
            double         rate = Cache.VesselInfo(v).connection.rate;

            // render experiment name
            string exp_label = Lib.BuildString
                               (
                "<b>",
                Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)),
                "</b> <size=", Styles.ScaleInteger(10).ToString(), ">",
                Lib.Ellipsis(ExperimentInfo.Situation(filename), Styles.ScaleStringLength((short_strings ? 32 : 62) - Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)).Length)),
                "</size>"
                               );
            string exp_tooltip = Lib.BuildString
                                 (
                exp.name, "\n",
                "<color=#aaaaaa>", ExperimentInfo.Situation(filename), "</color>"
                                 );
            double exp_value = Science.Value(filename, file.size);

            if (exp_value >= 0.1)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<b>", Lib.HumanReadableScience(exp_value), "</b>");
            }
            if (rate > 0)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<i>" + Lib.HumanReadableDuration(file.size / rate) + "</i>");
            }
            p.AddContent(exp_label, Lib.HumanReadableDataSize(file.size), exp_tooltip, (Action)null, () => Highlighter.Set(partId, Color.cyan));

            bool send = drive.GetFileSend(filename);

            p.AddIcon(send ? Icons.send_cyan : Icons.send_black, "Flag the file for transmission to <b>DSN</b>", () => { drive.Send(filename, !send); });
            p.AddIcon(Icons.toggle_red, "Delete the file", () =>
            {
                Lib.Popup("Warning!",
                          Lib.BuildString("Do you really want to delete ", exp.FullName(filename), "?"),
                          new DialogGUIButton("Delete it", () => drive.Delete_file(filename, double.MaxValue, v.protoVessel)),
                          new DialogGUIButton("Keep it", () => { }));
            }
                      );
        }
Ejemplo n.º 2
0
        private static bool DoRecord(Experiment experiment, string subject_id, Vessel vessel, Resource_info ec, uint hdId,
                                     Vessel_resources resources, List <KeyValuePair <string, double> > resourceDefs,
                                     double remainingSampleMass, double dataSampled,
                                     out double sampledOut, out double remainingSampleMassOut)
        {
            // default output values for early returns
            sampledOut             = dataSampled;
            remainingSampleMassOut = remainingSampleMass;

            var exp = Science.Experiment(subject_id);

            if (Done(exp, dataSampled))
            {
                return(true);
            }

            double elapsed   = Kerbalism.elapsed_s;
            double chunkSize = Math.Min(experiment.data_rate * elapsed, exp.max_amount);
            double massDelta = experiment.sample_mass * chunkSize / exp.max_amount;

            Drive drive = GetDrive(experiment, vessel, hdId, chunkSize, subject_id);

            // on high time warp this chunk size could be too big, but we could store a sizable amount if we process less
            bool   isFile      = experiment.sample_mass < float.Epsilon;
            double maxCapacity = isFile ? drive.FileCapacityAvailable() : drive.SampleCapacityAvailable(subject_id);

            Drive warpCacheDrive = null;

            if (isFile)
            {
                if (drive.GetFileSend(subject_id))
                {
                    warpCacheDrive = Cache.WarpCache(vessel);
                }
                if (warpCacheDrive != null)
                {
                    maxCapacity += warpCacheDrive.FileCapacityAvailable();
                }
            }

            double factor = Rate(vessel, chunkSize, maxCapacity, elapsed, ec, experiment.ec_rate, resources, resourceDefs);

            if (factor < double.Epsilon)
            {
                return(false);
            }

            chunkSize *= factor;
            massDelta *= factor;
            elapsed   *= factor;

            bool stored = false;

            if (chunkSize > double.Epsilon)
            {
                if (isFile)
                {
                    if (warpCacheDrive != null)
                    {
                        double s = Math.Min(chunkSize, warpCacheDrive.FileCapacityAvailable());
                        stored = warpCacheDrive.Record_file(subject_id, s, true);

                        if (chunkSize > s)                        // only write to persisted drive if the data cannot be transmitted in this tick
                        {
                            stored &= drive.Record_file(subject_id, chunkSize - s, true);
                        }
                    }
                    else
                    {
                        stored = drive.Record_file(subject_id, chunkSize, true);
                    }
                }
                else
                {
                    stored = drive.Record_sample(subject_id, chunkSize, massDelta);
                }
            }

            if (!stored)
            {
                return(false);
            }

            // consume resources
            ec.Consume(experiment.ec_rate * elapsed, "experiment");
            foreach (var p in resourceDefs)
            {
                resources.Consume(vessel, p.Key, p.Value * elapsed, "experiment");
            }

            dataSampled += chunkSize;
            dataSampled  = Math.Min(dataSampled, exp.max_amount);
            sampledOut   = dataSampled;
            if (!experiment.sample_collecting)
            {
                remainingSampleMass -= massDelta;
                remainingSampleMass  = Math.Max(remainingSampleMass, 0);
            }
            remainingSampleMassOut = remainingSampleMass;
            return(true);
        }
Ejemplo n.º 3
0
        static void Render_file(Panel p, uint partId, File file, Drive drive, bool short_strings, Vessel v)
        {
            // render experiment name
            string exp_label = Lib.BuildString
                               (
                "<b>",
                Lib.Ellipsis(file.subjectData.ExperimentTitle, Styles.ScaleStringLength(short_strings ? 24 : 38)),
                "</b> <size=", Styles.ScaleInteger(10).ToString(), ">",
                Lib.Ellipsis(file.subjectData.SituationTitle, Styles.ScaleStringLength((short_strings ? 32 : 62) - Lib.Ellipsis(file.subjectData.ExperimentTitle, Styles.ScaleStringLength(short_strings ? 24 : 38)).Length)),
                "</size>"
                               );
            string exp_tooltip = Lib.BuildString
                                 (
                file.subjectData.ExperimentTitle, "\n",
                Lib.Color(file.subjectData.SituationTitle, Lib.Kolor.LightGrey)
                                 );

            double exp_value = file.size * file.subjectData.SciencePerMB;

            if (file.subjectData.ScienceRemainingToRetrieve > 0f && file.size > 0.0)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<b>", Lib.HumanReadableScience(exp_value, false), "</b>");
            }
            if (file.transmitRate > 0.0)
            {
                if (file.size > 0.0)
                {
                    exp_tooltip = Lib.Color(Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_TransmittingRate.Format(Lib.HumanReadableDataRate(file.transmitRate)), " : <i>", Lib.HumanReadableCountdown(file.size / file.transmitRate), "</i>"), Lib.Kolor.Cyan);                    //Transmitting at <<1>>
                }
                else
                {
                    exp_tooltip = Lib.Color(Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_TransmittingRate.Format(Lib.HumanReadableDataRate(file.transmitRate))), Lib.Kolor.Cyan);                    //Transmitting at <<1>>
                }
            }
            else if (v.KerbalismData().Connection.rate > 0.0)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_Transmitduration, "<i>", Lib.HumanReadableDuration(file.size / v.KerbalismData().Connection.rate), "</i>");                //Transmit duration :
            }
            if (!string.IsNullOrEmpty(file.resultText))
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n", Lib.WordWrapAtLength(file.resultText, 50));
            }

            string size;

            if (file.transmitRate > 0.0)
            {
                if (file.size == 0.0)
                {
                    size = Lib.Color(Lib.BuildString("↑ ", Lib.HumanReadableDataRate(file.transmitRate)), Lib.Kolor.Cyan);
                }
                else
                {
                    size = Lib.Color(Lib.BuildString("↑ ", Lib.HumanReadableDataSize(file.size)), Lib.Kolor.Cyan);
                }
            }
            else
            {
                size = Lib.HumanReadableDataSize(file.size);
            }

            p.AddContent(exp_label, size, exp_tooltip, (Action)null, () => Highlighter.Set(partId, Color.cyan));

            bool send = drive.GetFileSend(file.subjectData.Id);

            p.AddRightIcon(send ? Textures.send_cyan : Textures.send_black, Local.FILEMANAGER_send, () => { drive.Send(file.subjectData.Id, !send); }); //"Flag the file for transmission to <b>DSN</b>"
            p.AddRightIcon(Textures.toggle_red, Local.FILEMANAGER_Delete, () =>                                                                         //"Delete the file"
            {
                Lib.Popup(Local.FILEMANAGER_Warning_title,                                                                                              //"Warning!"
                          Local.FILEMANAGER_DeleteConfirm.Format(file.subjectData.FullTitle),                                                           //Lib.BuildString(, "?"),//"Do you really want to delete <<1>>",
                          new DialogGUIButton(Local.FILEMANAGER_DeleteConfirm_button1, () => drive.Delete_file(file.subjectData)),                      //"Delete it"
                          new DialogGUIButton(Local.FILEMANAGER_DeleteConfirm_button2, () => { }));                                                     //"Keep it"
            }
                           );
        }