Skip to content
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

Isolated world patch & cache #142

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,072 changes: 1,030 additions & 1,042 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"publish:mainnet": "git tag mainnet-$(node -p -e \"require('./package.json').version\") && git push origin mainnet-$(node -p -e \"require('./package.json').version\")"
},
"dependencies": {
"@aresrpg/aresrpg-engine": "2.3.1",
"@aresrpg/aresrpg-protocol": "4.1.3",
"@aresrpg/aresrpg-engine": "^2.4.0",
"@aresrpg/aresrpg-protocol": "5.0.1",
"@aresrpg/aresrpg-sdk": "4.1.7",
"@aresrpg/aresrpg-world": "1.3.9",
"@bufbuild/buf": "1.35.0",
"@bufbuild/protobuf": "1.10.0",
"@bufbuild/protoc-gen-es": "1.10.0",
"@imengyu/vue3-context-menu": "1.4.1",
"@aresrpg/aresrpg-world": "1.4.1",
"@bufbuild/buf": "1.35.1",
"@bufbuild/protobuf": "2.0.0",
"@bufbuild/protoc-gen-es": "2.0.0",
"@imengyu/vue3-context-menu": "1.4.2",
"@intlify/unplugin-vue-i18n": "4.0.0",
"@mysten/enoki": "0.3.11",
"@mysten/kiosk": "0.9.11",
"@mysten/sui": "1.3.0",
"@mysten/wallet-standard": "0.12.12",
"@mysten/zksend": "0.10.1",
"@mysten/enoki": "0.3.13",
"@mysten/kiosk": "0.9.13",
"@mysten/sui": "1.4.0",
"@mysten/wallet-standard": "0.12.14",
"@mysten/zksend": "0.10.3",
"@vercel/analytics": "1.3.1",
"@vueuse/core": "10.11.0",
"bignumber.js": "9.1.2",
Expand All @@ -41,13 +41,13 @@
"meshoptimizer": "0.21.0",
"ndarray": "1.0.19",
"stats.js": "0.17.0",
"three": "0.166.1",
"three": "0.167.1",
"troika-three-text": "0.49.1",
"v-dropdown": "3.0.0",
"vue": "3.4.33",
"vue": "3.4.35",
"vue-i18n": "9.13.1",
"vue-next-breakpoints": "1.0.1",
"vue-router": "4.4.0",
"vue-router": "4.4.2",
"vuesax-alpha": "0.2.0-beta.78"
},
"devDependencies": {
Expand All @@ -58,7 +58,7 @@
"@iconify-json/eos-icons": "^1.1.10",
"@iconify-json/ep": "^1.1.15",
"@iconify-json/flat-color-icons": "^1.1.10",
"@iconify-json/fluent": "^1.1.59",
"@iconify-json/fluent": "^1.1.60",
"@iconify-json/fluent-emoji": "^1.1.18",
"@iconify-json/fluent-emoji-high-contrast": "^1.1.15",
"@iconify-json/fxemoji": "^1.1.8",
Expand All @@ -67,22 +67,22 @@
"@iconify-json/map": "^1.1.9",
"@iconify-json/material-symbols-light": "^1.1.25",
"@iconify-json/mdi": "^1.1.67",
"@iconify-json/noto": "^1.1.18",
"@iconify-json/noto": "^1.1.19",
"@iconify-json/oui": "^1.1.2",
"@iconify-json/ph": "^1.1.13",
"@iconify-json/radix-icons": "^1.1.14",
"@iconify-json/streamline-emojis": "^1.1.8",
"@iconify-json/token": "^1.1.6",
"@iconify-json/token-branded": "^1.1.7",
"@iconify-json/token": "^1.1.7",
"@iconify-json/token-branded": "^1.1.8",
"@iconify-json/twemoji": "^1.1.15",
"@modyfi/vite-plugin-yaml": "^1.1.0",
"@types/dat.gui": "^0.7.13",
"@types/node": "^20.14.11",
"@types/three": "^0.166.0",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@vitejs/plugin-vue": "^5.0.5",
"@vue/language-plugin-pug": "^2.0.28",
"@types/node": "^22.1.0",
"@types/three": "^0.167.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@vitejs/plugin-vue": "^5.1.2",
"@vue/language-plugin-pug": "^2.0.29",
"eslint": "^8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-standard": "17.1.0",
Expand All @@ -94,13 +94,13 @@
"prettier": "3.3.3",
"pug": "^3.0.3",
"stylus": "^0.63.0",
"unplugin-icons": "^0.19.0",
"vite": "^5.3.4",
"unplugin-icons": "^0.19.1",
"vite": "^5.3.5",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-pwa": "^0.20.0",
"vite-plugin-pwa": "^0.20.1",
"vite-plugin-wasm": "^3.3.0",
"vue-eslint-parser": "^9.4.3",
"vue-tsc": "^2.0.28"
"vue-tsc": "^2.0.29"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/game/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function spawn_entity(clone_model, { skin, height, radius, scale = 1 }) {

export const ENTITIES = {
/** @return {Type.ThreeEntity} */
from_character({ name, id, classe, sex, skin }) {
from_character({ name, id, classe, sex, skin = null }) {
const type = ENTITIES[skin || `${classe}_${sex}`]

if (type) return type({ name, id })
Expand Down
4 changes: 3 additions & 1 deletion src/core/game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ function connect_ws() {
const { status } = useWebSocket(
`${server_url}?address=${selected_address}`,
{
autoReconnect: true,
autoReconnect: {
retries: () => !!context.get_state().sui.selected_address,
},
async onDisconnected(ws, event) {
decrease_loading()
await handle_server_error(event.reason)
Expand Down
58 changes: 35 additions & 23 deletions src/core/modules/game_entites_stroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { Vector3 } from 'three'

import { abortable } from '../utils/iterator.js'
import { context, current_three_character } from '../game/game.js'
import { get_terrain_height } from '../utils/terrain/chunk_utils.js'
import {
get_optional_terrain_height,
get_terrain_height,
} from '../utils/terrain/chunk_utils.js'

const MOVE_INTERVAL = 5000 // 5 seconds in milliseconds
const MOVE_PROBABILITY = 0.1 // 10% chance to move
Expand Down Expand Up @@ -35,7 +38,12 @@ export default function () {
const movement = direction.multiplyScalar(MOB_SPEED * delta)

const new_position = mob.position.clone().add(movement)
const ground_height = get_terrain_height(new_position, mob.height)
const ground_height = get_optional_terrain_height(
new_position,
mob.height,
)

if (ground_height == null) continue

new_position.setY(ground_height)

Expand All @@ -61,30 +69,34 @@ export default function () {

aiter(
abortable(setInterval(MOVE_INTERVAL, null, { signal: context.signal })),
).forEach(() => {
visible_mobs_group.forEach(({ entities }) => {
entities.forEach(mob => {
// 10% chance to move the mob
const should_move = Math.random() < MOVE_PROBABILITY
if (should_move) {
const { mob_group_id } = mob
const { position: spawn_position } =
visible_mobs_group.get(mob_group_id)
).forEach(async () => {
visible_mobs_group.forEach(async ({ entities }) => {
await Promise.all(
entities.map(async mob => {
// 10% chance to move the mob
const should_move = Math.random() < MOVE_PROBABILITY
if (should_move) {
const { mob_group_id } = mob
const { position: spawn_position } =
visible_mobs_group.get(mob_group_id)

const offset_x = get_random_offset(MAX_MOVE_DISTANCE)
const offset_z = get_random_offset(MAX_MOVE_DISTANCE)
const target_position = new Vector3(
spawn_position.x,
0, // the target Y is corrected in the tick function
spawn_position.z,
).add(new Vector3(offset_x, 0, offset_z))
const offset_x = get_random_offset(MAX_MOVE_DISTANCE)
const offset_z = get_random_offset(MAX_MOVE_DISTANCE)
const target_position = new Vector3(
spawn_position.x,
0, // the target Y is corrected in the tick function
spawn_position.z,
).add(new Vector3(offset_x, 0, offset_z))

target_position.setY(
get_terrain_height(target_position, mob.height),
)
target_position.setY(
await get_terrain_height(target_position, mob.height),
)

mob.target_position = target_position
}
mob.target_position = target_position
}
}),
).catch(error => {
console.error('Error moving mobs:', error)
})
})
})
Expand Down
64 changes: 33 additions & 31 deletions src/core/modules/game_entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,43 +181,45 @@ export default function () {

events.on(
'packet/entityGroupSpawn',
({ id: group_id, position: spawn_position, entities }) => {
async ({ id: group_id, position: spawn_position, entities }) => {
const { visible_mobs_group } = get_state()

spawn_position.y = get_terrain_height(spawn_position, 1)
spawn_position.y = await get_terrain_height(spawn_position, 1)

visible_mobs_group.set(group_id, {
id: group_id,
position: spawn_position,
entities: entities.map(({ name, id, level, skin, size }) => {
const spawned_mob = {
...ENTITIES[skin]({
id,
name: `${name} (${level})`,
scale_factor: size,
}),
name,
level,
mob_group_id: group_id,
spawn_position,
}

// find a position in 4 block range of entity position
const position = new Vector3(
spawn_position.x + Math.random() * 4 - 2,
0,
spawn_position.z + Math.random() * 4 - 2,
)

const ground_height = get_terrain_height(
position,
spawned_mob.height,
)

position.setY(ground_height)
spawned_mob.move(position)
return spawned_mob
}),
entities: await Promise.all(
entities.map(async ({ name, id, level, skin, size }) => {
const spawned_mob = {
...ENTITIES[skin]({
id,
name: `${name} (${level})`,
scale_factor: size,
}),
name,
level,
mob_group_id: group_id,
spawn_position,
}

// find a position in 4 block range of entity position
const position = new Vector3(
spawn_position.x + Math.random() * 4 - 2,
0,
spawn_position.z + Math.random() * 4 - 2,
)

const ground_height = await get_terrain_height(
position,
spawned_mob.height,
)

position.setY(ground_height)
spawned_mob.move(position)
return spawned_mob
}),
),
})
},
)
Expand Down
41 changes: 24 additions & 17 deletions src/core/modules/game_fights.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,34 @@ export default function () {
return state
},
observe() {
context.events.on('packet/fightSpawn', fight => {
const { visible_fights, characters } = context.get_state()
context.events.on('packet/fightSpawn', async fight => {
try {
const { visible_fights, characters } = context.get_state()

fight.start_time = +fight.start_time
fight.start_time = +fight.start_time

visible_fights.set(fight.id, fight)
visible_fights.set(fight.id, fight)

characters.forEach(character => {
if (
is_in_team(fight.team1, character.id) ||
is_in_team(fight.team2, character.id) ||
is_in_team(fight.spectators, character.id)
) {
context.dispatch('action/join_fight', {
character_id: character.id,
fight_id: fight.id,
})
}
})
characters.forEach(character => {
if (
is_in_team(fight.team1, character.id) ||
is_in_team(fight.team2, character.id)
// is_in_team(fight.spectators, character.id)
) {
context.dispatch('action/join_fight', {
character_id: character.id,
fight_id: fight.id,
})
}
})

fight_swords.set(fight.id, spawn_crescent_sword(fight, context.scene))
fight_swords.set(
fight.id,
await spawn_crescent_sword(fight, context.scene),
)
} catch (error) {
console.error('Failed to spawn fight', error)
}
})

context.events.on('packet/fightsDespawn', ({ ids }) => {
Expand Down
Loading