Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit c4d963f

Browse files
committed
optimze gc equals zero
1 parent 0347cf9 commit c4d963f

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

Assets/TextInlineSprite/Scripts/InlineRender/EmojiRenderGroup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public void Dispose()
220220
if (target != null)
221221
{
222222
target.Draw(null);
223+
target.SetDirtyMask();
223224
target.SetVerticesDirty();
224225
}
225226

@@ -391,6 +392,7 @@ void RenderRebuild()
391392
else
392393
{
393394
group.graphic.Draw(null);
395+
group.graphic.SetDirtyMask();
394396
group.graphic.SetVerticesDirty();
395397
}
396398
}

Assets/TextInlineSprite/Scripts/InlineRender/UnitRender.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public void Dispose()
162162
if (target != null)
163163
{
164164
target.Draw(null);
165+
target.SetDirtyMask();
165166
target.SetVerticesDirty();
166167
}
167168
}
@@ -251,16 +252,12 @@ void RenderRebuild()
251252
if (renderData == null)
252253
renderData = new Dictionary<Graphic, UnitMeshInfo>(emojidata.Count);
253254

254-
List<SpriteGraphic> joblist = ListPool<SpriteGraphic>.Get();
255-
256255
for (int j = 0; j < emojidata.Count; ++j)
257256
{
258257
IFillData taginfo = emojidata[j];
259258
if (taginfo == null || taginfo.ignore)
260259
continue;
261-
SpriteGraphic job = Parse(text, taginfo, joblist);
262-
if (job)
263-
joblist.Add(job);
260+
Parse(text, taginfo);
264261
}
265262

266263
List<SpriteGraphic> list;
@@ -270,15 +267,14 @@ void RenderRebuild()
270267
{
271268
SpriteGraphic graphic = list[j];
272269
//not render
273-
if (graphic != null && !joblist.Contains(graphic))
270+
if (graphic != null && !graphic.isDirty)
274271
{
275272
graphic.Draw(null);
273+
graphic.SetDirtyMask();
276274
graphic.SetVerticesDirty();
277275
}
278276
}
279277
}
280-
281-
ListPool<SpriteGraphic>.Release(joblist);
282278
}
283279
else
284280
{
@@ -292,6 +288,7 @@ void RenderRebuild()
292288
if (graphic != null)
293289
{
294290
graphic.Draw(null);
291+
graphic.SetDirtyMask();
295292
graphic.SetVerticesDirty();
296293
}
297294
}
@@ -326,7 +323,6 @@ void PlayAnimation()
326323
List<IFillData> emojidata = text.PopEmojiData();
327324
if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0)
328325
{
329-
List<SpriteGraphic> joblist = ListPool<SpriteGraphic>.Get();
330326
for (int j = 0; j < emojidata.Count; ++j)
331327
{
332328
IFillData taginfo = emojidata[j];
@@ -351,13 +347,10 @@ void PlayAnimation()
351347
if (renderData == null)
352348
renderData = new Dictionary<Graphic, UnitMeshInfo>(emojidata.Count);
353349

354-
RefreshSubUIMesh(text, target, asset, taginfo.pos, taginfo.uv, joblist);
355-
joblist.Add(target);
350+
RefreshSubUIMesh(text, target, asset, taginfo.pos, taginfo.uv);
356351
}
357352
}
358353
}
359-
360-
ListPool<SpriteGraphic>.Release(joblist);
361354
}
362355
}
363356
}
@@ -367,16 +360,16 @@ void PlayAnimation()
367360
EmojiTools.EndSample();
368361
}
369362

370-
SpriteGraphic Parse(InlineText text, IFillData taginfo, List<SpriteGraphic> joblist)
363+
SpriteGraphic Parse(InlineText text, IFillData taginfo)
371364
{
372365
if (taginfo != null)
373366
{
374-
return ParsePosAndUV(text, taginfo.ID, taginfo.pos, taginfo.uv, joblist);
367+
return ParsePosAndUV(text, taginfo.ID, taginfo.pos, taginfo.uv);
375368
}
376369
return null;
377370
}
378371

379-
SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV, List<SpriteGraphic> joblist)
372+
SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV)
380373
{
381374
EmojiTools.BeginSample("Emoji_UnitParsePosAndUV");
382375
SpriteAsset matchAsset = null;
@@ -400,7 +393,7 @@ SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV
400393
list.Add(target);
401394
}
402395

403-
RefreshSubUIMesh(text, target, matchAsset, Pos, UV, joblist);
396+
RefreshSubUIMesh(text, target, matchAsset, Pos, UV);
404397

405398
EmojiTools.EndSample();
406399
return target;
@@ -413,7 +406,7 @@ SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV
413406
return null;
414407
}
415408

416-
void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV, List<SpriteGraphic> joblist)
409+
void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV)
417410
{
418411
// set mesh
419412
tempMesh.SetAtlas(matchAsset);
@@ -445,7 +438,7 @@ void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAs
445438

446439
if (!currentMesh.Equals(tempMesh))
447440
{
448-
if (joblist != null && joblist.Contains(target))
441+
if (target.isDirty)
449442
{
450443
currentMesh.AddCopy(tempMesh);
451444
tempMesh.Clear();
@@ -459,11 +452,13 @@ void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAs
459452
if (currentMesh.VertCnt() > 3 && currentMesh.UVCnt() > 3)
460453
{
461454
target.Draw(this);
455+
target.SetDirtyMask();
462456
target.SetVerticesDirty();
463457
}
464458
else
465459
{
466460
target.Draw(null);
461+
target.SetDirtyMask();
467462
target.SetVerticesDirty();
468463
}
469464
}

Assets/TextInlineSprite/Scripts/SpriteGraphic.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public override Texture mainTexture
2626
}
2727
}
2828

29+
public bool isDirty { get; protected set; }
30+
31+
public void SetDirtyMask()
32+
{
33+
isDirty = true;
34+
}
35+
2936
public void Draw(IEmojiRender rd)
3037
{
3138
_Render = rd;
@@ -57,6 +64,7 @@ protected override void OnPopulateMesh(VertexHelper vh)
5764
{
5865
_Render.FillMesh(this, vh);
5966
}
67+
isDirty = false;
6068
}
6169

6270
void OnDrawGizmos()

0 commit comments

Comments
 (0)