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

完善热更新管理器 #1168

Merged
merged 3 commits into from
Mar 4, 2020
Merged

完善热更新管理器 #1168

merged 3 commits into from
Mar 4, 2020

Conversation

xunyi0
Copy link
Contributor

@xunyi0 xunyi0 commented Mar 2, 2020

Fix #260
补充英文版缺失部分


这里需要注意的是,remote 信息(包括 packageUrlremoteVersionUrlremoteManifestUrl)是该 manifest 所指向远程包信息,也就是说,当这个 manifest 成为本地包或者缓存 manifest 之后,它们才有意义(偷偷透露个小秘密,更新版本时更改远程包地址也是一种玩法呢)。另外,md5 信息可以不是文件的 md5 码,也可以是某个版本号,这完全是由用户决定的,本地和远程 manifest 对比时,只要 md5 信息不同,我们就认为这个文件有改动。
这里需要注意的是,remote 信息(包括 `packageUrl`、`remoteVersionUrl`、`remoteManifestUrl`)是该 Manifest 所指向远程包信息,也就是说,当这个 Manifest 成为本地包或者缓存 Manifest 之后,它们才有意义(偷偷透露个小秘密,更新版本时更改远程包地址也是一种玩法呢)。另外,md5 信息可以不是文件的 md5 码,也可以是某个版本号,这完全是由用户决定的,本地和远程 Manifest 对比时,只要 md5 信息不同,我们就认为这个文件有改动。
Copy link
Contributor

Choose a reason for hiding this comment

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

manifest 不需要大写吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

就是特指这个文件,否则在英文文档中比较不好区分


1. JS 脚本的刷新

在热更新完成后,游戏中的所有脚本实际上已经执行过,所有的类、组件、对象都已经存在 JS context 中了,此时如果不重启直接加载脚本,同名的类和对象的确会被覆盖,但是已经用旧的类创建的对象是一直存在的,而被直接覆盖的全局对象在运行过程中修改的状态也全部丢失了。试想一下旧版本的对象和新版本的对象在一起打架的场景,一定很壮观。我还没有提对内存造成的额外开销呢
在热更新之前,游戏中的所有脚本已经执行过了,所有的类、组件、对象已经存在 JS context 中。所以热更新之后如果不重启游戏就直接加载脚本,同名的类和对象虽然会被覆盖,但是之前旧的类创建的对象是一直存在的。而被直接覆盖的全局对象,原先的状态也被重置了,就会造成新版本和旧版本的对象混杂在一起。并且对内存也会造成额外开销
Copy link
Contributor

Choose a reason for hiding this comment

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

就会导致新版本和旧版本的对象混杂在一起


2. 资源配置的刷新

在 Cocos2d-x/JS 中,的确可以做到不重启直接启用新的贴图、字体、音效等资源,但是这点在 Cocos Creator 中并不成立,原因在于 Cocos Creator 的资源也依赖于配置,场景依赖于 settings.js 中的场景列表,而 raw assets 依赖于 settings.js 中的 raw assets 列表。如果 settings.js 没有重新执行,并被 main.js 和 AssetsLibrary 重新读取,那么游戏中是加载不到新的场景和资源的
在 Cocos2d-x/JS 中可以不重启游戏就直接使用新的贴图、字体、音效等资源。但是在 Creator 中不可以,因为 Creator 的资源依赖于配置,场景依赖于 settings.js 中的场景列表,而 raw assets 依赖于 settings.js 中的 raw assets 列表。如果 settings.js 没有重新执行,并被 main.js 和 AssetsLibrary 重新读取,那么游戏中是加载不到热更新后的场景和资源的
Copy link
Contributor

Choose a reason for hiding this comment

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

因为 Creator 的资源依赖于配置,场景、资源依赖于 settings.js 中的场景列表,而 raw assets 依赖于 settings.js 中的 raw assets 列表
改为
因为 Creator 的场景和资源都依赖于 settings.js

@@ -241,6 +238,6 @@ if (jsb) {

### 更新引擎

升级游戏使用的引擎版本是可能会对热更新产生巨大影响的一个决定,开发者们可能注意过在原生项目中存在 src/jsb_polyfill.js 文件,这个文件是 JS 引擎编译出来的,包含了对 C++ 引擎的一些接口封装和 Entity Component 层的代码。在不同版本的引擎中,它的代码会产生比较大的差异,而 C++ 底层也会随之发生一些改变。这种情况下,如果游戏包内的 C++ 引擎版本和 src/jsb_polyfill.js 的引擎版本不一致,就可能导致严重的问题,甚至游戏完全无法运行。
升级游戏使用的引擎版本可能会对热更新产生巨大影响,开发者们可能有注意到在原生项目中存在 `src/jsb_polyfill.js` 文件,这个文件是 JS 引擎编译出来的,包含了对 C++ 引擎的一些接口封装和 `Entity Component` 层的代码。在不同版本的引擎中,它的代码会产生比较大的差异,而 C++ 底层也会随之发生一些改变。这种情况下,如果游戏包内的 C++ 引擎版本和 `src/jsb_polyfill.js` 的引擎版本不一致,可能会导致严重的问题,甚至游戏完全无法运行。
Copy link
Contributor

Choose a reason for hiding this comment

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

现在应该不是叫做 jsb_polyfill.js 了,麻烦和 PP 确认下

// When the return value is greater than 0, versionA > versionB.
// When the return value is equal to 0, versionA = versionB
// When the return value is less then 0, versionA = versionB
Copy link
Contributor

Choose a reason for hiding this comment

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

最后一行是 <

```
// 之前版本保存在 local Storage 中的版本号,如果没有认为是旧版本
```js
// local Storage 中保存的版本号,如果没有,则认为是旧版本
Copy link
Contributor

Choose a reason for hiding this comment

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

之前保存在 local Storage 中保存的版本号,如果没有,则认为是旧版本

// game.currentVersion is the current version's number.
if (previousVersion < game.currentVersion) {
// The hot update cache directory
Copy link
Contributor

Choose a reason for hiding this comment

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

热更新的储存路径,如果旧版本中有多个,可能需要记录在列表中,全部清理


```js
// The version number stored in local Storage
Copy link
Contributor

Choose a reason for hiding this comment

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

local Storage 中保存的版本号,如果没有,则认为是旧版本

### Update engine

Upgrading the engine version can have a huge impact on the hot update, and you may have noticed that there is a `src/jsb_polyfill.js` file in the native project, which is compiled by the JS engine and contains some interface encapsulation for the C++ engine and code for the `Entity Component` layer. In different versions of engine, its code will be quite different, and the bottom layer of C++ will also change accordingly. In this case, if the C++ engine version in the game pack does not match the engine version in the `src/jsb_polyfill.js`, it can cause serious problems and even prevent the game from running.
Copy link
Contributor

Choose a reason for hiding this comment

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

encapsulations
code for the Entity Component layer -> and the JS engine framework
accordingly -> simultaneously
In this case... -> Once the ...

Upgrading the engine version can have a huge impact on the hot update, and you may have noticed that there is a `src/jsb_polyfill.js` file in the native project, which is compiled by the JS engine and contains some interface encapsulation for the C++ engine and code for the `Entity Component` layer. In different versions of engine, its code will be quite different, and the bottom layer of C++ will also change accordingly. In this case, if the C++ engine version in the game pack does not match the engine version in the `src/jsb_polyfill.js`, it can cause serious problems and even prevent the game from running.

It is recommended to push the major version to the app store as much as possible after updating the engine. If you do not want to make hot update to the major version, please carefully complete the test of updating the old version to the new version.
Copy link
Contributor

Choose a reason for hiding this comment

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

push -> publish
the app store -> app stores

Copy link
Contributor

Choose a reason for hiding this comment

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

最后一句中英文意思存疑

var previousVersion = parseFloat(cc.sys.localStorage.getItem('currentVersion'));
// game.currentVersion is the current version's number.
if (previousVersion < game.currentVersion) {
// The hot update cache directory
// The hot update cache directory. If there are multiple in the old version, you may need to record in the list and clean all.
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are multiple versions,
in a list


```js
// The version number stored in local Storage
// The version number previously saved in local Storage, if not, is considered a new version
Copy link
Contributor

Choose a reason for hiding this comment

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

considered as


It is recommended to push the major version to the app store as much as possible after updating the engine. If you do not want to make hot update to the major version, please carefully complete the test of updating the old version to the new version.
It is recommended to publish the major version to app stores as much as possible after updating the engine. If you still want to use the hot update plan, please carefully complete the test of updating the old version to the new version.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you dicide to use hot update

@@ -246,4 +246,4 @@ Hot update is a frequent requirement for game developers, and multiple hot updat

Upgrading the engine version can have a huge impact on the hot update, and you may have noticed that there is a `src/cocos2d-jsb.js` file in the native project, which is compiled by the JS engine and contains some interface encapsulations for the C++ engine and the JS engine framework. In different versions of engine, its code will be quite different, and the bottom layer of C++ will also change simultaneously. Once the C++ engine version in the game pack does not match the engine version in the `src/cocos2d-jsb.js`, it can cause serious problems and even prevent the game from running.

It is recommended to publish the major version to app stores as much as possible after updating the engine. If you still want to use the hot update plan, please carefully complete the test of updating the old version to the new version.
It is recommended to publish the major version to app stores as much as possible after updating the engine. If you dicide to use hot update, please carefully complete the test of updating the old version to the new version.
Copy link
Contributor

Choose a reason for hiding this comment

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

是 decide,我拼错了

@xunyi0 xunyi0 merged commit ae992e2 into cocos:v2.3-release Mar 4, 2020
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.

热更新管理器
2 participants