Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.
Merged
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
19 changes: 15 additions & 4 deletions packages/client-core/src/admin/adminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import React, { Suspense, useEffect } from 'react'
import { Redirect, Switch } from 'react-router-dom'

import LoadingView from '@xrengine/client-core/src/common/components/LoadingView'
import { AvatarClientModule } from '@xrengine/engine/src/avatar/AvatarClientModule'
import { AvatarCommonModule } from '@xrengine/engine/src/avatar/AvatarCommonModule'
import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { EngineActions, useEngineState } from '@xrengine/engine/src/ecs/classes/EngineState'
import { initializeCoreSystems } from '@xrengine/engine/src/initializeCoreSystems'
import { initializeSceneSystems } from '@xrengine/engine/src/initializeSceneSystems'
import { initSystems } from '@xrengine/engine/src/ecs/functions/SystemFunctions'
import { SceneClientModule } from '@xrengine/engine/src/scene/SceneClientModule'
import { SceneCommonModule } from '@xrengine/engine/src/scene/SceneCommonModule'
import { TransformModule } from '@xrengine/engine/src/transform/TransformModule'
import { dispatchAction } from '@xrengine/hyperflux'

import CircularProgress from '@mui/material/CircularProgress'
Expand Down Expand Up @@ -58,8 +63,14 @@ const ProtectedRoutes = () => {
const scopes = admin?.scopes?.value || []

useEffect(() => {
initializeCoreSystems([AdminSystemInjection]).then(async () => {
await initializeSceneSystems()
Promise.all([
TransformModule(),
SceneCommonModule(),
SceneClientModule(),
AvatarCommonModule(),
AvatarClientModule(),
initSystems(Engine.instance.currentWorld, [AdminSystemInjection])
]).then(async () => {
dispatchAction(EngineActions.initializeEngine({ initialised: true }))
})
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next'

import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { initSystems } from '@xrengine/engine/src/ecs/functions/SystemFunctions'
import { initializeCoreSystems } from '@xrengine/engine/src/initializeCoreSystems'

import { Box, CircularProgress } from '@mui/material'
import Button from '@mui/material/Button'
Expand Down
13 changes: 5 additions & 8 deletions packages/client-core/src/components/World/LocationLoadHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import { SceneData } from '@xrengine/common/src/interfaces/SceneInterface'
import multiLogger from '@xrengine/common/src/logger'
import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { EngineActions, EngineState } from '@xrengine/engine/src/ecs/classes/EngineState'
import { SystemModuleType } from '@xrengine/engine/src/ecs/functions/SystemFunctions'
import { initializeCoreSystems } from '@xrengine/engine/src/initializeCoreSystems'
import { initializeRealtimeSystems } from '@xrengine/engine/src/initializeRealtimeSystems'
import { initializeSceneSystems } from '@xrengine/engine/src/initializeSceneSystems'
import { initSystems, SystemModuleType } from '@xrengine/engine/src/ecs/functions/SystemFunctions'
import { updateSceneFromJSON } from '@xrengine/engine/src/scene/systems/SceneLoadingSystem'
import { dispatchAction, getState } from '@xrengine/hyperflux'
import { loadEngineInjection } from '@xrengine/projects/loadEngineInjection'

import { API } from '../../API'
import { ClientModules } from '../../world/ClientModules'

const logger = multiLogger.child({ component: 'client-core:world' })

Expand All @@ -31,15 +29,14 @@ export const retrieveLocationByName = (locationName: string, userId: string) =>
}
}

export const initClient = async (injectedSystems?: SystemModuleType<any>[]) => {
export const initClient = async (injectedSystems: SystemModuleType<any>[] = []) => {
if (getState(EngineState).isEngineInitialized.value) return

const world = Engine.instance.currentWorld
const projects = API.instance.client.service('projects').find()

await initializeCoreSystems(injectedSystems)
await initializeRealtimeSystems()
await initializeSceneSystems()
await ClientModules()
await initSystems(world, injectedSystems)
await loadEngineInjection(world, await projects)

dispatchAction(EngineActions.initializeEngine({ initialised: true }))
Expand Down
33 changes: 33 additions & 0 deletions packages/client-core/src/world/ClientModules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MediaModule } from '@xrengine/engine/src/audio/MediaModule'
import { AvatarClientModule } from '@xrengine/engine/src/avatar/AvatarClientModule'
import { AvatarCommonModule } from '@xrengine/engine/src/avatar/AvatarCommonModule'
import { CameraModule } from '@xrengine/engine/src/camera/CameraModule'
import { DebugModule } from '@xrengine/engine/src/debug/DebugModule'
import { InputModule } from '@xrengine/engine/src/input/InputModule'
import { InteractionModule } from '@xrengine/engine/src/interaction/InteractionModule'
import { RealtimeNetworkingModule } from '@xrengine/engine/src/networking/RealtimeNetworkingModule'
import { RendererModule } from '@xrengine/engine/src/renderer/RendererModule'
import { SceneClientModule } from '@xrengine/engine/src/scene/SceneClientModule'
import { SceneCommonModule } from '@xrengine/engine/src/scene/SceneCommonModule'
import { TransformModule } from '@xrengine/engine/src/transform/TransformModule'
import { XRModule } from '@xrengine/engine/src/xr/XRModule'
import { XRUIModule } from '@xrengine/engine/src/xrui/XRUIModule'

export function ClientModules() {
return Promise.all([
XRModule(),
TransformModule(),
RendererModule(),
MediaModule(),
InputModule(),
SceneCommonModule(),
SceneClientModule(),
AvatarCommonModule(),
AvatarClientModule(),
CameraModule(),
XRUIModule(),
InteractionModule(),
RealtimeNetworkingModule(),
DebugModule()
])
}
10 changes: 3 additions & 7 deletions packages/editor/src/pages/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { LoadingCircle } from '@xrengine/client-core/src/components/LoadingCircl
import PortalLoadSystem from '@xrengine/client-core/src/systems/PortalLoadSystem'
import { useAuthState } from '@xrengine/client-core/src/user/services/AuthService'
import { userHasAccess } from '@xrengine/client-core/src/user/userHasAccess'
import { ClientModules } from '@xrengine/client-core/src/world/ClientModules'
import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { initSystems } from '@xrengine/engine/src/ecs/functions/SystemFunctions'
import { SystemUpdateType } from '@xrengine/engine/src/ecs/functions/SystemUpdateType'
import { initializeCoreSystems } from '@xrengine/engine/src/initializeCoreSystems'
import { initializeRealtimeSystems } from '@xrengine/engine/src/initializeRealtimeSystems'
import { initializeSceneSystems } from '@xrengine/engine/src/initializeSceneSystems'
import { loadEngineInjection } from '@xrengine/projects/loadEngineInjection'

import EditorCameraSystem from '../systems/EditorCameraSystem'
Expand Down Expand Up @@ -90,11 +88,9 @@ const EditorProtectedRoutes = () => {
useEffect(() => {
Engine.instance.isEditor = true
const world = Engine.instance.currentWorld
initializeCoreSystems().then(async () => {
const projects = API.instance.client.service('projects').find()
ClientModules().then(async () => {
initSystems(world, systems)
const projects = API.instance.client.service('projects').find()
await initializeRealtimeSystems(false)
await initializeSceneSystems()
await loadEngineInjection(world, await projects)
setEngineReady(true)
})
Expand Down
20 changes: 20 additions & 0 deletions packages/engine/src/audio/MediaModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Engine } from '../ecs/classes/Engine'
import { initSystems } from '../ecs/functions/SystemFunctions'
import { SystemUpdateType } from '../ecs/functions/SystemUpdateType'
import MediaSystem from './systems/MediaSystem'
import PositionalAudioSystem from './systems/PositionalAudioSystem'

export function MediaModule() {
return initSystems(Engine.instance.currentWorld, [
{
uuid: 'xre.engine.MediaSystem',
type: SystemUpdateType.PRE_RENDER,
systemLoader: () => Promise.resolve({ default: MediaSystem })
},
{
uuid: 'xre.engine.PositionalAudioSystem',
type: SystemUpdateType.POST_RENDER,
systemLoader: () => Promise.resolve({ default: PositionalAudioSystem })
}
])
}
2 changes: 0 additions & 2 deletions packages/engine/src/avatar/AnimationSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export default async function AnimationSystem(world: World) {
const animationQuery = defineQuery([AnimationComponent, VisibleComponent])
const avatarAnimationQueue = createActionQueue(WorldNetworkAction.avatarAnimation.matches)

await AnimationManager.instance.loadDefaultAnimations()

const execute = () => {
const { deltaSeconds } = world

Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/avatar/AvatarAnimationSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const _rotY90 = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI
const _rotYneg90 = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), -Math.PI / 2)

export default async function AvatarAnimationSystem(world: World) {
await AnimationManager.instance.loadDefaultAnimations()

const leftHandQuery = defineQuery([VisibleComponent, AvatarLeftHandIKComponent, AvatarRigComponent])
const rightHandQuery = defineQuery([VisibleComponent, AvatarRightHandIKComponent, AvatarRigComponent])
const headIKQuery = defineQuery([VisibleComponent, AvatarHeadIKComponent, AvatarRigComponent])
Expand Down
44 changes: 44 additions & 0 deletions packages/engine/src/avatar/AvatarClientModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Engine } from '../ecs/classes/Engine'
import { initSystems } from '../ecs/functions/SystemFunctions'
import { SystemUpdateType } from '../ecs/functions/SystemUpdateType'
import AnimationSystem from './AnimationSystem'
import AvatarControllerSystem from './AvatarControllerSystem'
import AvatarInputSystem from './AvatarInputSystem'
import AvatarLoadingSystem from './AvatarLoadingSystem'
import AvatarTeleportSystem from './AvatarTeleportSystem'
import FlyControlSystem from './FlyControlSystem'

export function AvatarClientModule() {
return initSystems(Engine.instance.currentWorld, [
{
uuid: 'xre.engine.FlyControlSystem',
type: SystemUpdateType.UPDATE_LATE,
systemLoader: () => Promise.resolve({ default: FlyControlSystem })
},
{
uuid: 'xre.engine.AvatarTeleportSystem',
type: SystemUpdateType.UPDATE_LATE,
systemLoader: () => Promise.resolve({ default: AvatarTeleportSystem })
},
{
uuid: 'xre.engine.AnimationSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: AnimationSystem })
},
{
uuid: 'xre.engine.AvatarInputSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: AvatarInputSystem })
},
{
uuid: 'xre.engine.AvatarControllerSystem',
type: SystemUpdateType.FIXED,
systemLoader: () => Promise.resolve({ default: AvatarControllerSystem })
},
{
uuid: 'xre.engine.AvatarLoadingSystem',
type: SystemUpdateType.PRE_RENDER,
systemLoader: () => Promise.resolve({ default: AvatarLoadingSystem })
}
])
}
20 changes: 20 additions & 0 deletions packages/engine/src/avatar/AvatarCommonModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Engine } from '../ecs/classes/Engine'
import { initSystems } from '../ecs/functions/SystemFunctions'
import { SystemUpdateType } from '../ecs/functions/SystemUpdateType'
import AvatarSpawnSystem from './AvatarSpawnSystem'
import AvatarSystem from './AvatarSystem'

export function AvatarCommonModule() {
return initSystems(Engine.instance.currentWorld, [
{
uuid: 'xre.engine.AvatarSpawnSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: AvatarSpawnSystem })
},
{
uuid: 'xre.engine.AvatarSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: AvatarSystem })
}
])
}
20 changes: 20 additions & 0 deletions packages/engine/src/camera/CameraModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Engine } from '../ecs/classes/Engine'
import { initSystems } from '../ecs/functions/SystemFunctions'
import { SystemUpdateType } from '../ecs/functions/SystemUpdateType'
import CameraInputSystem from './systems/CameraInputSystem'
import CameraSystem from './systems/CameraSystem'

export function CameraModule() {
return initSystems(Engine.instance.currentWorld, [
{
uuid: 'xre.engine.CameraInputSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: CameraInputSystem })
},
{
uuid: 'xre.engine.CameraSystem',
type: SystemUpdateType.UPDATE,
systemLoader: () => Promise.resolve({ default: CameraSystem })
}
])
}
20 changes: 20 additions & 0 deletions packages/engine/src/debug/DebugModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Engine } from '../ecs/classes/Engine'
import { initSystems } from '../ecs/functions/SystemFunctions'
import { SystemUpdateType } from '../ecs/functions/SystemUpdateType'
import DebugHelpersSystem from './systems/DebugHelpersSystem'
import DebugRenderer from './systems/DebugRenderer'

export function DebugModule() {
return initSystems(Engine.instance.currentWorld, [
{
uuid: 'xre.engine.DebugHelpersSystem',
type: SystemUpdateType.PRE_RENDER,
systemLoader: () => Promise.resolve({ default: DebugHelpersSystem })
},
{
uuid: 'xre.engine.DebugRenderer',
type: SystemUpdateType.PRE_RENDER,
systemLoader: () => Promise.resolve({ default: DebugRenderer })
}
])
}
50 changes: 28 additions & 22 deletions packages/engine/src/ecs/functions/SystemFunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,41 @@ const createExecute = (system: SystemDefintion, subsystems: SystemInstanceData[]
}
}

const loadSubsystems = (
world: World,
parentSystemFactory: SystemFactoryType<any>,
subsystems: Array<SystemLoader<any>> = []
) => {
return Promise.all(
subsystems.map(async (subsystemInit, i) => {
const subsystem = await subsystemInit()
const name = subsystem.default.name
const uuid = name
const type = 'SUB_SYSTEM' as any
return {
uuid,
name,
type,
sceneSystem: parentSystemFactory.sceneSystem,
enabled: true,
...(await loadSystemInjection(world, {
systemModule: subsystem,
uuid,
type
}))
}
})
)
}

const loadSystemInjection = async (world: World, s: SystemFactoryType<any>, type?: SystemUpdateType, args?: any) => {
const name = s.systemModule.default.name
try {
if (type) logger.info(`${name} initializing on ${type} pipeline`)
else logger.info(`${name} initializing`)
const system = await s.systemModule.default(world, args)
const subsystems = await loadSubsystems(world, s, system.subsystems)
logger.info(`${name} (${s.uuid}) ready`)
const subsystems = system.subsystems
? await Promise.all(
system.subsystems.map(async (subsystemInit, i) => {
const subsystem = await subsystemInit()
const name = subsystem.default.name
const uuid = name
const type = 'SUB_SYSTEM' as any
return {
uuid,
name,
type,
sceneSystem: s.sceneSystem,
enabled: true,
...(await loadSystemInjection(world, {
systemModule: subsystem,
uuid,
type
}))
}
})
)
: []
return {
execute: createExecute(system, subsystems, name, s.uuid),
cleanup: system.cleanup,
Expand Down
Loading