Skip to content

Commit 4e33cb5

Browse files
Merge pull request #1042 from TremblingMoeNew/fix/reserve-cubism-memory
支持预留cubism core堆内存容量配置,避免堆扩容破坏在场的Live2D立绘
2 parents d041e7a + d1a5f5d commit 4e33cb5

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎packages/webgal/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"mitt": "^3.0.0",
2525
"modern-css-reset": "^1.4.0",
2626
"pixi-filters": "^4.2.0",
27-
"pixi-live2d-display-webgal": "^0.5.16",
27+
"pixi-live2d-display-webgal": "^0.5.19",
2828
"pixi.js": "^6.3.0",
2929
"popmotion": "^11.0.5",
3030
"react": "^17.0.2",

‎packages/webgal/src/Core/live2DCore.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class Live2DCore {
3838
public Config: any;
3939

4040
public createCubism2Texture?: (texture: Texture) => Texture;
41+
public reserveCoreMemory?: (size: number) => void;
4142

4243
// 临时记录未初始化前的数据
4344
// 旧版表情混合模式
@@ -52,6 +53,18 @@ export class Live2DCore {
5253
}
5354
}
5455

56+
// CubismCore预留堆内存容量,单位MB;PLDW的对应API的单位是byte
57+
private _cubismMemoryReservedSize = 32
58+
public get CubismMemoryReservedSize() {
59+
return this._cubismMemoryReservedSize;
60+
}
61+
public set CubismMemoryReservedSize(size: number) {
62+
this._cubismMemoryReservedSize = size;
63+
if (this.isAvailable && this.reserveCoreMemory) {
64+
this.reserveCoreMemory(this.CubismMemoryReservedSize * 1024 * 1024);
65+
}
66+
}
67+
5568
public constructor() {
5669
this.ready = this.initLive2D();
5770
}
@@ -65,17 +78,27 @@ export class Live2DCore {
6578
console.warn('live2d plugin load failed');
6679
return;
6780
}
68-
const { Live2DModel, SoundManager, config, Live2DLoader, ModelSettings, createCubism2Texture } = await import(
69-
'pixi-live2d-display-webgal'
70-
);
81+
const {
82+
Live2DModel,
83+
SoundManager,
84+
config,
85+
Live2DLoader,
86+
ModelSettings,
87+
createCubism2Texture,
88+
reserveCoreMemory,
89+
} = await import('pixi-live2d-display-webgal');
7190
installLive2dAssetCache({ Live2DLoader, ModelSettings });
7291
this.Live2DModel = Live2DModel;
7392
this.SoundManager = SoundManager;
7493
this.Config = config;
7594
this.isAvailable = true;
7695
this.createCubism2Texture = createCubism2Texture;
96+
this.reserveCoreMemory = reserveCoreMemory;
7797
console.log('Live2D plugin load success');
7898
this.initConfig();
99+
if (this.reserveCoreMemory) {
100+
this.reserveCoreMemory(this.CubismMemoryReservedSize * 1024 * 1024);
101+
}
79102
})
80103
.catch((error) => {
81104
this.isAvailable = false;

‎packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const infoFetcher = (url: string): Promise<IGameVar> => {
6767
const appId = String(res);
6868
WebGAL.steam.initialize(appId);
6969
}
70+
if (command === 'Cubism_Memory_Reserved_Size_MB') {
71+
if (typeof res === 'number') {
72+
Live2D.CubismMemoryReservedSize = res;
73+
}
74+
}
7075
}
7176
}
7277
});

‎yarn.lock‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4993,10 +4993,10 @@ pixi-filters@^4.2.0:
49934993
"@pixi/filter-twist" "4.2.0"
49944994
"@pixi/filter-zoom-blur" "4.2.0"
49954995

4996-
pixi-live2d-display-webgal@^0.5.16:
4997-
version "0.5.16"
4998-
resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.16.tgz#eddc6a4a478f9fef51fce942d0a21faccc2a7074"
4999-
integrity sha512-dKKWLHRdC70FUGyo10R0oNtB0fH4q1sCmJxFr3DhHDlUI+rPtsCiGag5PJ8yF6KG9HX+rUpe6R2GrvuHk3N5PA==
4996+
pixi-live2d-display-webgal@^0.5.19:
4997+
version "0.5.19"
4998+
resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.19.tgz#3bec5c75b55477ab6896d72bceaa2ae139ed1224"
4999+
integrity sha512-486kQpM4O0wpxKaQUTefSI46xmTGe1GbSNsCv7Fs4+2isvTSBB3frbTIEgVOSaU2uH8MyfN/WqE50Q3+9j5zwA==
50005000
dependencies:
50015001
gh-pages "^4.0.0"
50025002

0 commit comments

Comments
 (0)