Skip to content

Commit

Permalink
add missing components to remove sdk7 observables (#6163)
Browse files Browse the repository at this point in the history
* add missing components to remove sdk7 observables

* remove logs

* fix version of ecs

* remove sdk
  • Loading branch information
gonpombo8 authored Apr 25, 2024
1 parent bb9a1bf commit 36e7a78
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 60 deletions.
100 changes: 60 additions & 40 deletions browser-interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions browser-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
},
"dependencies": {
"@dcl/crypto": "^3.3.1",
"@dcl/ecs": "7.4.16",
"@dcl/ecs": "7.4.19",
"@dcl/ecs-math": "^1.0.3",
"@dcl/ecs-quests": "^1.3.1",
"@dcl/feature-flags": "^1.1.0",
"@dcl/hashing": "^1.1.3",
"@dcl/kernel-interface": "^2.0.0-20230512115658.commit-b582e05",
"@dcl/legacy-ecs": "^6.11.11",
"@dcl/protocol": "1.0.0-8691799990.commit-4ba546c",
"@dcl/protocol": "1.0.0-8789372854.commit-f692c7a",
"@dcl/rpc": "^1.1.1",
"@dcl/scene-runtime": "7.0.6-20240220184109.commit-cf1e4e2",
"@dcl/schemas": "^9.1.1",
Expand Down
11 changes: 10 additions & 1 deletion browser-interface/packages/shared/sceneEvents/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,38 @@ import { getCurrentUserProfile } from 'shared/profiles/selectors'
import { SET_REALM_ADAPTER } from 'shared/realm/actions'
import { realmToConnectionString } from 'shared/realm/resolver'
import { getRealmAdapter } from 'shared/realm/selectors'
import type { RootRealmState } from 'shared/realm/types'
import type { IRealmAdapter, RootRealmState } from 'shared/realm/types'
import { toEnvironmentRealmType } from '../apis/host/EnvironmentAPI'
import { SET_COMMS_ISLAND, SET_ROOM_CONNECTION } from '../comms/actions'
import { getCommsIsland } from '../comms/selectors'
import { SAVE_DELTA_PROFILE_REQUEST } from '../profiles/actions'
import { takeLatestByUserId } from '../profiles/sagas'
import { allScenesEvent } from '../world/parcelSceneManager'
import mitt from 'mitt'

export function* sceneEventsSaga() {
yield takeLatest([SET_COMMS_ISLAND, SET_ROOM_CONNECTION, SET_REALM_ADAPTER], islandChanged)
yield takeLatestByUserId(SAVE_DELTA_PROFILE_REQUEST, submitProfileToScenes)
}

// used to notify the scenes that the realm changed using PBRealmInfo component.
type IRealmChangeEvent = {
change: { adapter: IRealmAdapter; room: string }
}
export const realmChangeEvent = mitt<IRealmChangeEvent>()

function* islandChanged() {
const { adapter, island } = (yield select(getRealmAdapterAndIsland)) as ReturnType<typeof getRealmAdapterAndIsland>

if (adapter) {
const payload = toEnvironmentRealmType(adapter, island)
yield call(allScenesEvent, { eventType: 'onRealmChanged', payload })
yield call(() => realmChangeEvent.emit('change', { adapter, room: island ?? '' }))
}

yield call(updateLocation, adapter ? realmToConnectionString(adapter) : undefined, island)
}

export function getRealmAdapterAndIsland(state: RootCommsState & RootRealmState) {
return {
adapter: getRealmAdapter(state),
Expand Down
6 changes: 3 additions & 3 deletions browser-interface/packages/shared/world/parcelSceneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function allScenesEvent<T extends IEventNames>(data: AllScenesEvents<T>)
for (const [, scene] of loadedSceneWorkers) {
scene.rpcContext.sendSceneEvent(data.eventType, data.payload)
}
TEST_OBJECT_ObservableAllScenesEvent.notifyObservers(data)
}

export const TEST_OBJECT_ObservableAllScenesEvent = new Observable<AllScenesEvents<any>>()
observableAllScenesEvent.notifyObservers(data)
}
export const observableAllScenesEvent = new Observable<AllScenesEvents<keyof IEvents>>()
51 changes: 49 additions & 2 deletions browser-interface/packages/shared/world/runtime-7/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
PlayerIdentityData as definePlayerIdentityData,
AvatarBase as defineAvatarBase,
AvatarEquippedData as defineAvatarEquippedData,
AvatarEmoteCommand as defineAvatarEmoteCommand
AvatarEmoteCommand as defineAvatarEmoteCommand,
PointerEventsResult as definePointerEventsResult,
RealmInfo as defineRealmInfo
} from '@dcl/ecs/dist-cjs/components'
import { PointerEventType, InputAction, PBRealmInfo } from '@dcl/ecs/dist-cjs'
import { Entity, EntityUtils, createEntityContainer } from '@dcl/ecs/dist-cjs/engine/entity'
import { avatarMessageObservable, getAllPeers } from '../../comms/peers'
import { encodeParcelPosition } from '../../../lib/decentraland'
Expand All @@ -22,6 +25,9 @@ import { Avatar } from '@dcl/schemas'
import { prepareAvatar } from '../../../lib/decentraland/profiles/transformations/profileToRendererFormat'
import { deepEqual } from '../../../lib/javascript/deepEqual'
import { positionObservable } from '../positionThings'
import { realmChangeEvent } from '../../sceneEvents/sagas'
import { urlWithProtocol } from '../../realm/resolver'
import { PREVIEW } from '../../../config'

export type IInternalEngine = {
engine: IEngine
Expand Down Expand Up @@ -60,14 +66,15 @@ function getUserData(userId: string) {
}

export const localProfileChanged = mitt<LocalProfileChange>()
export const playerClickedEvent = mitt<{ add: { data: IEvents['playerClicked']; sceneNumber: number } }>()
export const audioStreamEmitter = mitt<AudioStreamChange>()

/**
* We used this engine as an internal engine to add information to the worker.
* It handles the Avatar information for each player
*/
export function createInternalEngine(sceneNumber: number, parcels: string[], isGlobalScene: boolean): IInternalEngine {
const AVATAR_RESERVED_ENTITIES = { from: 10, to: 200 }
const AVATAR_RESERVED_ENTITIES = { from: 32, to: 255 }
const userId = getCurrentUserId(store.getState())!

// From 0 to 10 engine reserved entities.
Expand All @@ -78,6 +85,8 @@ export function createInternalEngine(sceneNumber: number, parcels: string[], isG
const AvatarEquippedData = defineAvatarEquippedData(engine)
const PlayerIdentityData = definePlayerIdentityData(engine)
const AvatarEmoteCommand = defineAvatarEmoteCommand(engine)
const PointerEventsResult = definePointerEventsResult(engine)
const RealmInfo = defineRealmInfo(engine)
const AudioEvent = defineAudioEvent(engine)
const avatarMap = new Map<string, Entity>()

Expand Down Expand Up @@ -242,6 +251,41 @@ export function createInternalEngine(sceneNumber: number, parcels: string[], isG
}
})

// Realm Change event
realmChangeEvent.on('change', ({ adapter, room }) => {
const value: PBRealmInfo = {
baseUrl: urlWithProtocol(new URL(adapter.baseUrl).hostname),
realmName: adapter.about.configurations?.realmName ?? '',
networkId: adapter.about.configurations?.networkId ?? 1,
commsAdapter: adapter.about.comms?.adapter ?? '',
room,
isPreview: PREVIEW
}
RealmInfo.createOrReplace(engine.RootEntity, value)
})

playerClickedEvent.on('add', (data) => {
if (data.sceneNumber !== sceneNumber) return
const userEntity = avatarMap.get(data.data.userId)
if (!userEntity) return
const pointerEventResult = PointerEventsResult.get(userEntity)
const lastPointerEvent = [...pointerEventResult.values()].pop()
const value = {
button: InputAction.IA_POINTER,
state: PointerEventType.PET_DOWN,
tickNumber: Date.now(),
hit: {
direction: data.data.ray.direction,
length: data.data.ray.distance,
globalOrigin: data.data.ray.origin,
normalHit: undefined,
position: undefined
},
timestamp: (lastPointerEvent?.timestamp ?? 0) + 1
}
PointerEventsResult.addValue(userEntity, value)
})

/**
* We used this transport to send only kernel-side updates (profile, emotes, audio stream...) to the client instead of the full state
* For example: every time there is an update on a profile, this would add those CRDT messages to internalMessages
Expand Down Expand Up @@ -279,6 +323,9 @@ export function createInternalEngine(sceneNumber: number, parcels: string[], isG
positionObservable.remove(userIdPositionObserver)
localProfileChanged.off('triggerEmote')
localProfileChanged.off('changeAvatar')
realmChangeEvent.off('change')
playerClickedEvent.off('add')
audioStreamEmitter.off('changeState')
}
}
}
Loading

0 comments on commit 36e7a78

Please sign in to comment.