-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
242 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
local RunService = game:GetService("RunService") | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Packages = ReplicatedStorage.ExamplePackages | ||
local Matter = require(ReplicatedStorage.Packages.Matter) | ||
local Plasma = require(Packages.plasma) | ||
local Components = require(ReplicatedStorage.Game.components) | ||
local RemoteEvent = ReplicatedStorage:WaitForChild("MatterRemote") | ||
|
||
local world = Matter.World.new() | ||
local state = {} | ||
local loop = Matter.Loop.new(world, state) | ||
|
||
local systems = {} | ||
for _, child in ipairs(script.systems:GetChildren()) do | ||
if child:IsA("ModuleScript") then | ||
table.insert(systems, require(child)) | ||
end | ||
end | ||
|
||
loop:scheduleSystems(systems) | ||
|
||
local plasmaNode = Plasma.new(workspace) | ||
|
||
loop:addMiddleware(function(nextFn) | ||
return function() | ||
Plasma.start(plasmaNode, nextFn) | ||
end | ||
end) | ||
|
||
loop:begin({ | ||
default = RunService.Heartbeat, | ||
RenderStepped = RunService.RenderStepped, | ||
}) | ||
|
||
local entityIdMap = {} | ||
|
||
RemoteEvent.OnClientEvent:Connect(function(entities) | ||
for serverEntityId, componentMap in entities do | ||
local clientEntityId = entityIdMap[serverEntityId] | ||
|
||
if clientEntityId and next(componentMap) == nil then | ||
world:despawn(clientEntityId) | ||
print(string.format("Despawn %ds%d", clientEntityId, serverEntityId)) | ||
continue | ||
end | ||
|
||
local componentsToInsert = {} | ||
local componentsToRemove = {} | ||
|
||
local insertNames = {} | ||
local removeNames = {} | ||
|
||
for name, container in componentMap do | ||
if container.data then | ||
table.insert(componentsToInsert, Components[name](container.data)) | ||
table.insert(insertNames, name) | ||
else | ||
table.insert(componentsToRemove, Components[name]) | ||
table.insert(removeNames, name) | ||
end | ||
end | ||
|
||
if clientEntityId == nil then | ||
clientEntityId = world:spawn(unpack(componentsToInsert)) | ||
|
||
entityIdMap[serverEntityId] = clientEntityId | ||
|
||
print(string.format("Spawn %ds%d with %s", clientEntityId, serverEntityId, table.concat(insertNames, ","))) | ||
else | ||
if #componentsToInsert > 0 then | ||
world:insert(clientEntityId, unpack(componentsToInsert)) | ||
end | ||
|
||
if #componentsToRemove > 0 then | ||
world:remove(clientEntityId, unpack(componentsToRemove)) | ||
end | ||
|
||
print( | ||
string.format( | ||
"Modify %ds%d adding %s, removing %s", | ||
clientEntityId, | ||
serverEntityId, | ||
if #insertNames > 0 then table.concat(insertNames, ", ") else "nothing", | ||
if #removeNames > 0 then table.concat(removeNames, ", ") else "nothing" | ||
) | ||
) | ||
end | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local HttpService = game:GetService("HttpService") | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Components = require(ReplicatedStorage.Game.components) | ||
local template = ReplicatedStorage.Assets.BillboardGui | ||
|
||
local function rainbowRoombas(world) | ||
for id, model in world:query(Components.Model) do | ||
local debugLabel = world:get(id, Components.DebugLabel) | ||
|
||
if not debugLabel then | ||
local label = template:Clone() | ||
label.Parent = model.model.PrimaryPart | ||
label.Adornee = model.model.PrimaryPart | ||
|
||
debugLabel = Components.DebugLabel({ | ||
label = label, | ||
}) | ||
|
||
world:insert(id, debugLabel) | ||
end | ||
|
||
local text = "" | ||
|
||
for _, component in Components do | ||
local data = world:get(id, component) | ||
|
||
if data then | ||
text ..= tostring(component) .. " {" | ||
|
||
if next(data) then | ||
for key, value in data do | ||
text ..= "\n " .. key .. ": " .. tostring(value) | ||
end | ||
|
||
text ..= "\n" | ||
end | ||
text ..= "}\n" | ||
end | ||
end | ||
|
||
debugLabel.label.TextLabel.Text = text | ||
end | ||
end | ||
|
||
return rainbowRoombas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
local Players = game:GetService("Players") | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Components = require(ReplicatedStorage.Game.components) | ||
local useEvent = require(ReplicatedStorage.Packages.Matter).useEvent | ||
|
||
local RemoteEvent = Instance.new("RemoteEvent") | ||
RemoteEvent.Name = "MatterRemote" | ||
RemoteEvent.Parent = ReplicatedStorage | ||
|
||
local replicatedComponents = { | ||
Components.Roomba, | ||
Components.Model, | ||
Components.Health, | ||
Components.Target, | ||
Components.Mothership, | ||
} | ||
|
||
local function replication(world) | ||
for _, player in useEvent(Players, "PlayerAdded") do | ||
local payload = {} | ||
|
||
for entityId, entityData in world do | ||
local entityPayload = {} | ||
payload[tostring(entityId)] = entityPayload | ||
|
||
for component, componentData in entityData do | ||
entityPayload[tostring(component)] = { data = componentData } | ||
end | ||
end | ||
|
||
print("Sending initial payload to", player) | ||
RemoteEvent:FireClient(player, payload) | ||
end | ||
|
||
local changes = {} | ||
|
||
for _, component in replicatedComponents do | ||
for entityId, record in world:queryChanged(component) do | ||
local key = tostring(entityId) | ||
local name = tostring(component) | ||
|
||
if changes[key] == nil then | ||
changes[key] = {} | ||
end | ||
|
||
if world:contains(entityId) then | ||
changes[key][name] = { data = record.new } | ||
end | ||
end | ||
end | ||
|
||
if next(changes) then | ||
RemoteEvent:FireAllClients(changes) | ||
end | ||
end | ||
|
||
return { | ||
system = replication, | ||
priority = math.huge, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters