-
Contributor
Did you know that PaintWorld(layer) is called twice?
Just for those that want to "optimize" their code, I ques.
I found that only MonsterPackPlugin does check which layer to use.
Code:
if (layer != WorldLayer.Ground)
return;
All other plugins execute their PaintWorld method twice, or I did not understand this at all.
For those plugins that draw both on world map and mini map this is of course convenient!
-
Post Thanks / Like - 1 Thanks
RNN (1 members gave Thanks to JarJarD3 for this useful post)
-
yes, it does, but it is by design, because each decorator has a "Layer" property.
public class MonsterRiftProgressionColoringPlugin : BasePlugin, IInGameWorldPainter
{
public void PaintWorld(WorldLayer layer)
{
.......
decorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
}
}
you can see? it passes the layer to the decorator (which is a WorldDecoratorCollection)
WorldDecoratorCollection.Paint iterates through all decorators which belongs to the given layer and paints only those
this way you don't have to separate your painter into two methods, but allow the same PaintWorld method be called twice, and let the automagic decide which decorator will be used
Do not send me private messages unless it is absolutely necessary or the content is sensitive or when I ask you to do that...
-
Contributor
Originally Posted by
KillerJohn
yes, it does, but it is by design, because each decorator has a "Layer" property.
public class MonsterRiftProgressionColoringPlugin : BasePlugin, IInGameWorldPainter
{
public void PaintWorld(WorldLayer layer)
{
.......
decorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
}
}
you can see? it passes the layer to the decorator (which is a WorldDecoratorCollection)
WorldDecoratorCollection.Paint iterates through all decorators which belongs to the given layer and paints only those
this way you don't have to separate your painter into two methods, but allow the same PaintWorld method be called twice, and let the automagic decide which decorator will be used
Yes, I understand that this is by design and for convenience.
And it is good but I have seen here code from people that do not understand programming so well as we
I just wanted to point out that you might want to optimize your code sometimes?
-
Legendary
It is good to know this. The plugins that use decorators that apply only to Ground can prevent Paintworld from being processed twice unnecessarily by adding
if (layer != WorldLayer.Ground) return;
-
Legendary
It is curious that this can be done to prevent PaintWorld from being processed twice, in plugins containing many instructions it can save a lot of processing time.
Code to express the idea, it is not functional:
Code:
public WorldDecoratorCollection Decorator { get; set; }
public void PaintWorld(WorldLayer layer)
{
Decorator.Paint(layer, actor, actor.FloorCoordinate, null);
}
replaced by this
Code:
public WorldDecoratorCollection Decorator { get; set; }
public void PaintWorld(WorldLayer layer)
{
if (layer != WorldLayer.Ground) return;
Decorator.Paint(layer, actor, actor.FloorCoordinate, null);
Decorator.Paint(WorldLayer.Map, actor, actor.FloorCoordinate, null);
}