Networking

Networked Actors

NetworkedActor, NetworkedGameObject, and state synchronization.

The engine provides networked variants of the core entity classes that can serialize and sync state over the network.

NetworkedActor

Extends Actor with network sync capabilities.

import { NetworkedActor } from '@mavonengine/core'

class MyNetworkedPlayer extends NetworkedActor {
  $typeName = 'MyNetworkedPlayer'

  updateFromNetwork(data: unknown): void {
    // Apply incoming server state to this actor
  }
}

Abstract members

MemberDescription
$typeNameString identifier used to reconstruct entities on the client
updateFromNetwork(data)Apply a state snapshot from the server

NetworkedGameObject mixin

Use NetworkedGameObjectMixin if your class already extends something else:

import { NetworkedGameObjectMixin, Entity3D } from '@mavonengine/core'

class MyNetworkedEntity extends NetworkedGameObjectMixin(Entity3D) {
  $typeName = 'MyNetworkedEntity'

  updateFromNetwork(data: unknown): void { /* ... */ }
}

NetworkedLivingActor

Combines NetworkedActor with the LivingActor health/damage system for networked entities that can take damage.

import { NetworkedLivingActor } from '@mavonengine/core'

class MyNetworkedEnemy extends NetworkedLivingActor {
  $typeName = 'MyNetworkedEnemy'
  health = 100
  maxHealth = 100

  isDead(): void { /* ... */ }
  takeDamage(amount: number): void { /* ... */ }
  heal(amount: number): void { /* ... */ }
  updateFromNetwork(data: unknown): void { /* ... */ }
}

State sync

syncStateStack

Use syncStateStack to synchronize an actor's state machine stack over the network:

import { syncStateStack } from '@mavonengine/core'

// On the server: serialize state
const stateData = syncStateStack(actor)

// On the client: apply state
actor.updateFromNetwork(stateData)

StateFactory type

The StateFactory type maps type name strings to state constructors, enabling the server to describe states that the client can reconstruct:

import type { StateFactory } from '@mavonengine/core'

const stateFactory: StateFactory = {
  'IdleState': (entity) => new IdleState(entity),
  'WalkState': (entity) => new WalkState(entity),
}

NetworkedEntityState

Wraps an EntityState with network metadata for state stack synchronization.