Skip to content

Commit eb55ff5

Browse files
Upgrade to 14.4.0 and QBI (#37)
* Use modular UDP. * Enable protocol logging and add interest component to snapshot. * Remove some debug logging. * Upgrade physics and client_direct to 14.4.0. * Switch from CBI to QBI. * CR from David. * Switch to modular KCP. * Nick CR. * Nick CR. Co-authored-by: David Avedissian <git@dga.dev>
1 parent 8a9aaae commit eb55ff5

File tree

10 files changed

+179
-98
lines changed

10 files changed

+179
-98
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ logs/
1212
dependencies/worker_sdk
1313

1414
# VS Code
15-
.vscode
15+
.vscode
16+
17+
.idea
18+
cmake-build-debug

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ component). The C++ worker then modifies the entity's write ACLs to delegate com
4747
(`sample.ClientData`) to the client, using the `CallerWorkerAttributes` field of the
4848
`CommandRequestOp`. This causes the entity to be checked out by the client worker, and the client
4949
worker will begin to receive component updates for position changes. The physics worker will also
50-
begin to send a simple command to the client every few seconds.
50+
begin to send a simple command to the client every few seconds. Due to the entity's QBI query,
51+
the client worker will check in/out another entity due to its movement.
5152

5253
## Snapshot
5354

54-
The snapshot exists in both json and binary format in the `snapshots` folder. There is no script
55-
to generate the snapshot as the snapshot was written by hand in the json format, but it's possible
56-
to make simple changes to the json format and regenerate the binary snapshot from it. To update the
55+
The snapshot exists in both JSON and binary format in the `snapshots` folder. There is no script
56+
to generate the snapshot as the snapshot was written by hand in JSON format, but it's possible
57+
to make simple changes to the JSON snapshot and regenerate the binary snapshot from it. To update the
5758
binary snapshot after making a change, run the following command:
5859

5960
```

default_launch.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
"dimensions": {
99
"x_meters": 1500,
1010
"z_meters": 1500
11-
}
11+
},
12+
"legacy_flags": [
13+
{
14+
"name": "interest_queries_components_are_filtered_by_component_delivery",
15+
"value": "false"
16+
}
17+
]
1218
},
1319
"load_balancing": {
1420
"layer_configurations": [

snapshots/default.json

Lines changed: 137 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,144 @@
11
{
2-
"__entity_id": "1",
3-
"improbable.EntityAcl": {
4-
"component_write_acl": [
2+
"__entity_id": "1",
3+
"improbable.EntityAcl": {
4+
"component_write_acl": [
5+
{
6+
"key": 54,
7+
"value": {
8+
"attribute_set": [
59
{
6-
"key": 54,
7-
"value": {
8-
"attribute_set": [
9-
{
10-
"attribute": [
11-
"physics"
12-
]
13-
}
14-
]
15-
}
16-
},
10+
"attribute": [
11+
"physics"
12+
]
13+
}
14+
]
15+
}
16+
},
17+
{
18+
"key": 50,
19+
"value": {
20+
"attribute_set": [
1721
{
18-
"key": 50,
19-
"value": {
20-
"attribute_set": [
21-
{
22-
"attribute": [
23-
"physics"
24-
]
25-
}
26-
]
27-
}
28-
},
22+
"attribute": [
23+
"physics"
24+
]
25+
}
26+
]
27+
}
28+
},
29+
{
30+
"key": 1000,
31+
"value": {
32+
"attribute_set": [
2933
{
30-
"key": 1000,
31-
"value": {
32-
"attribute_set": [
33-
{
34-
"attribute": [
35-
"physics"
36-
]
37-
}
38-
]
39-
}
34+
"attribute": [
35+
"physics"
36+
]
4037
}
41-
],
42-
"read_acl": {
43-
"attribute_set": [
44-
{
45-
"attribute": [
46-
"physics"
47-
]
48-
},
49-
{
50-
"attribute": [
51-
"client_direct"
52-
]
53-
},
54-
{
55-
"attribute": [
56-
"client_vtable"
57-
]
58-
}
59-
]
38+
]
39+
}
40+
}
41+
],
42+
"read_acl": {
43+
"attribute_set": [
44+
{
45+
"attribute": [
46+
"physics"
47+
]
48+
},
49+
{
50+
"attribute": [
51+
"client_direct"
52+
]
53+
},
54+
{
55+
"attribute": [
56+
"client_vtable"
57+
]
6058
}
61-
},
62-
"improbable.Persistence": {},
63-
"improbable.Position": {
64-
"coords": {
65-
"x": 0.0,
66-
"y": 0.0,
67-
"z": 0.0
59+
]
60+
}
61+
},
62+
"improbable.Interest": {
63+
"component_interest": [
64+
{
65+
"key": 1001,
66+
"value": {
67+
"queries": [
68+
{
69+
"constraint": {
70+
"and_constraint": [],
71+
"box_constraint": [],
72+
"component_constraint": [],
73+
"cylinder_constraint": [],
74+
"entity_id_constraint": [],
75+
"or_constraint": [],
76+
"relative_box_constraint": [],
77+
"relative_cylinder_constraint": [],
78+
"relative_sphere_constraint": [
79+
{
80+
"radius": 50.0
81+
}
82+
],
83+
"sphere_constraint": []
84+
},
85+
"frequency": [],
86+
"full_snapshot_result": [
87+
true
88+
],
89+
"result_component_id": []
90+
}
91+
]
92+
}
93+
}
94+
]
95+
},
96+
"improbable.Metadata": {
97+
"entity_type":"TestEntity"
98+
},
99+
"improbable.Persistence": {},
100+
"improbable.Position": {
101+
"coords": {
102+
"x": 0.0,
103+
"y": 0.0,
104+
"z": 0.0
105+
}
106+
},
107+
"sample.ClientData": {
108+
"input_state": 0.5
109+
},
110+
"sample.Login": {}
111+
}
112+
{
113+
"__entity_id": "2",
114+
"improbable.EntityAcl": {
115+
"component_write_acl": [],
116+
"read_acl": {
117+
"attribute_set": [
118+
{
119+
"attribute": [
120+
"physics"
121+
]
122+
},
123+
{
124+
"attribute": [
125+
"client_direct"
126+
]
127+
},
128+
{
129+
"attribute": [
130+
"client_vtable"
131+
]
68132
}
69-
},
70-
"improbable.Metadata": {
71-
"entity_type":"TestEntity"
72-
},
73-
"sample.ClientData": {
74-
"input_state": 0.5
75-
},
76-
"sample.Login": {}
77-
}
133+
]
134+
}
135+
},
136+
"improbable.Persistence": {},
137+
"improbable.Position": {
138+
"coords": {
139+
"x": 100.0,
140+
"y": 0.0,
141+
"z": 0.0
142+
}
143+
}
144+
}

snapshots/default.snapshot

41 Bytes
Binary file not shown.

workers/c_client_direct/client.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ void OnEntityQueryResponse(const Worker_EntityQueryResponseOp* op) {
5555
}
5656
}
5757

58+
void OnAddEntity(const Worker_AddEntityOp* op) {
59+
printf("received add entity op (entity: %" PRId64 ")\n", op->entity_id);
60+
}
61+
62+
void OnRemoveEntity(const Worker_RemoveEntityOp* op) {
63+
printf("received remove entity op (entity: %" PRId64 ")\n", op->entity_id);
64+
}
65+
5866
void OnAddComponent(const Worker_AddComponentOp* op) {
5967
printf("received add component op (entity: %" PRId64 ", component: %d)\n", op->entity_id,
6068
op->data.component_id);
@@ -129,6 +137,8 @@ int main(int argc, char** argv) {
129137

130138
/* Connect to SpatialOS. */
131139
Worker_ConnectionParameters params = Worker_DefaultConnectionParameters();
140+
params.network.connection_type = WORKER_NETWORK_CONNECTION_TYPE_MODULAR_KCP;
141+
params.network.modular_kcp.security_type = WORKER_NETWORK_SECURITY_TYPE_INSECURE;
132142
params.worker_type = "client_direct";
133143
params.network.tcp.multiplex_level = 4;
134144
params.default_component_vtable = &default_vtable;
@@ -177,6 +187,12 @@ int main(int argc, char** argv) {
177187
case WORKER_OP_TYPE_ENTITY_QUERY_RESPONSE:
178188
OnEntityQueryResponse(&op->op.entity_query_response);
179189
break;
190+
case WORKER_OP_TYPE_ADD_ENTITY:
191+
OnAddEntity(&op->op.add_entity);
192+
break;
193+
case WORKER_OP_TYPE_REMOVE_ENTITY:
194+
OnRemoveEntity(&op->op.remove_entity);
195+
break;
180196
case WORKER_OP_TYPE_ADD_COMPONENT:
181197
OnAddComponent(&op->op.add_component);
182198
break;

workers/c_client_direct/spatialos.client_direct.worker.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
"client_direct"
99
]
1010
},
11-
"entity_interest": {
12-
"range_entity_interest": {
13-
"radius": 10
14-
}
15-
},
1611
"component_delivery": {
1712
"default": "RELIABLE_ORDERED",
18-
"checkout_all_initially": true
13+
"checkout_all_initially": false,
14+
"override": {}
1915
}
2016
},
2117
"external": {

workers/c_client_vtable/spatialos.client_vtable.worker.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
"client_vtable"
99
]
1010
},
11-
"entity_interest": {
12-
"range_entity_interest": {
13-
"radius": 10
14-
}
15-
},
1611
"component_delivery": {
1712
"default": "RELIABLE_ORDERED",
18-
"checkout_all_initially": true
13+
"checkout_all_initially": false,
14+
"override": {}
1915
}
2016
},
2117
"external": {

workers/cpp_physics/physics.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int argc, char** argv) {
3636

3737
worker::ConnectionParameters parameters;
3838
parameters.WorkerType = "physics";
39-
parameters.Network.ConnectionType = worker::NetworkConnectionType::kTcp;
39+
parameters.Network.ConnectionType = worker::NetworkConnectionType::kModularKcp;
4040
parameters.Network.UseExternalIp = false;
4141
worker::Connection connection = worker::Connection::ConnectAsync(
4242
ComponentRegistry{}, std::string{argv[1]}, atoi(argv[2]), argv[3], parameters).Get();
@@ -80,14 +80,14 @@ int main(int argc, char** argv) {
8080
});
8181

8282
int tick_count = 0;
83-
float angle = 0;
83+
double angle = 0.0;
8484
while (is_connected) {
8585
view.Process(connection.GetOpList(kOpListTimeoutMs));
8686

8787
// Update position of entity.
88-
angle += 0.5f;
88+
angle += 0.5;
8989
improbable::Position::Update position_update;
90-
position_update.set_coords({sin(angle) * 10, 0.0, cos(angle) * 10});
90+
position_update.set_coords({std::sin(angle) * 100.0, 0.0, std::cos(angle) * 100.0});
9191
connection.SendComponentUpdate<improbable::Position>(entityId, position_update);
9292

9393
// Sleep for some time.

workers/cpp_physics/spatialos.physics.worker.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
"physics"
99
]
1010
},
11-
"entity_interest": {
12-
"range_entity_interest": {
13-
"radius": 2
14-
}
15-
},
1611
"component_delivery": {
1712
"default": "RELIABLE_ORDERED",
18-
"checkout_all_initially": true
13+
"checkout_all_initially": false,
14+
"override": {}
1915
}
2016
},
2117
"managed": {

0 commit comments

Comments
 (0)