mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
缓存读取到内存
Co-Authored-By: Wreathlit <820064+Wreathlit@users.noreply.github.com>
This commit is contained in:
parent
95b92e5240
commit
fb2a6ce768
@ -20,6 +20,8 @@ using LinePutScript;
|
|||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView;
|
||||||
using Panuon.WPF.UI;
|
using Panuon.WPF.UI;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
||||||
|
using System.Security.Policy;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
|
||||||
namespace VPet_Simulator.Core
|
namespace VPet_Simulator.Core
|
||||||
{
|
{
|
||||||
@ -71,6 +73,18 @@ namespace VPet_Simulator.Core
|
|||||||
private Action StopAction;
|
private Action StopAction;
|
||||||
int nowid;
|
int nowid;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 图片资源
|
||||||
|
/// </summary>
|
||||||
|
public MemoryStream stream;
|
||||||
|
/// <summary>
|
||||||
|
/// 回收图片资源Timer
|
||||||
|
/// </summary>
|
||||||
|
public System.Timers.Timer GCTimer = new System.Timers.Timer()
|
||||||
|
{
|
||||||
|
Interval = 10000,
|
||||||
|
AutoReset = false,
|
||||||
|
};
|
||||||
|
/// <summary>
|
||||||
/// 新建 PNG 动画
|
/// 新建 PNG 动画
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">文件夹位置</param>
|
/// <param name="path">文件夹位置</param>
|
||||||
@ -164,8 +178,6 @@ namespace VPet_Simulator.Core
|
|||||||
int wxi = -500 * i;
|
int wxi = -500 * i;
|
||||||
Animations.Add(new Animation(this, time, () => Margin = new Thickness(wxi, 0, 0, 0)));
|
Animations.Add(new Animation(this, time, () => Margin = new Thickness(wxi, 0, 0, 0)));
|
||||||
}
|
}
|
||||||
Dispatcher.Invoke(() => Source = new BitmapImage(new Uri(cp)));
|
|
||||||
IsReady = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -188,11 +200,18 @@ namespace VPet_Simulator.Core
|
|||||||
graph.Dispose();
|
graph.Dispose();
|
||||||
joinedBitmap.Dispose();
|
joinedBitmap.Dispose();
|
||||||
imgs.ForEach(x => x.Dispose());
|
imgs.ForEach(x => x.Dispose());
|
||||||
Dispatcher.Invoke(() => Source = new BitmapImage(new Uri(cp)));
|
|
||||||
IsReady = true;
|
|
||||||
}
|
}
|
||||||
|
stream = new MemoryStream(File.ReadAllBytes(cp));
|
||||||
|
//GCTimer
|
||||||
|
GCTimer.Elapsed += (a, b) =>
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() => Source = null);
|
||||||
|
GC.Collect();
|
||||||
|
};
|
||||||
|
IsReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单帧动画
|
/// 单帧动画
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -247,6 +266,7 @@ namespace VPet_Simulator.Core
|
|||||||
EndAction?.Invoke();//运行结束动画时事件
|
EndAction?.Invoke();//运行结束动画时事件
|
||||||
parent.StopAction?.Invoke();
|
parent.StopAction?.Invoke();
|
||||||
parent.StopAction = null;
|
parent.StopAction = null;
|
||||||
|
parent.GCTimer.Start();
|
||||||
////延时隐藏
|
////延时隐藏
|
||||||
//Task.Run(() =>
|
//Task.Run(() =>
|
||||||
//{
|
//{
|
||||||
@ -269,6 +289,7 @@ namespace VPet_Simulator.Core
|
|||||||
EndAction?.Invoke();//运行结束动画时事件
|
EndAction?.Invoke();//运行结束动画时事件
|
||||||
parent.StopAction?.Invoke();
|
parent.StopAction?.Invoke();
|
||||||
parent.StopAction = null;
|
parent.StopAction = null;
|
||||||
|
parent.GCTimer.Start();
|
||||||
//Task.Run(() =>
|
//Task.Run(() =>
|
||||||
//{
|
//{
|
||||||
// Thread.Sleep(25);
|
// Thread.Sleep(25);
|
||||||
@ -289,7 +310,7 @@ namespace VPet_Simulator.Core
|
|||||||
//}
|
//}
|
||||||
if (PlayState)
|
if (PlayState)
|
||||||
{//如果当前正在运行,重置状态
|
{//如果当前正在运行,重置状态
|
||||||
//IsResetPlay = true;
|
//IsResetPlay = true;
|
||||||
Stop(true);
|
Stop(true);
|
||||||
StopAction = () => Run(EndAction);
|
StopAction = () => Run(EndAction);
|
||||||
return;
|
return;
|
||||||
@ -297,6 +318,20 @@ namespace VPet_Simulator.Core
|
|||||||
nowid = 0;
|
nowid = 0;
|
||||||
PlayState = true;
|
PlayState = true;
|
||||||
DoEndAction = true;
|
DoEndAction = true;
|
||||||
|
GCTimer.Enabled = false;
|
||||||
|
if (Dispatcher.Invoke<bool>(() => Source == null))
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
var bitmap = new BitmapImage();
|
||||||
|
bitmap.BeginInit();
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
bitmap.StreamSource = stream;
|
||||||
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmap.EndInit();
|
||||||
|
Source = bitmap;
|
||||||
|
});
|
||||||
|
}
|
||||||
new Thread(() => Animations[0].Run(EndAction)).Start();
|
new Thread(() => Animations[0].Run(EndAction)).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user