remove github, add logger
This commit is contained in:
parent
eee1861752
commit
add6db3bb6
12 changed files with 99 additions and 116 deletions
|
@ -45,9 +45,9 @@ export function start<S extends object>(host: Host, state: S): [World, S] {
|
|||
})
|
||||
|
||||
if (host === Host.All || host === Host.Server) {
|
||||
const _ServerState = state as serverState
|
||||
const ServerState = state as serverState
|
||||
|
||||
startTags(world, tags)
|
||||
startTags(world, tags, ServerState)
|
||||
}
|
||||
|
||||
if (host === Host.All || host === Host.Client) {
|
||||
|
|
|
@ -6,27 +6,17 @@ import { clientState } from "./state"
|
|||
type ComponentNames = keyof typeof Components
|
||||
type ComponentConstructors = (typeof Components)[ComponentNames]
|
||||
|
||||
const DEBUG_SPAWN = "Spawn %ds%d with %s"
|
||||
const DEBUG_DESPAWN = "Despawn %ds%d"
|
||||
const DEBUG_MODIFY = "Modify %ds%d adding %s, removing %s"
|
||||
|
||||
let connection: RBXScriptConnection | undefined
|
||||
|
||||
/**
|
||||
* Starts the replication receiver.
|
||||
*
|
||||
* @param world - The world to replicate components in
|
||||
* @param ClientState - The client state for the ECS
|
||||
* @param client - The client state for the ECS
|
||||
*/
|
||||
export function start(world: World, ClientState: clientState): void {
|
||||
export function start(world: World, client: clientState): void {
|
||||
if (connection) return
|
||||
|
||||
function debugPrint(message: string, args: () => (string | number)[]): void {
|
||||
if (ClientState.debugEnabled) {
|
||||
print("ECS Replication>", string.format(message, ...args()))
|
||||
}
|
||||
}
|
||||
|
||||
const replicationEvent = waitForEvent("EcsReplication")
|
||||
const serverToClientEntity = new Map<string, AnyEntity>()
|
||||
|
||||
|
@ -38,7 +28,11 @@ export function start(world: World, ClientState: clientState): void {
|
|||
if (clientId !== undefined && next(componentMap)[0] === undefined) {
|
||||
world.despawn(clientId)
|
||||
serverToClientEntity.delete(serverId)
|
||||
debugPrint(DEBUG_DESPAWN, () => [clientId, serverId])
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Despawn {@clientId}s{@serverId}",
|
||||
clientId,
|
||||
serverId
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -72,7 +66,12 @@ export function start(world: World, ClientState: clientState): void {
|
|||
if (clientId === undefined) {
|
||||
const clientId = world.spawn(...componentsToInsert)
|
||||
serverToClientEntity.set(serverId, clientId)
|
||||
debugPrint(DEBUG_SPAWN, () => [clientId, serverId, insertNames.join(",")])
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Spawn {@clientId}s{@serverId} with {@insertNames}",
|
||||
clientId,
|
||||
serverId,
|
||||
insertNames.join(",")
|
||||
)
|
||||
} else {
|
||||
if (componentsToInsert.size() > 0) {
|
||||
world.insert(clientId, ...componentsToInsert)
|
||||
|
@ -82,12 +81,13 @@ export function start(world: World, ClientState: clientState): void {
|
|||
world.remove(clientId, ...componentsToRemove)
|
||||
}
|
||||
|
||||
debugPrint(DEBUG_MODIFY, () => [
|
||||
client.logger.Debug(
|
||||
"ECS Replication> Modify {@clientId}s{serverId} adding {@insertNames}, removing {@removeNames}",
|
||||
clientId,
|
||||
serverId,
|
||||
insertNames.size() > 0 ? insertNames.join(", ") : "nothing",
|
||||
removeNames.size() > 0 ? removeNames.join(", ") : "nothing"
|
||||
])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,54 @@
|
|||
/* eslint-disable roblox-ts/no-private-identifier */
|
||||
|
||||
import { CharacterRigR6 } from "@rbxts/character-promise"
|
||||
import { Logger } from "@rbxts/log"
|
||||
import { InputKind } from "ReplicatedStorage/inputKind"
|
||||
|
||||
/**
|
||||
* The client ECS state.
|
||||
*/
|
||||
export class clientState {
|
||||
[index: string]: unknown
|
||||
character?: CharacterRigR6
|
||||
player?: Player
|
||||
debugEnabled = false
|
||||
isRunning = false
|
||||
constructor(
|
||||
player: Player,
|
||||
character: CharacterRigR6,
|
||||
debugEnabled: boolean,
|
||||
isRunning: boolean,
|
||||
// lastProcessedCommand: Inputkind,
|
||||
|
||||
logger: Logger
|
||||
) {
|
||||
this.character = character
|
||||
this.player = player
|
||||
this.debugEnabled = debugEnabled
|
||||
this.isRunning = isRunning
|
||||
// this.lastProcessedCommand = lastProcessedCommand
|
||||
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
player: Player
|
||||
character: CharacterRigR6
|
||||
debugEnabled: boolean
|
||||
isRunning: boolean
|
||||
lastProcessedCommand?: InputKind
|
||||
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* The server ECS state.
|
||||
*/
|
||||
export class serverState {
|
||||
[index: string]: unknown
|
||||
}
|
||||
constructor(
|
||||
logger: Logger
|
||||
) {
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared ECS state.
|
||||
*/
|
||||
export type sharedState = serverState & clientState
|
|
@ -2,6 +2,7 @@ import { AnyEntity, Component, World } from "@rbxts/matter"
|
|||
import { CollectionService } from "@rbxts/services"
|
||||
import { getIdAttribute } from "ReplicatedStorage/idAttribute"
|
||||
import { Model, Transform } from "./components"
|
||||
import { serverState } from "./state"
|
||||
|
||||
export type ComponentConstructor<T extends object> = () => Component<T>
|
||||
|
||||
|
@ -15,7 +16,8 @@ const connections: RBXScriptConnection[] = []
|
|||
*/
|
||||
export function start(
|
||||
world: World,
|
||||
bound: ReadonlyMap<string, ComponentConstructor<object>>
|
||||
bound: ReadonlyMap<string, ComponentConstructor<object>>,
|
||||
server: serverState
|
||||
): void {
|
||||
function spawnBound<T extends object>(
|
||||
instance: Instance,
|
||||
|
@ -26,13 +28,13 @@ export function start(
|
|||
if (instance.PrimaryPart) {
|
||||
primaryPart = instance.PrimaryPart
|
||||
} else {
|
||||
warn("Attempted to tag a model that has no primary part:", instance)
|
||||
server.logger.Warn("Attempted to tag a model that has no primary part: {@instance}", instance)
|
||||
return
|
||||
}
|
||||
} else if (instance.IsA("BasePart")) {
|
||||
primaryPart = instance
|
||||
} else {
|
||||
warn("Attempted to tag an instance that is not a Model or BasePart:", instance)
|
||||
server.logger.Warn("Attempted to tag an instance that is not a Model or BasePart: {@instance}", instance)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue