@@ -5,68 +5,54 @@ import {
5
5
defineState ,
6
6
dispatchAction ,
7
7
getMutableState ,
8
- receiveActions ,
9
- useHookstate ,
10
8
none ,
11
- getState
9
+ useHookstate
12
10
} from '@etherealengine/hyperflux'
13
- import { defineSystem } from '@etherealengine/engine/src/ecs/functions/SystemFunctions'
14
11
15
12
import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
16
- import { isClient } from '@etherealengine/engine/src/common/functions/getEnvironment'
17
13
18
- import { matches , string } from '@etherealengine/engine/src/common/functions/MatchesUtils'
19
14
import { NetworkTopics } from '@etherealengine/engine/src/networking/classes/Network'
20
15
import { WorldNetworkAction } from '@etherealengine/engine/src/networking/functions/WorldNetworkAction'
21
16
22
17
import { PhysicsSystem } from '@etherealengine/engine/src/physics/PhysicsModule'
23
- import { Physics } from '@etherealengine/engine/src/physics/classes/Physics'
24
18
25
- import { Vector3 } from 'three'
26
- import { UUIDComponent } from '@etherealengine/engine/src/scene/components/UUIDComponent'
27
- import { getComponent , setComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
28
- import { TransformComponent } from '@etherealengine/engine/src/transform/components/TransformComponent'
29
- import { VisibleComponent } from '@etherealengine/engine/src/scene/components/VisibleComponent'
19
+ import { isClient } from '@etherealengine/common/src/utils/getEnvironment'
20
+ import { defineSystem , getComponent , setComponent } from '@etherealengine/ecs'
30
21
import { NameComponent } from '@etherealengine/engine/src/scene/components/NameComponent'
31
22
import { PrimitiveGeometryComponent } from '@etherealengine/engine/src/scene/components/PrimitiveGeometryComponent'
32
- import { ColliderComponent } from '@etherealengine/engine/src/scene/components/ColliderComponent'
33
- import { ColliderDesc , RigidBodyDesc } from '@dimforge/rapier3d-compat'
34
- import { PhysicsState } from '@etherealengine/engine/src/physics/state/PhysicsState'
35
- import { RigidBodyComponent } from '@etherealengine/engine/src/physics/components/RigidBodyComponent'
36
- import { getInteractionGroups } from '@etherealengine/engine/src/physics/functions/getInteractionGroups'
37
- import { CollisionGroups , DefaultCollisionMask } from '@etherealengine/engine/src/physics/enums/CollisionGroups'
23
+ import { UUIDComponent } from '@etherealengine/engine/src/scene/components/UUIDComponent'
24
+ import { VisibleComponent } from '@etherealengine/engine/src/scene/components/VisibleComponent'
25
+ import { TransformComponent } from '@etherealengine/engine/src/transform/components/TransformComponent'
38
26
39
27
//
40
28
// Description of the format of a spawn action to create a artifact
41
29
//
42
30
43
- const spawnAction = defineAction ( {
44
- ...WorldNetworkAction . spawnObject . actionShape ,
45
- prefab : 'ee.basic.ball' ,
46
- $topic : NetworkTopics . world
47
- } )
31
+ class BasicActions {
32
+ static spawnAction = defineAction ( {
33
+ ...WorldNetworkAction . spawnObject . actionShape ,
34
+ prefab : 'ee.basic.ball' ,
35
+ $topic : NetworkTopics . world
36
+ } )
37
+ }
48
38
49
39
//
50
40
// Global state that tracks locally spawned or destroyed artifacts by using action receptors
51
41
//
52
42
53
43
export const BasicState = defineState ( {
54
44
name : 'ee.basic.BasicState' ,
55
- initial : { } as Record < EntityUUID , { } > ,
56
- receptors : [
57
- [
58
- spawnAction ,
59
- ( state , action : typeof spawnAction . matches . _TYPE ) => {
60
- state [ action . entityUUID ] . merge ( { } )
61
- }
62
- ] ,
63
- [
64
- WorldNetworkAction . destroyObject ,
65
- ( state , action : typeof WorldNetworkAction . destroyObject . matches . _TYPE ) => {
66
- state [ action . entityUUID ] . set ( none )
67
- }
68
- ]
69
- ]
45
+ initial : { } as Record < EntityUUID , { } > ,
46
+ receptors : {
47
+ onSpawnAction : BasicActions . spawnAction . receive ( ( action ) => {
48
+ const state = getMutableState ( BasicState )
49
+ state [ action . entityUUID ] . merge ( { } )
50
+ } ) ,
51
+ onDestroyObject : WorldNetworkAction . destroyObject . receive ( ( action ) => {
52
+ const state = getMutableState ( BasicState )
53
+ state [ action . entityUUID ] . set ( none )
54
+ } )
55
+ }
70
56
} )
71
57
72
58
//
@@ -79,7 +65,7 @@ const ArtifactReactor = ({ entityUUID }: { entityUUID: EntityUUID }) => {
79
65
const entity = UUIDComponent . getEntityByUUID ( entityUUID )
80
66
setComponent ( entity , TransformComponent )
81
67
setComponent ( entity , VisibleComponent )
82
- setComponent ( entity , NameComponent , 'hello' )
68
+ setComponent ( entity , NameComponent , 'hello' )
83
69
setComponent ( entity , PrimitiveGeometryComponent , { geometryType : 1 } )
84
70
85
71
/*
@@ -104,23 +90,22 @@ const ArtifactReactor = ({ entityUUID }: { entityUUID: EntityUUID }) => {
104
90
105
91
*/
106
92
107
- if ( isClient ) return
93
+ if ( isClient ) return
108
94
109
95
// positions are networked intrinsically
110
96
111
- const x = Math . random ( ) * 10
97
+ const x = Math . random ( ) * 10
112
98
const y = 0
113
- const z = Math . random ( ) * 10
114
- const transform = getComponent ( entity , TransformComponent )
115
- transform . position . set ( x , y , z )
99
+ const z = Math . random ( ) * 10
100
+ const transform = getComponent ( entity , TransformComponent )
101
+ transform . position . set ( x , y , z )
116
102
117
103
// forces are networked intrinsically
118
104
119
105
//const angle = Math.random()*Math.PI*2
120
106
//const direction = new Vector3( Math.sin(angle),0,Math.cos(angle))
121
107
//const velocity = 0.025 + Math.random()*0.01
122
108
//rigidBody.body.applyImpulse(direction.multiplyScalar(velocity), true)
123
-
124
109
} , [ ] )
125
110
return null
126
111
}
@@ -148,15 +133,13 @@ let counter = 0
148
133
//
149
134
150
135
const execute = ( ) => {
151
- receiveActions ( BasicState )
152
-
153
- if ( isClient ) return
136
+ if ( isClient ) return
154
137
counter ++
155
- if ( counter & 255 ) return
138
+ if ( counter & 255 ) return
156
139
157
140
const entityUUID = `basic-${ counter } ` as EntityUUID
158
141
const prefab = 'ee.basic.ball'
159
- const action = spawnAction ( { entityUUID, prefab } )
142
+ const action = BasicActions . spawnAction ( { entityUUID, prefab } )
160
143
dispatchAction ( action )
161
144
}
162
145
0 commit comments