Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's talk about stroking the text. #399

Open
agariotips opened this issue Nov 28, 2016 · 4 comments
Open

Let's talk about stroking the text. #399

agariotips opened this issue Nov 28, 2016 · 4 comments

Comments

@agariotips
Copy link

agariotips commented Nov 28, 2016

Stroketext, one thing that makes the client fit more comfortably with the eye.
We need to figure out a way to do this but without (or barely) any performance issues.
This is the line of code that changes how thick you want it to be.

1440: ctx.lineWidth = 3;

If i set this value to 8 or 10, it looks like this:
https://streamable.com/vi2u
Looks nice when small, but it loses it's effect when big.

i used a code the @ZfsrGhS953 gave me a long time ago. It worked, but it caused performance issues when near multiple cells.
https://streamable.com/xdch
What @ZfsrGhS953 did was make it so the lineWidth increases as you zoom out. That's a big problem.
I've tried many ways to get around it, but it all ends up in it looking poor or causing performance issues.

Here is the code edited by @ZfsrGhS953:

if (0 != this.id) {
                    var b = ~~this.y;
                    if ((showName || c) && this.name && this.nameCache && (null == e || -1 == knownNameDict_noDisp.indexOf(skinName))) {
                        ncache = this.nameCache;
                        ncache.setValue(this.name);
                        ncache.setSize(this.getNameSize() * viewZoom);
                        var rnchache = ncache.render(),
                            m = ~~(rnchache.width / viewZoom),
                            h = ~~(rnchache.height / viewZoom);
                        ctx.drawImage(rnchache, ~~this.x - ~~(m / 2), b - ~~(h / 2), m, h);
                        b += rnchache.height / 2 / viewZoom + 4
                    }

                    //draw mass
                    if (showMass && (c || 0 == playerCells.length && (!this.isVirus || this.isAgitated) && 20 < this.size)) {
                        if (null == this.sizeCache) {
                            this.sizeCache = new UText(this.getNameSize() / 2, "#FFFFFF", true, "#000000")
                        }
                        c = this.sizeCache;
                        c.setSize(this.getNameSize() / 2 * viewZoom);
                        c.setValue(~~(this.size * this.size / 100));
                        e = c.render();
                        m = ~~(e.width / viewZoom);
                        h = ~~(e.height / viewZoom);
                        ctx.drawImage(e, ~~this.x - ~~(m / 2), b - ~~(h / 2), m, h);
                    }
                }
                ctx.restore()
            }
        }
    };
@ZfsrGhS953
Copy link

It's very strange that this decreases performance. This code was made when I noticed massive lag when having a cell over a billion mass. Then I realised that the mass text was drawn at a resolution many times more than the canvas resolution. So I made this code that made 1 pixel of the text always be equal to 1 pixel of the canvas.

@makandz
Copy link

makandz commented Nov 29, 2016

I'll look at this later, pretty busy this week.

@Luka967
Copy link
Collaborator

Luka967 commented Dec 18, 2016

A better alternative is to stroke it inside UText's render function. I'll see what I can do

@makandz
Copy link

makandz commented Dec 19, 2016

Can anyone confirm if the new text render fixes some of this?

@makandz makandz added the medium label Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants