Skip to content

Commit d62cb18

Browse files
authored
Merge branch 'master' into release/v2.4.0
Signed-off-by: Ryan <r.ekhoff@clockworklabs.io>
2 parents 1c3ee80 + ef293f7 commit d62cb18

186 files changed

Lines changed: 10588 additions & 79 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/docker-compose.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,131 @@ jobs:
760760
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
761761
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
762762

763+
godot-testsuite:
764+
needs: [lints]
765+
permissions:
766+
contents: read
767+
runs-on: spacetimedb-new-runner-2
768+
env:
769+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
770+
UseLocalBsatnRuntime: true
771+
steps:
772+
- name: Checkout repository
773+
id: checkout-stdb
774+
uses: actions/checkout@v4
775+
776+
- name: Setup dotnet
777+
uses: actions/setup-dotnet@v3
778+
with:
779+
global-json-file: global.json
780+
781+
- name: Override NuGet packages
782+
run: |
783+
dotnet pack -c Release crates/bindings-csharp/BSATN.Runtime
784+
dotnet pack -c Release crates/bindings-csharp/Runtime
785+
786+
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
787+
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
788+
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
789+
# This means that (if version numbers match) we will test the local versions of the C# packages, even
790+
# if they're not pushed to NuGet.
791+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
792+
cd sdks/csharp
793+
./tools~/write-nuget-config.sh ../..
794+
795+
- name: Restore .NET solution
796+
working-directory: sdks/csharp
797+
run: dotnet restore --configfile NuGet.Config SpacetimeDB.ClientSDK.sln
798+
799+
# Now, setup the Godot tests.
800+
- name: Patch spacetimedb dependency in Cargo.toml
801+
working-directory: demo/Blackholio/server-rust
802+
run: |
803+
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
804+
cat Cargo.toml
805+
806+
- name: Install Rust toolchain
807+
uses: dsherret/rust-toolchain-file@v1
808+
- name: Set default rust toolchain
809+
run: rustup default $(rustup show active-toolchain | cut -d' ' -f1)
810+
811+
- name: Cache Rust dependencies
812+
uses: Swatinem/rust-cache@v2
813+
with:
814+
workspaces: ${{ github.workspace }}
815+
shared-key: spacetimedb
816+
# Let the main CI job save the cache since it builds the most things
817+
save-if: false
818+
prefix-key: v1
819+
820+
# This step shouldn't be needed, but somehow we end up with caches that are missing librusty_v8.a.
821+
# ChatGPT suspects that this could be due to different build invocations using the same target dir,
822+
# and this makes sense to me because we only see it in this job where we mix `cargo build -p` with
823+
# `cargo build --manifest-path` (which apparently build different dependency trees).
824+
# However, we've been unable to fix it so... /shrug
825+
- name: Check v8 outputs
826+
run: |
827+
find "${CARGO_TARGET_DIR}"/ -type f | grep '[/_]v8' || true
828+
if ! [ -f "${CARGO_TARGET_DIR}"/release/gn_out/obj/librusty_v8.a ]; then
829+
echo "Could not find v8 output file librusty_v8.a; rebuilding manually."
830+
cargo clean --release -p v8 || true
831+
cargo build --release -p v8
832+
fi
833+
834+
- name: Install SpacetimeDB CLI from the local checkout
835+
run: |
836+
export CARGO_HOME="$HOME/.cargo"
837+
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
838+
cargo install --force --path crates/cli --locked --message-format=short
839+
cargo install --force --path crates/standalone --locked --message-format=short
840+
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
841+
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
842+
843+
- name: Generate client bindings
844+
working-directory: demo/Blackholio/server-rust
845+
run: bash ./generate.sh -y
846+
847+
- name: Check for changes
848+
run: |
849+
tools/check-diff.sh demo/Blackholio/client-godot/module_bindings || {
850+
echo 'Error: Godot bindings are dirty. Please run `demo/Blackholio/server-rust/generate.sh`.'
851+
exit 1
852+
}
853+
854+
- name: Patch SpacetimeDB Godot SDK dependency
855+
working-directory: demo/Blackholio/client-godot
856+
run: |
857+
dotnet remove package SpacetimeDB.ClientSDK.Godot
858+
dotnet add reference ../../../sdks/csharp/SpacetimeDB.ClientSDK.Godot.csproj
859+
cat blackholio.csproj
860+
861+
- name: Setup Godot
862+
uses: chickensoft-games/setup-godot@v2
863+
with:
864+
version: 4.6.2
865+
use-dotnet: true
866+
867+
- name: Restore Godot project
868+
working-directory: demo/Blackholio/client-godot
869+
run: dotnet restore --configfile ../../../NuGet.Config blackholio.csproj
870+
871+
- name: Build Godot project
872+
run: godot --headless --verbose --path demo/Blackholio/client-godot --build-solutions --quit
873+
874+
- name: Start SpacetimeDB
875+
run: |
876+
spacetime start &
877+
disown
878+
879+
- name: Publish godot-tests module to SpacetimeDB
880+
working-directory: demo/Blackholio/server-rust
881+
run: |
882+
spacetime login --server-issued-login local
883+
bash ./publish.sh
884+
885+
- name: Run Godot tests
886+
run: godot --headless --path demo/Blackholio/client-godot --scene res://tests/GodotPlayModeTests.tscn
887+
763888
csharp-testsuite:
764889
needs: [lints]
765890
runs-on: spacetimedb-new-runner-2
@@ -771,8 +896,6 @@ jobs:
771896
id: checkout-stdb
772897
uses: actions/checkout@v4
773898

774-
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.
775-
776899
- name: Setup dotnet
777900
uses: actions/setup-dotnet@v3
778901
with:

crates/bindings-typescript/src/sdk/decompress.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,24 @@ export async function decompress(
2828
const decompressedStream = readableStream.pipeThrough(decompressionStream);
2929

3030
// Collect the decompressed chunks efficiently
31-
const chunks = [];
32-
for await (const chunk of decompressedStream) {
33-
chunks.push(chunk);
31+
const reader = decompressedStream.getReader();
32+
const chunks: Uint8Array[] = [];
33+
let totalLength = 0;
34+
let result: any;
35+
36+
while (!(result = await reader.read()).done) {
37+
chunks.push(result.value);
38+
totalLength += result.value.length;
3439
}
35-
return new Blob(chunks).bytes();
40+
41+
// Allocate a single Uint8Array for the decompressed data
42+
const decompressedArray = new Uint8Array(totalLength);
43+
let chunkOffset = 0;
44+
45+
for (const chunk of chunks) {
46+
decompressedArray.set(chunk, chunkOffset);
47+
chunkOffset += chunk.length;
48+
}
49+
50+
return decompressedArray;
3651
}

demo/Blackholio/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ You should be prompted for a username and you should be able to move around, eat
6666
Blackholio/
6767
├── client-unity/ # Unity client project
6868
├── client-unreal/ # Unreal Engine client project
69+
├── client-ts/ # Browser client using Phaser and TypeScript
6970
├── server-csharp/ # SpacetimeDB server module (C# implementation)
7071
├── server-rust/ # SpacetimeDB server module (Rust implementation)
72+
├── server-ts/ # SpacetimeDB server module (TypeScript implementation)
7173
├── DEVELOP.md # Development guidelines
7274
└── README.md # This file
7375
```

demo/Blackholio/client-godot/Circle2D.cs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
using System;
12
using Godot;
23

3-
public partial class Circle2D : Node2D
4+
public enum CircleVisualStyle
5+
{
6+
Player,
7+
Food
8+
}
9+
10+
public abstract partial class Circle2D : Node2D
411
{
512
private float _radius = 10.0f;
613
[Export]
@@ -29,6 +36,68 @@ public Color Color
2936
QueueRedraw();
3037
}
3138
}
39+
40+
[Export]
41+
public CircleVisualStyle VisualStyle { get; set; } = CircleVisualStyle.Player;
42+
43+
[Export]
44+
public float AnimationSeed { get; set; }
3245

33-
public override void _Draw() => DrawCircle(Vector2.Zero, Radius, Color);
46+
public override void _Draw()
47+
{
48+
if (Radius <= 0.01f) return;
49+
50+
switch (VisualStyle)
51+
{
52+
case CircleVisualStyle.Player:
53+
DrawPlayerCircle();
54+
break;
55+
case CircleVisualStyle.Food:
56+
DrawFood();
57+
break;
58+
default:
59+
throw new ArgumentOutOfRangeException();
60+
}
61+
}
62+
63+
protected void RedrawAnimatedVisuals() => QueueRedraw();
64+
65+
private void DrawPlayerCircle()
66+
{
67+
var time = Time.GetTicksMsec() / 1000.0f;
68+
var pulse = 0.5f + 0.5f * Mathf.Sin(time * 2.2f + AnimationSeed);
69+
DrawCircle(Vector2.Zero, Radius * (1.16f + pulse * 0.04f), WithAlpha(Color, 0.14f));
70+
DrawCircle(Vector2.Zero, Radius, Shade(Color, 0.58f));
71+
DrawCircle(Vector2.Zero, Radius * 0.82f, Color);
72+
DrawCircle(new Vector2(-Radius * 0.22f, -Radius * 0.24f), Radius * 0.34f, WithAlpha(Shade(Color, 1.42f), 0.72f));
73+
74+
var outline = new Vector2[73];
75+
for (var i = 0; i < outline.Length; i++)
76+
{
77+
var angle = Mathf.Tau * i / (outline.Length - 1);
78+
var wave = Mathf.Sin(angle * 7.0f + time * 3.0f + AnimationSeed) * 0.035f;
79+
outline[i] = Vector2.FromAngle(angle) * Radius * (1.015f + wave);
80+
}
81+
82+
DrawPolyline(outline, WithAlpha(Shade(Color, 1.55f), 0.88f), Mathf.Clamp(Radius * 0.085f, 1.5f, 5.0f), true);
83+
}
84+
85+
private void DrawFood()
86+
{
87+
var time = Time.GetTicksMsec() / 1000.0f;
88+
var pulse = 0.5f + 0.5f * Mathf.Sin(time * 5.0f + AnimationSeed);
89+
DrawCircle(Vector2.Zero, Radius * (1.32f + pulse * 0.09f), WithAlpha(Color, 0.1f));
90+
DrawCircle(Vector2.Zero, Radius, Shade(Color, 0.72f));
91+
DrawCircle(Vector2.Zero, Radius * 0.64f, Color);
92+
DrawCircle(Vector2.Zero, Radius * 0.24f, WithAlpha(Shade(Color, 1.55f), 0.86f));
93+
}
94+
95+
private static Color Shade(Color color, float multiplier) => new Color(
96+
Mathf.Clamp(color.R * multiplier, 0.0f, 1.0f),
97+
Mathf.Clamp(color.G * multiplier, 0.0f, 1.0f),
98+
Mathf.Clamp(color.B * multiplier, 0.0f, 1.0f),
99+
color.A
100+
);
101+
102+
private static Color WithAlpha(Color color, float alpha) => new(color.R, color.G, color.B, alpha);
34103
}

demo/Blackholio/client-godot/CircleController.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ private Label Label
6969
{
7070
Name = $"{Name}_Label",
7171
TopLevel = false,
72-
MouseFilter = Control.MouseFilterEnum.Ignore
72+
MouseFilter = Control.MouseFilterEnum.Ignore,
73+
HorizontalAlignment = HorizontalAlignment.Center
7374
};
75+
_label.AddThemeFontSizeOverride("font_size", 13);
76+
_label.AddThemeColorOverride("font_color", Colors.White);
77+
_label.AddThemeColorOverride("font_shadow_color", new Color(0, 0, 0, 0.75f));
78+
_label.AddThemeConstantOverride("shadow_offset_x", 1);
79+
_label.AddThemeConstantOverride("shadow_offset_y", 1);
7480
LabelRoot.AddChild(_label);
7581
}
7682
return _label;
@@ -90,6 +96,7 @@ public CircleController(Circle circle, PlayerController ownerPlayer) : base(circ
9096
public override void _Process(double delta)
9197
{
9298
base._Process(delta);
99+
Label.Text = OwnerPlayer?.Username ?? "";
93100
UpdateScreenLabelPosition();
94101
}
95102

@@ -105,8 +112,20 @@ public override void OnDelete()
105112
OwnerPlayer?.OnCircleDeleted(this);
106113
}
107114

115+
public override void OnConsumed()
116+
{
117+
if (IsInstanceValid(Label))
118+
{
119+
Label.QueueFree();
120+
}
121+
122+
OwnerPlayer?.OnCircleDeleted(this);
123+
}
124+
108125
private void UpdateScreenLabelPosition()
109126
{
127+
if (!IsInstanceValid(Label)) return;
128+
110129
Label.Size = Label.GetCombinedMinimumSize();
111130
var screenPosition = GetGlobalTransformWithCanvas().Origin;
112131
var offset = new Vector2(0.0f, Radius + 8.0f);

0 commit comments

Comments
 (0)