-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only store beatmap in serialized state in multiplayer server
- Loading branch information
Marvin Schürz
committed
Jan 22, 2025
1 parent
3d1e47c
commit e8bbc22
Showing
8 changed files
with
142 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { ISummary, MutationContext } from '@osucad/multiplayer'; | ||
import type { Beatmap } from '../../beatmap/Beatmap'; | ||
import { SharedStructure } from '@osucad/multiplayer'; | ||
import { RulesetStore } from '../../rulesets/RulesetStore'; | ||
|
||
export interface BoxedBeatmapSummary extends ISummary { | ||
ruleset: string; | ||
beatmap: any; | ||
} | ||
|
||
export class BoxedBeatmap extends SharedStructure<never, BoxedBeatmapSummary> { | ||
constructor( | ||
public beatmap?: Beatmap<any>, | ||
) { | ||
super(); | ||
} | ||
|
||
override handle(mutation: never, ctx: MutationContext): void | null { | ||
} | ||
|
||
get rulesetId() { | ||
return this.beatmap!.beatmapInfo.ruleset.shortName; | ||
} | ||
|
||
override createSummary(): BoxedBeatmapSummary { | ||
return { | ||
id: this.id, | ||
ruleset: this.rulesetId, | ||
beatmap: this.beatmap!.createSummary(), | ||
}; | ||
} | ||
|
||
override initializeFromSummary(summary: BoxedBeatmapSummary): void { | ||
const rulesetInfo = RulesetStore.getByShortName(summary.ruleset); | ||
if (!rulesetInfo || !rulesetInfo.available) | ||
throw new Error(`Ruleset "${summary.ruleset}" is not supported`); | ||
|
||
const ruleset = rulesetInfo.createInstance(); | ||
const beatmap = this.beatmap = ruleset.createBeatmap(); | ||
|
||
beatmap.beatmapInfo.ruleset = rulesetInfo; | ||
beatmap.initializeFromSummary(summary.beatmap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './BoxedBeatmap'; | ||
export * from './MultiplayerClient'; | ||
export * from './MultiplayerEditor'; | ||
export * from './MultiplayerEditorBeatmap'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { MutationsSubmittedMessage, SubmitMutationsMessage } from '@osucad/multiplayer'; | ||
|
||
export class OrderingService { | ||
constructor(initialSummary: any) { | ||
this.#latestSummary = { | ||
clientId: -1, | ||
sequenceNumber: 0, | ||
summary: initialSummary, | ||
}; | ||
} | ||
|
||
#latestSummary: { | ||
clientId: number; | ||
sequenceNumber: number; | ||
summary: any; | ||
}; | ||
|
||
#ops: MutationsSubmittedMessage[] = []; | ||
|
||
#sequenceNumber = 0; | ||
|
||
get sequenceNumber() { | ||
return this.#sequenceNumber; | ||
} | ||
|
||
appendOps(clientId: number, message: SubmitMutationsMessage) { | ||
const sequencedMessage: MutationsSubmittedMessage = { | ||
mutations: message.mutations, | ||
clientId, | ||
version: message.version, | ||
sequenceNumber: ++this.#sequenceNumber, | ||
}; | ||
|
||
this.#ops.push(sequencedMessage); | ||
|
||
return sequencedMessage; | ||
} | ||
|
||
appendSummary(clientId: number, summary: any) { | ||
return this.#latestSummary = { | ||
clientId, | ||
summary, | ||
sequenceNumber: ++this.#sequenceNumber, | ||
}; | ||
} | ||
|
||
getMessagesSinceLastSummary() { | ||
return { summary: this.#latestSummary, ops: [...this.#ops] }; | ||
} | ||
|
||
get opCount() { | ||
return this.#ops.length; | ||
} | ||
} |