Skip to content

Commit

Permalink
fix: actions after prop deselect
Browse files Browse the repository at this point in the history
  • Loading branch information
7185 committed Dec 25, 2024
1 parent 6d8629b commit 240cdcd
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 388 deletions.
2 changes: 1 addition & 1 deletion action-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1",
"typescript-eslint": "^8.18.2",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
Expand Down
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"axios": "^1.7.9",
"cache-manager": "^5.7.6",
"class-validator": "^0.14.1",
"nestjs-pino": "^4.1.0",
"nestjs-pino": "^4.2.0",
"pino-http": "^10.3.0",
"pino-pretty": "^13.0.0",
"reflect-metadata": "^0.2.2",
Expand Down Expand Up @@ -65,7 +65,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1",
"typescript-eslint": "^8.18.2",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
Expand Down
2 changes: 1 addition & 1 deletion bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1"
"typescript-eslint": "^8.18.2"
}
}
28 changes: 14 additions & 14 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^19.0.0",
"@angular/cdk": "^19.0.0",
"@angular/common": "^19.0.0",
"@angular/compiler": "^19.0.0",
"@angular/core": "^19.0.0",
"@angular/forms": "^19.0.4",
"@angular/material": "^19.0.3",
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.4",
"@angular/router": "^19.0.4",
"@angular/animations": "^19.0.5",
"@angular/cdk": "^19.0.4",
"@angular/common": "^19.0.5",
"@angular/compiler": "^19.0.5",
"@angular/core": "^19.0.5",
"@angular/forms": "^19.0.5",
"@angular/material": "^19.0.4",
"@angular/platform-browser": "^19.0.5",
"@angular/platform-browser-dynamic": "^19.0.5",
"@angular/router": "^19.0.5",
"@fontsource/arimo": "^5.1.0",
"@fortawesome/angular-fontawesome": "^1.0.0",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
Expand All @@ -41,9 +41,9 @@
"tslib": "^2.8.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^19.0.1",
"@angular/cli": "^19.0.5",
"@angular/compiler-cli": "^19.0.0",
"@angular-devkit/build-angular": "^19.0.6",
"@angular/cli": "^19.0.6",
"@angular/compiler-cli": "^19.0.5",
"@eslint/js": "^9.10.0",
"@types/node": "^20.17.7",
"@types/three": "^0.171.0",
Expand All @@ -55,6 +55,6 @@
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": ">=5.5.0 <5.7.0",
"typescript-eslint": "^8.18.1"
"typescript-eslint": "^8.18.2"
}
}
30 changes: 16 additions & 14 deletions frontend/src/app/engine/build.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ export class BuildService {
if (this.propSelectionBox == null) {
return
}
this.propActionSvc
.parseActions(this.selectedProp)
.then(() => this.propActionSvc.showProp(this.selectedProp))
this.selectedProp.parent.userData.bvhUpdate.next()
this.buildMode = false
this.selectedProp = null
this.selectedPropSignal.set(null)
this.propSelectionBox.geometry.dispose()
;(this.propSelectionBox.material as Material).dispose()
this.axesHelper?.dispose()
buildNode.remove(this.propSelection)
this.propSelectionBox = null
this.axesHelper = null
this.propSelection = null
// Track the parent chunk in case of prop deletion since the code is async
const chunk = this.selectedProp.parent
this.propActionSvc.parseActions(this.selectedProp).then(() => {
this.propActionSvc.showProp(this.selectedProp)
chunk.userData.bvhUpdate.next()
this.buildMode = false
this.selectedProp = null
this.selectedPropSignal.set(null)
this.propSelectionBox.geometry.dispose()
;(this.propSelectionBox.material as Material).dispose()
this.axesHelper?.dispose()
buildNode.remove(this.propSelection)
this.propSelectionBox = null
this.axesHelper = null
this.propSelection = null
})
}

moveProp(action: PropCtl, cameraDirection: Vector3, buildNode: Group) {
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/app/engine/player-collider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Box3, Ray, Vector3} from 'three'
import type {Group, Mesh, Triangle} from 'three'
import {flattenGroup} from 'three-rwx-loader'
import {MeshBVH, MeshBVHHelper} from 'three-mesh-bvh'
import type {MeshBVHOptions} from 'three-mesh-bvh'
import {MeshBVHHelper} from 'three-mesh-bvh'
import type {MeshBVH, MeshBVHOptions} from 'three-mesh-bvh'
import {environment} from '../../environments/environment'

const playerHalfSide = environment.world.collider.boxSide / 2
Expand Down Expand Up @@ -70,7 +70,7 @@ export class PlayerCollider {
chunk.parent!.visible = true
return
}
chunk.parent!.userData.boundsTree = new MeshBVH(bvhMesh.geometry, {
chunk.parent!.userData.boundsTree = bvhMesh.geometry.computeBoundsTree({
onProgress: (progress: number) => {
chunk.parent!.visible = progress === 1
}
Expand All @@ -88,9 +88,7 @@ export class PlayerCollider {
return
}
// Force indirect (experimental) to avoid messed up faces
terrainMesh.geometry.boundsTree = new MeshBVH(terrainMesh.geometry, {
indirect: true
} as MeshBVHOptions)
terrainMesh.geometry.computeBoundsTree({indirect: true} as MeshBVHOptions)
if (!environment.debug) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/world/prop-action.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ export class PropActionService {
trigger: 'activate' | 'adone' | 'bump' | 'create'
) {
const action = prop.userData[trigger]
if (action == null) {
// A prop with no parent means it's being deleted
if (action == null || prop.parent == null) {
return
}
if (action.name != null) {
Expand Down
81 changes: 36 additions & 45 deletions frontend/src/app/world/terrain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ export class TerrainService {
})
}

private getPage(xPage: number, zPage: number) {
return this.terrain!.getObjectByName(`${xPage}_${zPage}`) as Mesh
}

private getPosAndIndex(page: Mesh) {
return [page.geometry.getAttribute('position'), page.geometry.getIndex()!]
}

/**
* Fix the height gaps between the pages
* Called only once per new page and calculate the BVH (or recalculate for neighbors)
Expand All @@ -326,32 +334,20 @@ export class TerrainService {
* @param zPage Z coordinate for page
*/
private fixPageGaps(page: Mesh, xPage: number, zPage: number) {
const northPage = this.terrain!.getObjectByName(
`${xPage}_${zPage + 1}`
) as Mesh
const westPage = this.terrain!.getObjectByName(
`${xPage + 1}_${zPage}`
) as Mesh
const southPage = this.terrain!.getObjectByName(
`${xPage}_${zPage - 1}`
) as Mesh
const eastPage = this.terrain!.getObjectByName(
`${xPage - 1}_${zPage}`
) as Mesh
const northWestPage = this.terrain!.getObjectByName(
`${xPage + 1}_${zPage + 1}`
) as Mesh
const southEastPage = this.terrain!.getObjectByName(
`${xPage - 1}_${zPage - 1}`
) as Mesh
const lastFaceIndex = TERRAIN_PAGE_SIZE * TERRAIN_PAGE_SIZE * 2 - 1
const pages = {
north: this.getPage(xPage, zPage + 1),
west: this.getPage(xPage + 1, zPage),
south: this.getPage(xPage, zPage - 1),
east: this.getPage(xPage - 1, zPage),
northWest: this.getPage(xPage + 1, zPage + 1),
southEast: this.getPage(xPage - 1, zPage - 1)
}

const positions = page.geometry.getAttribute('position')
const indices = page.geometry.getIndex()!
const lastFaceIndex = TERRAIN_PAGE_SIZE * TERRAIN_PAGE_SIZE * 2 - 1
const [positions, indices] = this.getPosAndIndex(page)

if (northPage) {
const northPositions = northPage.geometry.getAttribute('position')
const northIndices = northPage.geometry.getIndex()!
if (pages.north) {
const [northPositions, northIndices] = this.getPosAndIndex(pages.north)
// Get north page's south
const south = Array.from({length: TERRAIN_PAGE_SIZE}, (_, i) =>
northPositions.getY(northIndices.getX(i * 2 * 3))
Expand All @@ -369,9 +365,8 @@ export class TerrainService {
positions.needsUpdate = true
page.geometry.computeVertexNormals()
}
if (westPage) {
const westPositions = westPage.geometry.getAttribute('position')
const westIndices = westPage.geometry.getIndex()!
if (pages.west) {
const [westPositions, westIndices] = this.getPosAndIndex(pages.west)
// Get west page's east
const east = Array.from({length: TERRAIN_PAGE_SIZE}, (_, i) =>
westPositions.getY(westIndices.getX(i * TERRAIN_PAGE_SIZE * 2 * 3))
Expand All @@ -389,9 +384,8 @@ export class TerrainService {
positions.needsUpdate = true
page.geometry.computeVertexNormals()
}
if (southPage) {
const southPositions = southPage.geometry.getAttribute('position')
const southIndices = southPage.geometry.getIndex()!
if (pages.south) {
const [southPositions, southIndices] = this.getPosAndIndex(pages.south)
// Get current south
const south = Array.from({length: TERRAIN_PAGE_SIZE}, (_, i) =>
positions.getY(indices.getX(i * 2 * 3))
Expand All @@ -407,12 +401,11 @@ export class TerrainService {
southIndex++
}
southPositions.needsUpdate = true
southPage.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(southPage)
pages.south.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(pages.south)
}
if (eastPage) {
const eastPositions = eastPage.geometry.getAttribute('position')
const eastIndices = eastPage.geometry.getIndex()!
if (pages.east) {
const [eastPositions, eastIndices] = this.getPosAndIndex(pages.east)
// Get current east
const east = Array.from({length: TERRAIN_PAGE_SIZE}, (_, i) =>
positions.getY(indices.getX(i * TERRAIN_PAGE_SIZE * 2 * 3))
Expand All @@ -428,31 +421,29 @@ export class TerrainService {
eastIndex++
}
eastPositions.needsUpdate = true
eastPage.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(eastPage)
pages.east.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(pages.east)
}
if (northWestPage) {
if (pages.northWest) {
// We can fix current north-west corner
const nwPositions = northWestPage.geometry.getAttribute('position')
const nwIndices = northWestPage.geometry.getIndex()!
const [nwPositions, nwIndices] = this.getPosAndIndex(pages.northWest)
// Get north west page's south east corner (0 = first face)
const seCorner = nwPositions.getY(nwIndices.getX(0))
// Set corner
positions.setY(indices.getY(lastFaceIndex * 3), seCorner)
positions.needsUpdate = true
page.geometry.computeVertexNormals()
}
if (southEastPage) {
if (pages.southEast) {
// We can fix south-east page's north-west corner
const sePositions = southEastPage.geometry.getAttribute('position')
const seIndices = southEastPage.geometry.getIndex()!
const [sePositions, seIndices] = this.getPosAndIndex(pages.southEast)
// Get current south east corner (0 = first face)
const seCorner = positions.getY(indices.getX(0))
// Set corner
sePositions.setY(seIndices.getY(lastFaceIndex * 3), seCorner)
sePositions.needsUpdate = true
southEastPage.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(southEastPage)
pages.southEast.geometry.computeVertexNormals()
PlayerCollider.updateTerrainBVH(pages.southEast)
}
PlayerCollider.updateTerrainBVH(page)
}
Expand Down
Loading

0 comments on commit 240cdcd

Please sign in to comment.