-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: evaluate map async with worker
- Loading branch information
Showing
4 changed files
with
99 additions
and
14 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
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 |
---|---|---|
|
@@ -155,5 +155,8 @@ export default defineConfig({ | |
resolve: { | ||
alias: [resolver], | ||
}, | ||
server: { | ||
hmr: false, | ||
}, | ||
}, | ||
}); |
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,34 @@ | ||
import { ActionResponse } from '@deities/apollo/ActionResponse.tsx'; | ||
import executeGameAction from '@deities/apollo/actions/executeGameAction.tsx'; | ||
import { | ||
decodeEffects, | ||
Effects, | ||
encodeEffects, | ||
} from '@deities/apollo/Effects.tsx'; | ||
import { encodeActionResponse } from '@deities/apollo/EncodedActions.tsx'; | ||
import { encodeGameState, GameState } from '@deities/apollo/Types.tsx'; | ||
import MapData from '@deities/athena/MapData.tsx'; | ||
import AIRegistry from '@deities/dionysus/AIRegistry.tsx'; | ||
|
||
onmessage = function (event) { | ||
const [plainMap, encodedEffects, action, mutateAction] = event.data; | ||
|
||
const map = MapData.fromObject(plainMap); | ||
const currentViewer = map.getCurrentPlayer(); | ||
const vision = map.createVisionObject(currentViewer); | ||
const effects = decodeEffects(encodedEffects); | ||
|
||
const [actionResponse, initialActiveMap, gameState, newEffects]: [ | ||
ActionResponse | null, | ||
MapData | null, | ||
GameState | null, | ||
Effects | null, | ||
] = executeGameAction(map, vision, effects, action, AIRegistry, mutateAction); | ||
|
||
postMessage([ | ||
actionResponse ? encodeActionResponse(actionResponse) : null, | ||
initialActiveMap ? initialActiveMap?.toJSON() : null, | ||
gameState ? encodeGameState(gameState) : null, | ||
newEffects ? encodeEffects(newEffects) : null, | ||
]); | ||
}; |
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