Synchronizing group gameplay with TabletopKit
At a glance
| Item | Summary |
|---|---|
| Purpose | Maintain game state across multiple players in a race to capture all the coins. |
| App architecture | A Swift sample with the source-visible chain TabletopKitMini-GameApp → GameView → GroupActivityManager → GameRenderer → TabletopKit APIs. |
| Main patterns | Delegate or data-source callbacks |
| Project style | 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, Sendable or @Sendable, Task closure isolated to MainActor, Task, await suspension point; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | TabletopKit, RealityKit, SwiftUI, Spatial, Foundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── TabletopKit Mini-Game/
├── TabletopKit Mini-Game/
│ ├── TabletopKitMini-GameApp.swift
│ ├── CustomAction.swift
│ ├── GameEquipment.swift
│ ├── GroupActivityManager.swift
│ ├── GameInteraction.swift
│ ├── GameObserver.swift
│ ├── GameRenderer.swift
│ ├── CustomEquipmentState.swift
│ ├── Game.swift
│ └── GameSetup.swift
└── Packages/
└── RealityKitContent/
├── Sources/
│ └── RealityKitContent/
│ └── RealityKitContent.swift
└── Package.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 5 project/configuration file(s) and 36 source declaration(s).
Overall architecture
flowchart LR
N1["TabletopKitMini-GameApp"]
N2["GameView"]
N3["GroupActivityManager"]
N4["GameRenderer"]
N5["TabletopKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
TabletopKit Mini-Game/TabletopKit Mini-Game/TabletopKitMini-GameApp.swift:16 — architecture anchor
@MainActor
@main
struct MiniGameApp: App {
@State var game: Game
init() {
self.game = Game()
}
var body: some SwiftUI.Scene {
WindowGroup {
GameView()
.environment(game)
}
.windowStyle(.volumetric)
.defaultSize(width: 2, height: 2, depth: 2, in: .meters)
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into TabletopKit.
Ownership and state
classDiagram
ResetPlayer o-- EquipmentIdentifier : playerId
ResetPlayer *-- Int : seat
FreezePlayer o-- EquipmentIdentifier : playerId
ActivatePlayer o-- EquipmentIdentifier : playerId
Ownership evidence
TabletopKit Mini-Game/TabletopKit Mini-Game/CustomAction.swift:11 — stored dependency or nearest verified ownership anchor
struct ResetPlayer: CustomAction {
var playerId: EquipmentIdentifier
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ResetPlayer |
EquipmentIdentifier (playerId) |
stores or receives | App/module collaborators |
ResetPlayer |
Int (seat) |
owns value state | App/module collaborators |
FreezePlayer |
EquipmentIdentifier (playerId) |
stores or receives | App/module collaborators |
ActivatePlayer |
EquipmentIdentifier (playerId) |
stores or receives | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift:40 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift:23 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift:50 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift:50 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | TabletopKit Mini-Game/TabletopKit Mini-Game/GameRenderer.swift:26 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift:40 — representative execution boundary
@MainActor
init() {
renderer = GameRenderer()
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | @Observable |
Observation macro publishes source-visible changes. | TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift:11 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | TabletopKit Mini-Game/TabletopKit Mini-Game/TabletopKitMini-GameApp.swift:18 |
| Source import | TabletopKit |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/TabletopKit Mini-Game/CustomAction.swift:7 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift:8 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift:9 |
| Source import | Spatial |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/TabletopKit Mini-Game/CustomAction.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:7 |
| Source import | RealityKitContent |
The cited file imports this module; runtime use and architectural role are not inferred. | TabletopKit Mini-Game/TabletopKit Mini-Game/GameEquipment.swift:12 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
TabletopKit Mini-Game/TabletopKit Mini-Game/TabletopKitMini-GameApp.swift:17 — representative type boundary
@MainActor
@main
struct MiniGameApp: App {
@State var game: Game
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
MiniGameApp |
Application entry and top-level composition | App |
GameView |
User-interface presentation and input forwarding | View |
ResetPlayer |
Owns media or timeline playback | CustomAction |
FreezePlayer |
Owns media or timeline playback | CustomAction |
ActivatePlayer |
Owns media or timeline playback | CustomAction |
Player |
Owns media or timeline playback | EntityEquipment |
GroupActivityManager |
Long-lived feature or framework coordination | Observable |
GameObserver |
Observes and relays feature changes | TabletopGame.Observer |
GameRenderer |
Owns drawing, GPU, or presentation processing | Concrete collaborators/imported frameworks |
GameToolbar |
Represents a feature value or composable behavior | ToolbarContent |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
realityKitContentBundle (TabletopKit Mini-Game/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:10) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
activityManager (TabletopKit Mini-Game/TabletopKit Mini-Game/TabletopKitMini-GameApp.swift:36) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
GameEquipment (TabletopKit Mini-Game/TabletopKit Mini-Game/GameEquipment.swift:7) |
implicit internal |
No explicit modifier means the Swift declaration is internal to the module. | Inference: app-target collaboration needs no exported library surface. |
Reference code
TabletopKit Mini-Game/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:10 — representative boundary
public let realityKitContentBundle = Bundle.moduleSwift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | MiniGameApp |
The source’s App suffix makes this role explicit. |
| Long-lived feature or framework coordination | GroupActivityManager |
The source’s Manager suffix makes this role explicit. |
| Observes and relays feature changes | GameObserver |
The source’s Observer suffix makes this role explicit. |
| Owns media or timeline playback | ActivatePlayer, FreezePlayer, Player, ResetPlayer |
The source’s Player suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | GameRenderer |
The source’s Renderer suffix makes this role explicit. |
| User-interface presentation and input forwarding | GameView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: App: MiniGameApp; Manager: GroupActivityManager; Observer: GameObserver; Player: ActivatePlayer, FreezePlayer, Player, ResetPlayer; Renderer: GameRenderer; View: GameView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
apply,playerID,aimingSightID,bankID,stoneID,lilyPadID,logID,coinID. - Files:
TabletopKit Mini-Game/TabletopKit Mini-Game/GroupActivityManager.swift,TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift,TabletopKit Mini-Game/TabletopKit Mini-Game/GameObserver.swift,TabletopKit Mini-Game/TabletopKit Mini-Game/GameRenderer.swift,TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift,TabletopKit Mini-Game/TabletopKit Mini-Game/GameSetup.swift.
Architecture takeaways
TabletopKitMini-GameAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches TabletopKit, RealityKit, SwiftUI, Spatial through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
TabletopKit Mini-Game/TabletopKit Mini-Game/TabletopKitMini-GameApp.swift |
Cited implementation, MiniGameApp, SwiftUI state property wrapper, GameView, GameToolbar |
TabletopKit Mini-Game/TabletopKit Mini-Game/CustomAction.swift |
Cited implementation, TabletopKit, Spatial, ResetPlayer, FreezePlayer, ActivatePlayer, DecrementHealth, CollectCoin, ResetCoin, SinkLilyPad, ResetLilyPad |
TabletopKit Mini-Game/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift |
Cited implementation, Foundation, Feature implementation |
TabletopKit Mini-Game/TabletopKit Mini-Game/GameEquipment.swift |
GameEquipment, RealityKitContent, PlayerSeat, Table, Bank, Player, AimingSight, Stone, LilyPad, Log, MovementParams, Coin |
TabletopKit Mini-Game/TabletopKit Mini-Game/GameInteraction.swift |
Cited implementation, Sendable or @Sendable, Task closure isolated to MainActor, Task, GameInteraction, PlayerInteraction, LogInteraction, LilyPadInteraction |
TabletopKit Mini-Game/TabletopKit Mini-Game/Game.swift |
@MainActor, @Observable, RealityKit, SwiftUI, Game, LilyPadSinkState, PlayerStat |
TabletopKit Mini-Game/TabletopKit Mini-Game/GameRenderer.swift |
await suspension point, GameRenderer |
TabletopKit Mini-Game/TabletopKit Mini-Game/GroupActivityManager.swift |
Activity, GroupActivityManager |
TabletopKit Mini-Game/TabletopKit Mini-Game/GameObserver.swift |
GameObserver |
TabletopKit Mini-Game/TabletopKit Mini-Game/CustomEquipmentState.swift |
PlayerState, CoinState, LilyPadState |
TabletopKit Mini-Game/TabletopKit Mini-Game/GameSetup.swift |
GameSetup |
TabletopKit Mini-Game/Packages/RealityKitContent/Package.swift |
Feature implementation |