Skip to content

Commit

Permalink
fix(camera): if change arcballCameraController's gameObject's parent,…
Browse files Browse the repository at this point in the history
… should update the component

description
if change arcballCameraController's gameObject's parent or change its parent's transform, should update the component in update_camera job.

reason

solution
rewrite update_camera job in editor: update all arc camera controllers;
update wonder.js version
  • Loading branch information
yyc-git committed Feb 18, 2019
1 parent 7eeb4f1 commit c9fa3a8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"wonder-bs-most": "^0.0.3",
"wonder-commonlib": "0.2.26",
"wonder-log": "^0.2.10",
"wonder.js": "1.0.0-beta.1"
"wonder.js": "1.0.0-beta.1.1"
},
"resolutions": {
"wonder-log": "^0.2.10",
Expand Down
4 changes: 4 additions & 0 deletions src/core/job/loop/UpdateCameraJob.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let updateJob = (_, engineState) =>
engineState
|> Wonderjs.UpdatePerspectiveCameraProjectionMainService.update
|> Wonderjs.UpdateArcballCameraControllerMainService.updateAll;
4 changes: 4 additions & 0 deletions src/core/utils/engine/MainUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ let _registerJob = engineState =>
"reallocate_cpu_memory",
ReallocateCPUMemoryJob.reallocateJob,
)
|> JobEngineService.registerNoWorkerLoopJob(
"update_camera",
UpdateCameraJob.updateJob,
)
|> JobEngineService.registerNoWorkerLoopJob(
"update_transform_gizmos",
UpdateTransformGizmosJob.updateTransformJob,
Expand Down
74 changes: 74 additions & 0 deletions test/integration/job/updateCameraJob_test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
open Wonderjs;

open Wonder_jest;

open Expect;

open Expect.Operators;

open Sinon;

let _ =
describe("update camera job", () => {
let sandbox = getSandboxDefaultVal();

let _prepareState = () => {
MainEditorSceneTool.initStateWithJob(
~sandbox,
~isInitJob=false,
~noWorkerJobRecord=
NoWorkerJobConfigToolEngine.buildNoWorkerJobConfig(
~loopPipelines=
{|
[
{
"name": "default",
"jobs": [
{"name": "update_camera" }
]
}
]
|},
(),
),
(),
);

MainEditorSceneTool.createDefaultScene(
sandbox,
MainEditorSceneTool.setFirstCubeToBeCurrentSceneTreeNode,
);
};

beforeEach(() => sandbox := createSandbox());
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("update all arcballCameraControllers", () =>
test("update undirty ones", () => {
_prepareState();
StateLogicService.getAndSetEngineState(MainUtils._handleEngineState);

MainEditorInspectorAddComponentTool.addArcballCameraControllerComponent();

ArcballCameraControllerToolEngine.clearDirtyArray
|> StateLogicService.getAndSetEngineState;

let pos = (0., 0., 0.);
TransformGameObjectEngineService.setLocalPosition(
GameObjectTool.getCurrentSceneTreeNodeTransform(),
pos,
)
|> StateLogicService.getAndSetEngineState;

StateLogicService.getAndSetEngineState(
DirectorToolEngine.runWithDefaultTime,
);

TransformGameObjectEngineService.getLocalPosition(
GameObjectTool.getCurrentSceneTreeNodeTransform(),
)
|> StateLogicService.getEngineStateToGetData
|> expect != (0., 0., 0.);
})
);
});
7 changes: 6 additions & 1 deletion test/tool/engine/ArcballCameraControllerToolEngine.re
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ let addGameObjectArcballCameraControllerComponentAndBindArcballCameraControllerE
);

(engineState, gameObject, cameraController);
};
};

let clearDirtyArray = engineState =>
Wonderjs.UpdateArcballCameraControllerMainService._clearDirtyArray(
engineState,
);

0 comments on commit c9fa3a8

Please sign in to comment.