-
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.
Closes #11
- Loading branch information
Showing
16 changed files
with
270 additions
and
176 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
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 |
---|---|---|
@@ -1,89 +1,7 @@ | ||
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 start = require(ReplicatedStorage.Game.start) | ||
local receiveReplication = require(script.receiveReplication) | ||
|
||
local world = Matter.World.new() | ||
local state = {} | ||
local loop = Matter.Loop.new(world, state) | ||
local world, state = start(ReplicatedStorage.Game.clientSystems) | ||
|
||
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) | ||
receiveReplication(world, state) |
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,71 @@ | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Components = require(ReplicatedStorage.Game.components) | ||
local RemoteEvent = ReplicatedStorage:WaitForChild("MatterRemote") | ||
|
||
local function setupReplication(world, state) | ||
local function debugPrint(...) | ||
if state.debugEnabled then | ||
print("Replication>", ...) | ||
end | ||
end | ||
|
||
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) | ||
debugPrint(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 | ||
|
||
debugPrint( | ||
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 | ||
|
||
debugPrint( | ||
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) | ||
end | ||
|
||
return setupReplication |
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 |
---|---|---|
@@ -1,68 +1,7 @@ | ||
local RunService = game:GetService("RunService") | ||
local CollectionService = game:GetService("CollectionService") | ||
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 start = require(ReplicatedStorage.Game.start) | ||
local setupTags = require(ReplicatedStorage.Game.setupTags) | ||
|
||
local world = Matter.World.new() | ||
local state = {} | ||
local loop = Matter.Loop.new(world, state) | ||
local world = start(script.systems) | ||
|
||
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 boundTags = { | ||
Spinner = Components.Spinner, | ||
} | ||
|
||
local function spawnBound(instance, component) | ||
local id = world:spawn( | ||
component(), | ||
Components.Bind({ | ||
instance = instance, | ||
}), | ||
Components.Transform({ | ||
cframe = instance.CFrame, | ||
}) | ||
) | ||
|
||
instance:SetAttribute("entityId", id) | ||
end | ||
|
||
for tagName, component in pairs(boundTags) do | ||
for _, instance in ipairs(CollectionService:GetTagged(tagName)) do | ||
spawnBound(instance, component) | ||
end | ||
|
||
CollectionService:GetInstanceAddedSignal(tagName):Connect(function(instance) | ||
spawnBound(instance, component) | ||
end) | ||
|
||
CollectionService:GetInstanceRemovedSignal(tagName):Connect(function(instance) | ||
local id = instance:GetAttribute("entityId") | ||
if id then | ||
world:despawn(id) | ||
end | ||
end) | ||
end | ||
setupTags(world) |
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,10 @@ | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Components = require(ReplicatedStorage.Game.components) | ||
|
||
local function spinSpinners(world) | ||
for id, model in world:query(Components.Model, Components.Spinner) do | ||
model.model.PrimaryPart.CFrame = model.model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(5), 0) | ||
end | ||
end | ||
|
||
return spinSpinners |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ local COMPONENTS = { | |
"Mothership", | ||
"Lasering", | ||
"DebugLabel", | ||
"Spinner", | ||
} | ||
|
||
local components = {} | ||
|
Oops, something went wrong.