Skip to content

Commit

Permalink
Merge branch 'processor-rewrite'
Browse files Browse the repository at this point in the history
  • Loading branch information
ffrostfall committed Feb 15, 2024
2 parents 88777e6 + 4c2a9fc commit 0a1c365
Show file tree
Hide file tree
Showing 65 changed files with 1,661 additions and 992 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Packages

build
node_modules
sourcemap.json
sourcemap.json
site
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"luau-lsp.sourcemap.rojoProjectFile": "dev.project.json"
"luau-lsp.sourcemap.rojoProjectFile": "dev.project.json",
"luau-lsp.completion.imports.requireStyle": "alwaysRelative"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ This project uses [semantic versioning](https://semver.org/spec/v2.0.0.html).

---

## version 0.3.0

### Improvements
- Rewrote client/server processing. Should drastically improve stability and performance.

---

## version 0.2.1

### Fixes
Expand Down
17 changes: 12 additions & 5 deletions dev/client/clientTests.client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")

local testPackets = require(ReplicatedStorage.shared.testPackets)

testPackets.a:listen(function(data)
print("Confirming server -> client")
print(data)
--[[ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(data)
--print(data)
end)]]

testPackets.a:listen(function()
--print("Confirming server -> client")
--print(data)
end)

task.wait(2)

testPackets.a:send({
first = "hello world",
second = 5,
a = true,
b = { true, false, true, false, false, true },
c = { { false }, { true } },
d = true,
chained = "test",
})
30 changes: 0 additions & 30 deletions dev/concept.luau

This file was deleted.

51 changes: 47 additions & 4 deletions dev/server/serverTests.server.luau
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
--!native
--!optimize 2
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local testPackets = require(ReplicatedStorage.shared.testPackets)

Players.PlayerAdded:Connect(function(player)
local data = {
a = false,
b = { true, false, false },
c = { { false }, { true } },
d = nil,
e = { [8] = 4 },
f = {
[Vector3.new(15, 15, 15)] = 2554,
},
}

RunService.Heartbeat:Connect(function()
--[[for i = 1, 100 do
ReplicatedStorage.RemoteEvent:FireAllClients({
a = false,
b = { true, false, false },
c = { { false }, { true } },
d = nil,
e = { [8] = 4 },
f = {
[Vector3.new(15, 15, 15)] = 2554,
},
})
end]]
debug.profilebegin("send")
for _ = 1, 100 do
testPackets.a:sendToAll(data)
end
debug.profileend()
end)

Players.PlayerAdded:Connect(function()
task.wait(1)
testPackets.a:send({ first = "testB", second = math.random(1, 8) }, player)
testPackets.a:sendToAll({
a = false,
b = { true, false, false },
c = { { false }, { true } },
d = nil,
e = { [8] = 4 },
f = {
[Vector3.new(15, 15, 15)] = 2554,
},
})
end)

testPackets.a:listen(function(data)
testPackets.a:listen(function(a)
print("Confirming client -> server")
print(data)
print(a)
end)
12 changes: 11 additions & 1 deletion dev/shared/testPackets.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ByteNet = require(ReplicatedStorage.Packages.ByteNet)

return {
a = ByteNet.definePacket({ first = ByteNet.dataTypes.string, second = ByteNet.dataTypes.uint8 }),
a = ByteNet.definePacket({
structure = {
a = ByteNet.bool,
b = ByteNet.array(ByteNet.bool),
c = ByteNet.array(ByteNet.array(ByteNet.bool)),
d = ByteNet.optional(ByteNet.bool),
e = ByteNet.optional(ByteNet.map(ByteNet.uint16, ByteNet.uint8)),
f = ByteNet.optional(ByteNet.map(ByteNet.vec3, ByteNet.uint16)),
chained = ByteNet.optional(ByteNet.optional(ByteNet.optional(ByteNet.string))),
},
}),
}
14 changes: 0 additions & 14 deletions docs/Installation.md

This file was deleted.

44 changes: 0 additions & 44 deletions docs/Tutorials/Getting Started.md

This file was deleted.

4 changes: 0 additions & 4 deletions docs/Tutorials/_category_.json

This file was deleted.

29 changes: 29 additions & 0 deletions docs/api/dataTypes/Primitives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="docs" markdown="span">

<h1>Available primitive types</h1>

</div>

ByteNet provides a large amount of "primitive" types for you to build more complex types that suit your game. Since primitive types don't need any parameters, you can just access them like the following: `ByteNet.<typename>`. For building more complex data structures, go look at the <a href="../Specials">Specials page.</a>

---
## Supported generic types
- `string`: String
- `buff`: Buffer
- `bool`: Boolean
---
## Supported number types
- `uint8`: Unsigned 8-bit integer
- `uint16`: Unsigned 16-bit integer
- `uint32`: Unsigned 32-bit integer
- `int8`: Signed 8-bit integer
- `int16`: Signed 16-bit integer
- `int32`: Signed 32-bit integer
- `float32`: Standard 32-bit float
- `float64`: Standard 64-bit float
---
## Supported Roblox types
- `cframe`: CoordinateFrame
- `vec2`: Vector2
- `vec3`: Vector3
---
108 changes: 108 additions & 0 deletions docs/api/dataTypes/Specials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<div class="docs" markdown="span">

<h1>Available special types</h1>

</div>

Special types are how complex packet types are made. They can take in nearly any type, including themselves, and most importantly they are dynamic. This means you can have an array of any length, a map of any key type and any value type, and an optional value of any type.

Special types always take *parameters*. You have to call them: `ByteNet.<type name>(<any primitive type>)`.

!!!danger
### There are drawbacks to using these!

- Using these types incurs 1-2 bytes of overhead due to the dynamic nature.
- They take drastically more time to parse
- They are heavier on memory usage, as a new closure is created each time. You will never have to worry about this unless you have dozens of packets, though.

---

## Optionals
Optional types are a cool name for the concept of "This doesn't have to exist". It's good for optional parameters: for example if some invoked function were to fail, you might want to send back a blank copy to indicate that something is wrong.

```lua title="packets.luau"
return {
myCoolPacket = ByteNet.definePacket({
structure = {
-- An "optional" type takes in a parameter.
-- This can be anything! You can even have optional arrays.
helloWorldString = ByteNet.optional(ByteNet.string)

-- This works!
eachCharacter = ByteNet.optional(ByteNet.array(ByteNet.string))
},
})
}
```
You really don't have to think about using optional types. You just send it!
```lua title="server.luau"
local packets = require(path.to.packets)

local randomlyStringOrNil =
if math.random(1, 2) == 1 then "Hello, world!" else nil

packets.myCoolPacket:sendToAll({
helloWorldString = randomlyAppearingString,

-- Note that even if we don't put the "eachCharacter" field here,
-- it won't error. This is because it's optional!
})
```

---

## Arrays
Arrays are fairly self explanatory. They're just plain old arrays. However, it's important to note that mixed tables have **undefined** behavior when passed as an array. This means things might be missing when they come out on the other side!

There is a 2 byte overhead to sending an array in ByteNet. This is because these 2 bytes are an unsigned 16-bit integer, which stores the array length. As a side effect, arrays sent through ByteNet have a max length of **2^16**, which is equal to **65,536**. It's likely that in the future, you will be able to reduce the overhead to 1 byte through configuration, in turn reducing the max length of the array.

```lua title="packets.luau"
return {
myCoolPacket = ByteNet.definePacket({
structure = {
myArray = ByteNet.array(ByteNet.bool)
},
})
}
```

```lua title="server.luau"
local packets = require(path.to.packets)

packets.myCoolPacket:sendToAll({
-- Important to note that mixed arrays/arrays with holes
-- shouldn't be sent through.
myArray = { true, false, true }
})
```

---

## Maps
Maps are by far the most powerful "special" type in ByteNet. They let you send, what's most commonly referred to as a dictionary, through ByteNet. However it's important to keep in mind two things: the type of the key (or index), and the type of the value, cannot change.

Like arrays, maps have a 2-byte overhead to store the length of the map. This is done by iterating over the map using <a href="https://devforum.roblox.com/t/luau-recap-may-2022/1818869">generic iteration</a> and increasing a variable by 1 for every key-value pair. This, once again, means that there is a **2^16** (which equals to **65,536**) cap to the number of elements in the map.

```lua title="packets.luau"
return {
myCoolPacket = ByteNet.definePacket({
structure = {
-- [name] = age
people = ByteNet.map(ByteNet.string, ByteNet.uint16)
},
})
}
```

```lua title="server.luau"
local packets = require(path.to.packets)

packets.myCoolPacket:sendToAll({
people = {
john = 21,
jane = 24,
dave = 26,
you = 162,
}
})
```
Loading

0 comments on commit 0a1c365

Please sign in to comment.