-
Notifications
You must be signed in to change notification settings - Fork 16
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
65 changed files
with
1,661 additions
and
992 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ Packages | |
|
||
build | ||
node_modules | ||
sourcemap.json | ||
sourcemap.json | ||
site |
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,3 +1,4 @@ | ||
{ | ||
"luau-lsp.sourcemap.rojoProjectFile": "dev.project.json" | ||
"luau-lsp.sourcemap.rojoProjectFile": "dev.project.json", | ||
"luau-lsp.completion.imports.requireStyle": "alwaysRelative" | ||
} |
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 was deleted.
Oops, something went wrong.
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,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) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 | ||
--- |
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,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, | ||
} | ||
}) | ||
``` |
Oops, something went wrong.