Skip to content

fix bmfont parser cache#1553

Merged
nantas merged 2 commits intococos:v1.4from
zilongshanren:add-bmfont-parser-cache
Mar 16, 2017
Merged

fix bmfont parser cache#1553
nantas merged 2 commits intococos:v1.4from
zilongshanren:add-bmfont-parser-cache

Conversation

@zilongshanren
Copy link
Copy Markdown
Contributor

Re: https://github.com/cocos-creator/fireball/issues/5410

Changes proposed in this pull request:

  • add bmfont config cache

@cocos-creator/engine-admins

if (this.font.spriteFrame) {
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame);
if (CC_JSB) {
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSB 的 Label 有缓存嘛?还是说也是每次都解析?如果跟 web 一样的话,建议修改 JS 层 Label 的构造函数

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandamicro jsb 有 cache 的,不过有一个小 bug,我提交一下。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cocos/engine-native#572 @pandamicro 这个影响不大,放在 develop 分支了。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


//fontHandle it is a system font name, ttf file path or bmfont file path.
ctor: function(string, fontHandle, spriteFrame) {
ctor: function(string, fontHandle, spriteFrame, bmfontUUID) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议把这个参数改成 bmFontAsset,缓存放在 Asset 对象里。好处是 loader 自动确保全局 Asset 对象唯一,所以缓存也唯一。而 BMFont 释放后缓存也会跟着释放。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缓存在 Asset 对象里面,然后靠 loader 保证全局惟一,貌似耦合有点多。另外 BMFont 释放,其实缓存可以不用释放吧,比如从一个场景切换到另一个场景,如果 bmfont 释放了,那下次进场景又要重新 parser。

Copy link
Copy Markdown
Contributor

@pandamicro pandamicro Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我同意 jare 的看法。这个不能算耦合,是保障自治。
下一个场景依赖同样的 asset 的话,是不会被释放的

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandamicro 可以,我改一下。

@zilongshanren
Copy link
Copy Markdown
Contributor Author

@jareguo @pandamicro 修改完了,麻烦再 review 一下

self._config = fntConfig;
} else {
self._config = FntLoader.parseFnt(fntDataStr);
this._fontAsset._fntConfig = self._config;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实你已经不再需要 this._config 了,用的地方都用 this._fontAsset._fntConfig 就可以了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandamicro ok, 我改一下

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandamicro 暂时不改吧,改动的地方有点多,怕出 bug。

@zilongshanren
Copy link
Copy Markdown
Contributor Author

@nantas nantas merged commit 4ad87db into cocos:v1.4 Mar 16, 2017
@zilongshanren zilongshanren deleted the add-bmfont-parser-cache branch May 16, 2017 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants