mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32: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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Online.Chat;
|
||||
@ -43,11 +44,15 @@ namespace osu.Game.Overlays.Chat
|
||||
channel.NewMessagesArrived += newMessagesArrived;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
newMessagesArrived(Channel.Messages);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
newMessagesArrived(Channel.Messages);
|
||||
scrollToEnd();
|
||||
}
|
||||
|
||||
@ -59,13 +64,13 @@ namespace osu.Game.Overlays.Chat
|
||||
|
||||
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
|
||||
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
|
||||
|
||||
//up to last Channel.MAX_HISTORY messages
|
||||
flow.Add(displayMessages.Select(m => new ChatLine(m)));
|
||||
|
||||
if (!IsLoaded) return;
|
||||
|
||||
if (scroll.IsScrolledToEnd(10) || !flow.Children.Any())
|
||||
scrollToEnd();
|
||||
|
||||
|
@ -266,20 +266,30 @@ namespace osu.Game.Overlays
|
||||
|
||||
if (channelTabs.ChannelSelectorActive) return;
|
||||
|
||||
if (currentChannel != null)
|
||||
currentChannelContainer.Clear(false);
|
||||
|
||||
currentChannel = value;
|
||||
|
||||
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
|
||||
channelTabs.Current.Value = value;
|
||||
|
||||
var loaded = loadedChannels.Find(d => d.Channel == value);
|
||||
if (loaded == null)
|
||||
loadedChannels.Add(loaded = new DrawableChannel(currentChannel));
|
||||
{
|
||||
currentChannelContainer.FadeOut(500, EasingTypes.OutQuint);
|
||||
|
||||
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
|
||||
|
||||
currentChannelContainer.Add(loaded);
|
||||
|
||||
channelTabs.Current.Value = value;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user