Add launchable

This commit is contained in:
usernames122
2025-10-23 20:58:19 +02:00
parent 300bb16e5e
commit d9d5460856
27 changed files with 1743 additions and 85 deletions

View File

@@ -1,6 +1,7 @@
import { Instance } from "./Instance.js";
import { BaseService } from "./BaseService.js";
import { sha256, encoders } from "../core/util.js"; // Since SubtleCrypto isnt available in http only, we use a JS implementation
export class ReplicatorService extends Instance {
export class ReplicatorService extends BaseService {
constructor(datamodel, network) {
super("ReplicatorService");
// Get tickloop from RenderService
@@ -98,6 +99,9 @@ export class ReplicatorService extends Instance {
});
} else {
this._renderService.Heartbeat.Connect((dt) => this._onHeartbeat(dt));
this._networkService.registerHandler(0x01, 0x02, (payload,ws) => {
}); // Server side replicator reciever, will be used later for client to server replication
// aka what roblox does for certain instances like under the player character
}
this.SetParent(datamodel);
this.lastClearedStatCheck = 0; // If above 1 second, clear stats
@@ -132,9 +136,14 @@ export class ReplicatorService extends Instance {
const toReplicate = [];
// Get workspace and its children
const workspace = this.Parent.GetService("Workspace");
const players = this.Parent.GetService("Players");
if (workspace) {
toReplicate.push(...workspace.Children);
}
if (players) {
toReplicate.push(...players.Children); // Replicate player instances too
// (so players can see each other)
}
// Send over the pipe
for (const inst of toReplicate) {
// Check property hashes to see if anything changed
@@ -175,7 +184,8 @@ export class ReplicatorService extends Instance {
key === "scene" ||
key === "controls" ||
key === "physicsWorld" ||
key === "loader"
key === "loader" ||
key === "LuaState" // Script Lua state
) {
continue;
}
@@ -199,7 +209,14 @@ export class ReplicatorService extends Instance {
// Send to all clients
let outpay = JSON.stringify(payload);
this.bytesSent += outpay.length + 2; // +2 for ptype and psub
this._networkService.broadcast(0x00, 0x02, outpay); // Refer to ptype and psub definitions to see what these mean
this._networkService.broadcast(0x00, 0x02, outpay,true,(ws) => {
const player = players ? players.getByWs(ws) : null;
// Dont send to the player if its their own character
if (player && inst.InstanceId === player.InstanceId) {
return true;
}
return false;
}); // Refer to ptype and psub definitions to see what these mean
// Update the _lastHash property to avoid re-sending unchanged data
inst._lastHash = hash;
//console.log(`Replicated instance ${inst.Name} (${inst.InstanceId}) to clients.`);