Skip to content

Commit

Permalink
perf: avoid useless Vector3 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
7185 committed Jan 2, 2025
1 parent 7f1f633 commit 0982977
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 370 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lemuria.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
working-directory: .
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -33,7 +33,7 @@ jobs:
working-directory: .
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -53,7 +53,7 @@ jobs:
working-directory: .
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -73,7 +73,7 @@ jobs:
working-directory: .
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
4 changes: 2 additions & 2 deletions action-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
},
"devDependencies": {
"@eslint/js": "^9.10.0",
"@swc/core": "^1.10.3",
"@swc/core": "^1.10.4",
"@vitest/coverage-v8": "^2.1.8",
"eslint": "^9.17.0",
"globals": "^15.14.0",
"jiti": "^2.4.2",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.2",
"typescript-eslint": "^8.19.0",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
Expand Down
24 changes: 12 additions & 12 deletions action-parser/src/action.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ export const visitCoords = (

if (/a$/i.test(coordC)) {
res.coordinates.altitude = parseFloat(coordC.slice(0, -1))

if (coordD == null) {
// No more values
return
}
// Fourth value can only be direction at this point
if (coordD != null) {
res.coordinates.direction = parseFloat(coordD)
res.coordinates.direction = parseFloat(coordD)

// But invalid if types are not the same
if (
(/^[+-]/.test(coordD) && res.coordinates.type === 'absolute') ||
(!/^[+-]/.test(coordD) && res.coordinates.type === 'relative')
) {
delete res.commandType
delete res.coordinates
}
// But invalid if types are not the same
if (
(/^[+-]/.test(coordD) && res.coordinates.type === 'absolute') ||
(!/^[+-]/.test(coordD) && res.coordinates.type === 'relative')
) {
delete res.commandType
delete res.coordinates
}

return
}
// No altitude, so third value is direction
Expand Down
41 changes: 14 additions & 27 deletions action-parser/src/action.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ class ActionVisitor extends BaseActionVisitor {
animateCommand(ctx: AnimateCommandCtx) {
const res = {
commandType: 'animate',
mask: false // default
}
if (ctx.Mask != null) {
res.mask = true
mask: ctx.Mask != null
}
if (ctx.tagParameter) {
Object.assign(res, this.visit(ctx.tagParameter))
Expand Down Expand Up @@ -134,7 +131,7 @@ class ActionVisitor extends BaseActionVisitor {
targetName: (ctx.nameParameter[0].children.Resource[0] as IToken).image
})
}
return res.color == null ? null : res
return res.color != null ? res : null
}

coronaCommand(ctx: CoronaCommandCtx) {
Expand Down Expand Up @@ -256,23 +253,17 @@ class ActionVisitor extends BaseActionVisitor {
}
const args = ctx.signArgs?.map((arg) => this.visit(arg))[0]
const resource = ctx.Resource?.map((identToken) => identToken.image)
if (resource != null) {
let text = ''
if (resource.length > 1) {
if (!resource[0].startsWith('"')) {
// invalid sign
return {}
}
text = resource.join(' ')
} else {
text = resource[0]
}
text = text.replace(/(^"|"$)/g, '')
Object.assign(res, {text})
}
if (args) {
Object.assign(res, ...args)
}
if (resource == null) {
return res
}
if (resource.length > 1 && !resource[0].startsWith('"')) {
// invalid sign
return {}
}
Object.assign(res, {text: resource.join(' ').replace(/(^"|"$)/g, '')})
return res
}

Expand Down Expand Up @@ -663,20 +654,16 @@ export class Action {
parserInstance.input = lexResult.tokens

const cst = parserInstance.actions()
if (parserInstance.errors.length > 0) {
return {}
}
return this.visitor.visit(cst)
return parserInstance.errors.length > 0 ? {} : this.visitor.visit(cst)
}

debug(inputText: string) {
const lexResult = this.lexer.tokenize(inputText)
parserInstance.input = lexResult.tokens

parserInstance.actions()
if (parserInstance.errors.length > 0) {
return parserInstance.errors[0].message
}
return 'OK'
return parserInstance.errors.length > 0
? parserInstance.errors[0].message
: 'OK'
}
}
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.15",
"@swc/cli": "^0.5.2",
"@swc/core": "^1.10.3",
"@swc/core": "^1.10.4",
"@types/node": "^20.17.7",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13",
Expand All @@ -65,7 +65,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.2",
"typescript-eslint": "^8.19.0",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
Expand Down
16 changes: 8 additions & 8 deletions backend/src/world/world.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export class WorldService {

async getWorld(id: number) {
const world = await this.db.world.findFirst({where: {id}})
if (world != null) {
const attr = JSON.parse(world.data ?? '{}')
return new World({
id: world.id,
name: world.name,
...attr
})
if (world == null) {
return new World()
}
return new World()
const attr = JSON.parse(world.data ?? '{}')
return new World({
id: world.id,
name: world.name,
...attr
})
}

async getProps(
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.2"
"typescript-eslint": "^8.19.0"
}
}
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@angular/platform-browser": "^19.0.5",
"@angular/platform-browser-dynamic": "^19.0.5",
"@angular/router": "^19.0.5",
"@fontsource/arimo": "^5.1.0",
"@fontsource/arimo": "^5.1.1",
"@fortawesome/angular-fontawesome": "^1.0.0",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"@iharbeck/ngx-virtual-scroller": "^19.0.1",
Expand All @@ -35,7 +35,7 @@
"linkify-string": "^4.2.0",
"linkifyjs": "^4.2.0",
"rxjs": "~7.8.1",
"three": "^0.171.0",
"three": "^0.172.0",
"three-mesh-bvh": "^0.8.3",
"three-rwx-loader": "^0.12.4",
"tslib": "^2.8.1"
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.2"
"typescript-eslint": "^8.19.0"
}
}
17 changes: 6 additions & 11 deletions frontend/src/app/animation/prop-animation.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Injectable} from '@angular/core'
import type {Group} from 'three'
import {Vector3} from 'three'
import {RPM, X_AXIS, Y_AXIS, Z_AXIS} from '../utils/constants'

@Injectable({providedIn: 'root'})
Expand Down Expand Up @@ -30,11 +29,9 @@ export class PropAnimationService {
moveData.completion = 0
if (moveData.reset) {
// Reset the position to the original position
prop.position.copy(
new Vector3()
.add(prop.userData.posOrig)
.sub(prop.parent.parent.position)
)
prop.position
.copy(prop.userData.posOrig)
.sub(prop.parent.parent.position)
}

if (moveData.direction < 0) {
Expand All @@ -44,11 +41,9 @@ export class PropAnimationService {
return
}
// Move is complete for this loop so we can force the initial position back to avoid drifting issues
prop.position.copy(
new Vector3()
.add(prop.userData.posOrig)
.sub(prop.parent.parent.position)
)
prop.position
.copy(prop.userData.posOrig)
.sub(prop.parent.parent.position)
}
// Switch direction
moveData.direction *= -1
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/engine/audio.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Injectable} from '@angular/core'
import type {PerspectiveCamera} from 'three'
import {Audio, AudioListener} from 'three'

@Injectable({
Expand All @@ -10,7 +11,7 @@ export class AudioService {
private audio = new Audio(this.audioListener)
bgUrl = ''

addListener(camera) {
addListener(camera: PerspectiveCamera) {
camera.add(this.audioListener)
}

Expand Down
Loading

0 comments on commit 0982977

Please sign in to comment.