mirror of
https://github.com/imezx/Warp.git
synced 2025-04-24 15:10:03 +00:00
expanding buffer
This commit is contained in:
parent
4b568356c8
commit
01c5533394
11 changed files with 89 additions and 18 deletions
BIN
Warp.rbxm
BIN
Warp.rbxm
Binary file not shown.
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "Warp",
|
"name": "Warp",
|
||||||
"tree": {
|
"tree": {
|
||||||
|
"$className": "DataModel",
|
||||||
|
"ReplicatedStorage": {
|
||||||
|
"$className": "ReplicatedStorage",
|
||||||
|
"Warp": {
|
||||||
"$path": "src"
|
"$path": "src"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ function side() {
|
||||||
text: 'Utilities',
|
text: 'Utilities',
|
||||||
items: [
|
items: [
|
||||||
{ text: 'Signal', link: '/api/1.0/signal' },
|
{ text: 'Signal', link: '/api/1.0/signal' },
|
||||||
|
{ text: 'Buffer', link: '/api/1.0/buffer' },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
3
docs/api/1.0/buffer.md
Normal file
3
docs/api/1.0/buffer.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Buffer <Badge type="tip" text="utilities" />
|
||||||
|
|
||||||
|
A Additional buffer.
|
|
@ -87,7 +87,7 @@ Disconnect the event connection.
|
||||||
```lua [Variable]
|
```lua [Variable]
|
||||||
(
|
(
|
||||||
key: string
|
key: string
|
||||||
)
|
): boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua [Example]
|
```lua [Example]
|
||||||
|
@ -128,7 +128,7 @@ This function have rate limiting it self and configured from server.
|
||||||
|
|
||||||
## `:Invoke` <Badge type="warning" text="yield" />
|
## `:Invoke` <Badge type="warning" text="yield" />
|
||||||
|
|
||||||
Semiliar to `:InvokeServer`, its for Invoke to a server.
|
Semiliar to `:InvokeServer`, but it have timeout system that not exists on `RemoteFunction.InvokeServer`.
|
||||||
|
|
||||||
::: code-group
|
::: code-group
|
||||||
```lua [Variable]
|
```lua [Variable]
|
||||||
|
@ -139,7 +139,7 @@ Semiliar to `:InvokeServer`, its for Invoke to a server.
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua [Example]
|
```lua [Example]
|
||||||
local Request = Remote:Invoke(2, "Hello World!")
|
local Request = Remote:Invoke(2, "Hello World!") -- this yield until it response
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ This function is yielded, once it timeout it will return nil.
|
||||||
Wait the event being triggered.
|
Wait the event being triggered.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
Remote:Wait()
|
Remote:Wait() -- :Wait return number value
|
||||||
```
|
```
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
@ -161,7 +161,7 @@ This function is yielded, Invoke might also ping this one and also causing error
|
||||||
|
|
||||||
## `:Destroy`
|
## `:Destroy`
|
||||||
|
|
||||||
Disconnect all connection of event and remove the event from Warp
|
Disconnect all connection of event and remove the event from Warp list
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
Remote:Destroy()
|
Remote:Destroy()
|
||||||
|
|
|
@ -97,7 +97,7 @@ Disconnect the event connection.
|
||||||
```lua [Variable]
|
```lua [Variable]
|
||||||
(
|
(
|
||||||
key: string
|
key: string
|
||||||
)
|
): boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua [Example]
|
```lua [Example]
|
||||||
|
@ -170,7 +170,7 @@ Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World
|
||||||
|
|
||||||
## `:Invoke` <Badge type="warning" text="yield" />
|
## `:Invoke` <Badge type="warning" text="yield" />
|
||||||
|
|
||||||
Semiliar to `:InvokeClient`, its for Invoke to a client.
|
Semiliar to `:InvokeClient`, but it have timeout system that not exists on `RemoteFunction.InvokeClient`.
|
||||||
|
|
||||||
::: code-group
|
::: code-group
|
||||||
```lua [Variable]
|
```lua [Variable]
|
||||||
|
@ -195,7 +195,7 @@ This function is yielded, once it timeout it will return nil.
|
||||||
Wait the event being triggered.
|
Wait the event being triggered.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
Remote:Wait()
|
Remote:Wait() -- :Wait return number value
|
||||||
```
|
```
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
|
@ -16,7 +16,7 @@ local Buffer = require(Util.Buffer)
|
||||||
function Client.new(Identifier: string)
|
function Client.new(Identifier: string)
|
||||||
local self = setmetatable({}, Client)
|
local self = setmetatable({}, Client)
|
||||||
self._buffer = Buffer.new()
|
self._buffer = Buffer.new()
|
||||||
self._buffer:writeu8(Serdes(Identifier))
|
self._buffer:wu8(Serdes(Identifier))
|
||||||
self.id = Buffer.convert(self._buffer:build())
|
self.id = Buffer.convert(self._buffer:build())
|
||||||
self.fn = {}
|
self.fn = {}
|
||||||
self.IsConnected = false
|
self.IsConnected = false
|
||||||
|
|
|
@ -17,7 +17,7 @@ local Buffer = require(Util.Buffer)
|
||||||
function Server.new(Identifier: string, rateLimit: Type.rateLimitArg?)
|
function Server.new(Identifier: string, rateLimit: Type.rateLimitArg?)
|
||||||
local self = setmetatable({}, Server)
|
local self = setmetatable({}, Server)
|
||||||
self._buffer = Buffer.new()
|
self._buffer = Buffer.new()
|
||||||
self._buffer:writeu8(Serdes(Identifier))
|
self._buffer:wu8(Serdes(Identifier))
|
||||||
self.id = Buffer.convert(self._buffer:build())
|
self.id = Buffer.convert(self._buffer:build())
|
||||||
self.fn = {}
|
self.fn = {}
|
||||||
self.IsConnected = false
|
self.IsConnected = false
|
||||||
|
|
|
@ -6,12 +6,21 @@ DedicatedBuffer.__index = DedicatedBuffer
|
||||||
|
|
||||||
local create = buffer.create
|
local create = buffer.create
|
||||||
local copy = buffer.copy
|
local copy = buffer.copy
|
||||||
|
local writei8 = buffer.writei8
|
||||||
|
local writei16 = buffer.writei16
|
||||||
|
local writei32 = buffer.writei32
|
||||||
local writeu8 = buffer.writeu8
|
local writeu8 = buffer.writeu8
|
||||||
local tostring = buffer.tostring
|
local writeu16 = buffer.writeu16
|
||||||
|
local writeu32 = buffer.writeu32
|
||||||
|
local writef32 = buffer.writef32
|
||||||
|
local writef64 = buffer.writef64
|
||||||
|
local writestring = buffer.writestring
|
||||||
|
|
||||||
local default = {
|
local default = {
|
||||||
point = 0,
|
point = 0,
|
||||||
size = 256,
|
next = 0,
|
||||||
|
size = 128,
|
||||||
|
bufferSize = 128,
|
||||||
}
|
}
|
||||||
|
|
||||||
function DedicatedBuffer.alloc(self: any, byte: number)
|
function DedicatedBuffer.alloc(self: any, byte: number)
|
||||||
|
@ -23,9 +32,13 @@ function DedicatedBuffer.alloc(self: any, byte: number)
|
||||||
end
|
end
|
||||||
|
|
||||||
local newBuffer: buffer = create(size)
|
local newBuffer: buffer = create(size)
|
||||||
|
DedicatedBuffer.copy(self, 0, newBuffer)
|
||||||
copy(newBuffer, 0, b)
|
copy(newBuffer, 0, b)
|
||||||
|
|
||||||
b = newBuffer
|
b = newBuffer
|
||||||
|
|
||||||
|
self.point = self.next
|
||||||
|
self.next += byte
|
||||||
end
|
end
|
||||||
|
|
||||||
function DedicatedBuffer.build(self: any): buffer
|
function DedicatedBuffer.build(self: any): buffer
|
||||||
|
@ -36,23 +49,64 @@ function DedicatedBuffer.build(self: any): buffer
|
||||||
return build
|
return build
|
||||||
end
|
end
|
||||||
|
|
||||||
function DedicatedBuffer.writeu8(self: any, val: number)
|
function DedicatedBuffer.wi8(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 1)
|
||||||
|
writei8(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wi16(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 2)
|
||||||
|
writei16(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wi32(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 4)
|
||||||
|
writei32(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wu8(self: any, val: number)
|
||||||
DedicatedBuffer.alloc(self, 1)
|
DedicatedBuffer.alloc(self, 1)
|
||||||
writeu8(self.buffer, self.point, val)
|
writeu8(self.buffer, self.point, val)
|
||||||
self.point += 1
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wu16(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 2)
|
||||||
|
writeu16(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wu32(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 4)
|
||||||
|
writeu32(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wf32(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 4)
|
||||||
|
writef32(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wf64(self: any, val: number)
|
||||||
|
DedicatedBuffer.alloc(self, 8)
|
||||||
|
writef64(self.buffer, self.point, val)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DedicatedBuffer.wstring(self: any, val: string)
|
||||||
|
DedicatedBuffer.alloc(self, #val)
|
||||||
|
writestring(self.buffer, self.point, val)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DedicatedBuffer.flush(self: any)
|
function DedicatedBuffer.flush(self: any)
|
||||||
self.point = default.point
|
self.point = default.point
|
||||||
|
self.next = default.next
|
||||||
self.size = default.size
|
self.size = default.size
|
||||||
self.buffer = create(256)
|
self.buffer = create(default.bufferSize)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DedicatedBuffer.new()
|
function DedicatedBuffer.new()
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
point = default.point,
|
point = default.point,
|
||||||
|
next = default.next,
|
||||||
size = default.size,
|
size = default.size,
|
||||||
buffer = create(256)
|
buffer = create(default.bufferSize)
|
||||||
}, DedicatedBuffer)
|
}, DedicatedBuffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ local Client = script.Client
|
||||||
local Type = require(script.Type)
|
local Type = require(script.Type)
|
||||||
local Assert = require(Util.Assert)
|
local Assert = require(Util.Assert)
|
||||||
local Signal = require(script.Signal)
|
local Signal = require(script.Signal)
|
||||||
|
local Buffer = require(Util.Buffer)
|
||||||
|
|
||||||
if IsServer then
|
if IsServer then
|
||||||
require(Server.ServerProcess).start()
|
require(Server.ServerProcess).start()
|
||||||
|
@ -64,7 +65,11 @@ function Index.fromSignalArray(arrays: { any })
|
||||||
for _, identifier: string in arrays do
|
for _, identifier: string in arrays do
|
||||||
copy[identifier] = Index.Signal(identifier)
|
copy[identifier] = Index.Signal(identifier)
|
||||||
end
|
end
|
||||||
return copy :: typeof(copy)
|
return table.freeze(copy) :: typeof(copy)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Index.buffer()
|
||||||
|
return Buffer.new()
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.freeze(Index) :: typeof(Index)
|
return table.freeze(Index) :: typeof(Index)
|
|
@ -13,4 +13,6 @@ return {
|
||||||
|
|
||||||
Signal = Index.Signal,
|
Signal = Index.Signal,
|
||||||
fromSignalArray = Index.fromSignalArray,
|
fromSignalArray = Index.fromSignalArray,
|
||||||
|
|
||||||
|
buffer = Index.buffer,
|
||||||
}
|
}
|
Loading…
Reference in a new issue