mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 05:41:45 +00:00
Linedefs Mode: further speed improvements related to sector labels
This commit is contained in:
parent
e0bd927450
commit
6c2ad3efaf
2 changed files with 32 additions and 7 deletions
|
@ -467,6 +467,21 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
// This (re)loads the resources
|
||||
public void ReloadResource() { }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the whole label is in the viewport.
|
||||
/// </summary>
|
||||
/// <returns>true if the label in in the viewport, false if it isn't</returns>
|
||||
public bool IsInViewport()
|
||||
{
|
||||
(double width, double height) = texturesize.IsEmpty ? ( 0, 0 ) : (texturesize.Width, texturesize.Height);
|
||||
|
||||
return
|
||||
location.x >= (General.Map.CRenderer2D.Viewport.X - width) &&
|
||||
location.x < (General.Map.CRenderer2D.Viewport.X + General.Map.CRenderer2D.Viewport.Width + width) &&
|
||||
location.y <= (General.Map.CRenderer2D.Viewport.Y - height) &&
|
||||
location.y > (General.Map.CRenderer2D.Viewport.Y + General.Map.CRenderer2D.Viewport.Height + height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -366,8 +366,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
//mxd. This sets up new labels
|
||||
private void SetupSectorLabels()
|
||||
{
|
||||
// Dummy label we need for the font
|
||||
TextLabel dummylabel = new TextLabel();
|
||||
|
||||
// The "+" is always shown if the space for the label isn't big enough to show the full text
|
||||
textlabelsizecache["+"] = General.Interface.MeasureString("+", dummylabel.Font).Width;
|
||||
|
||||
// Dispose old labels
|
||||
if(sectorlabels != null)
|
||||
if (sectorlabels != null)
|
||||
{
|
||||
foreach(TextLabel[] larr in sectorlabels.Values)
|
||||
foreach(TextLabel l in larr) l.Dispose();
|
||||
|
@ -396,6 +402,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
tagdescarr[1] = "T" + s.Tag;
|
||||
}
|
||||
|
||||
// Add string lengths to the label size cache
|
||||
if (!textlabelsizecache.ContainsKey(tagdescarr[0]))
|
||||
textlabelsizecache[tagdescarr[0]] = General.Interface.MeasureString(tagdescarr[0], dummylabel.Font).Width;
|
||||
if (!textlabelsizecache.ContainsKey(tagdescarr[1]))
|
||||
textlabelsizecache[tagdescarr[1]] = General.Interface.MeasureString(tagdescarr[1], dummylabel.Font).Width;
|
||||
|
||||
// Add to collection
|
||||
sectortexts.Add(s, tagdescarr);
|
||||
|
||||
|
@ -501,19 +513,17 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
TextLabel[] labelarray = sectorlabels[group.Key];
|
||||
for (int i = 0; i < group.Key.Labels.Count; i++)
|
||||
{
|
||||
// Only process this label if it's actually in view
|
||||
if (!labelarray[i].IsInViewport())
|
||||
continue;
|
||||
|
||||
TextLabel l = labelarray[i];
|
||||
|
||||
// Render only when enough space for the label to see
|
||||
if (!textlabelsizecache.ContainsKey(group.Value[0]))
|
||||
textlabelsizecache[group.Value[0]] = General.Interface.MeasureString(group.Value[0], l.Font).Width;
|
||||
|
||||
float requiredsize = textlabelsizecache[group.Value[0]] / 2 / renderer.Scale;
|
||||
|
||||
if (requiredsize > group.Key.Labels[i].radius)
|
||||
{
|
||||
if (!textlabelsizecache.ContainsKey(group.Value[1]))
|
||||
textlabelsizecache[group.Value[1]] = General.Interface.MeasureString(group.Value[1], l.Font).Width;
|
||||
|
||||
requiredsize = textlabelsizecache[group.Value[1]] / 2 / renderer.Scale;
|
||||
|
||||
string newtext;
|
||||
|
|
Loading…
Reference in a new issue