@@ -7,6 +7,7 @@ import WebSocketListener from './websocket'
77import { useAppContext } from '../../../app-context'
88import Game from '../../../playback/Game'
99import Match from '../../../playback/Match'
10+ import { RingBuffer } from '../../../util/ring-buffer'
1011
1112export type JavaInstall = {
1213 display : string
@@ -23,7 +24,7 @@ type Scaffold = [
2324 scaffoldLoading : boolean ,
2425 runMatch : ( javaPath : string , teamA : string , teamB : string , selectedMaps : Set < string > ) => Promise < void > ,
2526 killMatch : ( ( ) => Promise < void > ) | undefined ,
26- console : ConsoleLine [ ]
27+ console : RingBuffer < ConsoleLine >
2728]
2829
2930export function useScaffold ( ) : Scaffold {
@@ -35,12 +36,15 @@ export function useScaffold(): Scaffold {
3536 const [ scaffoldPath , setScaffoldPath ] = useState < string | undefined > ( undefined )
3637 const matchPID = useRef < string | undefined > ( undefined )
3738 const forceUpdate = useForceUpdate ( )
38- const [ consoleLines , setConsoleLines ] = useState < ConsoleLine [ ] > ( [ ] )
39- const log = ( line : ConsoleLine ) =>
40- setConsoleLines ( ( prev ) => ( prev . length > 10000 ? [ ...prev . slice ( 1 ) , line ] : [ ...prev , line ] ) )
39+ const consoleLines = useRef < RingBuffer < ConsoleLine > > ( new RingBuffer ( 10000 ) )
4140
4241 const [ webSocketListener , setWebSocketListener ] = useState < WebSocketListener | undefined > ( )
4342
43+ const log = ( line : ConsoleLine ) => {
44+ consoleLines . current . push ( line )
45+ forceUpdate ( )
46+ }
47+
4448 async function manuallySetupScaffold ( ) {
4549 if ( ! nativeAPI ) return
4650 setLoading ( true )
@@ -52,6 +56,7 @@ export function useScaffold(): Scaffold {
5256 async function runMatch ( javaPath : string , teamA : string , teamB : string , selectedMaps : Set < string > ) : Promise < void > {
5357 if ( matchPID . current || ! scaffoldPath ) return
5458 const shouldProfile = false
59+ consoleLines . current . clear ( )
5560 try {
5661 const newPID = await dispatchMatch (
5762 javaPath ,
@@ -63,10 +68,9 @@ export function useScaffold(): Scaffold {
6368 appContext . state . config . validateMaps ,
6469 shouldProfile
6570 )
66- setConsoleLines ( [ ] )
6771 matchPID . current = newPID
6872 } catch ( e : any ) {
69- setConsoleLines ( [ { content : e , type : 'error' } ] )
73+ consoleLines . current . push ( { content : e , type : 'error' } )
7074 }
7175 forceUpdate ( )
7276 }
@@ -193,7 +197,7 @@ export function useScaffold(): Scaffold {
193197 loading ,
194198 runMatch ,
195199 matchPID . current ? killMatch : undefined ,
196- consoleLines
200+ consoleLines . current
197201 ]
198202}
199203
0 commit comments