Skip to content

Commit

Permalink
Refactor to use range (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSpicyBurrito authored Dec 1, 2024
1 parent a0bd59f commit 9bf8102
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 107 deletions.
16 changes: 7 additions & 9 deletions play/src/engine/playData/archetypes/SimLine.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ export class SimLine extends Archetype {

targetTime = this.entityMemory(Number)

visualTime = this.entityMemory({
min: Number,
max: Number,
hidden: Number,
})
visualTime = this.entityMemory(Range)
hiddenTime = this.entityMemory(Number)

spawnTime = this.entityMemory(Number)

Expand All @@ -31,8 +28,9 @@ export class SimLine extends Archetype {

this.targetTime = bpmChanges.at(this.aImport.beat).time

this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - note.duration
this.visualTime.copyFrom(
Range.l.mul(note.duration).add(timeScaleChanges.at(this.targetTime).scaledTime),
)

this.spawnTime = this.visualTime.min
}
Expand All @@ -51,7 +49,7 @@ export class SimLine extends Archetype {

initialize() {
if (options.hidden > 0)
this.visualTime.hidden = this.visualTime.max - note.duration * options.hidden
this.hiddenTime = this.visualTime.max - note.duration * options.hidden

let l = this.aImport.lane
let r = this.bImport.lane
Expand All @@ -74,7 +72,7 @@ export class SimLine extends Archetype {
this.despawn = true
if (this.despawn) return

if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

this.render()
}
Expand Down
37 changes: 12 additions & 25 deletions play/src/engine/playData/archetypes/notes/flatNotes/FlatNote.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { approach } from '../../../../../../../shared/src/engine/data/note.mjs'
import { perspectiveLayout } from '../../../../../../../shared/src/engine/data/utils.mjs'
import { toBucketWindows, Windows } from '../../../../../../../shared/src/engine/data/windows.mjs'
import { options } from '../../../../configuration/options.mjs'
import { sfxDistance } from '../../../effect.mjs'
import { getHitbox, lane } from '../../../lane.mjs'
Expand Down Expand Up @@ -35,20 +36,14 @@ export abstract class FlatNote extends Note {
abstract slotEffect: SlotEffect
abstract slotGlowEffect: SlotGlowEffect

abstract windows: JudgmentWindows
abstract windows: Windows

abstract bucket: Bucket

visualTime = this.entityMemory({
min: Number,
max: Number,
hidden: Number,
})
visualTime = this.entityMemory(Range)
hiddenTime = this.entityMemory(Number)

inputTime = this.entityMemory({
min: Number,
max: Number,
})
inputTime = this.entityMemory(Range)

spriteLayouts = this.entityMemory({
left: Quad,
Expand All @@ -60,27 +55,19 @@ export abstract class FlatNote extends Note {
y = this.entityMemory(Number)

globalPreprocess() {
const toMs = ({ min, max }: RangeLike) => ({
min: Math.round(min * 1000),
max: Math.round(max * 1000),
})

this.bucket.set({
perfect: toMs(this.windows.perfect),
great: toMs(this.windows.great),
good: toMs(this.windows.good),
})
this.bucket.set(toBucketWindows(this.windows))

this.life.miss = -80
}

preprocess() {
super.preprocess()

this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - note.duration
this.visualTime.copyFrom(
Range.l.mul(note.duration).add(timeScaleChanges.at(this.targetTime).scaledTime),
)

this.inputTime.min = this.targetTime + this.windows.good.min + input.offset
this.inputTime.copyFrom(this.windows.good.add(this.targetTime).add(input.offset))

this.spawnTime = Math.min(
this.visualTime.min,
Expand All @@ -92,7 +79,7 @@ export abstract class FlatNote extends Note {

initialize() {
if (options.hidden > 0)
this.visualTime.hidden = this.visualTime.max - note.duration * options.hidden
this.hiddenTime = this.visualTime.max - note.duration * options.hidden

this.inputTime.max = this.targetTime + this.windows.good.max + input.offset

Expand Down Expand Up @@ -126,7 +113,7 @@ export abstract class FlatNote extends Note {
if (this.despawn) return

if (time.scaled < this.visualTime.min) return
if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

this.render()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ export abstract class VisibleSlideTickNote extends SlideTickNote {

abstract effect: ParticleEffect

visualTime = this.entityMemory({
min: Number,
max: Number,
hidden: Number,
})
visualTime = this.entityMemory(Range)
hiddenTime = this.entityMemory(Number)

spriteLayout = this.entityMemory(Quad)
z = this.entityMemory(Number)
Expand All @@ -35,8 +32,9 @@ export abstract class VisibleSlideTickNote extends SlideTickNote {
preprocess() {
super.preprocess()

this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - note.duration
this.visualTime.copyFrom(
Range.l.mul(note.duration).add(timeScaleChanges.at(this.targetTime).scaledTime),
)

this.spawnTime = Math.min(
this.visualTime.min,
Expand All @@ -50,7 +48,7 @@ export abstract class VisibleSlideTickNote extends SlideTickNote {
super.initialize()

if (options.hidden > 0)
this.visualTime.hidden = this.visualTime.max - note.duration * options.hidden
this.hiddenTime = this.visualTime.max - note.duration * options.hidden

const b = 1 + note.h
const t = 1 - note.h
Expand Down Expand Up @@ -81,7 +79,7 @@ export abstract class VisibleSlideTickNote extends SlideTickNote {
if (this.despawn) return

if (time.scaled < this.visualTime.min) return
if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

this.render()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export abstract class SlideConnector extends Archetype {

visualTime = this.entityMemory({
min: Number,
hidden: Number,
})
hiddenTime = this.entityMemory(Number)

spawnTime = this.entityMemory(Number)

Expand Down Expand Up @@ -113,7 +113,7 @@ export abstract class SlideConnector extends Archetype {
this.tail.r = this.tail.lane + this.tailImport.size

if (options.hidden > 0)
this.visualTime.hidden = this.tail.scaledTime - note.duration * options.hidden
this.hiddenTime = this.tail.scaledTime - note.duration * options.hidden

this.z = getZ(layer.note.connector, this.start.time, this.startImport.lane)

Expand Down Expand Up @@ -223,7 +223,7 @@ export abstract class SlideConnector extends Archetype {
}

renderConnector() {
if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

const hiddenDuration = options.hidden > 0 ? note.duration * options.hidden : 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ export abstract class SlotGlowEffect extends SpawnableArchetype({
endTime = this.entityMemory(Number)

layout = this.entityMemory({
l: {
min: Number,
max: Number,
},
r: {
min: Number,
max: Number,
},
l: Range,
r: Range,
h: Number,
})
z = this.entityMemory(Number)
Expand Down
18 changes: 16 additions & 2 deletions shared/src/engine/data/windows.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
export type Windows = {
perfect: Range
great: Range
good: Range
}

const toMs = ({ min, max }: Range) => new Range(Math.round(min * 1000), Math.round(max * 1000))

export const toBucketWindows = (windows: Windows) => ({
perfect: toMs(windows.perfect),
great: toMs(windows.great),
good: toMs(windows.good),
})

type Frames = number | [min: number, max: number]

const fromFrames = (perfect: Frames, great: Frames, good: Frames) => {
const toWindow = (frames: Frames) =>
typeof frames === 'number'
? { min: -frames / 60, max: frames / 60 }
: { min: -frames[0] / 60, max: frames[1] / 60 }
? Range.one.mul(frames).div(60)
: new Range(-frames[0], frames[1]).div(60)

return {
perfect: toWindow(perfect),
Expand Down
16 changes: 7 additions & 9 deletions watch/src/engine/watchData/archetypes/SimLine.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ export class SimLine extends Archetype {

targetTime = this.entityMemory(Number)

visualTime = this.entityMemory({
min: Number,
max: Number,
hidden: Number,
})
visualTime = this.entityMemory(Range)
hiddenTime = this.entityMemory(Number)

initialized = this.entityMemory(Boolean)

Expand All @@ -29,8 +26,9 @@ export class SimLine extends Archetype {

this.targetTime = bpmChanges.at(this.aImport.beat).time

this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - note.duration
this.visualTime.copyFrom(
Range.l.mul(note.duration).add(timeScaleChanges.at(this.targetTime).scaledTime),
)
}

spawnTime() {
Expand All @@ -55,7 +53,7 @@ export class SimLine extends Archetype {
}

updateParallel() {
if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

this.render()
}
Expand All @@ -78,7 +76,7 @@ export class SimLine extends Archetype {

globalInitialize() {
if (options.hidden > 0)
this.visualTime.hidden = this.visualTime.max - note.duration * options.hidden
this.hiddenTime = this.visualTime.max - note.duration * options.hidden

let l = this.aImport.lane
let r = this.bImport.lane
Expand Down
30 changes: 10 additions & 20 deletions watch/src/engine/watchData/archetypes/notes/flatNotes/FlatNote.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { lane } from '../../../../../../../shared/src/engine/data/lane.mjs'
import { approach } from '../../../../../../../shared/src/engine/data/note.mjs'
import { perspectiveLayout } from '../../../../../../../shared/src/engine/data/utils.mjs'
import { toBucketWindows, Windows } from '../../../../../../../shared/src/engine/data/windows.mjs'
import { options } from '../../../../configuration/options.mjs'
import { sfxDistance } from '../../../effect.mjs'
import { note } from '../../../note.mjs'
Expand Down Expand Up @@ -35,19 +36,16 @@ export abstract class FlatNote extends Note {
abstract slotEffect: SlotEffect
abstract slotGlowEffect: SlotGlowEffect

abstract windows: JudgmentWindows
abstract windows: Windows

abstract bucket: Bucket

sharedMemory = this.defineSharedMemory({
despawnTime: Number,
})

visualTime = this.entityMemory({
min: Number,
max: Number,
hidden: Number,
})
visualTime = this.entityMemory(Range)
hiddenTime = this.entityMemory(Number)

initialized = this.entityMemory(Boolean)

Expand All @@ -61,25 +59,17 @@ export abstract class FlatNote extends Note {
y = this.entityMemory(Number)

globalPreprocess() {
const toMs = ({ min, max }: RangeLike) => ({
min: Math.round(min * 1000),
max: Math.round(max * 1000),
})

this.bucket.set({
perfect: toMs(this.windows.perfect),
great: toMs(this.windows.great),
good: toMs(this.windows.good),
})
this.bucket.set(toBucketWindows(this.windows))

this.life.miss = -80
}

preprocess() {
super.preprocess()

this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - note.duration
this.visualTime.copyFrom(
Range.l.mul(note.duration).add(timeScaleChanges.at(this.targetTime).scaledTime),
)

this.sharedMemory.despawnTime = timeScaleChanges.at(this.hitTime).scaledTime

Expand Down Expand Up @@ -119,7 +109,7 @@ export abstract class FlatNote extends Note {
}

updateParallel() {
if (options.hidden > 0 && time.scaled > this.visualTime.hidden) return
if (options.hidden > 0 && time.scaled > this.hiddenTime) return

this.render()
}
Expand Down Expand Up @@ -162,7 +152,7 @@ export abstract class FlatNote extends Note {

globalInitialize() {
if (options.hidden > 0)
this.visualTime.hidden = this.visualTime.max - note.duration * options.hidden
this.hiddenTime = this.visualTime.max - note.duration * options.hidden

const l = this.import.lane - this.import.size
const r = this.import.lane + this.import.size
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FlatNote } from '../FlatNote.mjs'

export abstract class SlideStartNote extends FlatNote {
abstract windows: JudgmentWindows

render() {
if (time.scaled > this.visualTime.max) return

Expand Down
Loading

0 comments on commit 9bf8102

Please sign in to comment.