Example #1
0
    private void Instance_OnTargetChanged(Character obj)
    {
        if (lastTarget != null)
        {
            lastTarget.Stats.OnStatChanged -= Stats_OnStatChanged;
        }

        if (obj == null)
        {
            panel.Deactivate();
        }
        else
        {
            obj.Stats.OnStatChanged += Stats_OnStatChanged;
            foreach (var item in obj.Stats.stats)
            {
                Stats_OnStatChanged(0, item.Key, item.Value);
            }
            panel.Activate();
        }

        lastTarget = obj;
    }
        private void RecalculateMemory()
        {
            _memoryBarItems.Clear();
            _hoverPanel = new UIPanel();
            _hoverPanel.Activate();

#if WINDOWS                                    //TODO: 64bit?
            _maxMemory = Environment.Is64BitOperatingSystem ? 4294967296 : 3221225472;
            long availableMemory = _maxMemory; // CalculateAvailableMemory(maxMemory); This is wrong, 4GB is not shared.
#else
            long maxMemory       = GetTotalMemory();
            long availableMemory = GetAvailableMemory();
#endif

            long totalModMemory = 0;
            int  i = 0;
            foreach (var entry in MemoryTracking.modMemoryUsageEstimates.OrderBy(v => - v.Value.total))
            {
                var modName = entry.Key;
                var usage   = entry.Value;
                if (usage.total <= 0 || modName == "tModLoader")
                {
                    continue;
                }

                totalModMemory += usage.total;
                var sb = new StringBuilder();
                sb.Append(ModLoader.GetMod(modName).DisplayName);
                sb.Append($"\nEstimate last load RAM usage: {SizeSuffix(usage.total)}");
                if (usage.managed > 0)
                {
                    sb.Append($"\n Managed: {SizeSuffix(usage.managed)}");
                }
                if (usage.managed > 0)
                {
                    sb.Append($"\n Code: {SizeSuffix(usage.code)}");
                }
                if (usage.sounds > 0)
                {
                    sb.Append($"\n Sounds: {SizeSuffix(usage.sounds)}");
                }
                if (usage.textures > 0)
                {
                    sb.Append($"\n Textures: {SizeSuffix(usage.textures)}");
                }
                _memoryBarItems.Add(new MemoryBarItem(sb.ToString(), usage.total, _colors[i++ % _colors.Length]));
            }

            long allocatedMemory = Process.GetCurrentProcess().WorkingSet64;
            var  nonModMemory    = allocatedMemory - totalModMemory;
            _memoryBarItems.Add(new MemoryBarItem(
                                    $"Terraria + misc: {SizeSuffix(nonModMemory)}\n Total: {SizeSuffix(allocatedMemory)}",
                                    nonModMemory, Color.DeepSkyBlue));

            var remainingMemory = availableMemory - allocatedMemory;
            _memoryBarItems.Add(new MemoryBarItem(
                                    $"Available Memory: {SizeSuffix(remainingMemory)}\n Total: {SizeSuffix(availableMemory)}",
                                    remainingMemory, Color.Gray));

            //portion = (maxMemory - availableMemory - meminuse) / (float)maxMemory;
            //memoryBarItems.Add(new MemoryBarData($"Other programs: {SizeSuffix(maxMemory - availableMemory - meminuse)}", portion, Color.Black));

            RecalculateMemoryNeeded = false;
        }
Example #3
0
 public void FillSkillHoverWithSkillData(SkillDataHandler skillData)
 {
     skillHoverController.Fill(skillData);
     uiPanelSkillHoverController.Activate();
 }