Skip to content

Commit e5f1cd7

Browse files
committed
feat(texture): fix "assemble wdb"->BatchSetTextureAllDataSystem->batchSetNewDiffueMaps
solution now add to texture group
1 parent 33d2053 commit e5f1cd7

File tree

7 files changed

+166
-72
lines changed

7 files changed

+166
-72
lines changed

src/asset/assemble/BatchSetTextureAllDataSystem.re

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,59 @@ let _batchSetNewMap =
66
(
77
(materialArr, textureArr, mapCount),
88
(setMapUnitFunc, setTextureIndexFunc),
9-
(
10-
textureCountPerMaterial,
11-
textureIndices,
12-
mapUnits,
13-
emptyMapUnitArrayMap,
14-
),
9+
textureCountPerMaterial,
10+
state,
1511
) => {
1612
let newTextureCount = mapCount |> succ;
1713

18-
materialArr
19-
|> WonderCommonlib.ArrayService.reduceOneParami(
20-
(. (textureIndices, mapUnits, emptyMapUnitArrayMap), material, index) => {
21-
let texture = Array.unsafe_get(textureArr, index);
22-
23-
let (mapUnit, emptyMapUnitArrayMap) =
24-
EmptyMapUnitArrayMapService.unsafeGetEmptyMapUnitAndPop(
25-
material,
26-
emptyMapUnitArrayMap,
27-
);
14+
let state =
15+
materialArr
16+
|> WonderCommonlib.ArrayService.reduceOneParami(
17+
(. state, material, index) => {
18+
let texture = Array.unsafe_get(textureArr, index);
2819

29-
(
30-
setTextureIndexFunc(.
31-
(material, mapUnit, textureCountPerMaterial),
32-
texture,
33-
textureIndices,
34-
),
35-
setMapUnitFunc(. material, mapUnit, mapUnits),
36-
emptyMapUnitArrayMap,
37-
);
38-
},
39-
(textureIndices, mapUnits, emptyMapUnitArrayMap),
40-
);
41-
};
20+
state
21+
|> GroupTextureMainService.addMaterial(
22+
(material, MaterialType.LightMaterial),
23+
texture,
24+
);
25+
},
26+
state,
27+
);
4228

43-
let batchSetNewDiffueMaps =
44-
(
45-
diffuseMapLightMaterials,
46-
lightMaterialDiffuseMaps,
47-
{settingRecord} as state,
48-
) => {
4929
let (
5030
{textureIndices, diffuseMapUnits, emptyMapUnitArrayMap}: LightMaterialType.lightMaterialRecord
5131
) as lightMaterialRecord =
5232
RecordLightMaterialMainService.getRecord(state);
53-
let (textureIndices, diffuseMapUnits, emptyMapUnitArrayMap) =
54-
_batchSetNewMap(
55-
(diffuseMapLightMaterials, lightMaterialDiffuseMaps, 0),
56-
(
57-
OperateTypeArrayLightMaterialService.setDiffuseMapUnit,
58-
OperateTypeArrayLightMaterialService.setTextureIndex,
59-
),
60-
(
61-
BufferSettingService.getTextureCountPerMaterial(settingRecord),
62-
textureIndices,
63-
diffuseMapUnits,
64-
emptyMapUnitArrayMap,
65-
),
66-
);
33+
34+
let (textureIndices, mapUnits, emptyMapUnitArrayMap) =
35+
materialArr
36+
|> WonderCommonlib.ArrayService.reduceOneParami(
37+
(.
38+
(textureIndices, mapUnits, emptyMapUnitArrayMap),
39+
material,
40+
index,
41+
) => {
42+
let texture = Array.unsafe_get(textureArr, index);
43+
44+
let (mapUnit, emptyMapUnitArrayMap) =
45+
EmptyMapUnitArrayMapService.unsafeGetEmptyMapUnitAndPop(
46+
material,
47+
emptyMapUnitArrayMap,
48+
);
49+
50+
(
51+
setTextureIndexFunc(.
52+
(material, mapUnit, textureCountPerMaterial),
53+
texture,
54+
textureIndices,
55+
),
56+
setMapUnitFunc(. material, mapUnit, mapUnits),
57+
emptyMapUnitArrayMap,
58+
);
59+
},
60+
(textureIndices, diffuseMapUnits, emptyMapUnitArrayMap),
61+
);
6762

6863
{
6964
...state,
@@ -77,6 +72,22 @@ let batchSetNewDiffueMaps =
7772
};
7873
};
7974

75+
let batchSetNewDiffueMaps =
76+
(
77+
diffuseMapLightMaterials,
78+
lightMaterialDiffuseMaps,
79+
{settingRecord} as state,
80+
) =>
81+
_batchSetNewMap(
82+
(diffuseMapLightMaterials, lightMaterialDiffuseMaps, 0),
83+
(
84+
OperateTypeArrayLightMaterialService.setDiffuseMapUnit,
85+
OperateTypeArrayLightMaterialService.setTextureIndex,
86+
),
87+
BufferSettingService.getTextureCountPerMaterial(settingRecord),
88+
state,
89+
);
90+
8091
let batchSetBasicSourceTextureData =
8192
(
8293
samplerBasicSourceTextures,

src/service/primitive/texture/DisposeTextureService.re

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ let disposeGlTextureMap = (texture, gl, glTextureMap) =>
1010

1111
glTextureMap |> WonderCommonlib.MutableSparseMapService.deleteVal(texture);
1212
| None => glTextureMap
13-
};
13+
};
14+
15+
let addDisposeIndex = (texture, disposedIndexArray) =>
16+
disposedIndexArray |> ArrayService.push(texture);
17+
18+
let isAlive = (texture, disposedIndexArray) =>
19+
DisposeComponentService.isAlive(texture, disposedIndexArray);

src/service/state/main/texture/arrayBufferView_source/DisposeArrayBufferViewSourceTextureMainService.re

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ open ArrayBufferViewSourceTextureType;
44

55
open DisposeComponentService;
66

7+
let isAlive = (texture, {disposedIndexArray}) =>
8+
DisposeTextureService.isAlive(texture, disposedIndexArray);
9+
710
let _disposeData = (texture, textureIndexInTypeArr, state) => {
811
let {
912
wrapSs,
@@ -132,7 +135,23 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {
132135
};
133136
};
134137

135-
let handleDispose = (materialData, textureArr, state) =>
138+
let handleDispose = (materialData, textureArr, state) => {
139+
WonderLog.Contract.requireCheck(
140+
() =>
141+
WonderLog.(
142+
Contract.(
143+
Operators.(
144+
DisposeComponentService.checkComponentShouldAliveWithBatchDispose(
145+
textureArr,
146+
isAlive,
147+
state |> RecordArrayBufferViewSourceTextureMainService.getRecord,
148+
)
149+
)
150+
)
151+
),
152+
IsDebugMainService.getIsDebug(StateDataMain.stateData),
153+
);
154+
136155
textureArr
137156
|> WonderCommonlib.ArrayService.reduceOneParam(
138157
(. state, texture) => {
@@ -176,7 +195,7 @@ let handleDispose = (materialData, textureArr, state) =>
176195
Some({
177196
...arrayBufferViewSourceTextureRecord,
178197
disposedIndexArray:
179-
DisposeMaterialService.addDisposeIndex(
198+
DisposeTextureService.addDisposeIndex(
180199
textureIndexInTypeArr,
181200
arrayBufferViewSourceTextureRecord.disposedIndexArray,
182201
),
@@ -185,4 +204,5 @@ let handleDispose = (materialData, textureArr, state) =>
185204
};
186205
},
187206
state,
188-
);
207+
);
208+
};

src/service/state/main/texture/basic_source/DisposeBasicSourceTextureMainService.re

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ open BasicSourceTextureType;
44

55
open DisposeComponentService;
66

7+
let isAlive = (texture, {disposedIndexArray}) =>
8+
DisposeTextureService.isAlive(texture, disposedIndexArray);
9+
710
let _disposeData = (texture, state) => {
811
let {
912
wrapSs,
@@ -108,7 +111,23 @@ let _disposeData = (texture, state) => {
108111
};
109112
};
110113

111-
let handleDispose = (materialData, textureArr, state) =>
114+
let handleDispose = (materialData, textureArr, state) => {
115+
WonderLog.Contract.requireCheck(
116+
() =>
117+
WonderLog.(
118+
Contract.(
119+
Operators.(
120+
DisposeComponentService.checkComponentShouldAliveWithBatchDispose(
121+
textureArr,
122+
isAlive,
123+
state |> RecordBasicSourceTextureMainService.getRecord,
124+
)
125+
)
126+
)
127+
),
128+
IsDebugMainService.getIsDebug(StateDataMain.stateData),
129+
);
130+
112131
textureArr
113132
|> WonderCommonlib.ArrayService.reduceOneParam(
114133
(. state, texture) => {
@@ -142,7 +161,7 @@ let handleDispose = (materialData, textureArr, state) =>
142161
Some({
143162
...basicSourceTextureRecord,
144163
disposedIndexArray:
145-
DisposeMaterialService.addDisposeIndex(
164+
DisposeTextureService.addDisposeIndex(
146165
texture,
147166
basicSourceTextureRecord.disposedIndexArray,
148167
),
@@ -151,4 +170,5 @@ let handleDispose = (materialData, textureArr, state) =>
151170
};
152171
},
153172
state,
154-
);
173+
);
174+
};

test/integration/no_worker/asset/assemble/fixAssembleWDBBug_test.re

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,31 @@ let _ =
8282
},
8383
)
8484
);
85+
86+
describe("test dispose gameObject after assemble", () =>
87+
describe("test basic source texture", () =>
88+
testPromise(
89+
"if the wdb use shared texture, the disposedIndexArray after dispose should has no duplicate items",
90+
() => {
91+
let state = state^;
92+
let state =
93+
state
94+
|> FakeGlTool.setFakeGl(FakeGlTool.buildFakeGl(~sandbox, ()));
95+
96+
AssembleWDBSystemTool.testGLB(
97+
sandbox^,
98+
GLBTool.buildGLBFilePath("AlphaBlendModeTest.glb"),
99+
((state, _, rootGameObject)) => {
100+
let state =
101+
GameObjectTool.disposeAllGameObjects(rootGameObject, state);
102+
103+
BasicSourceTextureTool.getDisposedIndexArray(state)
104+
|> expect == [|1, 0|];
105+
},
106+
state,
107+
);
108+
},
109+
)
110+
)
111+
);
85112
});

test/tool/service/gameObject/GameObjectTool.re

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,11 @@ let unsafeFindGameObjectByName = (targetGameObject, name, state) =>
367367
|> ArrayService.unsafeGetFirst;
368368

369369
let isDeferDisposed = (gameObject, state) =>
370-
state.gameObjectRecord.disposedUidArray |> Js.Array.includes(gameObject);
370+
state.gameObjectRecord.disposedUidArray |> Js.Array.includes(gameObject);
371+
372+
let disposeAllGameObjects = (rootGameObject, state) =>
373+
GameObjectAPI.getAllGameObjects(rootGameObject, state)
374+
|> WonderCommonlib.ArrayService.reduceOneParam(
375+
(. state, gameObject) => disposeGameObject(gameObject, state),
376+
state,
377+
);

test/tool/service/texture/BasicSourceTextureTool.re

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ let setBindTextureUnitCacheMap = (unit, bindedTexture, state) => {
129129
};
130130

131131
/* let setBindTextureUnitMap = (texture, unit, state) => {
132-
let basicSourceTextureRecord =
133-
RecordBasicSourceTextureMainService.getRecord(state);
134-
135-
{
136-
...state,
137-
basicSourceTextureRecord:
138-
Some({
139-
...basicSourceTextureRecord,
140-
bindTextureUnitMap:
141-
basicSourceTextureRecord.bindTextureUnitMap
142-
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
143-
}),
144-
};
145-
}; */
132+
let basicSourceTextureRecord =
133+
RecordBasicSourceTextureMainService.getRecord(state);
134+
135+
{
136+
...state,
137+
basicSourceTextureRecord:
138+
Some({
139+
...basicSourceTextureRecord,
140+
bindTextureUnitMap:
141+
basicSourceTextureRecord.bindTextureUnitMap
142+
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
143+
}),
144+
};
145+
}; */
146146

147147
let getBasicSourceTextureSource = (texture, state: StateDataMainType.state) => {
148148
let {sourceMap} = RecordBasicSourceTextureMainService.getRecord(state);
@@ -155,4 +155,7 @@ let getNeedAddedSourceArray = state =>
155155

156156
let getNeedInitedTextureIndexArray = state =>
157157
RecordBasicSourceTextureMainService.getRecord(state).
158-
needInitedTextureIndexArray;
158+
needInitedTextureIndexArray;
159+
160+
let getDisposedIndexArray = state =>
161+
RecordBasicSourceTextureMainService.getRecord(state).disposedIndexArray;

0 commit comments

Comments
 (0)