mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:22:55 +08:00
Load initial channel content asynchronously
Quite often, the first time loading a chat channel will be loading font characters (textures) that were previously never displayed. This stops the game from stuttering in such a scenario.
This commit is contained in:
parent
900e3ce3e2
commit
5b80c8ac49
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
@ -43,11 +44,15 @@ namespace osu.Game.Overlays.Chat
|
|||||||
channel.NewMessagesArrived += newMessagesArrived;
|
channel.NewMessagesArrived += newMessagesArrived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
newMessagesArrived(Channel.Messages);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
newMessagesArrived(Channel.Messages);
|
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,13 +64,13 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
||||||
{
|
{
|
||||||
if (!IsLoaded) return;
|
|
||||||
|
|
||||||
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
|
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
|
||||||
|
|
||||||
//up to last Channel.MAX_HISTORY messages
|
//up to last Channel.MAX_HISTORY messages
|
||||||
flow.Add(displayMessages.Select(m => new ChatLine(m)));
|
flow.Add(displayMessages.Select(m => new ChatLine(m)));
|
||||||
|
|
||||||
|
if (!IsLoaded) return;
|
||||||
|
|
||||||
if (scroll.IsScrolledToEnd(10) || !flow.Children.Any())
|
if (scroll.IsScrolledToEnd(10) || !flow.Children.Any())
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
|
|
||||||
|
@ -266,20 +266,30 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
if (channelTabs.ChannelSelectorActive) return;
|
if (channelTabs.ChannelSelectorActive) return;
|
||||||
|
|
||||||
if (currentChannel != null)
|
|
||||||
currentChannelContainer.Clear(false);
|
|
||||||
|
|
||||||
currentChannel = value;
|
currentChannel = value;
|
||||||
|
|
||||||
|
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
|
||||||
|
channelTabs.Current.Value = value;
|
||||||
|
|
||||||
var loaded = loadedChannels.Find(d => d.Channel == value);
|
var loaded = loadedChannels.Find(d => d.Channel == value);
|
||||||
if (loaded == null)
|
if (loaded == null)
|
||||||
loadedChannels.Add(loaded = new DrawableChannel(currentChannel));
|
{
|
||||||
|
currentChannelContainer.FadeOut(500, EasingTypes.OutQuint);
|
||||||
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
|
|
||||||
|
|
||||||
|
loaded = new DrawableChannel(currentChannel);
|
||||||
|
loadedChannels.Add(loaded);
|
||||||
|
LoadComponentAsync(loaded, l =>
|
||||||
|
{
|
||||||
|
currentChannelContainer.Clear(false);
|
||||||
|
currentChannelContainer.Add(l);
|
||||||
|
currentChannelContainer.FadeIn(500, EasingTypes.OutQuint);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentChannelContainer.Clear(false);
|
||||||
currentChannelContainer.Add(loaded);
|
currentChannelContainer.Add(loaded);
|
||||||
|
}
|
||||||
channelTabs.Current.Value = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user