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

network module #16

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
network module
  • Loading branch information
HexaField committed Mar 5, 2024
commit dc6f308d17fd555c94d7fd8d34d11347f1ff1479
13 changes: 7 additions & 6 deletions src/PaddleState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
defineState,
dispatchAction,
getMutableState,
matches,
matchesUserId,
none,
useHookstate
} from '@etherealengine/hyperflux'
import { matches, matchesEntityUUID, matchesUserId } from '@etherealengine/spatial/src/common/functions/MatchesUtils'
import { NetworkTopics } from '@etherealengine/spatial/src/networking/classes/Network'
import { NetworkTopics, WorldNetworkAction } from '@etherealengine/network'
import React, { useEffect } from 'react'

import { getComponent, setComponent } from '@etherealengine/ecs'
import { getComponent, matchesEntityUUID, setComponent } from '@etherealengine/ecs'
import {
GrabbableComponent,
GrabbedComponent
Expand All @@ -21,12 +22,12 @@ import { GrabbableNetworkAction } from '@etherealengine/engine/src/interaction/s
import { PrimitiveGeometryComponent } from '@etherealengine/engine/src/scene/components/PrimitiveGeometryComponent'
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { UUIDComponent } from '@etherealengine/spatial/src/common/UUIDComponent'
import { WorldNetworkAction } from '@etherealengine/spatial/src/networking/functions/WorldNetworkAction'
import { ColliderComponent } from '@etherealengine/spatial/src/physics/components/ColliderComponent'
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent'
import { CollisionGroups } from '@etherealengine/spatial/src/physics/enums/CollisionGroups'
import { BodyTypes } from '@etherealengine/spatial/src/physics/types/PhysicsTypes'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
import { SpawnObjectActions } from '@etherealengine/spatial/src/transform/SpawnObjectActions'
import {
DistanceFromCameraComponent,
FrustumCullCameraComponent
Expand All @@ -40,7 +41,7 @@ export enum PongCollisionGroups {

export class PaddleActions {
static spawnPaddle = defineAction({
...WorldNetworkAction.spawnObject.actionShape,
...SpawnObjectActions.spawnObject.actionShape,
prefab: 'ee.pong.paddle',
gameEntityUUID: matchesEntityUUID,
handedness: matches.literals('left', 'right'),
Expand Down Expand Up @@ -69,7 +70,7 @@ export const PaddleState = defineState({
gameEntityUUID: action.gameEntityUUID
})
}),
onDestroyPaddle: WorldNetworkAction.destroyObject.receive((action) => {
onDestroyPaddle: WorldNetworkAction.destroyEntity.receive((action) => {
const state = getMutableState(PaddleState)
state[action.entityUUID].set(none)
})
Expand Down
31 changes: 15 additions & 16 deletions src/PongGameState.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
import multiLogger from '@etherealengine/common/src/logger'
import { UserID } from '@etherealengine/common/src/schema.type.module'
import { UndefinedEntity, getComponent, matchesEntityUUID } from '@etherealengine/ecs'
import { Engine } from '@etherealengine/ecs/src/Engine'
import { SceneState } from '@etherealengine/engine/src/scene/Scene'
import {
defineAction,
defineState,
dispatchAction,
getMutableState,
matches,
matchesUserId,
none,
useHookstate
} from '@etherealengine/hyperflux'
import { matches, matchesEntityUUID, matchesUserId } from '@etherealengine/spatial/src/common/functions/MatchesUtils'
import { NetworkTopics } from '@etherealengine/spatial/src/networking/classes/Network'
import React, { useEffect } from 'react'

import './PlateComponent'
import './PongComponent'

import multiLogger from '@etherealengine/common/src/logger'
import { UndefinedEntity, defineSystem, getComponent } from '@etherealengine/ecs'
import { Engine } from '@etherealengine/ecs/src/Engine'
import { SceneState } from '@etherealengine/engine/src/scene/Scene'
import { NetworkTopics, WorldNetworkAction } from '@etherealengine/network'
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { UUIDComponent } from '@etherealengine/spatial/src/common/UUIDComponent'
import { WorldNetworkAction } from '@etherealengine/spatial/src/networking/functions/WorldNetworkAction'
import { SpawnObjectActions } from '@etherealengine/spatial/src/transform/SpawnObjectActions'
import { iterateEntityNode } from '@etherealengine/spatial/src/transform/components/EntityTree'
import { TransformComponent } from '@etherealengine/spatial/src/transform/components/TransformComponent'
import React, { useEffect } from 'react'
import { PaddleActions } from './PaddleState'
import './PlateComponent'
import './PongComponent'
import { spawnBall } from './PongPhysicsSystem'

const logger = multiLogger.child({ component: 'PongSystem' })
Expand Down Expand Up @@ -58,7 +57,7 @@ export class PongActions {
})

static spawnBall = defineAction({
...WorldNetworkAction.spawnObject.actionShape,
...SpawnObjectActions.spawnObject.actionShape,
prefab: 'ee.pong.ball',
gameEntityUUID: matchesEntityUUID,
$topic: NetworkTopics.world
Expand Down Expand Up @@ -123,7 +122,7 @@ export const PongState = defineState({
const state = getMutableState(PongState)
state[action.gameEntityUUID].ball.set(action.entityUUID)
}),
onDestroyBall: WorldNetworkAction.destroyObject.receive((action) => {
onDestroyBall: WorldNetworkAction.destroyEntity.receive((action) => {
const state = getMutableState(PongState)
for (const gameUUID of state.keys) {
const game = state[gameUUID as EntityUUID]
Expand Down Expand Up @@ -189,12 +188,12 @@ const PlayerReactor = (props: { playerIndex: number; gameUUID: EntityUUID }) =>
logger.info(`Player ${props.playerIndex} disconnected`)

dispatchAction(
WorldNetworkAction.destroyObject({
WorldNetworkAction.destroyEntity({
entityUUID: (userID + '_paddle_left') as EntityUUID
})
)
dispatchAction(
WorldNetworkAction.destroyObject({
WorldNetworkAction.destroyEntity({
entityUUID: (userID + '_paddle_right') as EntityUUID
})
)
Expand Down
4 changes: 2 additions & 2 deletions src/PongPhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { isClient } from '@etherealengine/common/src/utils/getEnvironment'
import { defineSystem, getComponent, getOptionalComponent, setComponent } from '@etherealengine/ecs'
import { ECSState } from '@etherealengine/ecs/src/ECSState'
import { PrimitiveGeometryComponent } from '@etherealengine/engine/src/scene/components/PrimitiveGeometryComponent'
import { WorldNetworkAction } from '@etherealengine/network'
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { UUIDComponent } from '@etherealengine/spatial/src/common/UUIDComponent'
import { WorldNetworkAction } from '@etherealengine/spatial/src/networking/functions/WorldNetworkAction'
import { Physics } from '@etherealengine/spatial/src/physics/classes/Physics'
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent'
import { CollisionGroups, DefaultCollisionMask } from '@etherealengine/spatial/src/physics/enums/CollisionGroups'
Expand Down Expand Up @@ -146,7 +146,7 @@ const gameLogic = (gameUUID: EntityUUID) => {

if (vec3.y < 0.2) {
dispatchAction(
WorldNetworkAction.destroyObject({
WorldNetworkAction.destroyEntity({
entityUUID: game.ball.value
})
)
Expand Down