Skip to content

Commit

Permalink
Merge pull request #30 from BarthPaleologue/WIP
Browse files Browse the repository at this point in the history
1.6.1 - Fixed memory leak
  • Loading branch information
BarthPaleologue authored Feb 21, 2024
2 parents 650e19b + c781e77 commit 299e041
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 27 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/tauri-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'tauri build and release'

# This will trigger the action on each push to the `release` branch.
on:
push:
branches:
- main

jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
run: pnpm install

- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: __VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version
releaseName: 'Cosmos Journeyer __VERSION__'
releaseBody: 'The new version of Cosmos Journeyer is online at https://barthpaleologue.github.io/CosmosJourneyer/ You can also install the app built using Tauri.'
releaseDraft: true
prerelease: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Cosmos Journeyer can be built as a desktop application using Tauri!
First you will need a bazillion dependencies, here is a list of some of them if you are using a Debian base OS:

```bash
sudo apt install -y libwebkit2gtk-4.0-dev libgtk-3-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev librsvg2-dev
sudo apt install -y libwebkit2gtk-4.0-dev libgtk-3-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev librsvg2-dev libwebkit2gtk-4.0-dev libappindicator3-dev patchelf
```

Then you can build the application with `pnpm tauri build`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"version": "1.6.0",
"version": "1.6.1",
"description": "CosmosJourneyer",
"name": "cosmos-journeyer",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/ts/spaceship/spaceship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ export class Spaceship implements Transformable {
if (currentForwardSpeed < this.warpDrive.getWarpSpeed()) {
this.acceleratingWarpDriveSound.setTargetVolume(1);
this.deceleratingWarpDriveSound.setTargetVolume(0);
console.log(this.acceleratingWarpDriveSound.sound.getVolume());
} else {
this.deceleratingWarpDriveSound.setTargetVolume(1);
this.acceleratingWarpDriveSound.setTargetVolume(0);
Expand Down
3 changes: 2 additions & 1 deletion src/ts/starSystem/starSystemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { getRotationQuaternion, setRotationQuaternion } from "../uberCore/transf
import { Observable } from "@babylonjs/core/Misc/observable";
import { NeutronStar } from "../stellarObjects/neutronStar/neutronStar";
import { View } from "../utils/view";
import { syncCamera } from "../utils/cameraSyncing";

export class StarSystemView implements View {
private readonly helmetOverlay: HelmetOverlay;
Expand Down Expand Up @@ -375,7 +376,7 @@ export class StarSystemView implements View {
public render() {
this.scene.render();

this.ui.syncCamera(this.scene.getActiveCamera());
syncCamera(this.scene.getActiveCamera(), this.ui.camera);
this.ui.scene.render();
}

Expand Down
3 changes: 2 additions & 1 deletion src/ts/starmap/starMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { SystemSeed } from "../utils/systemSeed";
import { NeutronStarModel } from "../stellarObjects/neutronStar/neutronStarModel";
import { View } from "../utils/view";
import { Assets } from "../assets";
import { syncCamera } from "../utils/cameraSyncing";

export class StarMap implements View {
readonly scene: Scene;
Expand Down Expand Up @@ -552,7 +553,7 @@ export class StarMap implements View {

public render() {
this.scene.render();
this.starMapUI.syncCamera(this.controls.getActiveCamera());
syncCamera(this.controls.getActiveCamera(), this.starMapUI.uiCamera);
this.starMapUI.scene.render();
}

Expand Down
11 changes: 0 additions & 11 deletions src/ts/starmap/starMapUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,4 @@ export class StarMapUI {
this.namePlate.text = name;
this.descriptionPanel.text = text;
}

public syncCamera(camera: Camera) {
this.uiCamera.position = camera.globalPosition;
this.uiCamera.rotationQuaternion = camera.absoluteRotation;
this.uiCamera.onViewMatrixChangedObservable.add(() => {
this.uiCamera.getViewMatrix().copyFrom(camera.getViewMatrix())
})
this.uiCamera.fov = camera.fov;
this.uiCamera.minZ = camera.minZ;
this.uiCamera.maxZ = camera.maxZ;
}
}
11 changes: 0 additions & 11 deletions src/ts/ui/systemUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ export class SystemUI {
this.target = object;
}

public syncCamera(camera: Camera) {
this.camera.position = camera.globalPosition;
this.camera.rotationQuaternion = camera.absoluteRotation;
this.camera.onViewMatrixChangedObservable.add(() => {
this.camera.getViewMatrix().copyFrom(camera.getViewMatrix())
})
this.camera.fov = camera.fov;
this.camera.minZ = camera.minZ;
this.camera.maxZ = camera.maxZ;
}

getTarget() {
return this.target;
}
Expand Down
28 changes: 28 additions & 0 deletions src/ts/utils/cameraSyncing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Camera } from "@babylonjs/core/Cameras/camera";
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";

/**
* From a given source camera, computes its position and rotation in world space and applies it to the target camera
* @param sourceCamera The camera to copy the position and rotation from
* @param targetCamera the camera to apply the position and rotation to
* @see https://forum.babylonjs.com/t/gui-linkwithmesh-not-behaving-properly-using-right-handed-system/48089/8
*/
export function syncCamera(sourceCamera: Camera, targetCamera: FreeCamera) {
targetCamera.position = sourceCamera.globalPosition;
targetCamera.rotationQuaternion = sourceCamera.absoluteRotation;

targetCamera.fov = sourceCamera.fov;
targetCamera.minZ = sourceCamera.minZ;
targetCamera.maxZ = sourceCamera.maxZ;

// this is necessary to ensure the view matrix is overwritten
const observer = targetCamera.onViewMatrixChangedObservable.addOnce(() => {
targetCamera.getViewMatrix().copyFrom(sourceCamera.getViewMatrix());
});

// if the camera stay stills, the view matrix is never updated, hence the number of observers keeps growing
// to avoid memory leaks, we remove the observer after the next render
targetCamera.getScene().onAfterRenderObservable.addOnce(() => {
targetCamera.onViewMatrixChangedObservable.remove(observer);
});
}

0 comments on commit 299e041

Please sign in to comment.