-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix rendering of maps and add chunk config per map #49
Changes from 5 commits
88ac14d
ba49c73
7ff0832
d2d183e
c1317c5
6a30c94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { generateFrames } from "./utils"; | |
import { createInput } from "./createInput"; | ||
|
||
export async function createPhaserEngine<S extends ScenesConfig>(options: PhaserEngineConfig<S>) { | ||
const { scale, sceneConfig, cameraConfig, chunkSize } = options; | ||
const { scale, sceneConfig, cameraConfig, cullingChunkSize } = options; | ||
|
||
// Set up Phaser scenes | ||
const sceneConstructors = Object.keys(sceneConfig).map((key) => { | ||
|
@@ -60,11 +60,11 @@ export async function createPhaserEngine<S extends ScenesConfig>(options: Phaser | |
// Setup camera | ||
const camera = createCamera(phaserScene.cameras.main, cameraConfig); | ||
|
||
// Setup chunks | ||
const chunks = createChunks(camera.worldView$, chunkSize); | ||
// Setup chunks for viewport culling | ||
const cullingChunks = createChunks(camera.worldView$, cullingChunkSize); | ||
|
||
// Setup viewport culling | ||
const culling = createCulling(objectPool, camera, chunks); | ||
const culling = createCulling(objectPool, camera, cullingChunks); | ||
|
||
// Setup sprite animations | ||
for (const anim of config.animations) { | ||
|
@@ -87,7 +87,12 @@ export async function createPhaserEngine<S extends ScenesConfig>(options: Phaser | |
// Setup maps | ||
const partialMaps: Partial<Maps<keyof S[typeof key]["maps"]>> = {}; | ||
for (const mapKey of Object.keys(config.maps)) { | ||
const { layers, backgroundTile, tileWidth, tileHeight, animationInterval, tileAnimations } = config.maps[mapKey]; | ||
const { layers, backgroundTile, tileWidth, tileHeight, animationInterval, tileAnimations, chunkSize } = | ||
config.maps[mapKey]; | ||
|
||
// Setup chunks | ||
const chunks = createChunks(camera.worldView$, chunkSize); | ||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chunk sizes can now be configured per map instead of global (before chunk sizes for the lowest LOD map was 2x2 tiles, way too small and way to high chunking overhead) |
||
|
||
const map = createAnimatedTilemap({ | ||
scene: phaserScene, | ||
tilesets, | ||
|
@@ -112,7 +117,7 @@ export async function createPhaserEngine<S extends ScenesConfig>(options: Phaser | |
|
||
const input = createInput(phaserScene.input); | ||
|
||
partialScenes[key] = { phaserScene, objectPool, camera, chunks, culling, maps, input }; | ||
partialScenes[key] = { phaserScene, objectPool, camera, culling, maps, input }; | ||
} | ||
const scenes = partialScenes as Scenes<S>; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends | |
params: ChunkedTilemapConfig<TileKeys, LayerKeys> | ||
): ChunkedTilemap<TileKeys, LayerKeys> { | ||
const { scene, tilesets, layerConfig, chunks, backgroundTile, tiles, tileWidth, tileHeight } = params; | ||
const relevantTilesets = Object.keys(layerConfig.layers) | ||
.map((key) => layerConfig.layers[key as LayerKeys].tilesets) | ||
.flat(); | ||
|
||
// Chunk pixel size must be a multiple of tile witdth and height. | ||
if (mod(chunks.chunkSize, tileWidth) !== 0 || mod(chunks.chunkSize, tileHeight) !== 0) { | ||
|
@@ -98,7 +101,9 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends | |
tileWidth, | ||
width: chunkTileSize.x, | ||
height: chunkTileSize.y, | ||
tilesets: Object.values(tilesets), | ||
tilesets: Object.entries(tilesets) | ||
.filter(([key]) => relevantTilesets.includes(key)) | ||
.map(([, tileset]) => tileset), | ||
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were including all tilesets on every map, now we only include the ones relevant for this map (currently we only have one tileset, but we might have different ones for different LOD maps in the future) |
||
}); | ||
|
||
const map = new Phaser.Tilemaps.Tilemap(scene, data); | ||
|
@@ -128,6 +133,8 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends | |
if (!visible.current) return; | ||
const map = getMapAtTileCoord(coord); | ||
const putTile = map.putTileAt(tile, mod(coord.x, chunkTileSize.x), mod(coord.y, chunkTileSize.y), undefined, layer); | ||
putTile.width = map.tileWidth; | ||
putTile.height = map.tileHeight; | ||
Comment on lines
+136
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Phaser is automatically setting the tile width/hight to the tileset tileWith/tileHeight when setting a single tile: https://github.com/photonstorm/phaser/blob/1591ebdb777a9be5c706fc18f86a6107fb66717f/src/tilemaps/components/PutTileAt.js#L78-L79 Out tileset has a tile size of 16x16px, but we explicitly want to render it at a larger size for our Tactic/Strategic map with lower level of detail / larger tile sizes. So we have to manually reset the tile size to the map tile size here. |
||
|
||
if (tint) { | ||
putTile.tint = tint; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,10 @@ async function bootLayers() { | |
const privateKey = params.get("burnerWalletPrivateKey"); | ||
const chainIdString = params.get("chainId"); | ||
const personaIdString = params.get("personaId"); | ||
const jsonRpc = params.get("rpc") ?? undefined; | ||
const wsRpc = jsonRpc && jsonRpc.replace("http", "ws"); | ||
const checkpointUrl = params.get("checkpoint") ?? undefined; | ||
const devMode = params.get("dev") === "true" ?? false; | ||
const jsonRpc = params.get("rpc") || undefined; | ||
const wsRpc = params.get("wsRpc") || (jsonRpc && jsonRpc.replace("http", "ws")); | ||
const checkpointUrl = params.get("checkpoint") || undefined; | ||
const devMode = params.get("dev") === "true" || false; | ||
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible to configure rpc/wsRpc now via get params as well |
||
|
||
let networkLayerConfig; | ||
if (contractAddress && privateKey && chainIdString && personaIdString) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We extend the viewport for chunking by 100px on each side to "prerender" beyond the actual viewport and avoid panning into unrendered areas