Пример #1
0
 public string ToEscapedString()
 {
     return(TagParser.Escape(Name) + "[secondary=" + (SecondaryName == null ? "" : EscapeTagBase.Escape(SecondaryName)) + ";display=" + EscapeTagBase.Escape(DisplayName) + ";count=" + Count
            + ";weight=" + Weight + ";volume=" + Volume + ";temperature=" + Temperature + ";renderascomponent=" + (RenderAsComponent ? "true" : "false") + ";componentrenderoffset=" + ComponentRenderOffset.ToSimpleString()
            + ";description=" + EscapeTagBase.Escape(Description) + ";texture=" + EscapeTagBase.Escape(GetTextureName()) + ";model=" + EscapeTagBase.Escape(GetModelName()) + ";bound=" + (IsBound ? "true" : "false")
            + ";drawcolor=" + new ColorTag(DrawColor).ToString() + ";datum=" + Datum + ";shared=" + SharedStr() + ";local=" + EscapedLocalStr() + ";components=" + ComponentEscapedString() + "]");
 }
Пример #2
0
        public string EscapedLocalStr()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (KeyValuePair <string, TemplateObject> val in Attributes)
            {
                string type;
                if (val.Value is NumberTag)
                {
                    type = "numb";
                }
                else if (val.Value is IntegerTag)
                {
                    type = "inte";
                }
                else if (val.Value is BooleanTag)
                {
                    type = "bool";
                }
                else if (val.Value is ItemTag)
                {
                    type = "item";
                }
                else
                {
                    type = "text";
                }
                sb.Append(EscapeTagBase.Escape(val.Key) + "=" + type + "/" + EscapeTagBase.Escape(val.Value.ToString()) + ";");
            }
            sb.Append("}");
            return(sb.ToString());
        }
Пример #3
0
        public void OncePerSecondActions()
        {
            long cid;

            lock (CIDLock)
            {
                cid = cID;
            }
            if (cid != prev_eid)
            {
                prev_eid = cid;
                Schedule.StartASyncTask(() =>
                {
                    Files.WriteText("server_eid.txt", cid.ToString());
                });
            }
            TPS  = tpsc;
            tpsc = 0;
            if (CVars.system.Modified)
            {
                CVars.system.Modified = false;
                StringBuilder cvarsave = new StringBuilder(CVars.system.CVarList.Count * 100);
                cvarsave.Append("// THIS FILE IS AUTOMATICALLY GENERATED.\n");
                cvarsave.Append("// This file is run very early in startup, be careful with it!\n");
                cvarsave.Append("debug minimal;\n");
                for (int i = 0; i < CVars.system.CVarList.Count; i++)
                {
                    if (!CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ServerControl) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ReadOnly) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.DoNotSave))
                    {
                        string val = CVars.system.CVarList[i].Value;
                        if (val.Contains('\"'))
                        {
                            val = "<{unescape[" + EscapeTagBase.Escape(val) + "]}>";
                        }
                        cvarsave.Append("set \"" + CVars.system.CVarList[i].Name + "\" \"" + val + "\";\n");
                    }
                }
                SaveStr = cvarsave.ToString();
                Thread thread = new Thread(new ThreadStart(SaveCFG));
                thread.Start();
            }
            //   SysConsole.Output(OutputType.INFO, "Tick: " + (TickTimeC / TickTimes) + ", Schedule: " + (ScheduleTimeC / ScheduleTimes)
            //       + ", Physics: " + (PhysicsTimeC / PhysicsTimes) + ", Entity: " + (EntityTimeC / EntityTimes) + " Ticked: " + TickTimes);
            TickTimes     = 0;
            TickTimeC     = 0;
            ScheduleTimes = 0;
            ScheduleTimeC = 0;
            PhysicsTimes  = 0;
            PhysicsTimeC  = 0;
            EntityTimes   = 0;
            EntityTimeC   = 0;
        }
Пример #4
0
        /// <summary>
        /// Runs any actions that are necessary to be ran exactly once per second.
        /// Includes any data saving.
        /// </summary>
        public void OncePerSecondActions()
        {
            long cid;

            lock (CIDLock)
            {
                cid = cID;
            }
            if (cid != prev_eid)
            {
                prev_eid = cid;
                Schedule.StartAsyncTask(() =>
                {
                    try
                    {
                        lock (SaveFileLock)
                        {
                            Files.WriteText("server_eid.txt", cid.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        SysConsole.Output(OutputType.ERROR, "Saving the current EID: " + ex.ToString());
                    }
                });
            }
            TPS  = tpsc;
            tpsc = 0;
            if (CVars.system.Modified)
            {
                CVars.system.Modified = false;
                StringBuilder cvarsave = new StringBuilder(CVars.system.CVarList.Count * 100);
                cvarsave.Append("// THIS FILE IS AUTOMATICALLY GENERATED.\n");
                cvarsave.Append("// This file is run very early in startup, be careful with it!\n");
                cvarsave.Append("debug minimal;\n");
                for (int i = 0; i < CVars.system.CVarList.Count; i++)
                {
                    if (!CVars.system.CVarList[i].Flags.HasFlag(FreneticScript.CVarFlag.ServerControl) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(FreneticScript.CVarFlag.ReadOnly) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(FreneticScript.CVarFlag.DoNotSave))
                    {
                        string val = CVars.system.CVarList[i].Value;
                        if (val.Contains('\"'))
                        {
                            val = "<{unescape[" + EscapeTagBase.Escape(val) + "]}>";
                        }
                        cvarsave.Append("set \"" + CVars.system.CVarList[i].Name + "\" \"" + val + "\";\n");
                    }
                }
                string SaveStr = cvarsave.ToString();
                Schedule.StartAsyncTask(() =>
                {
                    try
                    {
                        lock (SaveFileLock)
                        {
                            Files.WriteText("serverdefaultsettings.cfg", SaveStr);
                        }
                    }
                    catch (Exception ex)
                    {
                        SysConsole.Output(OutputType.ERROR, "Saving settings: " + ex.ToString());
                    }
                });
            }
            TickTimes     = 0;
            TickTimeC     = 0;
            ScheduleTimes = 0;
            ScheduleTimeC = 0;
            PhysicsTimes  = 0;
            PhysicsTimeC  = 0;
            EntityTimes   = 0;
            EntityTimeC   = 0;
        }
Пример #5
0
        /// <summary>
        /// Fires once per second, every second, for the client.
        /// </summary>
        public void OncePerSecondActions()
        {
            FixMouse();
            gFPS   = gTicks;
            gTicks = 0;
            bool edited = false;

            if (CVars.system.Modified || first)
            {
                edited = true;
                CVars.system.Modified = false;
                StringBuilder cvarsave = new StringBuilder(CVars.system.CVarList.Count * 100);
                for (int i = 0; i < CVars.system.CVarList.Count; i++)
                {
                    if (!CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ServerControl) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ReadOnly) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.DoNotSave))
                    {
                        string val = CVars.system.CVarList[i].Value;
                        if (val.Contains('\"'))
                        {
                            val = "<{unescape[" + EscapeTagBase.Escape(val) + "]}>";
                        }
                        cvarsave.Append("set \"" + CVars.system.CVarList[i].Name + "\" \"" + val + "\";\n");
                    }
                }
                lock (saveLock)
                {
                    CSaveStr = cvarsave.ToString();
                }
            }
            if (KeyHandler.Modified || first)
            {
                edited = true;
                KeyHandler.Modified = false;
                StringBuilder keybindsave = new StringBuilder(KeyHandler.keystonames.Count * 100);
                keybindsave.Append("wait 0.5;\n");
                foreach (KeyValuePair <string, Key> keydat in KeyHandler.namestokeys)
                {
                    CommandScript cs = KeyHandler.GetBind(keydat.Value);
                    if (cs == null)
                    {
                        keybindsave.Append("unbind \"" + keydat.Key + "\";\n");
                    }
                    else
                    {
                        keybindsave.Append("bindblock \"" + keydat.Key + "\"\n{\n" + cs.FullString("\t") + "}\n");
                    }
                }
                lock (saveLock)
                {
                    BSaveStr = keybindsave.ToString();
                }
            }
            if (Gamepad.Modified || first)
            {
                edited           = true;
                Gamepad.Modified = false;
                StringBuilder gamepadbindsave = new StringBuilder(GamePadHandler.GP_BUTTON_COUNT * 256);
                gamepadbindsave.Append("wait 0.5;\n");
                for (int i = 0; i < GamePadHandler.GP_BUTTON_COUNT; i++)
                {
                    CommandScript cs     = Gamepad.ButtonBinds[i];
                    GamePadButton button = (GamePadButton)i;
                    if (cs == null)
                    {
                        gamepadbindsave.Append("gp_unbind \"" + button.ToString().ToLowerFast() + "\";\n");
                    }
                    else
                    {
                        gamepadbindsave.Append("gp_bindblock \"" + button.ToString().ToLowerFast() + "\"\n{\n" + cs.FullString("\t") + "}\n");
                    }
                }
                lock (saveLock)
                {
                    GPBSaveStr = gamepadbindsave.ToString();
                }
            }
            if (edited)
            {
                first = false;
                Schedule.StartAsyncTask(SaveCFG);
            }
            ops_spike++;
            if (ops_spike >= 5)
            {
                ops_spike = 0;
                MainWorldView.ShadowSpikeTime = 0;
                TickSpikeTime = 0;
                MainWorldView.FBOSpikeTime    = 0;
                MainWorldView.LightsSpikeTime = 0;
                FinishSpikeTime           = 0;
                TWODSpikeTime             = 0;
                TotalSpikeTime            = 0;
                TheRegion.CrunchSpikeTime = 0;
                gFPS_Min = 0;
                gFPS_Max = 0;
            }
            for (int i = 0; i < (int)NetUsageType.COUNT; i++)
            {
                Network.UsagesLastSecond[i] = Network.UsagesThisSecond[i];
                Network.UsagesThisSecond[i] = 0;
            }
            ops_extra++;
            if (CVars.r_compute.ValueB)
            {
                HashSet <Vector3i> handled = new HashSet <Vector3i>();
                foreach (Chunk chk in TheRegion.LoadedChunks.Values)
                {
                    if (chk.PosMultiplier < 5)
                    {
                        continue;
                    }
                    Vector3i slodpos = TheRegion.SLODLocFor(chk.WorldPosition);
                    if (handled.Contains(slodpos))
                    {
                        continue;
                    }
                    handled.Add(slodpos);
                    if (!TheRegion.SLODs.TryGetValue(slodpos, out ChunkSLODHelper slod))
                    {
                        slod = new ChunkSLODHelper()
                        {
                            Coordinate = slodpos, OwningRegion = TheRegion
                        };
                        TheRegion.SLODs[slodpos] = slod;
                    }
                    Chunk[] res    = TheRegion.LoadedChunks.Values.Where((c) => c.PosMultiplier >= 5 && TheRegion.SLODLocFor(c.WorldPosition) == slodpos).ToArray();
                    bool    recomp = slod.NeedsComp;
                    foreach (Chunk c in res)
                    {
                        if (c.SLODComputed && c._VBOSolid != null)
                        {
                            recomp         = true;
                            c.SLODMode     = true;
                            c.SLODComputed = false;
                            slod.NeedsComp = false;
                        }
                    }
                    if (recomp)
                    {
                        if (!VoxelComputer.Combinulate(slod, res))
                        {
                            TheRegion.SLODs.Remove(slodpos);
                        }
                    }
                }
                List <Vector3i> needsRem = new List <Vector3i>();
                foreach (ChunkSLODHelper slod in TheRegion.SLODs.Values)
                {
                    if (slod.NeedsComp)
                    {
                        slod._VBO?.Destroy();
                        needsRem.Add(slod.Coordinate);
                        continue;
                    }
                    int count = TheRegion.LoadedChunks.Values.Where((c) => c.PosMultiplier >= 5 && TheRegion.SLODLocFor(c.WorldPosition) == slod.Coordinate).Count();
                    if (count == 0)
                    {
                        slod._VBO?.Destroy();
                        needsRem.Add(slod.Coordinate);
                        continue;
                    }
                }
                foreach (Vector3i vec in needsRem)
                {
                    TheRegion.SLODs.Remove(vec);
                }
            }
            else
            {
                foreach (ChunkSLODHelper slod in new List <ChunkSLODHelper>(TheRegion.SLODs.Values))
                {
                    if (slod.NeedsComp)
                    {
                        slod.CompileInternal();
                        if (slod._VBO == null)
                        {
                            TheRegion.SLODs.Remove(slod.Coordinate);
                        }
                    }
                    else if (ops_extra > 3 && ((slod.Coordinate.ToLocation() + new Location(0.5, 0.5, 0.5)) * Constants.CHUNK_SLOD_WIDTH).DistanceSquared(Player.GetPosition()) < Constants.CHUNK_SLOD_WIDTH * Constants.CHUNK_SLOD_WIDTH * 2)
                    {
                        TheRegion.RecalcSLODExact(slod.Coordinate);
                    }
                }
            }
            if (ops_extra > 3)
            {
                ops_extra = 0;
            }
        }
Пример #6
0
        public void OncePerSecondActions()
        {
            FixMouse();
            gFPS   = gTicks;
            gTicks = 0;
            bool edited = false;

            if (CVars.system.Modified || first)
            {
                edited = true;
                CVars.system.Modified = false;
                StringBuilder cvarsave = new StringBuilder(CVars.system.CVarList.Count * 100);
                for (int i = 0; i < CVars.system.CVarList.Count; i++)
                {
                    if (!CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ServerControl) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.ReadOnly) &&
                        !CVars.system.CVarList[i].Flags.HasFlag(CVarFlag.DoNotSave))
                    {
                        string val = CVars.system.CVarList[i].Value;
                        if (val.Contains('\"'))
                        {
                            val = "<{unescape[" + EscapeTagBase.Escape(val) + "]}>";
                        }
                        cvarsave.Append("set \"" + CVars.system.CVarList[i].Name + "\" \"" + val + "\";\n");
                    }
                }
                lock (saveLock)
                {
                    CSaveStr = cvarsave.ToString();
                }
            }
            if (KeyHandler.Modified || first)
            {
                edited = true;
                KeyHandler.Modified = false;
                first = false;
                StringBuilder keybindsave = new StringBuilder(KeyHandler.keystonames.Count * 100);
                keybindsave.Append("wait 0.5;\n");
                foreach (KeyValuePair <string, Key> keydat in KeyHandler.namestokeys)
                {
                    CommandScript cs = KeyHandler.GetBind(keydat.Value);
                    if (cs == null)
                    {
                        keybindsave.Append("unbind \"" + keydat.Key + "\";\n");
                    }
                    else
                    {
                        keybindsave.Append("bindblock \"" + keydat.Key + "\"\n{\n" + cs.FullString("\t") + "}\n");
                    }
                }
                lock (saveLock)
                {
                    BSaveStr = keybindsave.ToString();
                }
            }
            if (edited)
            {
                Schedule.StartASyncTask(SaveCFG);
            }
            MainWorldView.ShadowSpikeTime = 0;
            TickSpikeTime = 0;
            MainWorldView.FBOSpikeTime    = 0;
            MainWorldView.LightsSpikeTime = 0;
            FinishSpikeTime = 0;
            TWODSpikeTime   = 0;
            TotalSpikeTime  = 0;
            for (int i = 0; i < (int)NetUsageType.COUNT; i++)
            {
                Network.UsagesLastSecond[i] = Network.UsagesThisSecond[i];
                Network.UsagesThisSecond[i] = 0;
            }
        }